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

The following examples show how to use org.eclipse.jdt.core.Flags#isInterface() . 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: TypeInfoFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean matchesModifiers(TypeNameMatch type) {
	if (fElementKind == IJavaSearchConstants.TYPE)
		return true;
	int modifiers= type.getModifiers() & TYPE_MODIFIERS;
	switch (fElementKind) {
		case IJavaSearchConstants.CLASS:
			return modifiers == 0;
		case IJavaSearchConstants.ANNOTATION_TYPE:
			return Flags.isAnnotation(modifiers);
		case IJavaSearchConstants.INTERFACE:
			return modifiers == Flags.AccInterface;
		case IJavaSearchConstants.ENUM:
			return Flags.isEnum(modifiers);
		case IJavaSearchConstants.CLASS_AND_INTERFACE:
			return modifiers == 0 || modifiers == Flags.AccInterface;
		case IJavaSearchConstants.CLASS_AND_ENUM:
			return modifiers == 0 || Flags.isEnum(modifiers);
		case IJavaSearchConstants.INTERFACE_AND_ANNOTATION:
			return Flags.isInterface(modifiers);
	}
	return false;
}
 
Example 2
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isSuperType(ITypeHierarchy hierarchy, IType possibleSuperType, IType type) {
	// filed bug 112635 to add this method to ITypeHierarchy
	IType superClass= hierarchy.getSuperclass(type);
	if (superClass != null && (possibleSuperType.equals(superClass) || isSuperType(hierarchy, possibleSuperType, superClass))) {
		return true;
	}
	if (Flags.isInterface(hierarchy.getCachedFlags(possibleSuperType))) {
		IType[] superInterfaces= hierarchy.getSuperInterfaces(type);
		for (int i= 0; i < superInterfaces.length; i++) {
			IType curr= superInterfaces[i];
			if (possibleSuperType.equals(curr) || isSuperType(hierarchy, possibleSuperType, curr)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 3
Source File: AbstractHierarchyViewerSorter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int category(Object element) {
	if (element instanceof IType) {
		IType type= (IType) element;
		try {
			if (type.isAnonymous() || type.isLambda()) {
				return ANONYM;
			}
		} catch (JavaModelException e1) {
			if (type.getElementName().length() == 0) {
				return ANONYM;
			}
		}
		try {
			int flags= getTypeFlags(type);
			if (Flags.isInterface(flags)) {
				return INTERFACE;
			} else {
				return CLASS;
			}
		} catch (JavaModelException e) {
			// ignore
		}
	}
	return OTHER;
}
 
Example 4
Source File: AbstractHierarchyViewerSorter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private int compareInHierarchy(IType def1, IType def2) {
	if (JavaModelUtil.isSuperType(getHierarchy(def1), def2, def1)) {
		return 1;
	} else if (JavaModelUtil.isSuperType(getHierarchy(def2), def1, def2)) {
		return -1;
	}
	// interfaces after classes
	try {
		int flags1= getTypeFlags(def1);
		int flags2= getTypeFlags(def2);
		if (Flags.isInterface(flags1)) {
			if (!Flags.isInterface(flags2)) {
				return 1;
			}
		} else if (Flags.isInterface(flags2)) {
			return -1;
		}
	} catch (JavaModelException e) {
		// ignore
	}
	String name1= def1.getElementName();
	String name2= def2.getElementName();

	return getComparator().compare(name1, name2);
}
 
Example 5
Source File: InterfaceIndicatorLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addOverlaysFromFlags(int flags, IDecoration decoration) {
	ImageDescriptor type;
	if (Flags.isAnnotation(flags)) {
		type= JavaPluginImages.DESC_OVR_ANNOTATION;
	} else if (Flags.isEnum(flags)) {
		type= JavaPluginImages.DESC_OVR_ENUM;
	} else if (Flags.isInterface(flags)) {
		type= JavaPluginImages.DESC_OVR_INTERFACE;
	} else if (/* is class */ Flags.isAbstract(flags)) {
		type= JavaPluginImages.DESC_OVR_ABSTRACT_CLASS;
	} else {
		type= null;
	}
	
	boolean deprecated= Flags.isDeprecated(flags);
	boolean packageDefault= Flags.isPackageDefault(flags);
	
	/* Each decoration position can only be used once. Since we don't want to take all positions
	 * away from other decorators, we confine ourselves to only use the top right position. */
	
	if (type != null && !deprecated && !packageDefault) {
		decoration.addOverlay(type, IDecoration.TOP_RIGHT);
		
	} else if (type == null && deprecated && !packageDefault) {
		decoration.addOverlay(JavaPluginImages.DESC_OVR_DEPRECATED, IDecoration.TOP_RIGHT);
		
	} else if (type != null || deprecated || packageDefault) {
		decoration.addOverlay(new TypeIndicatorOverlay(type, deprecated, packageDefault), IDecoration.TOP_RIGHT);
	}
}
 
Example 6
Source File: SimilarElementsRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static final int getKind(int flags, char[] typeNameSig) {
	if (Signature.getTypeSignatureKind(typeNameSig) == Signature.TYPE_VARIABLE_SIGNATURE) {
		return VARIABLES;
	}
	if (Flags.isAnnotation(flags)) {
		return ANNOTATIONS;
	}
	if (Flags.isInterface(flags)) {
		return INTERFACES;
	}
	if (Flags.isEnum(flags)) {
		return ENUMS;
	}
	return CLASSES;
}
 
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 isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
	int flags= curr.getModifiers();
	if (Flags.isAnnotation(flags)) {
		return is50OrHigher && ((typeKinds & SimilarElementsRequestor.ANNOTATIONS) != 0);
	}
	if (Flags.isEnum(flags)) {
		return is50OrHigher && ((typeKinds & SimilarElementsRequestor.ENUMS) != 0);
	}
	if (Flags.isInterface(flags)) {
		return (typeKinds & SimilarElementsRequestor.INTERFACES) != 0;
	}
	return (typeKinds & SimilarElementsRequestor.CLASSES) != 0;
}
 
Example 8
Source File: OrganizeImportsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
	int flags= curr.getModifiers();
	if (Flags.isAnnotation(flags)) {
		return is50OrHigher && (typeKinds & SimilarElementsRequestor.ANNOTATIONS) != 0;
	}
	if (Flags.isEnum(flags)) {
		return is50OrHigher && (typeKinds & SimilarElementsRequestor.ENUMS) != 0;
	}
	if (Flags.isInterface(flags)) {
		return (typeKinds & SimilarElementsRequestor.INTERFACES) != 0;
	}
	return (typeKinds & SimilarElementsRequestor.CLASSES) != 0;
}
 
Example 9
Source File: AddImportsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
	int flags= curr.getModifiers();
	if (Flags.isAnnotation(flags)) {
		return is50OrHigher && (typeKinds & SimilarElementsRequestor.ANNOTATIONS) != 0;
	}
	if (Flags.isEnum(flags)) {
		return is50OrHigher && (typeKinds & SimilarElementsRequestor.ENUMS) != 0;
	}
	if (Flags.isInterface(flags)) {
		return (typeKinds & SimilarElementsRequestor.INTERFACES) != 0;
	}
	return (typeKinds & SimilarElementsRequestor.CLASSES) != 0;
}
 
Example 10
Source File: TypeNameMatchLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ImageDescriptor getImageDescriptor(TypeNameMatch typeRef, int flags) {
	if (isSet(SHOW_TYPE_CONTAINER_ONLY, flags)) {
		if (typeRef.getPackageName().equals(typeRef.getTypeContainerName()))
			return JavaPluginImages.DESC_OBJS_PACKAGE;

		// XXX cannot check outer type for interface efficiently (5887)
		return JavaPluginImages.DESC_OBJS_CLASS;

	} else if (isSet(SHOW_PACKAGE_ONLY, flags)) {
		return JavaPluginImages.DESC_OBJS_PACKAGE;
	} else {
		boolean isInner= typeRef.getTypeContainerName().indexOf('.') != -1;
		int modifiers= typeRef.getModifiers();

		ImageDescriptor desc= JavaElementImageProvider.getTypeImageDescriptor(isInner, false, modifiers, false);
		int adornmentFlags= 0;
		if (Flags.isFinal(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.FINAL;
		}
		if (Flags.isAbstract(modifiers) && !Flags.isInterface(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.ABSTRACT;
		}
		if (Flags.isStatic(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.STATIC;
		}
		if (Flags.isDeprecated(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.DEPRECATED;
		}

		return new JavaElementImageDescriptor(desc, adornmentFlags, JavaElementImageProvider.BIG_SIZE);
	}
}
 
Example 11
Source File: TypeMatchFilters.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName,
		char[][] enclosingTypeNames, String path) {
	if (isInternalClass(simpleTypeName, enclosingTypeNames)) {
		return false;
	}
	return !Flags.isAbstract(modifiers) && !Flags.isInterface(modifiers);
}
 
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 getTypeImageDescriptor(boolean isInner, boolean isInInterfaceOrAnnotation, int flags, boolean useLightIcons) {
	if (Flags.isEnum(flags)) {
		if (useLightIcons) {
			return JavaPluginImages.DESC_OBJS_ENUM_ALT;
		}
		if (isInner) {
			return getInnerEnumImageDescriptor(isInInterfaceOrAnnotation, flags);
		}
		return getEnumImageDescriptor(flags);
	} else if (Flags.isAnnotation(flags)) {
		if (useLightIcons) {
			return JavaPluginImages.DESC_OBJS_ANNOTATION_ALT;
		}
		if (isInner) {
			return getInnerAnnotationImageDescriptor(isInInterfaceOrAnnotation, flags);
		}
		return getAnnotationImageDescriptor(flags);
	}  else if (Flags.isInterface(flags)) {
		if (useLightIcons) {
			return JavaPluginImages.DESC_OBJS_INTERFACEALT;
		}
		if (isInner) {
			return getInnerInterfaceImageDescriptor(isInInterfaceOrAnnotation, flags);
		}
		return getInterfaceImageDescriptor(flags);
	} else {
		if (useLightIcons) {
			return JavaPluginImages.DESC_OBJS_CLASSALT;
		}
		if (isInner) {
			return getInnerClassImageDescriptor(isInInterfaceOrAnnotation, flags);
		}
		return getClassImageDescriptor(flags);
	}
}
 
Example 13
Source File: TraditionalHierarchyViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected final void getRootTypes(List<IType> res) {
	ITypeHierarchy hierarchy= getHierarchy();
	if (hierarchy != null) {
		IType input= hierarchy.getType();
		if (input == null) {
			IType[] classes= hierarchy.getRootClasses();
			for (int i= 0; i < classes.length; i++) {
				res.add(classes[i]);
			}
			IType[] interfaces= hierarchy.getRootInterfaces();
			for (int i= 0; i < interfaces.length; i++) {
				res.add(interfaces[i]);
			}
		} else {
			if (Flags.isInterface(hierarchy.getCachedFlags(input))) {
				res.add(input);
			} else if (isAnonymousFromInterface(input)) {
				res.add(hierarchy.getSuperInterfaces(input)[0]);
			} else {
				IType[] roots= hierarchy.getRootClasses();
				for (int i= 0; i < roots.length; i++) {
					if (isObject(roots[i])) {
						res.add(roots[i]);
						return;
					}
				}
				res.addAll(Arrays.asList(roots)); // something wrong with the hierarchy
			}
		}
	}
}
 
Example 14
Source File: SimilarElementsRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static final int getKind(int flags, char[] typeNameSig) {
	if (Signature.getTypeSignatureKind(typeNameSig) == Signature.TYPE_VARIABLE_SIGNATURE) {
		return VARIABLES;
	}
	if (Flags.isAnnotation(flags)) {
		return ANNOTATIONS;
	}
	if (Flags.isInterface(flags)) {
		return INTERFACES;
	}
	if (Flags.isEnum(flags)) {
		return ENUMS;
	}
	return CLASSES;
}
 
Example 15
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns a version of <code>descriptor</code> decorated according to
 * the passed <code>modifier</code> flags.
 *
 * @param descriptor the image descriptor to decorate
 * @param proposal the proposal
 * @return an image descriptor for a method proposal
 * @see Flags
 */
private ImageDescriptor decorateImageDescriptor(ImageDescriptor descriptor, CompletionProposal proposal) {
	int adornments= 0;
	int flags= proposal.getFlags();
	int kind= proposal.getKind();

	boolean deprecated= Flags.isDeprecated(flags);
	if (!deprecated) {
		CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
		if (requiredProposals != null) {
			for (int i= 0; i < requiredProposals.length; i++) {
				CompletionProposal requiredProposal= requiredProposals[i];
				if (requiredProposal.getKind() == CompletionProposal.TYPE_REF) {
					deprecated |= Flags.isDeprecated(requiredProposal.getFlags());
				}
			}
		}
	}
	if (deprecated)
		adornments |= JavaElementImageDescriptor.DEPRECATED;

	if (kind == CompletionProposal.FIELD_REF || kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE
			|| kind == CompletionProposal.METHOD_REF || kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
		if (Flags.isStatic(flags))
			adornments |= JavaElementImageDescriptor.STATIC;

	if (kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE || kind == CompletionProposal.METHOD_REF
			|| kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
		if (Flags.isSynchronized(flags))
			adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
	if (kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE || kind == CompletionProposal.METHOD_REF)
		if (Flags.isDefaultMethod(flags))
			adornments|= JavaElementImageDescriptor.DEFAULT_METHOD;
	if (kind == CompletionProposal.ANNOTATION_ATTRIBUTE_REF)
		if (Flags.isAnnnotationDefault(flags))
			adornments|= JavaElementImageDescriptor.ANNOTATION_DEFAULT;

	if (kind == CompletionProposal.TYPE_REF && Flags.isAbstract(flags) && !Flags.isInterface(flags))
		adornments |= JavaElementImageDescriptor.ABSTRACT;

	if (kind == CompletionProposal.FIELD_REF) {
		if (Flags.isFinal(flags))
			adornments |= JavaElementImageDescriptor.FINAL;
		if (Flags.isTransient(flags))
			adornments |= JavaElementImageDescriptor.TRANSIENT;
		if (Flags.isVolatile(flags))
			adornments |= JavaElementImageDescriptor.VOLATILE;
	}

	return new JavaElementImageDescriptor(descriptor, adornments, JavaElementImageProvider.SMALL_SIZE);
}
 
Example 16
Source File: HierarchyLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private ImageDescriptor getTypeImageDescriptor(IType type) {
	ITypeHierarchy hierarchy= fHierarchy.getHierarchy();
	if (hierarchy == null) {
		return new JavaElementImageDescriptor(JavaPluginImages.DESC_OBJS_CLASS, 0, JavaElementImageProvider.BIG_SIZE);
	}

	int flags= hierarchy.getCachedFlags(type);
	if (flags == -1) {
		return new JavaElementImageDescriptor(JavaPluginImages.DESC_OBJS_CLASS, 0, JavaElementImageProvider.BIG_SIZE);
	}

	boolean isInterface= Flags.isInterface(flags);
	IType declaringType= type.getDeclaringType();
	boolean isInner= declaringType != null;
	boolean isInInterfaceOrAnnotation= false;
	if (isInner) {
		int declaringTypeFlags= hierarchy.getCachedFlags(declaringType);
		if (declaringTypeFlags != -1) {
			isInInterfaceOrAnnotation= Flags.isInterface(declaringTypeFlags);
		} else {
			// declaring type is not in hierarchy, so we have to pay the price for resolving here
			try {
				isInInterfaceOrAnnotation= declaringType.isInterface();
			} catch (JavaModelException e) {
			}
		}
	}

	ImageDescriptor desc= JavaElementImageProvider.getTypeImageDescriptor(isInner, isInInterfaceOrAnnotation, flags, isInDifferentHierarchyScope(type));

	int adornmentFlags= 0;
	if (Flags.isFinal(flags)) {
		adornmentFlags |= JavaElementImageDescriptor.FINAL;
	}
	if (Flags.isAbstract(flags) && !isInterface) {
		adornmentFlags |= JavaElementImageDescriptor.ABSTRACT;
	}
	if (Flags.isStatic(flags)) {
		adornmentFlags |= JavaElementImageDescriptor.STATIC;
	}
	if (Flags.isDeprecated(flags)) {
		adornmentFlags |= JavaElementImageDescriptor.DEPRECATED;
	}

	return new JavaElementImageDescriptor(desc, adornmentFlags, JavaElementImageProvider.BIG_SIZE);
}
 
Example 17
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
ImageDescriptor createTypeImageDescriptor(CompletionProposal proposal) {
	final int flags= proposal.getFlags();
	boolean isInterfaceOrAnnotation= Flags.isInterface(flags) || Flags.isAnnotation(flags);
	return decorateImageDescriptor(JavaElementImageProvider.getTypeImageDescriptor(true /* in order to get all visibility decorations */, isInterfaceOrAnnotation, flags, false), proposal);
}
 
Example 18
Source File: CompletionProposalRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private CompletionItemKind mapKind(final CompletionProposal proposal) {
	//When a new CompletionItemKind is added, don't forget to update SUPPORTED_KINDS
	int kind = proposal.getKind();
	int flags = proposal.getFlags();
	switch (kind) {
	case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
	case CompletionProposal.CONSTRUCTOR_INVOCATION:
		return CompletionItemKind.Constructor;
	case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
	case CompletionProposal.TYPE_REF:
		if (Flags.isInterface(flags)) {
			return CompletionItemKind.Interface;
		} else if (Flags.isEnum(flags)) {
			return CompletionItemKind.Enum;
		}
		return CompletionItemKind.Class;
	case CompletionProposal.FIELD_IMPORT:
	case CompletionProposal.METHOD_IMPORT:
	case CompletionProposal.METHOD_NAME_REFERENCE:
	case CompletionProposal.PACKAGE_REF:
	case CompletionProposal.TYPE_IMPORT:
	case CompletionProposal.MODULE_DECLARATION:
	case CompletionProposal.MODULE_REF:
		return CompletionItemKind.Module;
	case CompletionProposal.FIELD_REF:
		if (Flags.isEnum(flags)) {
			return CompletionItemKind.EnumMember;
		}
		if (Flags.isStatic(flags) && Flags.isFinal(flags)) {
			return CompletionItemKind.Constant;
		}
		return CompletionItemKind.Field;
	case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
		return CompletionItemKind.Field;
	case CompletionProposal.KEYWORD:
		return CompletionItemKind.Keyword;
	case CompletionProposal.LABEL_REF:
		return CompletionItemKind.Reference;
	case CompletionProposal.LOCAL_VARIABLE_REF:
	case CompletionProposal.VARIABLE_DECLARATION:
		return CompletionItemKind.Variable;
	case CompletionProposal.METHOD_DECLARATION:
	case CompletionProposal.METHOD_REF:
	case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
	case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
		return CompletionItemKind.Method;
		//text
	case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
	case CompletionProposal.JAVADOC_BLOCK_TAG:
	case CompletionProposal.JAVADOC_FIELD_REF:
	case CompletionProposal.JAVADOC_INLINE_TAG:
	case CompletionProposal.JAVADOC_METHOD_REF:
	case CompletionProposal.JAVADOC_PARAM_REF:
	case CompletionProposal.JAVADOC_TYPE_REF:
	case CompletionProposal.JAVADOC_VALUE_REF:
	default:
		return CompletionItemKind.Text;
	}
}