Java Code Examples for org.eclipse.jdt.core.Flags#isProtected()

The following examples show how to use org.eclipse.jdt.core.Flags#isProtected() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsniMethodBodyCompletionProposalComputer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private static JavaCompletionProposal createProposal(int flags,
    String replacementString, int replacementOffset, int numCharsFilled, 
    int numCharsToOverwrite, String displayString) {
  Image image;
  GWTPlugin plugin = GWTPlugin.getDefault();
  if (Flags.isPublic(flags)) {
    image = plugin.getImage(GWTImages.JSNI_PUBLIC_METHOD_SMALL);
  } else if (Flags.isPrivate(flags)) {
    image = plugin.getImage(GWTImages.JSNI_PRIVATE_METHOD_SMALL);
  } else if (Flags.isProtected(flags)) {
    image = plugin.getImage(GWTImages.JSNI_PROTECTED_METHOD_SMALL);
  } else {
    image = plugin.getImage(GWTImages.JSNI_DEFAULT_METHOD_SMALL);
  }
  replacementString = replacementString.substring(numCharsFilled);
  return new JavaCompletionProposal(replacementString, replacementOffset,
      numCharsToOverwrite, image, "/*-{ " + displayString + " }-*/;", 0);
}
 
Example 2
Source File: SelfEncapsulateFieldInputPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Object[] createData(int visibility) {
	String pub= RefactoringMessages.SelfEncapsulateFieldInputPage_public;
	String pro= RefactoringMessages.SelfEncapsulateFieldInputPage_protected;
	String def= RefactoringMessages.SelfEncapsulateFieldInputPage_default;
	String priv= RefactoringMessages.SelfEncapsulateFieldInputPage_private;

	String[] labels= null;
	Integer[] data= null;
	if (Flags.isPrivate(visibility)) {
		labels= new String[] { pub, pro, def, priv };
		data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected), new Integer(0), new Integer(Flags.AccPrivate) };
	} else if (Flags.isProtected(visibility)) {
		labels= new String[] { pub, pro };
		data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected)};
	} else {
		labels= new String[] { pub, def };
		data= new Integer[] {new Integer(Flags.AccPublic), new Integer(0)};
	}
	return new Object[] {labels, data};
}
 
Example 3
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Evaluates if a member in the focus' element hierarchy is visible from
 * elements in a package.
 * @param member The member to test the visibility for
 * @param pack The package of the focus element focus
 * @return returns <code>true</code> if the member is visible from the package
 * @throws JavaModelException thrown when the member can not be accessed
 */
public static boolean isVisibleInHierarchy(IMember member, IPackageFragment pack) throws JavaModelException {
	int type= member.getElementType();
	if  (type == IJavaElement.INITIALIZER ||  (type == IJavaElement.METHOD && member.getElementName().startsWith("<"))) { //$NON-NLS-1$
		return false;
	}

	int otherflags= member.getFlags();

	IType declaringType= member.getDeclaringType();
	if (Flags.isPublic(otherflags) || Flags.isProtected(otherflags) || (declaringType != null && isInterfaceOrAnnotation(declaringType))) {
		return true;
	} else if (Flags.isPrivate(otherflags)) {
		return false;
	}

	IPackageFragment otherpack= (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
	return (pack != null && pack.equals(otherpack));
}
 
Example 4
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the modifiers.
 *
 * @param modifiers <code>F_PUBLIC</code>, <code>F_PRIVATE</code>,
 * <code>F_PROTECTED</code>, <code>F_ABSTRACT</code>, <code>F_FINAL</code>
 * or <code>F_STATIC</code> or a valid combination.
 * @param canBeModified if <code>true</code> the modifier fields are
 * editable; otherwise they are read-only
 * @see Flags
 */
public void setModifiers(int modifiers, boolean canBeModified) {
	if (Flags.isPublic(modifiers)) {
		fAccMdfButtons.setSelection(PUBLIC_INDEX, true);
	} else if (Flags.isPrivate(modifiers)) {
		fAccMdfButtons.setSelection(PRIVATE_INDEX, true);
	} else if (Flags.isProtected(modifiers)) {
		fAccMdfButtons.setSelection(PROTECTED_INDEX, true);
	} else {
		fAccMdfButtons.setSelection(DEFAULT_INDEX, true);
	}
	if (Flags.isAbstract(modifiers)) {
		fOtherMdfButtons.setSelection(ABSTRACT_INDEX, true);
	}
	if (Flags.isFinal(modifiers)) {
		fOtherMdfButtons.setSelection(FINAL_INDEX, true);
	}
	if (Flags.isStatic(modifiers)) {
		fOtherMdfButtons.setSelection(STATIC_INDEX, true);
	}

	fAccMdfButtons.setEnabled(canBeModified);
	fOtherMdfButtons.setEnabled(canBeModified);
}
 
Example 5
Source File: DialogFactoryHelperImpl.java    From jenerate with Eclipse Public License 1.0 5 votes vote down vote up
private IField[] getNonStaticNonCacheFieldsAndAccessibleNonStaticFieldsOfSuperclasses(IType objectClass,
        PreferencesManager preferencesManager) throws JavaModelException {
    List<IField> result = new ArrayList<>();

    ITypeHierarchy typeHierarchy = objectClass.newSupertypeHierarchy(null);
    IType[] superclasses = typeHierarchy.getAllSuperclasses(objectClass);

    for (int i = 0; i < superclasses.length; i++) {
        IField[] fields = superclasses[i].getFields();

        boolean samePackage = objectClass.getPackageFragment().getElementName()
                .equals(superclasses[i].getPackageFragment().getElementName());

        for (int j = 0; j < fields.length; j++) {

            if (!samePackage && !Flags.isPublic(fields[j].getFlags()) && !Flags.isProtected(fields[j].getFlags())) {
                continue;
            }

            if (!Flags.isPrivate(fields[j].getFlags()) && !Flags.isStatic(fields[j].getFlags())) {
                result.add(fields[j]);
            }
        }
    }

    result.addAll(Arrays.asList(getNonStaticNonCacheFields(objectClass, preferencesManager)));

    return result.toArray(new IField[result.size()]);
}
 
Example 6
Source File: SelfEncapsulateFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int createModifiers() throws JavaModelException {
	int result= 0;
	if (Flags.isPublic(fVisibility))
		result |= Modifier.PUBLIC;
	else if (Flags.isProtected(fVisibility))
		result |= Modifier.PROTECTED;
	else if (Flags.isPrivate(fVisibility))
		result |= Modifier.PRIVATE;
	if (JdtFlags.isStatic(fField))
		result |= Modifier.STATIC;
	return result;
}
 
Example 7
Source File: JavaContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isVisible(TypeNameMatch curr, ICompilationUnit cu) {
	int flags= curr.getModifiers();
	if (Flags.isPrivate(flags)) {
		return false;
	}
	if (Flags.isPublic(flags) || Flags.isProtected(flags)) {
		return true;
	}
	return curr.getPackageName().equals(cu.getParent().getElementName());
}
 
Example 8
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ImageDescriptor getInnerClassImageDescriptor(boolean isInInterfaceOrAnnotation, int flags) {
	if (Flags.isPublic(flags) || isInInterfaceOrAnnotation)
		return JavaPluginImages.DESC_OBJS_INNER_CLASS_PUBLIC;
	else if (Flags.isPrivate(flags))
		return JavaPluginImages.DESC_OBJS_INNER_CLASS_PRIVATE;
	else if (Flags.isProtected(flags))
		return JavaPluginImages.DESC_OBJS_INNER_CLASS_PROTECTED;
	else
		return JavaPluginImages.DESC_OBJS_INNER_CLASS_DEFAULT;
}
 
Example 9
Source File: Jdt2Ecore.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies if the target feature is visible from the type.
 *
 * <p>The type finder could be obtained with {@link #toTypeFinder(IJavaProject)}.
 *
 * @param typeFinder the type finder to be used for finding the type definitions.
 * @param fromType the type from which the feature visibility is tested.
 * @param target the feature to test for the visibility.
 * @return <code>true</code> if the given type can see the target feature.
 * @throws JavaModelException if the Java model is invalid.
 * @see #toTypeFinder(IJavaProject)
 */
public boolean isVisible(TypeFinder typeFinder, IType fromType, IMember target) throws JavaModelException {
	final int flags = target.getFlags();
	if (Flags.isPublic(flags)) {
		return true;
	}
	final String fromTypeName = fromType.getFullyQualifiedName();
	final String memberType = target.getDeclaringType().getFullyQualifiedName();
	if (Flags.isPrivate(flags)) {
		return target.getDeclaringType().getFullyQualifiedName().equals(fromTypeName);
	}
	if (Flags.isProtected(flags)) {
		IType t = fromType;
		while (t != null) {
			if (memberType.equals(t.getFullyQualifiedName())) {
				return true;
			}
			final String typeName = t.getSuperclassName();
			if (Strings.isNullOrEmpty(typeName)) {
				t = null;
			} else {
				t = typeFinder.findType(typeName);
			}
		}
	}
	final IPackageFragment f1 = target.getDeclaringType().getPackageFragment();
	final IPackageFragment f2 = fromType.getPackageFragment();
	if (f1.isDefaultPackage()) {
		return f2.isDefaultPackage();
	}
	return f1.getElementName().equals(f2.getElementName());
}
 
Example 10
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ImageDescriptor getInnerAnnotationImageDescriptor(boolean isInInterfaceOrAnnotation, int flags) {
	if (Flags.isPublic(flags) || isInInterfaceOrAnnotation)
		return JavaPluginImages.DESC_OBJS_ANNOTATION;
	else if (Flags.isPrivate(flags))
		return JavaPluginImages.DESC_OBJS_ANNOTATION_PRIVATE;
	else if (Flags.isProtected(flags))
		return JavaPluginImages.DESC_OBJS_ANNOTATION_PROTECTED;
	else
		return JavaPluginImages.DESC_OBJS_ANNOTATION_DEFAULT;
}
 
Example 11
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ImageDescriptor getInnerInterfaceImageDescriptor(boolean isInInterfaceOrAnnotation, int flags) {
	if (Flags.isPublic(flags) || isInInterfaceOrAnnotation)
		return JavaPluginImages.DESC_OBJS_INNER_INTERFACE_PUBLIC;
	else if (Flags.isPrivate(flags))
		return JavaPluginImages.DESC_OBJS_INNER_INTERFACE_PRIVATE;
	else if (Flags.isProtected(flags))
		return JavaPluginImages.DESC_OBJS_INNER_INTERFACE_PROTECTED;
	else
		return JavaPluginImages.DESC_OBJS_INTERFACE_DEFAULT;
}
 
Example 12
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ImageDescriptor getMethodImageDescriptor(boolean isInInterfaceOrAnnotation, int flags) {
	if (Flags.isPublic(flags) || isInInterfaceOrAnnotation)
		return JavaPluginImages.DESC_MISC_PUBLIC;
	if (Flags.isProtected(flags))
		return JavaPluginImages.DESC_MISC_PROTECTED;
	if (Flags.isPrivate(flags))
		return JavaPluginImages.DESC_MISC_PRIVATE;

	return JavaPluginImages.DESC_MISC_DEFAULT;
}
 
Example 13
Source File: MembersOrderPreferenceCache.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int getVisibilityIndex(int modifierFlags) {
	if (fVisibilityOffsets == null) {
		fVisibilityOffsets= getVisibilityOffsets();
	}
	int kind= DEFAULT_INDEX;
	if (Flags.isPublic(modifierFlags)) {
		kind= PUBLIC_INDEX;
	} else if (Flags.isProtected(modifierFlags)) {
		kind= PROTECTED_INDEX;
	} else if (Flags.isPrivate(modifierFlags)) {
		kind= PRIVATE_INDEX;
	}

	return fVisibilityOffsets[kind];
}
 
Example 14
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static ImageDescriptor getAnnotationImageDescriptor(int flags) {
	if (Flags.isPublic(flags) || Flags.isProtected(flags) || Flags.isPrivate(flags))
		return JavaPluginImages.DESC_OBJS_ANNOTATION;
	else
		return JavaPluginImages.DESC_OBJS_ANNOTATION_DEFAULT;
}
 
Example 15
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean isProtected(IMember member) throws JavaModelException{
	return Flags.isProtected(member.getFlags());
}
 
Example 16
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static ImageDescriptor getEnumImageDescriptor(int flags) {
	if (Flags.isPublic(flags) || Flags.isProtected(flags) || Flags.isPrivate(flags))
		return JavaPluginImages.DESC_OBJS_ENUM;
	else
		return JavaPluginImages.DESC_OBJS_ENUM_DEFAULT;
}
 
Example 17
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static ImageDescriptor getClassImageDescriptor(int flags) {
	if (Flags.isPublic(flags) || Flags.isProtected(flags) || Flags.isPrivate(flags))
		return JavaPluginImages.DESC_OBJS_CLASS;
	else
		return JavaPluginImages.DESC_OBJS_CLASS_DEFAULT;
}
 
Example 18
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isProtected(IMember member) throws JavaModelException{
	return Flags.isProtected(member.getFlags());
}
 
Example 19
Source File: StubCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void appendMembers(final IType type, final IProgressMonitor monitor) throws JavaModelException {
	try {
		monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 1);
		final IJavaElement[] children= type.getChildren();
		for (int index= 0; index < children.length; index++) {
			final IMember child= (IMember) children[index];
			final int flags= child.getFlags();
			final boolean isPrivate= Flags.isPrivate(flags);
			final boolean isDefault= !Flags.isPublic(flags) && !Flags.isProtected(flags) && !isPrivate;
			final boolean stub= fStubInvisible || (!isPrivate && !isDefault);
			if (child instanceof IType) {
				if (stub)
					appendTypeDeclaration((IType) child, new SubProgressMonitor(monitor, 1));
			} else if (child instanceof IField) {
				if (stub && !Flags.isEnum(flags) && !Flags.isSynthetic(flags))
					appendFieldDeclaration((IField) child);
			} else if (child instanceof IMethod) {
				final IMethod method= (IMethod) child;
				final String name= method.getElementName();
				if (method.getDeclaringType().isEnum()) {
					final int count= method.getNumberOfParameters();
					if (count == 0 && "values".equals(name)) //$NON-NLS-1$
						continue;
					if (count == 1 && "valueOf".equals(name) && "Ljava.lang.String;".equals(method.getParameterTypes()[0])) //$NON-NLS-1$ //$NON-NLS-2$
						continue;
					if (method.isConstructor())
						continue;
				}
				boolean skip= !stub || name.equals("<clinit>"); //$NON-NLS-1$
				if (method.isConstructor())
					skip= false;
				skip= skip || Flags.isSynthetic(flags) || Flags.isBridge(flags);
				if (!skip)
					appendMethodDeclaration(method);
			}
			fBuffer.append("\n"); //$NON-NLS-1$
		}
	} finally {
		monitor.done();
	}
}
 
Example 20
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static ImageDescriptor getInterfaceImageDescriptor(int flags) {
	if (Flags.isPublic(flags) || Flags.isProtected(flags) || Flags.isPrivate(flags))
		return JavaPluginImages.DESC_OBJS_INTERFACE;
	else
		return JavaPluginImages.DESC_OBJS_INTERFACE_DEFAULT;
}