org.eclipse.jdt.core.dom.SimpleName Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.SimpleName. 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: AbstractLoopUtilities.java    From JDeodorant with MIT License 6 votes vote down vote up
private static List<SimpleName> getOccurrencesOfSimpleName(Expression expression, SimpleName simpleName)
{
	List<SimpleName> returnList = new ArrayList<SimpleName>();
	ExpressionExtractor expressionExtractor = new ExpressionExtractor();
	List<Expression> simpleNames = expressionExtractor.getVariableInstructions(expression);
	for (Expression currentExpression : simpleNames)
	{
		SimpleName currentSimpleName = (SimpleName)currentExpression;
		IBinding currentSimpleNameBinding = currentSimpleName.resolveBinding();
		if (currentSimpleNameBinding != null && currentSimpleNameBinding.isEqualTo(simpleName.resolveBinding()))
		{
			returnList.add(currentSimpleName);
		}
	}
	return returnList;
}
 
Example #2
Source File: DeclarationInfoManager.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
public VariableDeclaration getVariableDeclaration(SimpleName name) {
	ASTNode node = name;
	do {
		node = node.getParent();
	} while ( node != null && !(node instanceof MethodDeclaration) );
	
	String key = null;
	
	if(node != null) {
		key = node.toString() + "/" + name.getFullyQualifiedName();
	}else {
		key = "GLOBAL" + name.getFullyQualifiedName();	
	}
	
	logError("Trying " + key);
	VariableDeclaration var = getVariableDeclaration(key);
	if(var == null && node != null) {
		key = "GLOBAL" + name.getFullyQualifiedName();
		log("Trying " + key);
		var = getVariableDeclaration(key);
	}
	
	return var;
}
 
Example #3
Source File: NewVariableCorrectionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) {
	SimpleName node= fOriginalNode;

	ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding);
	if (newTypeDecl == null) {
		astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
		newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
	}

	if (newTypeDecl != null) {
		AST ast= newTypeDecl.getAST();

		ASTRewrite rewrite= ASTRewrite.create(ast);

		EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration();
		constDecl.setName(ast.newSimpleName(node.getIdentifier()));

		ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY);
		listRewriter.insertLast(constDecl, null);

		return rewrite;
	}
	return null;
}
 
Example #4
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
	ASTRewrite rewrite= cuRewrite.getASTRewrite();
	TextEditGroup group= createTextEditGroup(getDescription(), cuRewrite);
	AST ast= rewrite.getAST();

	FieldAccess fieldAccess= ast.newFieldAccess();

	ThisExpression thisExpression= ast.newThisExpression();
	if (fQualifier != null)
		thisExpression.setQualifier(ast.newName(fQualifier));

	fieldAccess.setExpression(thisExpression);
	fieldAccess.setName((SimpleName) rewrite.createMoveTarget(fName));

	rewrite.replace(fName, fieldAccess, group);
}
 
Example #5
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void removeParamTagElementFromJavadoc(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter, String parameterToBeRemoved) {
	if(newMethodDeclaration.getJavadoc() != null) {
		Javadoc javadoc = newMethodDeclaration.getJavadoc();
		List<TagElement> tags = javadoc.tags();
		for(TagElement tag : tags) {
			if(tag.getTagName() != null && tag.getTagName().equals(TagElement.TAG_PARAM)) {
				List<ASTNode> tagFragments = tag.fragments();
				boolean paramFound = false;
				for(ASTNode node : tagFragments) {
					if(node instanceof SimpleName) {
						SimpleName simpleName = (SimpleName)node;
						if(simpleName.getIdentifier().equals(parameterToBeRemoved)) {
							paramFound = true;
							break;
						}
					}
				}
				if(paramFound) {
					ListRewrite tagsRewrite = targetRewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);
					tagsRewrite.remove(tag, null);
					break;
				}
			}
		}
	}
}
 
Example #6
Source File: PreconditionExaminer.java    From JDeodorant with MIT License 6 votes vote down vote up
private boolean isVariableWithTypeMismatchDifference(Expression expression1, Expression expression2, ASTNodeDifference difference) {
	if(expression1 instanceof SimpleName && expression2 instanceof SimpleName) {
		SimpleName simpleName1 = (SimpleName)expression1;
		SimpleName simpleName2 = (SimpleName)expression2;
		IBinding binding1 = simpleName1.resolveBinding();
		IBinding binding2 = simpleName2.resolveBinding();
		//check if both simpleNames refer to variables
		if(binding1 != null && binding1.getKind() == IBinding.VARIABLE && binding2 != null && binding2.getKind() == IBinding.VARIABLE) {
			List<Difference> differences = difference.getDifferences();
			if(differences.size() == 1) {
				Difference diff = differences.get(0);
				if(diff.getType().equals(DifferenceType.SUBCLASS_TYPE_MISMATCH) || diff.getType().equals(DifferenceType.VARIABLE_TYPE_MISMATCH)) {
					return true;
				}
			}
		}
	}
	return false;
}
 
Example #7
Source File: ExtractClassRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Expression handleSimpleNameAssignment(ASTNode replaceNode, ParameterObjectFactory pof, String parameterName, AST ast, IJavaProject javaProject, boolean useSuper) {
	if (replaceNode instanceof Assignment) {
		Assignment assignment= (Assignment) replaceNode;
		Expression rightHandSide= assignment.getRightHandSide();
		if (rightHandSide.getNodeType() == ASTNode.SIMPLE_NAME) {
			SimpleName sn= (SimpleName) rightHandSide;
			IVariableBinding binding= ASTNodes.getVariableBinding(sn);
			if (binding != null && binding.isField()) {
				if (fDescriptor.getType().getFullyQualifiedName().equals(binding.getDeclaringClass().getQualifiedName())) {
					FieldInfo fieldInfo= getFieldInfo(binding.getName());
					if (fieldInfo != null && binding == fieldInfo.pi.getOldBinding()) {
						return pof.createFieldReadAccess(fieldInfo.pi, parameterName, ast, javaProject, useSuper, null);
					}
				}
			}
		}
	}
	return null;
}
 
Example #8
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) {

	// 1: match types
	SimpleName name = token.getNode();
	ASTNode node = name.getParent();
	int nodeType = node.getNodeType();
	if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION
			&& nodeType != ASTNode.METHOD_INVOCATION) {
		return false;
	}
	while (nodeType == ASTNode.QUALIFIED_NAME) {
		node = node.getParent();
		nodeType = node.getNodeType();
		if (nodeType == ASTNode.IMPORT_DECLARATION) {
			return false;
		}
	}

	// 2: match classes
	IBinding binding = token.getBinding();
	return binding instanceof ITypeBinding && ((ITypeBinding) binding).isClass();
}
 
Example #9
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) {

	// 1: match types
	SimpleName name = token.getNode();
	ASTNode node = name.getParent();
	int nodeType = node.getNodeType();
	if (nodeType != ASTNode.METHOD_INVOCATION && nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.QUALIFIED_NAME
			&& nodeType != ASTNode.ENUM_DECLARATION) {
		return false;
	}
	while (nodeType == ASTNode.QUALIFIED_NAME) {
		node = node.getParent();
		nodeType = node.getNodeType();
		if (nodeType == ASTNode.IMPORT_DECLARATION) {
			return false;
		}
	}

	// 2: match enums
	IBinding binding = token.getBinding();
	return binding instanceof ITypeBinding && ((ITypeBinding) binding).isEnum();
}
 
Example #10
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
	ASTRewrite rewrite= cuRewrite.getASTRewrite();
	CompilationUnit compilationUnit= cuRewrite.getRoot();
	importType(fDeclaringClass, fName, cuRewrite.getImportRewrite(), compilationUnit);
	TextEditGroup group;
	if (fName.resolveBinding() instanceof IMethodBinding) {
		group= createTextEditGroup(FixMessages.CodeStyleFix_QualifyMethodWithDeclClass_description, cuRewrite);
	} else {
		group= createTextEditGroup(FixMessages.CodeStyleFix_QualifyFieldWithDeclClass_description, cuRewrite);
	}
	IJavaElement javaElement= fDeclaringClass.getJavaElement();
	if (javaElement instanceof IType) {
		Name qualifierName= compilationUnit.getAST().newName(((IType)javaElement).getElementName());
		SimpleName simpleName= (SimpleName)rewrite.createMoveTarget(fName);
		QualifiedName qualifiedName= compilationUnit.getAST().newQualifiedName(qualifierName, simpleName);
		rewrite.replace(fName, qualifiedName, group);
	}
}
 
Example #11
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private SimpleName addSourceClassParameterToMovedMethod(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter) {
	AST ast = newMethodDeclaration.getAST();
	SingleVariableDeclaration parameter = ast.newSingleVariableDeclaration();
	SimpleName typeName = ast.newSimpleName(sourceTypeDeclaration.getName().getIdentifier());
	Type parameterType = ast.newSimpleType(typeName);
	targetRewriter.set(parameter, SingleVariableDeclaration.TYPE_PROPERTY, parameterType, null);
	String sourceTypeName = sourceTypeDeclaration.getName().getIdentifier();
	SimpleName parameterName = ast.newSimpleName(sourceTypeName.replaceFirst(Character.toString(sourceTypeName.charAt(0)), Character.toString(Character.toLowerCase(sourceTypeName.charAt(0)))));
	targetRewriter.set(parameter, SingleVariableDeclaration.NAME_PROPERTY, parameterName, null);
	ListRewrite parametersRewrite = targetRewriter.getListRewrite(newMethodDeclaration, MethodDeclaration.PARAMETERS_PROPERTY);
	parametersRewrite.insertLast(parameter, null);
	this.additionalArgumentsAddedToMovedMethod.add("this");
	this.additionalTypeBindingsToBeImportedInTargetClass.add(sourceTypeDeclaration.resolveBinding());
	addParamTagElementToJavadoc(newMethodDeclaration, targetRewriter, parameterName.getIdentifier());
	setPublicModifierToSourceTypeDeclaration();
	return parameterName;
}
 
Example #12
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 #13
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Is the specified name a field access?
 *
 * @param name
 *            the name to check
 * @return <code>true</code> if this name is a field access,
 *         <code>false</code> otherwise
 */
protected static boolean isFieldAccess(final SimpleName name) {
	Assert.isNotNull(name);
	final IBinding binding= name.resolveBinding();
	if (!(binding instanceof IVariableBinding))
		return false;
	final IVariableBinding variable= (IVariableBinding) binding;
	if (!variable.isField())
		return false;
	if ("length".equals(name.getIdentifier())) { //$NON-NLS-1$
		final ASTNode parent= name.getParent();
		if (parent instanceof QualifiedName) {
			final QualifiedName qualified= (QualifiedName) parent;
			final ITypeBinding type= qualified.getQualifier().resolveTypeBinding();
			if (type != null && type.isArray())
				return false;
		}
	}
	return !Modifier.isStatic(variable.getModifiers());
}
 
Example #14
Source File: MoveMethodRefactoring.java    From JDeodorant with MIT License 6 votes vote down vote up
private void replaceThisExpressionWithSourceClassParameterInMethodInvocationArguments(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter) {
	ExpressionExtractor extractor = new ExpressionExtractor();
	List<Expression> methodInvocations = extractor.getMethodInvocations(newMethodDeclaration.getBody());
	for(Expression invocation : methodInvocations) {
		if(invocation instanceof MethodInvocation) {
			MethodInvocation methodInvocation = (MethodInvocation)invocation;
			List<Expression> arguments = methodInvocation.arguments();
			for(Expression argument : arguments) {
				if(argument instanceof ThisExpression) {
					SimpleName parameterName = null;
					if(!additionalArgumentsAddedToMovedMethod.contains("this")) {
						parameterName = addSourceClassParameterToMovedMethod(newMethodDeclaration, targetRewriter);
					}
					else {
						AST ast = newMethodDeclaration.getAST();
						String sourceTypeName = sourceTypeDeclaration.getName().getIdentifier();
						parameterName = ast.newSimpleName(sourceTypeName.replaceFirst(Character.toString(sourceTypeName.charAt(0)), Character.toString(Character.toLowerCase(sourceTypeName.charAt(0)))));
					}
					ListRewrite argumentRewrite = targetRewriter.getListRewrite(methodInvocation, MethodInvocation.ARGUMENTS_PROPERTY);
					argumentRewrite.replace(argument, parameterName, null);
				}
			}
		}
	}
}
 
Example #15
Source File: NullAnnotationsCorrectionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fix for {@link IProblem#NullableFieldReference}
 * @param context context
 * @param problem problem to be fixed
 * @param proposals accumulator for computed proposals
 */
public static void addExtractCheckedLocalProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	CompilationUnit compilationUnit = context.getASTRoot();
	ICompilationUnit cu= (ICompilationUnit) compilationUnit.getJavaElement();

	ASTNode selectedNode= problem.getCoveringNode(compilationUnit);

	SimpleName name= findProblemFieldName(selectedNode, problem.getProblemId());
	if (name == null)
		return;

	ASTNode method= ASTNodes.getParent(selectedNode, MethodDeclaration.class);
	if (method == null)
		method= ASTNodes.getParent(selectedNode, Initializer.class);
	if (method == null)
		return;
	
	proposals.add(new ExtractToNullCheckedLocalProposal(cu, compilationUnit, name, method));
}
 
Example #16
Source File: OrganizeImportsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean needsImport(ITypeBinding typeBinding, SimpleName ref) {
	if (!typeBinding.isTopLevel() && !typeBinding.isMember() || typeBinding.isRecovered()) {
		return false; // no imports for anonymous, local, primitive types or parameters types
	}
	int modifiers= typeBinding.getModifiers();
	if (Modifier.isPrivate(modifiers)) {
		return false; // imports for privates are not required
	}
	ITypeBinding currTypeBinding= Bindings.getBindingOfParentType(ref);
	if (currTypeBinding == null) {
		if (ASTNodes.getParent(ref, ASTNode.PACKAGE_DECLARATION) != null) {
			return true; // reference in package-info.java
		}
		return false; // not in a type
	}
	if (!Modifier.isPublic(modifiers)) {
		if (!currTypeBinding.getPackage().getName().equals(typeBinding.getPackage().getName())) {
			return false; // not visible
		}
	}

	ASTNode parent= ref.getParent();
	while (parent instanceof Type) {
		parent= parent.getParent();
	}
	if (parent instanceof AbstractTypeDeclaration && parent.getParent() instanceof CompilationUnit) {
		return true;
	}

	if (typeBinding.isMember()) {
		if (fAnalyzer.isDeclaredInScope(typeBinding, ref, ScopeAnalyzer.TYPES | ScopeAnalyzer.CHECK_VISIBILITY))
			return false;
	}
	return true;
}
 
Example #17
Source File: FlowInfo.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected void removeLabel(SimpleName label) {
	if (fBranches != null) {
		fBranches.remove(makeString(label));
		if (fBranches.isEmpty()) {
			fBranches = null;
		}
	}
}
 
Example #18
Source File: ConvertAnonymousToNestedRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final boolean visit(final SimpleName node) {
	Assert.isNotNull(node);
	final ITypeBinding binding= node.resolveTypeBinding();
	if (binding != null && binding.isTypeVariable() && !fBindings.containsKey(binding.getKey())) {
		fBindings.put(binding.getKey(), binding);
		fFound.add(binding);
	}
	return true;
}
 
Example #19
Source File: UiBinderJavaValidator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void validateUiFieldExistenceInUiXml(FieldDeclaration uiFieldDecl) {
  List<VariableDeclarationFragment> varDecls = uiFieldDecl.fragments();
  for (VariableDeclarationFragment varDecl : varDecls) {
    SimpleName fieldNameDecl = varDecl.getName();
    validateFieldExistenceInUiXml(
        (TypeDeclaration) uiFieldDecl.getParent(), fieldNameDecl,
        fieldNameDecl.getIdentifier());
  }
}
 
Example #20
Source File: LinkedNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
	ArrayList<SimpleName> res= new ArrayList<SimpleName>();

	ASTNode astRoot = parent.getRoot();
	if (!(astRoot instanceof CompilationUnit)) {
		return null;
	}

	IProblem[] problems= ((CompilationUnit) astRoot).getProblems();
	int nameNodeKind= getNameNodeProblemKind(problems, nameNode);
	if (nameNodeKind == 0) { // no problem on node
		return null;
	}

	int bodyStart= parent.getStartPosition();
	int bodyEnd= bodyStart + parent.getLength();

	String name= nameNode.getIdentifier();

	for (int i= 0; i < problems.length; i++) {
		IProblem curr= problems[i];
		int probStart= curr.getSourceStart();
		int probEnd= curr.getSourceEnd() + 1;

		if (probStart > bodyStart && probEnd < bodyEnd) {
			int currKind= getProblemKind(curr);
			if ((nameNodeKind & currKind) != 0) {
				ASTNode node= NodeFinder.perform(parent, probStart, (probEnd - probStart));
				if (node instanceof SimpleName && name.equals(((SimpleName) node).getIdentifier())) {
					res.add((SimpleName) node);
				}
			}
		}
	}
	return res.toArray(new SimpleName[res.size()]);
}
 
Example #21
Source File: LocalVariableDeclarationObject.java    From JDeodorant with MIT License 5 votes vote down vote up
public VariableDeclaration getVariableDeclaration() {
	//return variableDeclaration;
   	ASTNode node = this.variableDeclaration.recoverASTNode();
   	if(node instanceof SimpleName) {
   		return (VariableDeclaration)node.getParent();
   	}
   	else {
   		return (VariableDeclaration)node;
   	}
}
 
Example #22
Source File: QuickAssistProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static SimpleName getMethodInvocationName(MethodReference methodReference) {
	SimpleName name = null;
	if (methodReference instanceof ExpressionMethodReference) {
		name = ((ExpressionMethodReference) methodReference).getName();
	} else if (methodReference instanceof TypeMethodReference) {
		name = ((TypeMethodReference) methodReference).getName();
	} else if (methodReference instanceof SuperMethodReference) {
		name = ((SuperMethodReference) methodReference).getName();
	}
	return name;
}
 
Example #23
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean hasConflict(int startPosition, SimpleName name, int flag) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer(fCompilationUnit);
	IBinding[] declarationsInScope= analyzer.getDeclarationsInScope(startPosition, flag);
	for (int i= 0; i < declarationsInScope.length; i++) {
		IBinding decl= declarationsInScope[i];
		if (decl.getName().equals(name.getIdentifier()) && name.resolveBinding() != decl)
			return true;
	}
	return false;
}
 
Example #24
Source File: ExtractConstantRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void replaceExpressionsWithConstant() throws JavaModelException {
	ASTRewrite astRewrite= fCuRewrite.getASTRewrite();
	AST ast= astRewrite.getAST();

	IASTFragment[] fragmentsToReplace= getFragmentsToReplace();
	for (int i= 0; i < fragmentsToReplace.length; i++) {
		IASTFragment fragment= fragmentsToReplace[i];
		ASTNode node= fragment.getAssociatedNode();
		boolean inTypeDeclarationAnnotation= isInTypeDeclarationAnnotation(node);
		if (inTypeDeclarationAnnotation && JdtFlags.VISIBILITY_STRING_PRIVATE == getVisibility())
			continue;

		SimpleName ref= ast.newSimpleName(fConstantName);
		Name replacement= ref;
		boolean qualifyReference= qualifyReferencesWithDeclaringClassName();
		if (!qualifyReference) {
			qualifyReference= inTypeDeclarationAnnotation;
		}
		if (qualifyReference) {
			replacement= ast.newQualifiedName(ast.newSimpleName(getContainingTypeBinding().getName()), ref);
		}
		TextEditGroup description= fCuRewrite.createGroupDescription(RefactoringCoreMessages.ExtractConstantRefactoring_replace);

		fragment.replace(astRewrite, replacement, description);
		if (fLinkedProposalModel != null)
			fLinkedProposalModel.getPositionGroup(KEY_NAME, true).addPosition(astRewrite.track(ref), false);
	}
}
 
Example #25
Source File: NewCUProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static String getSimpleName(Name name) {
	if (name.isQualifiedName()) {
		return ((QualifiedName) name).getName().getIdentifier();
	} else {
		return ((SimpleName) name).getIdentifier();
	}
}
 
Example #26
Source File: CodeStyleFix.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 (fFindUnqualifiedAccesses || fFindUnqualifiedStaticAccesses) {
		handleSimpleName(node);
	}
	return false;
}
 
Example #27
Source File: DeclarationInfoManager.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
private String getKey(SimpleName name) {
	String result = null;
	if(fCurrentMethod != null) {
		result = fCurrentMethod.toString() + "/" + name.getFullyQualifiedName();
	}else {
		result = "GLOBAL" + name.getFullyQualifiedName();
	}
	log("Creating key " + result);
	
	return result;
}
 
Example #28
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 #29
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();
	StructuralPropertyDescriptor location = node.getLocationInParent();
	if (location == VariableDeclarationFragment.NAME_PROPERTY || location == SingleVariableDeclaration.NAME_PROPERTY) {
		ASTNode parent = node.getParent();
		if (parent instanceof VariableDeclaration) {
			parent = parent.getParent();
			return parent == null || !(parent instanceof FieldDeclaration);
		}
	}
	return false;
}
 
Example #30
Source File: VariableOrParameterUsageCount.java    From ck with Apache License 2.0 5 votes vote down vote up
public void visit(SimpleName node) {
	if(declaredVariables.contains(node.toString())) {
		String var = node.getIdentifier();
		if (!occurrences.containsKey(var))
			occurrences.put(var, -1);

		occurrences.put(var, occurrences.get(var) + 1);
	}
}