本文整理汇总了Java中org.eclipse.jdt.internal.corext.refactoring.code.Invocations.resolveBinding方法的典型用法代码示例。如果您正苦于以下问题:Java Invocations.resolveBinding方法的具体用法?Java Invocations.resolveBinding怎么用?Java Invocations.resolveBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.refactoring.code.Invocations
的用法示例。
在下文中一共展示了Invocations.resolveBinding方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDeprecatedFieldsToMethodsProposals
import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入方法依赖的package包/类
public static void addDeprecatedFieldsToMethodsProposals(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode instanceof Name) {
IBinding binding = ((Name) selectedNode).resolveBinding();
if (binding instanceof IVariableBinding) {
IVariableBinding variableBinding = (IVariableBinding) binding;
if (variableBinding.isField()) {
String qualifiedName =
variableBinding.getDeclaringClass().getTypeDeclaration().getQualifiedName();
String fieldName = variableBinding.getName();
String[] methodName = getMethod(JavaModelUtil.concatenateName(qualifiedName, fieldName));
if (methodName != null) {
AST ast = selectedNode.getAST();
ASTRewrite astRewrite = ASTRewrite.create(ast);
ImportRewrite importRewrite =
StubUtility.createImportRewrite(context.getASTRoot(), true);
MethodInvocation method = ast.newMethodInvocation();
String qfn = importRewrite.addImport(methodName[0]);
method.setExpression(ast.newName(qfn));
method.setName(ast.newSimpleName(methodName[1]));
ASTNode parent = selectedNode.getParent();
ICompilationUnit cu = context.getCompilationUnit();
// add explicit type arguments if necessary (for 1.8 and later, we're optimistic that
// inference just works):
if (Invocations.isInvocationWithArguments(parent)
&& !JavaModelUtil.is18OrHigher(cu.getJavaProject())) {
IMethodBinding methodBinding = Invocations.resolveBinding(parent);
if (methodBinding != null) {
ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
int i = Invocations.getArguments(parent).indexOf(selectedNode);
if (parameterTypes.length >= i && parameterTypes[i].isParameterizedType()) {
ITypeBinding[] typeArguments = parameterTypes[i].getTypeArguments();
for (int j = 0; j < typeArguments.length; j++) {
ITypeBinding typeArgument = typeArguments[j];
typeArgument = Bindings.normalizeForDeclarationUse(typeArgument, ast);
if (!TypeRules.isJavaLangObject(typeArgument)) {
// add all type arguments if at least one is found to be necessary:
List<Type> typeArgumentsList = method.typeArguments();
for (int k = 0; k < typeArguments.length; k++) {
typeArgument = typeArguments[k];
typeArgument = Bindings.normalizeForDeclarationUse(typeArgument, ast);
typeArgumentsList.add(importRewrite.addImport(typeArgument, ast));
}
break;
}
}
}
}
}
astRewrite.replace(selectedNode, method, null);
String label =
Messages.format(
CorrectionMessages
.LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description,
BasicElementLabels.getJavaElementName(ASTNodes.asString(method)));
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label,
cu,
astRewrite,
IProposalRelevance.REPLACE_FIELD_ACCESS_WITH_METHOD,
image);
proposal.setImportRewrite(importRewrite);
proposals.add(proposal);
}
}
}
}
}
示例2: addDeprecatedFieldsToMethodsProposals
import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入方法依赖的package包/类
public static void addDeprecatedFieldsToMethodsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
if (selectedNode instanceof Name) {
IBinding binding= ((Name) selectedNode).resolveBinding();
if (binding instanceof IVariableBinding) {
IVariableBinding variableBinding= (IVariableBinding) binding;
if (variableBinding.isField()) {
String qualifiedName= variableBinding.getDeclaringClass().getTypeDeclaration().getQualifiedName();
String fieldName= variableBinding.getName();
String[] methodName= getMethod(JavaModelUtil.concatenateName(qualifiedName, fieldName));
if (methodName != null) {
AST ast= selectedNode.getAST();
ASTRewrite astRewrite= ASTRewrite.create(ast);
ImportRewrite importRewrite= StubUtility.createImportRewrite(context.getASTRoot(), true);
MethodInvocation method= ast.newMethodInvocation();
String qfn= importRewrite.addImport(methodName[0]);
method.setExpression(ast.newName(qfn));
method.setName(ast.newSimpleName(methodName[1]));
ASTNode parent= selectedNode.getParent();
ICompilationUnit cu= context.getCompilationUnit();
// add explicit type arguments if necessary (for 1.8 and later, we're optimistic that inference just works):
if (Invocations.isInvocationWithArguments(parent) && !JavaModelUtil.is18OrHigher(cu.getJavaProject())) {
IMethodBinding methodBinding= Invocations.resolveBinding(parent);
if (methodBinding != null) {
ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
int i= Invocations.getArguments(parent).indexOf(selectedNode);
if (parameterTypes.length >= i && parameterTypes[i].isParameterizedType()) {
ITypeBinding[] typeArguments= parameterTypes[i].getTypeArguments();
for (int j= 0; j < typeArguments.length; j++) {
ITypeBinding typeArgument= typeArguments[j];
typeArgument= Bindings.normalizeForDeclarationUse(typeArgument, ast);
if (! TypeRules.isJavaLangObject(typeArgument)) {
// add all type arguments if at least one is found to be necessary:
List<Type> typeArgumentsList= method.typeArguments();
for (int k= 0; k < typeArguments.length; k++) {
typeArgument= typeArguments[k];
typeArgument= Bindings.normalizeForDeclarationUse(typeArgument, ast);
typeArgumentsList.add(importRewrite.addImport(typeArgument, ast));
}
break;
}
}
}
}
}
astRewrite.replace(selectedNode, method, null);
String label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description, BasicElementLabels.getJavaElementName(ASTNodes.asString(method)));
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, astRewrite, IProposalRelevance.REPLACE_FIELD_ACCESS_WITH_METHOD, image);
proposal.setImportRewrite(importRewrite);
proposals.add(proposal);
}
}
}
}
}
示例3: addDeprecatedFieldsToMethodsProposals
import org.eclipse.jdt.internal.corext.refactoring.code.Invocations; //导入方法依赖的package包/类
public static void addDeprecatedFieldsToMethodsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
if (selectedNode instanceof Name) {
IBinding binding= ((Name) selectedNode).resolveBinding();
if (binding instanceof IVariableBinding) {
IVariableBinding variableBinding= (IVariableBinding) binding;
if (variableBinding.isField()) {
String qualifiedName= variableBinding.getDeclaringClass().getTypeDeclaration().getQualifiedName();
String fieldName= variableBinding.getName();
String[] methodName= getMethod(JavaModelUtil.concatenateName(qualifiedName, fieldName));
if (methodName != null) {
AST ast= selectedNode.getAST();
ASTRewrite astRewrite= ASTRewrite.create(ast);
ImportRewrite importRewrite= StubUtility.createImportRewrite(context.getASTRoot(), true);
MethodInvocation method= ast.newMethodInvocation();
String qfn= importRewrite.addImport(methodName[0]);
method.setExpression(ast.newName(qfn));
method.setName(ast.newSimpleName(methodName[1]));
ASTNode parent= selectedNode.getParent();
// add explicit type arguments if necessary:
if (Invocations.isInvocationWithArguments(parent)) {
IMethodBinding methodBinding= Invocations.resolveBinding(parent);
if (methodBinding != null) {
ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
int i= Invocations.getArguments(parent).indexOf(selectedNode);
if (parameterTypes.length >= i && parameterTypes[i].isParameterizedType()) {
ITypeBinding[] typeArguments= parameterTypes[i].getTypeArguments();
for (int j= 0; j < typeArguments.length; j++) {
ITypeBinding typeArgument= typeArguments[j];
if (! TypeRules.isJavaLangObject(typeArgument)) {
List<Type> typeArgumentsList= method.typeArguments();
for (int k= 0; k < typeArguments.length; k++) {
typeArgument= typeArguments[k];
typeArgumentsList.add(importRewrite.addImport(typeArgument, ast));
}
break;
}
}
}
}
}
astRewrite.replace(selectedNode, method, null);
String label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description, BasicElementLabels.getJavaElementName(ASTNodes.asString(method)));
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), astRewrite, 10, image);
proposal.setImportRewrite(importRewrite);
proposals.add(proposal);
}
}
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:56,代码来源:LocalCorrectionsSubProcessor.java