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

The following examples show how to use org.eclipse.jdt.core.Flags#isFinal() . 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: 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 2
Source File: StubUtility2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IMethodBinding[] getDelegateCandidates(ITypeBinding binding, ITypeBinding hierarchy) {
	List<IMethodBinding> allMethods= new ArrayList<IMethodBinding>();
	boolean isInterface= binding.isInterface();
	IMethodBinding[] typeMethods= binding.getDeclaredMethods();
	for (int index= 0; index < typeMethods.length; index++) {
		final int modifiers= typeMethods[index].getModifiers();
		if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && (isInterface || Modifier.isPublic(modifiers))) {
			IMethodBinding result= Bindings.findOverriddenMethodInHierarchy(hierarchy, typeMethods[index]);
			if (result != null && Flags.isFinal(result.getModifiers()))
				continue;
			ITypeBinding[] parameterBindings= typeMethods[index].getParameterTypes();
			boolean upper= false;
			for (int offset= 0; offset < parameterBindings.length; offset++) {
				if (parameterBindings[offset].isWildcardType() && parameterBindings[offset].isUpperbound())
					upper= true;
			}
			if (!upper)
				allMethods.add(typeMethods[index]);
		}
	}
	return allMethods.toArray(new IMethodBinding[allMethods.size()]);
}
 
Example 3
Source File: AccessAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public AccessAnalyzer(SelfEncapsulateFieldRefactoring refactoring, ICompilationUnit unit, IVariableBinding field, ITypeBinding declaringClass, ASTRewrite rewriter, ImportRewrite importRewrite) {
	Assert.isNotNull(refactoring);
	Assert.isNotNull(unit);
	Assert.isNotNull(field);
	Assert.isNotNull(declaringClass);
	Assert.isNotNull(rewriter);
	Assert.isNotNull(importRewrite);
	fCUnit = unit;
	fFieldBinding = field.getVariableDeclaration();
	fDeclaringClassBinding = declaringClass;
	fRewriter = rewriter;
	fImportRewriter = importRewrite;
	fGroupDescriptions = new ArrayList<>();
	fGetter = refactoring.getGetterName();
	fSetter = refactoring.getSetterName();
	fEncapsulateDeclaringClass = refactoring.getEncapsulateDeclaringClass();
	try {
		fIsFieldFinal = Flags.isFinal(refactoring.getField().getFlags());
	} catch (JavaModelException e) {
		// assume non final field
	}
	fStatus = new RefactoringStatus();
}
 
Example 4
Source File: SARLProposalProvider.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName,
		char[][] enclosingTypeNames, String path) {
	// Avoid auto reference of type.
	final String fullName = JavaModelUtil.concatenateName(packageName, simpleTypeName);
	if (Objects.equals(this.modelFullName, fullName)) {
		return false;
	}
	//The following tests are done by the visibility filter.
	//if (TypeMatchFilters.isInternalClass(simpleTypeName, enclosingTypeNames)) {
	//	return false;
	//}
	//if (!TypeMatchFilters.isAcceptableByPreference().accept(modifiers, packageName,
	//		simpleTypeName, enclosingTypeNames, path)) {
	//	return false;
	//}
	// Final modifier test
	if (Flags.isFinal(modifiers)) {
		return false;
	}
	return this.visibilityFilter.accept(modifiers, packageName, simpleTypeName, enclosingTypeNames, path);
}
 
Example 5
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 6
Source File: AccessAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public AccessAnalyzer(SelfEncapsulateFieldRefactoring refactoring, ICompilationUnit unit, IVariableBinding field, ITypeBinding declaringClass, ASTRewrite rewriter, ImportRewrite importRewrite) {
	Assert.isNotNull(refactoring);
	Assert.isNotNull(unit);
	Assert.isNotNull(field);
	Assert.isNotNull(declaringClass);
	Assert.isNotNull(rewriter);
	Assert.isNotNull(importRewrite);
	fCUnit= unit;
	fFieldBinding= field.getVariableDeclaration();
	fDeclaringClassBinding= declaringClass;
	fRewriter= rewriter;
	fImportRewriter= importRewrite;
	fGroupDescriptions= new ArrayList<TextEditGroup>();
	fGetter= refactoring.getGetterName();
	fSetter= refactoring.getSetterName();
	fEncapsulateDeclaringClass= refactoring.getEncapsulateDeclaringClass();
	try {
		fIsFieldFinal= Flags.isFinal(refactoring.getField().getFlags());
	} catch (JavaModelException e) {
		// assume non final field
	}
	fStatus= new RefactoringStatus();
}
 
Example 7
Source File: SearchUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isPrimitiveConstantOrString(IJavaElement element) {
	if (element != null && element.getElementType() == IJavaElement.FIELD) {
		IField field= (IField)element;
		int flags;
		try {
			flags= field.getFlags();
		} catch (JavaModelException ex) {
			return false;
		}
		return Flags.isStatic(flags) && Flags.isFinal(flags) && isPrimitiveOrString(field);
	}
	return false;
}
 
Example 8
Source File: StubUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String[] getFieldNameSuggestions(IJavaProject project, String baseName, int dimensions, int modifiers, String[] excluded) {
	if (Flags.isFinal(modifiers) && Flags.isStatic(modifiers)) {
		return getVariableNameSuggestions(NamingConventions.VK_STATIC_FINAL_FIELD, project, baseName, dimensions, new ExcludedCollection(excluded), true);
	} else if (Flags.isStatic(modifiers)) {
		return getVariableNameSuggestions(NamingConventions.VK_STATIC_FIELD, project, baseName, dimensions, new ExcludedCollection(excluded), true);
	}
	return getVariableNameSuggestions(NamingConventions.VK_INSTANCE_FIELD, project, baseName, dimensions, new ExcludedCollection(excluded), true);
}
 
Example 9
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 10
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isFinal(IMember member) throws JavaModelException{
	if (isInterfaceOrAnnotationField(member))
		return true;
	if (isAnonymousType(member))
		return true;
	if (isEnumConstant(member) || isEnumTypeFinal(member))
		return true;
	return Flags.isFinal(member.getFlags());
}
 
Example 11
Source File: StubCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void appendFieldDeclaration(final IField field) throws JavaModelException {
	appendFlags(field);
	fBuffer.append(" "); //$NON-NLS-1$
	final String signature= field.getTypeSignature();
	fBuffer.append(Signature.toString(signature));
	fBuffer.append(" "); //$NON-NLS-1$
	fBuffer.append(field.getElementName());
	if (Flags.isFinal(field.getFlags())) {
		fBuffer.append("="); //$NON-NLS-1$
		appendExpression(signature);
	}
	fBuffer.append(";"); //$NON-NLS-1$
}
 
Example 12
Source File: ExtractFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return proposed field names (may be empty, but not null). The first proposal
 *         should be used as "best guess" (if it exists).
 */
public String[] guessFieldNames() {
	if (fGuessedFieldNames == null) {
		try {
			Expression expression = getSelectedExpression().getAssociatedExpression();
			if (expression != null) {
				ITypeBinding binding = guessBindingForReference(expression);
				int modifiers = getModifiers();
				int variableKind;
				if (Flags.isFinal(modifiers) && Flags.isStatic(modifiers)) {
					variableKind = NamingConventions.VK_STATIC_FINAL_FIELD;
				} else if (Flags.isStatic(modifiers)) {
					variableKind = NamingConventions.VK_STATIC_FIELD;
				} else {
					variableKind = NamingConventions.VK_INSTANCE_FIELD;
				}

				fGuessedFieldNames = StubUtility.getVariableNameSuggestions(variableKind, fCu.getJavaProject(), binding, expression, Arrays.asList(getExcludedFieldNames()));
			}
		} catch (JavaModelException e) {
		}
		if (fGuessedFieldNames == null) {
			fGuessedFieldNames = new String[0];
		}
	}
	return fGuessedFieldNames;
}
 
Example 13
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isFinal(IMember member) throws JavaModelException{
	if (isInterfaceOrAnnotationField(member)) {
		return true;
	}
	if (isAnonymousType(member)) {
		return true;
	}
	if (isEnumConstant(member) || isEnumTypeFinal(member)) {
		return true;
	}
	return Flags.isFinal(member.getFlags());
}
 
Example 14
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isDelegateCreationAvailable(final IField field) throws JavaModelException {
	return field.exists() && (Flags.isStatic(field.getFlags()) && Flags.isFinal(field.getFlags()) /*
	 * &&
	 * hasInitializer(field)
	 */);
}
 
Example 15
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 16
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean isDelegateCreationAvailable(final IField field) throws JavaModelException {
	return field.exists() && (Flags.isStatic(field.getFlags()) && Flags.isFinal(field.getFlags()) /*
																									* &&
																									* hasInitializer(field)
																									*/);
}
 
Example 17
Source File: GetterSetterUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create a stub for a getter of the given field using getter/setter templates. The resulting code
 * has to be formatted and indented.
 * @param field The field to create a getter for
 * @param setterName The chosen name for the setter
 * @param addComments If <code>true</code>, comments will be added.
 * @param flags The flags signaling visibility, if static, synchronized or final
 * @return Returns the generated stub.
 * @throws CoreException when stub creation failed
 */
public static String getSetterStub(IField field, String setterName, boolean addComments, int flags) throws CoreException {

	String fieldName= field.getElementName();
	IType parentType= field.getDeclaringType();

	String returnSig= field.getTypeSignature();
	String typeName= Signature.toString(returnSig);

	IJavaProject project= field.getJavaProject();

	String accessorName= StubUtility.getBaseName(field);
	String argname= StubUtility.suggestArgumentName(project, accessorName, EMPTY);

	boolean isStatic= Flags.isStatic(flags);
	boolean isSync= Flags.isSynchronized(flags);
	boolean isFinal= Flags.isFinal(flags);

	String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$
	StringBuffer buf= new StringBuffer();
	if (addComments) {
		String comment= CodeGeneration.getSetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, field.getElementName(), typeName, argname, accessorName, lineDelim);
		if (comment != null) {
			buf.append(comment);
			buf.append(lineDelim);
		}
	}
	buf.append(JdtFlags.getVisibilityString(flags));
	buf.append(' ');
	if (isStatic)
		buf.append("static "); //$NON-NLS-1$
	if (isSync)
		buf.append("synchronized "); //$NON-NLS-1$
	if (isFinal)
		buf.append("final "); //$NON-NLS-1$

	buf.append("void "); //$NON-NLS-1$
	buf.append(setterName);
	buf.append('(');
	buf.append(typeName);
	buf.append(' ');
	buf.append(argname);
	buf.append(") {"); //$NON-NLS-1$
	buf.append(lineDelim);

	boolean useThis= StubUtility.useThisForFieldAccess(project);
	if (argname.equals(fieldName) || (useThis && !isStatic)) {
		if (isStatic)
			fieldName= parentType.getElementName() + '.' + fieldName;
		else
			fieldName= "this." + fieldName; //$NON-NLS-1$
	}
	String body= CodeGeneration.getSetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, fieldName, argname, lineDelim);
	if (body != null) {
		buf.append(body);
	}
	buf.append("}"); //$NON-NLS-1$
	buf.append(lineDelim);
	return buf.toString();
}
 
Example 18
Source File: GetterSetterUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create a stub for a getter of the given field using getter/setter templates. The resulting code
 * has to be formatted and indented.
 * @param field The field to create a getter for
 * @param getterName The chosen name for the getter
 * @param addComments If <code>true</code>, comments will be added.
 * @param flags The flags signaling visibility, if static, synchronized or final
 * @return Returns the generated stub.
 * @throws CoreException when stub creation failed
 */
public static String getGetterStub(IField field, String getterName, boolean addComments, int flags) throws CoreException {
	String fieldName= field.getElementName();
	IType parentType= field.getDeclaringType();

	boolean isStatic= Flags.isStatic(flags);
	boolean isSync= Flags.isSynchronized(flags);
	boolean isFinal= Flags.isFinal(flags);

	String typeName= Signature.toString(field.getTypeSignature());
	String accessorName= StubUtility.getBaseName(field);

	String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$
	StringBuffer buf= new StringBuffer();
	if (addComments) {
		String comment= CodeGeneration.getGetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, field.getElementName(), typeName, accessorName, lineDelim);
		if (comment != null) {
			buf.append(comment);
			buf.append(lineDelim);
		}
	}

	buf.append(JdtFlags.getVisibilityString(flags));
	buf.append(' ');
	if (isStatic)
		buf.append("static "); //$NON-NLS-1$
	if (isSync)
		buf.append("synchronized "); //$NON-NLS-1$
	if (isFinal)
		buf.append("final "); //$NON-NLS-1$

	buf.append(typeName);
	buf.append(' ');
	buf.append(getterName);
	buf.append("() {"); //$NON-NLS-1$
	buf.append(lineDelim);

	boolean useThis= StubUtility.useThisForFieldAccess(field.getJavaProject());
	if (useThis && !isStatic) {
		fieldName= "this." + fieldName; //$NON-NLS-1$
	}

	String body= CodeGeneration.getGetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, fieldName, lineDelim);
	if (body != null) {
		buf.append(body);
	}
	buf.append("}"); //$NON-NLS-1$
	buf.append(lineDelim);
	return buf.toString();
}
 
Example 19
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 20
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;
	}
}