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


Java AST.newThisExpression方法代碼示例

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


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

示例1: addQualifierToOuterProposal

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
private static void addQualifierToOuterProposal(IInvocationContext context, MethodInvocation invocationNode,
		IMethodBinding binding, Collection<CUCorrectionProposal> proposals) {
	ITypeBinding declaringType= binding.getDeclaringClass();
	ITypeBinding parentType= Bindings.getBindingOfParentType(invocationNode);
	ITypeBinding currType= parentType;

	boolean isInstanceMethod= !Modifier.isStatic(binding.getModifiers());

	while (currType != null && !Bindings.isSuperType(declaringType, currType)) {
		if (isInstanceMethod && Modifier.isStatic(currType.getModifiers())) {
			return;
		}
		currType= currType.getDeclaringClass();
	}
	if (currType == null || currType == parentType) {
		return;
	}

	ASTRewrite rewrite= ASTRewrite.create(invocationNode.getAST());

	String label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changetoouter_description,
			ASTResolving.getTypeSignature(currType));
	ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(),
			rewrite, IProposalRelevance.QUALIFY_WITH_ENCLOSING_TYPE);

	ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
	ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(invocationNode, imports);
	AST ast= invocationNode.getAST();

	String qualifier= imports.addImport(currType, importRewriteContext);
	Name name= ASTNodeFactory.newName(ast, qualifier);

	Expression newExpression;
	if (isInstanceMethod) {
		ThisExpression expr= ast.newThisExpression();
		expr.setQualifier(name);
		newExpression= expr;
	} else {
		newExpression= name;
	}

	rewrite.set(invocationNode, MethodInvocation.EXPRESSION_PROPERTY, newExpression, null);

	proposals.add(proposal);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:46,代碼來源:UnresolvedElementsSubProcessor.java


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