當前位置: 首頁>>代碼示例>>Java>>正文


Java AST.newSimpleName方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.AST.newSimpleName方法的典型用法代碼示例。如果您正苦於以下問題:Java AST.newSimpleName方法的具體用法?Java AST.newSimpleName怎麽用?Java AST.newSimpleName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.AST的用法示例。


在下文中一共展示了AST.newSimpleName方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createStaticMethodInvocation

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
public MethodInvocation createStaticMethodInvocation(AST ast, String className, String methodName) {
    SimpleName typeName = ast.newSimpleName(className);

    MethodInvocation methodInvocation = ast.newMethodInvocation();
    methodInvocation.setName(ast.newSimpleName(methodName));
    methodInvocation.setExpression(typeName);

    return methodInvocation;
}
 
開發者ID:helospark,項目名稱:SparkBuilderGenerator,代碼行數:10,代碼來源:StaticMethodInvocationFragment.java

示例2: computeProposals

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
@Override
protected Expression computeProposals(AST ast, ITypeBinding returnBinding, int returnOffset, CompilationUnit root, Expression result) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);

	org.eclipse.jdt.core.dom.NodeFinder finder= new org.eclipse.jdt.core.dom.NodeFinder(root, returnOffset, 0);
	ASTNode varDeclFrag= ASTResolving.findAncestor(finder.getCoveringNode(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
	IVariableBinding varDeclFragBinding= null;
	if (varDeclFrag != null)
		varDeclFragBinding= ((VariableDeclarationFragment) varDeclFrag).resolveBinding();
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		// Bindings are compared to make sure that a lambda does not return a variable which is yet to be initialised.
		if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr) && !Bindings.equals(curr, varDeclFragBinding)) {
			if (result == null) {
				result= ast.newSimpleName(curr.getName());
			}
			addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName());
		}
	}
	return result;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:24,代碼來源:MissingReturnTypeInLambdaCorrectionProposal.java

示例3: evaluateArgumentExpressions

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
private Expression evaluateArgumentExpressions(AST ast, ITypeBinding requiredType, String key) {
	CompilationUnit root= (CompilationUnit) fCallerNode.getRoot();

	int offset= fCallerNode.getStartPosition();
	Expression best= null;
	ITypeBinding bestType= null;

	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(offset, ScopeAnalyzer.VARIABLES);
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		if (type != null && canAssign(type, requiredType) && testModifier(curr)) {
			if (best == null || isMoreSpecific(bestType, type)) {
				best= ast.newSimpleName(curr.getName());
				bestType= type;
			}
		}
	}
	Expression defaultExpression= ASTNodeFactory.newDefaultExpression(ast, requiredType);
	if (best == null) {
		best= defaultExpression;
	}
	return best;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:26,代碼來源:AddArgumentCorrectionProposal.java

示例4: testExtractTypeNameWithoutGenerics

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
@Test
public void testExtractTypeNameWithoutGenerics() {
  AST ast = AST.newAST(AST.JLS4);
  org.eclipse.jdt.core.dom.SimpleName entry = ast.newSimpleName("Entry");
  ParameterizedType map = ast.newParameterizedType(ast.newSimpleType(ast.newSimpleName("Map")));
  map.typeArguments().add(ast.newSimpleType(ast.newSimpleName("Foo")));
  QualifiedType type = ast.newQualifiedType(map, entry);
  assertThat(type.toString()).isEqualTo("Map<Foo>.Entry");
  assertThat(ReferencedClassesParser.extractTypeNameWithoutGenerics(type)).isEqualTo("Map.Entry");
}
 
開發者ID:bazelbuild,項目名稱:BUILD_file_generator,代碼行數:11,代碼來源:ReferencedClassesParserTest.java

示例5: getNewName

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
private SimpleName getNewName(ASTRewrite rewrite) {
	try {
		AST ast = rewrite.getAST();
		SimpleName newNameNode = ast.newSimpleName(getFunctionName());
		return newNameNode;
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Get newname for getter/setter ", e);
	}
	return null;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:11,代碼來源:SelfEncapsulateFieldProposal.java

示例6: computeProposals

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
protected Expression computeProposals(AST ast, ITypeBinding returnBinding, int returnOffset, CompilationUnit root, Expression result) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr)) {
			if (result == null) {
				result= ast.newSimpleName(curr.getName());
			}
			addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName());
		}
	}
	return result;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:16,代碼來源:MissingReturnTypeCorrectionProposal.java

示例7: getNewName

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
private SimpleName getNewName(ASTRewrite rewrite) {
	AST ast= rewrite.getAST();
	String name;
	if (fInvocationNode.getLocationInParent() == MemberValuePair.NAME_PROPERTY) {
		name= ((SimpleName) fInvocationNode).getIdentifier();
	} else {
		name= "value"; //$NON-NLS-1$
	}


	SimpleName newNameNode= ast.newSimpleName(name);
	return newNameNode;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:14,代碼來源:NewAnnotationMemberProposal.java

示例8: getNewName

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
@Override
protected SimpleName getNewName(ASTRewrite rewrite) {
	ASTNode invocationNode= getInvocationNode();
	String name;
	if (invocationNode instanceof MethodInvocation) {
		name= ((MethodInvocation)invocationNode).getName().getIdentifier();
	} else if (invocationNode instanceof SuperMethodInvocation) {
		name= ((SuperMethodInvocation)invocationNode).getName().getIdentifier();
	} else {
		name= getSenderBinding().getName(); // name of the class
	}
	AST ast= rewrite.getAST();
	SimpleName newNameNode= ast.newSimpleName(name);
	return newNameNode;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:16,代碼來源:NewMethodCorrectionProposal.java

示例9: doAddParam

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
private ASTRewrite doAddParam(CompilationUnit cu) {
	AST ast= cu.getAST();
	SimpleName node= fOriginalNode;

	BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(node);
	if (decl instanceof MethodDeclaration) {
		MethodDeclaration methodDeclaration= (MethodDeclaration) decl;

		ASTRewrite rewrite= ASTRewrite.create(ast);

		ImportRewrite imports= createImportRewrite((CompilationUnit) decl.getRoot());
		ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);

		SingleVariableDeclaration newDecl= ast.newSingleVariableDeclaration();
		newDecl.setType(evaluateVariableType(ast, imports, importRewriteContext, methodDeclaration.resolveBinding(), TypeLocation.PARAMETER));
		newDecl.setName(ast.newSimpleName(node.getIdentifier()));

		ListRewrite listRewriter= rewrite.getListRewrite(decl, MethodDeclaration.PARAMETERS_PROPERTY);
		listRewriter.insertLast(newDecl, null);

		// add javadoc tag
		Javadoc javadoc= methodDeclaration.getJavadoc();
		if (javadoc != null) {
			HashSet<String> leadingNames= new HashSet<>();
			for (Iterator<SingleVariableDeclaration> iter= methodDeclaration.parameters().iterator(); iter.hasNext();) {
				SingleVariableDeclaration curr= iter.next();
				leadingNames.add(curr.getName().getIdentifier());
			}
			SimpleName newTagRef= ast.newSimpleName(node.getIdentifier());

			TagElement newTagElement= ast.newTagElement();
			newTagElement.setTagName(TagElement.TAG_PARAM);
			newTagElement.fragments().add(newTagRef);
			TextElement commentStart= ast.newTextElement();
			newTagElement.fragments().add(commentStart);

			ListRewrite tagsRewriter= rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);
			JavadocTagsSubProcessor.insertTag(tagsRewriter, newTagElement, leadingNames);
		}

		return rewrite;
	}
	return null;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:45,代碼來源:NewVariableCorrectionProposal.java


注:本文中的org.eclipse.jdt.core.dom.AST.newSimpleName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。