| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2007, 2009 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
| 11 | package org.eclipse.pde.api.tools.internal.provisional; |
| 12 | |
| 13 | import org.eclipse.pde.api.tools.internal.search.UseReportConverter; |
| 14 | import org.eclipse.pde.api.tools.internal.util.Util; |
| 15 | |
| 16 | /** |
| 17 | * Class containing constants and utility methods for visibility modifiers |
| 18 | * |
| 19 | * @since 1.0.0 |
| 20 | */ |
| 21 | public final class VisibilityModifiers { |
| 22 | |
| 23 | /** |
| 24 | * Visibility constant indicating an element is public API. |
| 25 | */ |
| 26 | public static final int API = 0x0001; |
| 27 | /** |
| 28 | * Visibility constant indicating a element should not be referenced. This |
| 29 | * indicates the element is internal and not intended for general use. |
| 30 | */ |
| 31 | public static final int PRIVATE = 0x0002; |
| 32 | /** |
| 33 | * Visibility constant indicating an element is public for a specific |
| 34 | * audience (service provider interface). |
| 35 | */ |
| 36 | public static final int SPI = 0x0004; |
| 37 | |
| 38 | /** |
| 39 | * Visibility constant indicating an element is private, but some |
| 40 | * clients have been permitted access to the element. |
| 41 | */ |
| 42 | public static final int PRIVATE_PERMISSIBLE = 0x0008; |
| 43 | |
| 44 | /** |
| 45 | * Bit mask of all visibilities. |
| 46 | */ |
| 47 | public static final int ALL_VISIBILITIES = 0xFFFF; |
| 48 | |
| 49 | /** |
| 50 | * Constructor |
| 51 | * no instantiating |
| 52 | */ |
| 53 | private VisibilityModifiers() {} |
| 54 | |
| 55 | /** |
| 56 | * Returns if the modifier is 'API' |
| 57 | * |
| 58 | * @param modifiers the modifiers to resolve |
| 59 | * @return if the modifier is 'API' |
| 60 | */ |
| 61 | public static final boolean isAPI(int modifiers) { |
| 62 | return (modifiers & API) > 0; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns if the modifier is 'SPI' |
| 67 | * |
| 68 | * @param modifiers the modifiers to resolve |
| 69 | * @return if the modifier is 'SPI' |
| 70 | */ |
| 71 | public static final boolean isSPI(int modifiers) { |
| 72 | return (modifiers & SPI) > 0; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns if the modifier is 'Private' |
| 77 | * |
| 78 | * @param modifiers the modifiers to resolve |
| 79 | * @return if the modifier is 'Private' |
| 80 | */ |
| 81 | public static final boolean isPrivate(int modifiers) { |
| 82 | return (modifiers & PRIVATE) > 0; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns if the modifier is 'Private Permissible' |
| 87 | * |
| 88 | * @param modifiers the modifiers to resolve |
| 89 | * @return if the modifier is 'Private Permissible' |
| 90 | */ |
| 91 | public static final boolean isPermissiblePrivate(int modifiers) { |
| 92 | return (modifiers & PRIVATE_PERMISSIBLE) > 0; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns the string representation of the specified visibility modifier or <code>UNKNOWN_VISIBILITY</code> |
| 97 | * if the modifier is unknown. |
| 98 | * |
| 99 | * @param visibility |
| 100 | * @return the string representation of the visibility or <code>UNKNOWN_VISIBILITY</code> |
| 101 | * @since 1.0.1 |
| 102 | */ |
| 103 | public static String getVisibilityName(int visibility) { |
| 104 | switch(visibility) { |
| 105 | case ALL_VISIBILITIES: { |
| 106 | return "ALL_VISIBILITIES"; //$NON-NLS-1$ |
| 107 | } |
| 108 | case API: { |
| 109 | return "API"; //$NON-NLS-1$ |
| 110 | } |
| 111 | case PRIVATE: { |
| 112 | return "PRIVATE"; //$NON-NLS-1$ |
| 113 | } |
| 114 | case PRIVATE_PERMISSIBLE: { |
| 115 | return "PRIVATE_PERMISSIBLE"; //$NON-NLS-1$ |
| 116 | } |
| 117 | case UseReportConverter.FRAGMENT_PERMISSIBLE: { |
| 118 | return "FRAGMENT_PERMISSIBLE"; //$NON-NLS-1$ |
| 119 | } |
| 120 | case SPI: { |
| 121 | return "SPI"; //$NON-NLS-1$ |
| 122 | } |
| 123 | case 0: { |
| 124 | return "INHERITED"; //$NON-NLS-1$ |
| 125 | } |
| 126 | } |
| 127 | return Util.UNKNOWN_VISIBILITY; |
| 128 | } |
| 129 | } |