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

The following examples show how to use org.eclipse.jdt.core.dom.IVariableBinding#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: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
protected JvmField createField(StringBuilder typeName, IVariableBinding field) {
	JvmField result;
	if (!field.isEnumConstant()) {
		result = TypesFactory.eINSTANCE.createJvmField();
		Object constantValue = field.getConstantValue();
		if (constantValue != null) {
			result.setConstant(true);
			result.setConstantValue(constantValue);
		} else {
			result.setConstant(false);
		}
	} else
		result = TypesFactory.eINSTANCE.createJvmEnumerationLiteral();
	String name = field.getName();
	result.internalSetIdentifier(typeName.append(name).toString());
	result.setSimpleName(name);
	int modifiers = field.getModifiers();
	result.setFinal(Modifier.isFinal(modifiers));
	result.setStatic(Modifier.isStatic(modifiers));
	result.setTransient(Modifier.isTransient(modifiers));
	result.setVolatile(Modifier.isVolatile(modifiers));
	result.setDeprecated(field.isDeprecated());
	setVisibility(result, modifiers);
	result.setType(createTypeReference(field.getType()));
	createAnnotationValues(field, result);
	return result;
}
 
Example 2
Source File: AddArgumentCorrectionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private boolean testModifier(IVariableBinding curr) {
	int modifiers= curr.getModifiers();
	int staticFinal= Modifier.STATIC | Modifier.FINAL;
	if ((modifiers & staticFinal) == staticFinal) {
		return false;
	}
	if (Modifier.isStatic(modifiers) && !ASTResolving.isInStaticContext(fCallerNode)) {
		return false;
	}
	return true;
}
 
Example 3
Source File: MissingReturnTypeCorrectionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean testModifier(IVariableBinding curr) {
	int modifiers= curr.getModifiers();
	int staticFinal= Modifier.STATIC | Modifier.FINAL;
	if ((modifiers & staticFinal) == staticFinal) {
		return false;
	}
	if (Modifier.isStatic(modifiers) && !Modifier.isStatic(getModifiers())) {
		return false;
	}
	return true;
}
 
Example 4
Source File: ParameterObjectFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ExpressionStatement createInitializer(ParameterInfo pi, String paramName, CompilationUnitRewrite cuRewrite) {
	AST ast= cuRewrite.getAST();

	VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
	fragment.setName(ast.newSimpleName(pi.getOldName()));
	fragment.setInitializer(createFieldReadAccess(pi, paramName, ast, cuRewrite.getCu().getJavaProject(), false, null));
	VariableDeclarationExpression declaration= ast.newVariableDeclarationExpression(fragment);
	IVariableBinding variable= pi.getOldBinding();
	declaration.setType(importBinding(pi.getNewTypeBinding(), cuRewrite));
	int modifiers= variable.getModifiers();
	List<Modifier> newModifiers= ast.newModifiers(modifiers);
	declaration.modifiers().addAll(newModifiers);
	return ast.newExpressionStatement(declaration);
}
 
Example 5
Source File: VariableDeclarationFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean canAddFinal(IBinding binding, ASTNode declNode) {
	if (!(binding instanceof IVariableBinding))
		return false;

	IVariableBinding varbinding= (IVariableBinding)binding;
	int modifiers= varbinding.getModifiers();
	if (Modifier.isFinal(modifiers) || Modifier.isVolatile(modifiers) || Modifier.isTransient(modifiers))
		return false;

	ASTNode parent= ASTNodes.getParent(declNode, VariableDeclarationExpression.class);
	if (parent != null && ((VariableDeclarationExpression)parent).fragments().size() > 1)
		return false;

	if (varbinding.isField() && !Modifier.isPrivate(modifiers))
		return false;

	if (varbinding.isParameter()) {
		ASTNode varDecl= declNode.getParent();
		if (varDecl instanceof MethodDeclaration) {
			MethodDeclaration declaration= (MethodDeclaration)varDecl;
			if (declaration.getBody() == null)
				return false;
		}
	}

	return true;
}
 
Example 6
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
boolean markOccurrencesOfType(IBinding binding) {

		if (binding == null)
			return false;

		int kind= binding.getKind();

		if (fMarkTypeOccurrences && kind == IBinding.TYPE)
			return true;

		if (fMarkMethodOccurrences && kind == IBinding.METHOD)
			return true;

		if (kind == IBinding.VARIABLE) {
			IVariableBinding variableBinding= (IVariableBinding)binding;
			if (variableBinding.isField()) {
				int constantModifier= IModifierConstants.ACC_STATIC | IModifierConstants.ACC_FINAL;
				boolean isConstant= (variableBinding.getModifiers() & constantModifier) == constantModifier;
				if (isConstant)
					return fMarkConstantOccurrences;
				else
					return fMarkFieldOccurrences;
			}

			return fMarkLocalVariableypeOccurrences;
		}

		return false;
	}
 
Example 7
Source File: AddArgumentCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean testModifier(IVariableBinding curr) {
	int modifiers= curr.getModifiers();
	int staticFinal= Modifier.STATIC | Modifier.FINAL;
	if ((modifiers & staticFinal) == staticFinal) {
		return false;
	}
	if (Modifier.isStatic(modifiers) && !ASTResolving.isInStaticContext(fCallerNode)) {
		return false;
	}
	return true;
}
 
Example 8
Source File: MissingReturnTypeCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean testModifier(IVariableBinding curr) {
	int modifiers= curr.getModifiers();
	int staticFinal= Modifier.STATIC | Modifier.FINAL;
	if ((modifiers & staticFinal) == staticFinal) {
		return false;
	}
	if (Modifier.isStatic(modifiers) && !Modifier.isStatic(getModifiers())) {
		return false;
	}
	return true;
}
 
Example 9
Source File: BindingLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ImageDescriptor getFieldImageDescriptor(IVariableBinding binding) {
	final int modifiers= binding.getModifiers();
	if (Modifier.isPublic(modifiers) || binding.isEnumConstant())
		return JavaPluginImages.DESC_FIELD_PUBLIC;
	if (Modifier.isProtected(modifiers))
		return JavaPluginImages.DESC_FIELD_PROTECTED;
	if (Modifier.isPrivate(modifiers))
		return JavaPluginImages.DESC_FIELD_PRIVATE;

	return JavaPluginImages.DESC_FIELD_DEFAULT;
}
 
Example 10
Source File: AbstractVariable.java    From JDeodorant with MIT License 5 votes vote down vote up
public AbstractVariable(VariableDeclaration name) {
	IVariableBinding variableBinding = name.resolveBinding();
	this.variableBindingKey = variableBinding.getKey();
	this.variableName = variableBinding.getName();
	this.variableType = variableBinding.getType().getQualifiedName();
	this.isField = variableBinding.isField();
	this.isParameter = variableBinding.isParameter();
	this.isStatic = (variableBinding.getModifiers() & Modifier.STATIC) != 0;
}
 
Example 11
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
private boolean isNamedConstant(ASTNode node){
	if (node instanceof SimpleName){
		SimpleName simpleName = (SimpleName) node;
		IBinding binding = simpleName.resolveBinding();
		if(binding != null && binding.getKind() == IBinding.VARIABLE) {
			IVariableBinding variableBinding = (IVariableBinding)binding;
			if(variableBinding.isField() && (variableBinding.getModifiers() & Modifier.STATIC) != 0) 
				return true;
		}
	}
	return false;
}
 
Example 12
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
private boolean isNonStaticField(ASTNode node){
	if (node instanceof SimpleName){
		SimpleName simpleName = (SimpleName) node;
		IBinding binding = simpleName.resolveBinding();
		if(binding != null && binding.getKind() == IBinding.VARIABLE) {
			IVariableBinding variableBinding = (IVariableBinding)binding;
			if(variableBinding.isField() && (variableBinding.getModifiers() & Modifier.STATIC) == 0) 
				return true;
		}
	}
	return false;
}
 
Example 13
Source File: AbstractVariable.java    From JDeodorant with MIT License 4 votes vote down vote up
public AbstractVariable(IVariableBinding variableBinding) {
	this(variableBinding.getKey(), variableBinding.getName(), variableBinding.getType().getQualifiedName(),
			variableBinding.isField(), variableBinding.isParameter(), (variableBinding.getModifiers() & Modifier.STATIC) != 0);
}