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

The following examples show how to use org.eclipse.jdt.core.Flags#isEnum() . 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: AddGetterSetterAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param type the type
 * @return map IField -> GetterSetterEntry[]
 * @throws JavaModelException if the type does not exist or if an exception occurs while
 *             accessing its corresponding resource
 */
private Map<IField, GetterSetterEntry[]> createGetterSetterMapping(IType type) throws JavaModelException {
	IField[] fields= type.getFields();
	Map<IField, GetterSetterEntry[]> result= new LinkedHashMap<IField, GetterSetterEntry[]>();
	for (int i= 0; i < fields.length; i++) {
		IField field= fields[i];
		int flags= field.getFlags();
		if (!Flags.isEnum(flags)) {
			List<GetterSetterEntry> l= new ArrayList<GetterSetterEntry>(2);
			if (GetterSetterUtil.getGetter(field) == null) {
				l.add(new GetterSetterEntry(field, true, Flags.isFinal(flags)));
				incNumEntries();
			}

			if (GetterSetterUtil.getSetter(field) == null) {
				l.add(new GetterSetterEntry(field, false, Flags.isFinal(flags)));
				incNumEntries();
			}

			if (!l.isEmpty())
				result.put(field, l.toArray(new GetterSetterEntry[l.size()]));
		}
	}
	return result;
}
 
Example 3
Source File: GenerateGetterSetterOperation.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static AccessorField[] getUnimplementedAccessors(IType type) throws JavaModelException {
	if (!supportsGetterSetter(type)) {
		return new AccessorField[0];
	}

	List<AccessorField> unimplemented = new ArrayList<>();
	IField[] fields = type.getFields();
	for (IField field : fields) {
		int flags = field.getFlags();
		if (!Flags.isEnum(flags)) {
			boolean isStatic = Flags.isStatic(flags);
			boolean generateGetter = (GetterSetterUtil.getGetter(field) == null);
			boolean generateSetter = (!Flags.isFinal(flags) && GetterSetterUtil.getSetter(field) == null);
			if (generateGetter || generateSetter) {
				unimplemented.add(new AccessorField(field.getElementName(), isStatic, generateGetter, generateSetter));
			}
		}
	}

	return unimplemented.toArray(new AccessorField[0]);
}
 
Example 4
Source File: HierarchyProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected static List<ASTNode> getDeclarationNodes(final CompilationUnit cuNode, final List<IMember> members) throws JavaModelException {
	final List<ASTNode> result= new ArrayList<ASTNode>(members.size());
	for (final Iterator<IMember> iterator= members.iterator(); iterator.hasNext();) {
		final IMember member= iterator.next();
		ASTNode node= null;
		if (member instanceof IField) {
			if (Flags.isEnum(member.getFlags()))
				node= ASTNodeSearchUtil.getEnumConstantDeclaration((IField) member, cuNode);
			else
				node= ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) member, cuNode);
		} else if (member instanceof IType)
			node= ASTNodeSearchUtil.getAbstractTypeDeclarationNode((IType) member, cuNode);
		else if (member instanceof IMethod)
			node= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) member, cuNode);
		if (node != null)
			result.add(node);
	}
	return result;
}
 
Example 5
Source File: TypedSource.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static String getFieldSource(IField field, SourceTuple tuple) throws CoreException {
	if (Flags.isEnum(field.getFlags())) {
		String source= field.getSource();
		if (source != null)
			return source;
	} else {
		if (tuple.node == null) {
			ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
			parser.setSource(tuple.unit);
			tuple.node= (CompilationUnit) parser.createAST(null);
		}
		FieldDeclaration declaration= ASTNodeSearchUtil.getFieldDeclarationNode(field, tuple.node);
		if (declaration.fragments().size() == 1)
			return getSourceOfDeclararationNode(field, tuple.unit);
		VariableDeclarationFragment declarationFragment= ASTNodeSearchUtil.getFieldDeclarationFragmentNode(field, tuple.node);
		IBuffer buffer= tuple.unit.getBuffer();
		StringBuffer buff= new StringBuffer();
		buff.append(buffer.getText(declaration.getStartPosition(), ((ASTNode) declaration.fragments().get(0)).getStartPosition() - declaration.getStartPosition()));
		buff.append(buffer.getText(declarationFragment.getStartPosition(), declarationFragment.getLength()));
		buff.append(";"); //$NON-NLS-1$
		return buff.toString();
	}
	return ""; //$NON-NLS-1$
}
 
Example 6
Source File: MoveStaticMembersProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean canMoveToInterface(IMember member, boolean is18OrHigher) throws JavaModelException {
	int flags= member.getFlags();
	switch (member.getElementType()) {
		case IJavaElement.FIELD:
			if (!(Flags.isStatic(flags) && Flags.isFinal(flags)))
				return false;
			if (Flags.isEnum(flags))
				return false;
			VariableDeclarationFragment declaration= ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) member, fSource.getRoot());
			if (declaration != null)
				return declaration.getInitializer() != null;
			return false;
		case IJavaElement.TYPE: {
			IType type= (IType) member;
			if (type.isInterface() && !Checks.isTopLevel(type))
				return true;
			return Flags.isStatic(flags);
		}
		case IJavaElement.METHOD: {
			return is18OrHigher && Flags.isStatic(flags);
		}
		default:
			return false;
	}
}
 
Example 7
Source File: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adjusts the visibility of the referenced body declaration.
 *
 * @param member the member where to adjust the visibility
 * @param threshold the visibility keyword representing the required visibility, or <code>null</code> for default visibility
 * @param template the message template to use
 * @throws JavaModelException if an error occurs
 */
private void adjustOutgoingVisibility(final IMember member, final ModifierKeyword threshold, final String template) throws JavaModelException {
	Assert.isTrue(!member.isBinary() && !member.isReadOnly());
	boolean adjust= true;
	final IType declaring= member.getDeclaringType();
	if (declaring != null && (JavaModelUtil.isInterfaceOrAnnotation(declaring)
			|| (member instanceof IField) && Flags.isEnum(member.getFlags()) 
			|| declaring.equals(fReferenced)))
		adjust= false;
	if (adjust && hasLowerVisibility(member.getFlags(), keywordToVisibility(threshold)) && needsVisibilityAdjustment(member, threshold))
		fAdjustments.put(member, new OutgoingMemberVisibilityAdjustment(member, threshold, RefactoringStatus.createStatus(fVisibilitySeverity, Messages.format(template, new String[] { JavaElementLabels.getTextLabel(member, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.ALL_FULLY_QUALIFIED), getLabel(threshold)}), JavaStatusContext.create(member), null, RefactoringStatusEntry.NO_CODE, null)));
}
 
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: 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 10
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 11
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ImageDescriptor getFieldImageDescriptor(boolean isInInterfaceOrAnnotation, int flags) {
	if (Flags.isPublic(flags) || isInInterfaceOrAnnotation || Flags.isEnum(flags))
		return JavaPluginImages.DESC_FIELD_PUBLIC;
	if (Flags.isProtected(flags))
		return JavaPluginImages.DESC_FIELD_PROTECTED;
	if (Flags.isPrivate(flags))
		return JavaPluginImages.DESC_FIELD_PRIVATE;

	return JavaPluginImages.DESC_FIELD_DEFAULT;
}
 
Example 12
Source File: StubCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void appendEnumConstants(final IType type) throws JavaModelException {
	final IField[] fields= type.getFields();
	final List<IField> list= new ArrayList<IField>(fields.length);
	for (int index= 0; index < fields.length; index++) {
		final IField field= fields[index];
		if (Flags.isEnum(field.getFlags()))
			list.add(field);
	}
	for (int index= 0; index < list.size(); index++) {
		if (index > 0)
			fBuffer.append(","); //$NON-NLS-1$
		fBuffer.append(list.get(index).getElementName());
	}
	fBuffer.append(";"); //$NON-NLS-1$
}
 
Example 13
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isRenameElementAvailable(IJavaElement element) throws CoreException {
	switch (element.getElementType()) {
		case IJavaElement.JAVA_PROJECT:
			return isRenameAvailable((IJavaProject) element);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return isRenameAvailable((IPackageFragmentRoot) element);
		case IJavaElement.PACKAGE_FRAGMENT:
			return isRenameAvailable((IPackageFragment) element);
		case IJavaElement.COMPILATION_UNIT:
			return isRenameAvailable((ICompilationUnit) element);
		case IJavaElement.TYPE:
			return isRenameAvailable((IType) element);
		case IJavaElement.METHOD:
			final IMethod method= (IMethod) element;
			if (method.isConstructor())
				return isRenameAvailable(method.getDeclaringType());
			else
				return isRenameAvailable(method);
		case IJavaElement.FIELD:
			final IField field= (IField) element;
			if (Flags.isEnum(field.getFlags()))
				return isRenameEnumConstAvailable(field);
			else
				return isRenameFieldAvailable(field);
		case IJavaElement.TYPE_PARAMETER:
			return isRenameAvailable((ITypeParameter) element);
		case IJavaElement.LOCAL_VARIABLE:
			return isRenameAvailable((ILocalVariable) element);
	}
	return false;
}
 
Example 14
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 15
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 16
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 17
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;
	}
}
 
Example 18
Source File: BinaryField.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean isEnumConstant() throws JavaModelException {
	return Flags.isEnum(getFlags());
}
 
Example 19
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isEnum(IMember member) throws JavaModelException{
	return Flags.isEnum(member.getFlags());
}
 
Example 20
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean isEnum(IMember member) throws JavaModelException{
	return Flags.isEnum(member.getFlags());
}