Java Code Examples for org.eclipse.jdt.core.dom.SimpleName#isDeclaration()

The following examples show how to use org.eclipse.jdt.core.dom.SimpleName#isDeclaration() . 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(final SemanticToken token) {
	final SimpleName node= token.getNode();
	if (node.isDeclaration()) {
		return false;
	}

	final IBinding binding= token.getBinding();
	if (binding == null || binding.getKind() != IBinding.VARIABLE) {
		return false;
	}

	ITypeBinding currentType= Bindings.getBindingOfParentType(node);
	ITypeBinding declaringType= ((IVariableBinding) binding).getDeclaringClass();
	if (declaringType == null || currentType == declaringType)
		return false;

	return Bindings.isSuperType(declaringType, currentType);
}
 
Example 2
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();
	if (binding == null || binding.getKind() != IBinding.METHOD)
		return false;

	ITypeBinding currentType= Bindings.getBindingOfParentType(node);
	ITypeBinding declaringType= ((IMethodBinding) binding).getDeclaringClass();
	if (currentType == declaringType || currentType == null)
		return false;

	return Bindings.isSuperType(declaringType, currentType);
}
 
Example 3
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 4
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void endVisit(SimpleName node) {
	if (skipNode(node) || node.isDeclaration())
		return;
	IBinding binding= node.resolveBinding();
	if (binding instanceof IVariableBinding) {
		IVariableBinding variable= (IVariableBinding)binding;
		if (!variable.isField()) {
			setFlowInfo(node, new LocalFlowInfo(
				variable,
				FlowInfo.READ,
				fFlowContext));
		}
	} else if (binding instanceof ITypeBinding) {
		ITypeBinding type= (ITypeBinding)binding;
		if (type.isTypeVariable()) {
			setFlowInfo(node, new TypeVariableFlowInfo(type, fFlowContext));
		}
	}
}
 
Example 5
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void endVisit(SimpleName node) {
	if (skipNode(node) || node.isDeclaration()) {
		return;
	}
	IBinding binding = node.resolveBinding();
	if (binding instanceof IVariableBinding) {
		IVariableBinding variable = (IVariableBinding) binding;
		if (!variable.isField()) {
			setFlowInfo(node, new LocalFlowInfo(variable, FlowInfo.READ, fFlowContext));
		}
	} else if (binding instanceof ITypeBinding) {
		ITypeBinding type = (ITypeBinding) binding;
		if (type.isTypeVariable()) {
			setFlowInfo(node, new TypeVariableFlowInfo(type, fFlowContext));
		}
	}
}
 
Example 6
Source File: SemanticHighlightings.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean consumes(final SemanticToken token) {
	final SimpleName node = token.getNode();
	if (node.isDeclaration()) {
		return false;
	}

	final IBinding binding = token.getBinding();
	if (binding == null || binding.getKind() != IBinding.VARIABLE) {
		return false;
	}

	ITypeBinding currentType = Bindings.getBindingOfParentType(node);
	ITypeBinding declaringType = ((IVariableBinding) binding).getDeclaringClass();
	if (declaringType == null || currentType == declaringType) {
		return false;
	}

	return Bindings.isSuperType(declaringType, currentType);
}
 
Example 7
Source File: SemanticHighlightings.java    From eclipse.jdt.ls with Eclipse Public License 2.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();
	if (binding == null || binding.getKind() != IBinding.METHOD) {
		return false;
	}

	ITypeBinding currentType = Bindings.getBindingOfParentType(node);
	ITypeBinding declaringType = ((IMethodBinding) binding).getDeclaringClass();
	if (currentType == declaringType || currentType == null) {
		return false;
	}

	return Bindings.isSuperType(declaringType, currentType);
}
 
Example 8
Source File: SnippetFinder.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean match(SimpleName candidate, Object s) {
	if (!(s instanceof SimpleName)) {
		return false;
	}

	SimpleName snippet = (SimpleName) s;
	if (candidate.isDeclaration() != snippet.isDeclaration()) {
		return false;
	}

	IBinding cb = candidate.resolveBinding();
	IBinding sb = snippet.resolveBinding();
	if (cb == null || sb == null) {
		return false;
	}
	IVariableBinding vcb = ASTNodes.getVariableBinding(candidate);
	IVariableBinding vsb = ASTNodes.getVariableBinding(snippet);
	if (vcb == null || vsb == null) {
		return Bindings.equals(cb, sb);
	}
	if (!vcb.isField() && !vsb.isField() && Bindings.equals(vcb.getType(), vsb.getType())) {
		SimpleName mapped = fMatch.getMappedName(vsb);
		if (mapped != null) {
			IVariableBinding mappedBinding = ASTNodes.getVariableBinding(mapped);
			if (!Bindings.equals(vcb, mappedBinding)) {
				return false;
			}
		}
		fMatch.addLocal(vsb, candidate);
		return true;
	}
	return Bindings.equals(cb, sb);
}
 
Example 9
Source File: LocalTypeAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(SimpleName node) {
	if (node.isDeclaration()) {
		return true;
	}
	IBinding binding = node.resolveBinding();
	if (binding instanceof ITypeBinding) {
		processLocalTypeBinding((ITypeBinding) binding, fSelection.getVisitSelectionMode(node));
	}

	return true;
}
 
Example 10
Source File: ExtractFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(SimpleName node) {
	ITypeBinding typeBinding = node.resolveTypeBinding();
	if (typeBinding != null && typeBinding.isLocal()) {
		if (node.isDeclaration()) {
			fLocalDefinitions.add(typeBinding);
		} else if (!fLocalDefinitions.contains(typeBinding)) {
			fLocalReferencesToEnclosing.add(node);
		}
	}
	if (typeBinding != null && typeBinding.isTypeVariable()) {
		if (node.isDeclaration()) {
			fLocalDefinitions.add(typeBinding);
		} else if (!fLocalDefinitions.contains(typeBinding)) {
			if (fMethodTypeVariables.contains(typeBinding)) {
				fLocalReferencesToEnclosing.add(node);
			} else {
				fClassTypeVariablesUsed = true;
			}
		}
	}
	IBinding binding = node.resolveBinding();
	if (binding != null && binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) {
		if (node.isDeclaration()) {
			fLocalDefinitions.add(binding);
		} else if (!fLocalDefinitions.contains(binding)) {
			fLocalReferencesToEnclosing.add(node);
		}
	}
	return super.visit(node);
}
 
Example 11
Source File: AccessAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(SimpleName node) {
	if (!node.isDeclaration() && considerBinding(node.resolveBinding(), node)) {
		fReferencingGetter = true;
		fRewriter.replace(node, fRewriter.createStringPlaceholder(fGetter + "()", ASTNode.METHOD_INVOCATION), //$NON-NLS-1$
				createGroupDescription(READ_ACCESS));
	}
	return true;
}
 
Example 12
Source File: MovedMemberAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(SimpleName node) {
	if (node.isDeclaration() || isProcessed(node))
		return super.visit(node);
	IBinding binding= node.resolveBinding();
	if (isMovedMember(binding))
		return super.visit(node);

	if (isSourceAccess(binding))
		rewrite(node, fSource);
	return super.visit(node);
}
 
Example 13
Source File: PromoteTempToFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(SimpleName node) {
	ITypeBinding typeBinding= node.resolveTypeBinding();
	if (typeBinding != null && typeBinding.isLocal()) {
		if (node.isDeclaration()) {
			fLocalDefinitions.add(typeBinding);
		} else if (! fLocalDefinitions.contains(typeBinding)) {
			fLocalReferencesToEnclosing.add(node);
		}
	}
	if (typeBinding != null && typeBinding.isTypeVariable()) {
		if (node.isDeclaration()) {
			fLocalDefinitions.add(typeBinding);
		} else if (! fLocalDefinitions.contains(typeBinding)) {
			if (fMethodTypeVariables.contains(typeBinding)) {
				fLocalReferencesToEnclosing.add(node);
			} else {
				fClassTypeVariablesUsed= true;
			}
		}
	}
	IBinding binding= node.resolveBinding();
	if (binding != null && binding.getKind() == IBinding.VARIABLE && ! ((IVariableBinding)binding).isField()) {
		if (node.isDeclaration()) {
			fLocalDefinitions.add(binding);
		} else if (! fLocalDefinitions.contains(binding)) {
			fLocalReferencesToEnclosing.add(node);
		}
	}
	return super.visit(node);
}
 
Example 14
Source File: SnippetFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean match(SimpleName candidate, Object s) {
	if (!(s instanceof SimpleName))
		return false;

	SimpleName snippet= (SimpleName)s;
	if (candidate.isDeclaration() != snippet.isDeclaration())
		return false;

	IBinding cb= candidate.resolveBinding();
	IBinding sb= snippet.resolveBinding();
	if (cb == null || sb == null)
		return false;
	IVariableBinding vcb= ASTNodes.getVariableBinding(candidate);
	IVariableBinding vsb= ASTNodes.getVariableBinding(snippet);
	if (vcb == null || vsb == null)
		return Bindings.equals(cb, sb);
	if (!vcb.isField() && !vsb.isField() && Bindings.equals(vcb.getType(), vsb.getType())) {
		SimpleName mapped= fMatch.getMappedName(vsb);
		if (mapped != null) {
			IVariableBinding mappedBinding= ASTNodes.getVariableBinding(mapped);
			if (!Bindings.equals(vcb, mappedBinding))
				return false;
		}
		fMatch.addLocal(vsb, candidate);
		return true;
	}
	return Bindings.equals(cb, sb);
}
 
Example 15
Source File: LocalTypeAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(SimpleName node) {
	if (node.isDeclaration())
		return true;
	IBinding binding= node.resolveBinding();
	if (binding instanceof ITypeBinding)
		processLocalTypeBinding((ITypeBinding) binding, fSelection.getVisitSelectionMode(node));

	return true;
}
 
Example 16
Source File: LocalDeclarationAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(SimpleName node) {
	IVariableBinding binding= null;
	if (node.isDeclaration() || !considerNode(node) || (binding= ASTNodes.getLocalVariableBinding(node)) == null)
		return false;
	handleReferenceToLocal(node, binding);
	return true;
}
 
Example 17
Source File: AccessAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(SimpleName node) {
	if (!node.isDeclaration() && considerBinding(node.resolveBinding(), node)) {
		fReferencingGetter= true;
		fRewriter.replace(
			node,
			fRewriter.createStringPlaceholder(fGetter + "()", ASTNode.METHOD_INVOCATION), //$NON-NLS-1$
			createGroupDescription(READ_ACCESS));
	}
	return true;
}
 
Example 18
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 19
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 20
Source File: ReferenceAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(SimpleName node) {
	if (! node.isDeclaration() && isMovedMember(node.resolveBinding()) && ! isProcessed(node))
		rewrite(node, fTarget);
	return false;
}