本文整理汇总了Java中org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal.setImportRewrite方法的典型用法代码示例。如果您正苦于以下问题:Java ASTRewriteCorrectionProposal.setImportRewrite方法的具体用法?Java ASTRewriteCorrectionProposal.setImportRewrite怎么用?Java ASTRewriteCorrectionProposal.setImportRewrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal
的用法示例。
在下文中一共展示了ASTRewriteCorrectionProposal.setImportRewrite方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDeprecatedFieldsToMethodsProposals
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入方法依赖的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: addStaticImportFavoriteProposals
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入方法依赖的package包/类
private static void addStaticImportFavoriteProposals(
IInvocationContext context,
SimpleName node,
boolean isMethod,
Collection<ICommandAccess> proposals)
throws JavaModelException {
IJavaProject project = context.getCompilationUnit().getJavaProject();
if (JavaModelUtil.is50OrHigher(project)) {
String pref =
PreferenceConstants.getPreference(
PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
String[] favourites = pref.split(";"); // $NON-NLS-1$
if (favourites.length == 0) {
return;
}
CompilationUnit root = context.getASTRoot();
AST ast = root.getAST();
String name = node.getIdentifier();
String[] staticImports =
SimilarElementsRequestor.getStaticImportFavorites(
context.getCompilationUnit(), name, isMethod, favourites);
for (int i = 0; i < staticImports.length; i++) {
String curr = staticImports[i];
ImportRewrite importRewrite = StubUtility.createImportRewrite(root, true);
ASTRewrite astRewrite = ASTRewrite.create(ast);
String label;
String qualifiedTypeName = Signature.getQualifier(curr);
String elementLabel =
BasicElementLabels.getJavaElementName(
JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));
String res =
importRewrite.addStaticImport(
qualifiedTypeName,
name,
isMethod,
new ContextSensitiveImportRewriteContext(
root, node.getStartPosition(), importRewrite));
int dot = res.lastIndexOf('.');
if (dot != -1) {
String usedTypeName = importRewrite.addImport(qualifiedTypeName);
Name newName = ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
astRewrite.replace(node, newName, null);
label =
Messages.format(
CorrectionMessages
.UnresolvedElementsSubProcessor_change_to_static_import_description,
elementLabel);
} else {
label =
Messages.format(
CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description,
elementLabel);
}
Image image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label,
context.getCompilationUnit(),
astRewrite,
IProposalRelevance.ADD_STATIC_IMPORT,
image);
proposal.setImportRewrite(importRewrite);
proposals.add(proposal);
}
}
}
示例3: addDeprecatedFieldsToMethodsProposals
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入方法依赖的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);
}
}
}
}
}
示例4: addStaticImportFavoriteProposals
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入方法依赖的package包/类
private static void addStaticImportFavoriteProposals(IInvocationContext context, SimpleName node, boolean isMethod, Collection<ICommandAccess> proposals) throws JavaModelException {
IJavaProject project= context.getCompilationUnit().getJavaProject();
if (JavaModelUtil.is50OrHigher(project)) {
String pref= PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
String[] favourites= pref.split(";"); //$NON-NLS-1$
if (favourites.length == 0) {
return;
}
CompilationUnit root= context.getASTRoot();
AST ast= root.getAST();
String name= node.getIdentifier();
String[] staticImports= SimilarElementsRequestor.getStaticImportFavorites(context.getCompilationUnit(), name, isMethod, favourites);
for (int i= 0; i < staticImports.length; i++) {
String curr= staticImports[i];
ImportRewrite importRewrite= StubUtility.createImportRewrite(root, true);
ASTRewrite astRewrite= ASTRewrite.create(ast);
String label;
String qualifiedTypeName= Signature.getQualifier(curr);
String elementLabel= BasicElementLabels.getJavaElementName(JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));
String res= importRewrite.addStaticImport(qualifiedTypeName, name, isMethod, new ContextSensitiveImportRewriteContext(root, node.getStartPosition(), importRewrite));
int dot= res.lastIndexOf('.');
if (dot != -1) {
String usedTypeName= importRewrite.addImport(qualifiedTypeName);
Name newName= ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
astRewrite.replace(node, newName, null);
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_change_to_static_import_description, elementLabel);
} else {
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description, elementLabel);
}
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_STATIC_IMPORT, image);
proposal.setImportRewrite(importRewrite);
proposals.add(proposal);
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:43,代码来源:UnresolvedElementsSubProcessor.java
示例5: addDeprecatedFieldsToMethodsProposals
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入方法依赖的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
示例6: addStaticImportFavoriteProposals
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入方法依赖的package包/类
private static void addStaticImportFavoriteProposals(IInvocationContext context, SimpleName node, boolean isMethod, Collection<ICommandAccess> proposals) throws JavaModelException {
IJavaProject project= context.getCompilationUnit().getJavaProject();
if (JavaModelUtil.is50OrHigher(project)) {
String pref= PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
String[] favourites= pref.split(";"); //$NON-NLS-1$
if (favourites.length == 0) {
return;
}
CompilationUnit root= context.getASTRoot();
AST ast= root.getAST();
String name= node.getIdentifier();
String[] staticImports= SimilarElementsRequestor.getStaticImportFavorites(context.getCompilationUnit(), name, isMethod, favourites);
for (int i= 0; i < staticImports.length; i++) {
String curr= staticImports[i];
ImportRewrite importRewrite= StubUtility.createImportRewrite(root, true);
ASTRewrite astRewrite= ASTRewrite.create(ast);
String label;
String qualifiedTypeName= Signature.getQualifier(curr);
String elementLabel= BasicElementLabels.getJavaElementName(JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));
String res= importRewrite.addStaticImport(qualifiedTypeName, name, isMethod, new ContextSensitiveImportRewriteContext(root, node.getStartPosition(), importRewrite));
int dot= res.lastIndexOf('.');
if (dot != -1) {
String usedTypeName= importRewrite.addImport(qualifiedTypeName);
Name newName= ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
astRewrite.replace(node, newName, null);
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_change_to_static_import_description, elementLabel);
} else {
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description, elementLabel);
}
Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), astRewrite, 5, image);
proposal.setImportRewrite(importRewrite);
proposals.add(proposal);
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:43,代码来源:UnresolvedElementsSubProcessor.java