类org.eclipse.jdt.core.dom.SimpleName源码实例Demo

下面列出了怎么用org.eclipse.jdt.core.dom.SimpleName的API类实例代码及写法,或者点击链接到github查看源代码。

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;
}
 
/**
 * {@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);
}
 
源代码3 项目: lapse-plus   文件: DeclarationInfoManager.java
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;
}
 
源代码4 项目: JDeodorant   文件: MoveMethodRefactoring.java
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;
				}
			}
		}
	}
}
 
源代码5 项目: JDeodorant   文件: AbstractLoopUtilities.java
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;
}
 
源代码6 项目: JDeodorant   文件: PreconditionExaminer.java
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;
}
 
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;
}
 
源代码8 项目: eclipse.jdt.ls   文件: SemanticHighlightings.java
@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();
}
 
源代码9 项目: eclipse.jdt.ls   文件: SemanticHighlightings.java
@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();
}
 
/**
 * {@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);
	}
}
 
源代码11 项目: JDeodorant   文件: MoveMethodRefactoring.java
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;
}
 
@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;
}
 
/**
 * 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());
}
 
源代码14 项目: JDeodorant   文件: MoveMethodRefactoring.java
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);
				}
			}
		}
	}
}
 
/**
 * 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));
}
 
public static TagElement createParamTag(String parameterName, AST ast, IJavaProject javaProject) {
	TagElement paramNode= ast.newTagElement();
	paramNode.setTagName(TagElement.TAG_PARAM);

	SimpleName simpleName= ast.newSimpleName(parameterName);
	paramNode.fragments().add(simpleName);

	TextElement textElement= ast.newTextElement();
	String text= StubUtility.getTodoTaskTag(javaProject);
	if (text != null)
		textElement.setText(text); //TODO: use template with {@todo} ...
	paramNode.fragments().add(textElement);

	return paramNode;
}
 
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()]);
}
 
/**
 * Creates an {@link Assignment} as first expression appearing in an index based
 * <code>for</code> loop's body. This Assignment declares a local variable and initializes it
 * using the {@link List}'s current element identified by the loop index.
 * 
 * @param rewrite the current {@link ASTRewrite} instance
 * @param loopVariableName the name of the index variable in String representation
 * @return a completed {@link Assignment} containing the mentioned declaration and
 *         initialization
 */
private Expression getIndexBasedForBodyAssignment(ASTRewrite rewrite, SimpleName loopVariableName) {
	AST ast= rewrite.getAST();
	ITypeBinding loopOverType= extractElementType(ast);

	Assignment assignResolvedVariable= ast.newAssignment();

	// left hand side
	SimpleName resolvedVariableName= resolveLinkedVariableNameWithProposals(rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
	VariableDeclarationFragment resolvedVariableDeclarationFragment= ast.newVariableDeclarationFragment();
	resolvedVariableDeclarationFragment.setName(resolvedVariableName);
	VariableDeclarationExpression resolvedVariableDeclaration= ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
	resolvedVariableDeclaration.setType(getImportRewrite().addImport(loopOverType, ast, new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
	assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);

	// right hand side
	MethodInvocation invokeGetExpression= ast.newMethodInvocation();
	invokeGetExpression.setName(ast.newSimpleName("get")); //$NON-NLS-1$
	SimpleName indexVariableName= ast.newSimpleName(loopVariableName.getIdentifier());
	addLinkedPosition(rewrite.track(indexVariableName), LinkedPositionGroup.NO_STOP, indexVariableName.getIdentifier());
	invokeGetExpression.arguments().add(indexVariableName);
	invokeGetExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
	assignResolvedVariable.setRightHandSide(invokeGetExpression);

	assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

	return assignResolvedVariable;
}
 
@Override
public boolean visit(SimpleName node) {
	if (fFindUnqualifiedAccesses || fFindUnqualifiedStaticAccesses) {
		handleSimpleName(node);
	}
	return false;
}
 
源代码20 项目: lapse-plus   文件: DeclarationInfoManager.java
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;
}
 
private void importStatically(SimpleName toImport, IBinding binding) {
	String newName= fNewLocationCuRewrite.getImportRewrite().addStaticImport(binding);
	fNewLocationCuRewrite.getImportRemover().registerAddedStaticImport(binding);

	Name newReference= ASTNodeFactory.newName(fInitializerRewrite.getAST(), newName);
	fInitializerRewrite.replace(toImport, newReference, null);
}
 
@Override
public final boolean visit(final SimpleName node) {
	Assert.isNotNull(node);
	if (isFieldAccess(node) && !isTargetAccess(node)) {
		fResult.add(node);
		fStatus.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_this_reference, JavaStatusContext.create(fMethod.getCompilationUnit(), node)));
	}
	return false;
}
 
private RefactoringStatus checkExpression() {
	//TODO: adjust error messages (or generalize for all refactorings on expression-selections?)
	Expression selectedExpression= fSelectedExpression;

	if (selectedExpression instanceof Name && selectedExpression.getParent() instanceof ClassInstanceCreation)
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_name_in_new);
		//TODO: let's just take the CIC automatically (no ambiguity -> no problem -> no dialog ;-)

	if (selectedExpression instanceof NullLiteral) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
	} else if (selectedExpression instanceof ArrayInitializer) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
	} else if (selectedExpression instanceof Assignment) {
		if (selectedExpression.getParent() instanceof Expression)
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
		else
			return null;

	} else if (selectedExpression instanceof SimpleName){
		if ((((SimpleName)selectedExpression)).isDeclaration())
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
		if (selectedExpression.getParent() instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY
				|| selectedExpression.getParent() instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY)
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
	}

	return null;
}
 
private String generateSubclassName(SimpleName variable) {
	String subclassName = "";
	StringTokenizer tokenizer = new StringTokenizer(variable.getIdentifier(),"_");
	while(tokenizer.hasMoreTokens()) {
		String tempName = tokenizer.nextToken().toLowerCase().toString();
		subclassName += tempName.subSequence(0, 1).toString().toUpperCase() + 
		tempName.subSequence(1, tempName.length()).toString();
	}
	return subclassName;
}
 
private static String getThisExpressionQualifier(ITypeBinding declaringClass, ImportRewrite imports, SimpleName name) {
	ITypeBinding parentType= Bindings.getBindingOfParentType(name);
	ITypeBinding currType= parentType;
	while (currType != null && !Bindings.isSuperType(declaringClass, currType)) {
		currType= currType.getDeclaringClass();
	}
	if (currType == null) {
		declaringClass= declaringClass.getTypeDeclaration();
		currType= parentType;
		while (currType != null && !Bindings.isSuperType(declaringClass, currType)) {
			currType= currType.getDeclaringClass();
		}
	}
	if (currType != parentType) {
		if (currType == null)
			return null;

		if (currType.isAnonymous())
			//If we access a field of a super class of an anonymous class
			//then we can only qualify with 'this' but not with outer.this
			//see bug 115277
			return null;

		return imports.addImport(currType);
	} else {
		return ""; //$NON-NLS-1$
	}
}
 
@Override
public boolean visit(SimpleName node) {
	IBinding binding= node.resolveBinding();
	if (binding == null && !status.hasFatalError()) {
		// fixes bug #42753
		if (!ASTNodes.isLabel(node)) {
			status.addFatalError(
				RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_declaration_has_errors,
				JavaStatusContext.create(fTypeRoot, fDeclaration));
			return false;
		}
	}
	return true;
}
 
源代码27 项目: SimFix   文件: Purification.java
public boolean visit(SimpleName node){
	String name = node.getIdentifier();
	if(name.equals("this") || node.getParent().toString().contains(name + "(")){
		return true;
	}
	if(Character.isUpperCase(name.charAt(0))){
		return true;
	}
	variable.add(name);
	return true;
}
 
源代码28 项目: Eclipse-Postfix-Code-Completion   文件: FlowInfo.java
protected void removeLabel(SimpleName label) {
	if (fBranches != null) {
		fBranches.remove(makeString(label));
		if (fBranches.isEmpty())
			fBranches= null;
	}
}
 
private static ASTNode getDeclaringNode(ASTNode selectedNode) {
	ASTNode declaringNode= null;
	if (selectedNode instanceof MethodDeclaration) {
		declaringNode= selectedNode;
	} else if (selectedNode instanceof SimpleName) {
		StructuralPropertyDescriptor locationInParent= selectedNode.getLocationInParent();
		if (locationInParent == MethodDeclaration.NAME_PROPERTY || locationInParent == TypeDeclaration.NAME_PROPERTY) {
			declaringNode= selectedNode.getParent();
		} else if (locationInParent == VariableDeclarationFragment.NAME_PROPERTY) {
			declaringNode= selectedNode.getParent().getParent();
		}
	}
	return declaringNode;
}
 
源代码30 项目: eclipse.jdt.ls   文件: ExtractFieldRefactoring.java
private RefactoringStatus checkExpression() throws JavaModelException {
	Expression selectedExpression = getSelectedExpression().getAssociatedExpression();
	if (selectedExpression != null) {
		final ASTNode parent = selectedExpression.getParent();
		if (selectedExpression instanceof NullLiteral) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_null_literals);
		} else if (selectedExpression instanceof ArrayInitializer) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_array_initializer);
		} else if (selectedExpression instanceof Assignment) {
			if (parent instanceof Expression && !(parent instanceof ParenthesizedExpression)) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_assignment);
			} else {
				return null;
			}
		} else if (selectedExpression instanceof SimpleName) {
			if ((((SimpleName) selectedExpression)).isDeclaration()) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_names_in_declarations);
			}
			if (parent instanceof QualifiedName && selectedExpression.getLocationInParent() == QualifiedName.NAME_PROPERTY || parent instanceof FieldAccess && selectedExpression.getLocationInParent() == FieldAccess.NAME_PROPERTY) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_select_expression);
			}
		} else if (selectedExpression instanceof VariableDeclarationExpression && parent instanceof TryStatement) {
			return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractTempRefactoring_resource_in_try_with_resources);
		}
	}

	return null;
}
 
 类所在包
 同包方法