本文整理汇总了Java中org.eclipse.jdt.internal.corext.dom.ASTNodes.findVariableDeclaration方法的典型用法代码示例。如果您正苦于以下问题:Java ASTNodes.findVariableDeclaration方法的具体用法?Java ASTNodes.findVariableDeclaration怎么用?Java ASTNodes.findVariableDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.dom.ASTNodes
的用法示例。
在下文中一共展示了ASTNodes.findVariableDeclaration方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDeclaration
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private VariableDeclarationStatement createDeclaration(
IVariableBinding binding, Expression intilizer) {
VariableDeclaration original =
ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment();
fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName()));
fragment.setInitializer(intilizer);
VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment);
result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
result.setType(
ASTNodeFactory.newType(
fAST,
original,
fImportRewriter,
new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
return result;
}
示例2: initializeParameterInfos
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private void initializeParameterInfos() {
IVariableBinding[] arguments = fAnalyzer.getArguments();
fParameterInfos = new ArrayList<ParameterInfo>(arguments.length);
ASTNode root = fAnalyzer.getEnclosingBodyDeclaration();
ParameterInfo vararg = null;
for (int i = 0; i < arguments.length; i++) {
IVariableBinding argument = arguments[i];
if (argument == null) continue;
VariableDeclaration declaration = ASTNodes.findVariableDeclaration(argument, root);
boolean isVarargs =
declaration instanceof SingleVariableDeclaration
? ((SingleVariableDeclaration) declaration).isVarargs()
: false;
ParameterInfo info =
new ParameterInfo(argument, getType(declaration, isVarargs), argument.getName(), i);
if (isVarargs) {
vararg = info;
} else {
fParameterInfos.add(info);
}
}
if (vararg != null) {
fParameterInfos.add(vararg);
}
}
示例3: getVariableDeclaration
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static VariableDeclaration getVariableDeclaration(Name node) {
IBinding binding = node.resolveBinding();
if (binding == null && node.getParent() instanceof VariableDeclaration)
return (VariableDeclaration) node.getParent();
if (binding != null && binding.getKind() == IBinding.VARIABLE) {
CompilationUnit cu = (CompilationUnit) ASTNodes.getParent(node, CompilationUnit.class);
return ASTNodes.findVariableDeclaration(((IVariableBinding) binding), cu);
}
return null;
}
示例4: handleReferenceToLocal
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private void handleReferenceToLocal(SimpleName node, IVariableBinding binding) {
VariableDeclaration declaration = ASTNodes.findVariableDeclaration(binding, node);
if (declaration != null && fSelection.covers(declaration)) {
addLocalDeclaration(declaration);
}
}
示例5: initReturnType
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private void initReturnType(ImportRewrite rewriter) {
AST ast = fEnclosingBodyDeclaration.getAST();
fReturnType = null;
fReturnTypeBinding = null;
switch (fReturnKind) {
case ACCESS_TO_LOCAL:
VariableDeclaration declaration =
ASTNodes.findVariableDeclaration(fReturnValue, fEnclosingBodyDeclaration);
fReturnType =
ASTNodeFactory.newType(
ast,
declaration,
rewriter,
new ContextSensitiveImportRewriteContext(declaration, rewriter));
if (declaration.resolveBinding() != null) {
fReturnTypeBinding = declaration.resolveBinding().getType();
}
break;
case EXPRESSION:
Expression expression = (Expression) getFirstSelectedNode();
if (expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
fExpressionBinding = ((ClassInstanceCreation) expression).getType().resolveBinding();
} else {
fExpressionBinding = expression.resolveTypeBinding();
}
if (fExpressionBinding != null) {
if (fExpressionBinding.isNullType()) {
getStatus()
.addFatalError(
RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_null_type,
JavaStatusContext.create(fCUnit, expression));
} else {
ITypeBinding normalizedBinding =
Bindings.normalizeForDeclarationUse(fExpressionBinding, ast);
if (normalizedBinding != null) {
ImportRewriteContext context =
new ContextSensitiveImportRewriteContext(fEnclosingBodyDeclaration, rewriter);
fReturnType = rewriter.addImport(normalizedBinding, ast, context);
fReturnTypeBinding = normalizedBinding;
}
}
} else {
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
fReturnTypeBinding = ast.resolveWellKnownType("void"); // $NON-NLS-1$
getStatus()
.addError(
RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_determine_return_type,
JavaStatusContext.create(fCUnit, expression));
}
break;
case RETURN_STATEMENT_VALUE:
LambdaExpression enclosingLambdaExpr =
ASTResolving.findEnclosingLambdaExpression(getFirstSelectedNode());
if (enclosingLambdaExpr != null) {
fReturnType = ASTNodeFactory.newReturnType(enclosingLambdaExpr, ast, rewriter, null);
IMethodBinding methodBinding = enclosingLambdaExpr.resolveMethodBinding();
fReturnTypeBinding = methodBinding != null ? methodBinding.getReturnType() : null;
} else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) {
fReturnType = ((MethodDeclaration) fEnclosingBodyDeclaration).getReturnType2();
fReturnTypeBinding = fReturnType != null ? fReturnType.resolveBinding() : null;
}
break;
default:
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
fReturnTypeBinding = ast.resolveWellKnownType("void"); // $NON-NLS-1$
}
if (fReturnType == null) {
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
fReturnTypeBinding = ast.resolveWellKnownType("void"); // $NON-NLS-1$
}
}
示例6: getVariableDeclaration
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private VariableDeclaration getVariableDeclaration(ParameterInfo parameter) {
return ASTNodes.findVariableDeclaration(
parameter.getOldBinding(), fAnalyzer.getEnclosingBodyDeclaration());
}
示例7: handleReferenceToLocal
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private void handleReferenceToLocal(SimpleName node, IVariableBinding binding) {
VariableDeclaration declaration = ASTNodes.findVariableDeclaration(binding, node);
if (declaration != null && fSelection.covers(declaration)) addLocalDeclaration(declaration);
}