Java Code Examples for org.eclipse.jdt.core.dom.IBinding#getModifiers()

The following examples show how to use org.eclipse.jdt.core.dom.IBinding#getModifiers() . 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: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	SimpleName node= token.getNode();
	if (node.isDeclaration())
		return false;

	IBinding binding= token.getBinding();
	boolean isAbstractMethod= binding != null && binding.getKind() == IBinding.METHOD && (binding.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT;
	if (!isAbstractMethod)
		return false;

	// filter out annotation value references
	if (binding != null) {
		ITypeBinding declaringType= ((IMethodBinding)binding).getDeclaringClass();
		if (declaringType.isAnnotation())
			return false;
	}

	return true;
}
 
Example 2
Source File: ScopeAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Evaluates if the declaration is visible in a certain context.
 * @param binding The binding of the declaration to examine
 * @param context The context to test in
 * @return Returns
 */
public static boolean isVisible(IBinding binding, ITypeBinding context) {
	if (binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) {
		return true; // all local variables found are visible
	}
	ITypeBinding declaring= getDeclaringType(binding);
	if (declaring == null) {
		return false;
	}

	declaring= declaring.getTypeDeclaration();

	int modifiers= binding.getModifiers();
	if (Modifier.isPublic(modifiers) || declaring.isInterface()) {
		return true;
	} else if (Modifier.isProtected(modifiers) || !Modifier.isPrivate(modifiers)) {
		if (declaring.getPackage() == context.getPackage()) {
			return true;
		}
		return isTypeInScope(declaring, context, Modifier.isProtected(modifiers));
	}
	// private visibility
	return isTypeInScope(declaring, context, false);
}
 
Example 3
Source File: InlineConstantRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Name findConstantNameNode() {
	ASTNode node= NodeFinder.perform(fSelectionCuRewrite.getRoot(), fSelectionStart, fSelectionLength);
	if (node == null)
		return null;
	if (node instanceof FieldAccess)
		node= ((FieldAccess) node).getName();
	if (!(node instanceof Name))
		return null;
	Name name= (Name) node;
	IBinding binding= name.resolveBinding();
	if (!(binding instanceof IVariableBinding))
		return null;
	IVariableBinding variableBinding= (IVariableBinding) binding;
	if (!variableBinding.isField() || variableBinding.isEnumConstant())
		return null;
	int modifiers= binding.getModifiers();
	if (! (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)))
		return null;

	return name;
}
 
Example 4
Source File: BindingLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ImageDescriptor getBaseImageDescriptor(IBinding binding, int flags) {
	if (binding instanceof ITypeBinding) {
		ITypeBinding typeBinding= (ITypeBinding) binding;
		if (typeBinding.isArray()) {
			typeBinding= typeBinding.getElementType();
		}
		if (typeBinding.isCapture()) {
			typeBinding.getWildcard();
		}
		return getTypeImageDescriptor(typeBinding.getDeclaringClass() != null, typeBinding, flags);
	} else if (binding instanceof IMethodBinding) {
		ITypeBinding type= ((IMethodBinding) binding).getDeclaringClass();
		int modifiers= binding.getModifiers();
		if (type.isEnum() && (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers) && !Modifier.isPrivate(modifiers)) && ((IMethodBinding) binding).isConstructor())
			return JavaPluginImages.DESC_MISC_PRIVATE;
		return getMethodImageDescriptor(binding.getModifiers());
	} else if (binding instanceof IVariableBinding)
		return getFieldImageDescriptor((IVariableBinding) binding);
	return JavaPluginImages.DESC_OBJS_UNKNOWN;
}
 
Example 5
Source File: ConstantChecks.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private boolean visitName(Name name) {
	IBinding binding = name.resolveBinding();
	if (binding == null) {
		/* If the binding is null because of compile errors etc.,
		   scenarios which may have been deemed unacceptable in
		   the presence of semantic information will be admitted.
		   Descend deeper.
		 */
		return true;
	}

	int modifiers = binding.getModifiers();
	if (binding instanceof IVariableBinding) {
		if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers))) {
			fResult = false;
			return false;
		}
	} else if (binding instanceof IMethodBinding) {
		if (!Modifier.isStatic(modifiers)) {
			fResult = false;
			return false;
		}
	} else if (binding instanceof ITypeBinding) {
		return false; // It's o.k.  Don't descend deeper.

	} else {
		return false; // e.g. a NameQualifiedType's qualifier, which can be a package binding
	}

	//Descend deeper:
	return true;
}
 
Example 6
Source File: BindingLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static int getAdornmentFlags(IBinding binding) {
	int adornments= 0;
	final int modifiers= binding.getModifiers();
	if (Modifier.isAbstract(modifiers))
		adornments|= JavaElementImageDescriptor.ABSTRACT;
	if (Modifier.isFinal(modifiers))
		adornments|= JavaElementImageDescriptor.FINAL;
	if (Modifier.isStatic(modifiers))
		adornments|= JavaElementImageDescriptor.STATIC;
	
	if (binding.isDeprecated())
		adornments|= JavaElementImageDescriptor.DEPRECATED;
	
	if (binding instanceof IMethodBinding) {
		if (((IMethodBinding) binding).isConstructor())
			adornments|= JavaElementImageDescriptor.CONSTRUCTOR;
		if (Modifier.isSynchronized(modifiers))
			adornments|= JavaElementImageDescriptor.SYNCHRONIZED;
		if (Modifier.isNative(modifiers))
			adornments|= JavaElementImageDescriptor.NATIVE;
		ITypeBinding type= ((IMethodBinding) binding).getDeclaringClass();
		if (type.isInterface() && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers))
			adornments|= JavaElementImageDescriptor.DEFAULT_METHOD;
		if (((IMethodBinding) binding).getDefaultValue() != null)
			adornments|= JavaElementImageDescriptor.ANNOTATION_DEFAULT;
	}
	if (binding instanceof IVariableBinding && ((IVariableBinding) binding).isField()) {
		if (Modifier.isTransient(modifiers))
			adornments|= JavaElementImageDescriptor.TRANSIENT;
		if (Modifier.isVolatile(modifiers))
			adornments|= JavaElementImageDescriptor.VOLATILE;
	}
	return adornments;
}
 
Example 7
Source File: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	SimpleName node= token.getNode();
	if (node.isDeclaration())
		return false;

	IBinding binding= token.getBinding();
	return binding != null && binding.getKind() == IBinding.METHOD && (binding.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
}
 
Example 8
Source File: ConstantChecks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean visitName(Name name) {
	IBinding binding= name.resolveBinding();
	if(binding == null) {
		/* If the binding is null because of compile errors etc.,
		   scenarios which may have been deemed unacceptable in
		   the presence of semantic information will be admitted.
		   Descend deeper.
		 */
		 return true;
	}

	int modifiers= binding.getModifiers();
	if(binding instanceof IVariableBinding) {
		if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers))) {
			fResult= false;
			return false;
		}
	} else if(binding instanceof IMethodBinding) {
		if (!Modifier.isStatic(modifiers)) {
			fResult= false;
			return false;
		}
	} else if(binding instanceof ITypeBinding) {
		return false; // It's o.k.  Don't descend deeper.

	} else {
		return false; // e.g. a NameQualifiedType's qualifier, which can be a package binding
	}

	//Descend deeper:
	return true;
}
 
Example 9
Source File: InlineConstantRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isStaticAccess(SimpleName memberName) {
	IBinding binding= memberName.resolveBinding();
	Assert.isTrue(binding instanceof IVariableBinding || binding instanceof IMethodBinding || binding instanceof ITypeBinding);

	if (binding instanceof ITypeBinding)
		return true;

	if (binding instanceof IVariableBinding)
		return ((IVariableBinding) binding).isField();

	int modifiers= binding.getModifiers();
	return Modifier.isStatic(modifiers);
}
 
Example 10
Source File: TokenModifiers.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean applies(IBinding binding) {
    int flags = binding.getModifiers();
    if ((flags & Modifier.STATIC) != 0) {
        return true;
    }
    return false;
}
 
Example 11
Source File: SemanticHighlightings.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	SimpleName node = token.getNode();
	if (node.isDeclaration()) {
		return false;
	}

	IBinding binding = token.getBinding();
	return binding != null && binding.getKind() == IBinding.METHOD && (binding.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
}
 
Example 12
Source File: TokenModifiers.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean applies(IBinding binding) {
    int flags = binding.getModifiers();
    if ((flags & Modifier.ABSTRACT) != 0) {
        return true;
    }
    return false;
}
 
Example 13
Source File: TokenModifiers.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean applies(IBinding binding) {
    int flags = binding.getModifiers();
    if ((flags & Modifier.PROTECTED) != 0) {
        return true;
    }
    return false;
}
 
Example 14
Source File: TokenModifiers.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean applies(IBinding binding) {
    int flags = binding.getModifiers();
    if ((flags & Modifier.PRIVATE) != 0) {
        return true;
    }
    return false;
}
 
Example 15
Source File: TokenModifiers.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean applies(IBinding binding) {
    int flags = binding.getModifiers();
    if ((flags & Modifier.PUBLIC) != 0) {
        return true;
    }
    return false;
}
 
Example 16
Source File: TokenModifiers.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean applies(IBinding binding) {
    int flags = binding.getModifiers();
    if ((flags & Modifier.FINAL) != 0) {
        return true;
    }
    return false;
}
 
Example 17
Source File: SemanticHighlightings.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	IBinding binding = token.getBinding();
	return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding) binding).isField() && (binding.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
}
 
Example 18
Source File: SemanticHighlightings.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	IBinding binding = token.getBinding();
	return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding) binding).isField() && (binding.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) == (Modifier.FINAL | Modifier.STATIC);
}
 
Example 19
Source File: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	IBinding binding= token.getBinding();
	return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding)binding).isField() && (binding.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) == (Modifier.FINAL | Modifier.STATIC);
}
 
Example 20
Source File: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	IBinding binding= token.getBinding();
	return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding)binding).isField() && (binding.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
}