当前位置: 首页>>代码示例>>Java>>正文


Java IProblemLocation.getCoveringNode方法代码示例

本文整理汇总了Java中org.eclipse.jdt.ui.text.java.IProblemLocation.getCoveringNode方法的典型用法代码示例。如果您正苦于以下问题:Java IProblemLocation.getCoveringNode方法的具体用法?Java IProblemLocation.getCoveringNode怎么用?Java IProblemLocation.getCoveringNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.ui.text.java.IProblemLocation的用法示例。


在下文中一共展示了IProblemLocation.getCoveringNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSelectedTypeNode

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static ASTNode getSelectedTypeNode(CompilationUnit root, IProblemLocation problem) {
  ASTNode selectedNode = problem.getCoveringNode(root);
  if (selectedNode == null) return null;

  if (selectedNode.getNodeType() == ASTNode.ANONYMOUS_CLASS_DECLARATION) { // bug 200016
    selectedNode = selectedNode.getParent();
  }

  if (selectedNode.getLocationInParent() == EnumConstantDeclaration.NAME_PROPERTY) {
    selectedNode = selectedNode.getParent();
  }
  if (selectedNode.getNodeType() == ASTNode.SIMPLE_NAME
      && selectedNode.getParent() instanceof AbstractTypeDeclaration) {
    return selectedNode.getParent();
  } else if (selectedNode.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
    return ((ClassInstanceCreation) selectedNode).getAnonymousClassDeclaration();
  } else if (selectedNode.getNodeType() == ASTNode.ENUM_CONSTANT_DECLARATION) {
    EnumConstantDeclaration enumConst = (EnumConstantDeclaration) selectedNode;
    if (enumConst.getAnonymousClassDeclaration() != null)
      return enumConst.getAnonymousClassDeclaration();
    return enumConst;
  } else {
    return null;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:UnimplementedCodeFix.java

示例2: createFix

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
private static Java50Fix createFix(
    CompilationUnit compilationUnit, IProblemLocation problem, String annotation, String label) {
  ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
  if (!JavaModelUtil.is50OrHigher(cu.getJavaProject())) return null;

  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
  if (selectedNode == null) return null;

  ASTNode declaringNode = getDeclaringNode(selectedNode);
  if (!(declaringNode instanceof BodyDeclaration)) return null;

  BodyDeclaration declaration = (BodyDeclaration) declaringNode;

  AnnotationRewriteOperation operation = new AnnotationRewriteOperation(declaration, annotation);

  return new Java50Fix(label, compilationUnit, new CompilationUnitRewriteOperation[] {operation});
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:Java50Fix.java

示例3: createRemoveUnusedCastFix

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static UnusedCodeFix createRemoveUnusedCastFix(
    CompilationUnit compilationUnit, IProblemLocation problem) {
  if (problem.getProblemId() != IProblem.UnnecessaryCast) return null;

  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);

  ASTNode curr = selectedNode;
  while (curr instanceof ParenthesizedExpression) {
    curr = ((ParenthesizedExpression) curr).getExpression();
  }

  if (!(curr instanceof CastExpression)) return null;

  return new UnusedCodeFix(
      FixMessages.UnusedCodeFix_RemoveCast_description,
      compilationUnit,
      new CompilationUnitRewriteOperation[] {new RemoveCastOperation((CastExpression) curr)});
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:UnusedCodeFix.java

示例4: removeOverrideAnnotationProposal

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static void removeOverrideAnnotationProposal(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals)
    throws CoreException {
  ICompilationUnit cu = context.getCompilationUnit();

  ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
  if (!(selectedNode instanceof MethodDeclaration)) {
    return;
  }
  MethodDeclaration methodDecl = (MethodDeclaration) selectedNode;
  Annotation annot = findAnnotation("java.lang.Override", methodDecl.modifiers()); // $NON-NLS-1$
  if (annot != null) {
    ASTRewrite rewrite = ASTRewrite.create(annot.getAST());
    rewrite.remove(annot, null);
    String label = CorrectionMessages.ModifierCorrectionSubProcessor_remove_override;
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal =
        new ASTRewriteCorrectionProposal(
            label, cu, rewrite, IProposalRelevance.REMOVE_OVERRIDE, image);
    proposals.add(proposal);

    QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ModifierCorrectionSubProcessor.java

示例5: getName

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
private static SimpleName getName(CompilationUnit compilationUnit, IProblemLocation problem) {
  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);

  while (selectedNode instanceof QualifiedName) {
    selectedNode = ((QualifiedName) selectedNode).getQualifier();
  }
  if (!(selectedNode instanceof SimpleName)) {
    return null;
  }
  return (SimpleName) selectedNode;
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:CodeStyleFix.java

示例6: createAddOverrideAnnotationOperations

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
private static void createAddOverrideAnnotationOperations(
    CompilationUnit compilationUnit,
    boolean addOverrideInterfaceAnnotation,
    IProblemLocation[] locations,
    List<CompilationUnitRewriteOperation> result) {
  for (int i = 0; i < locations.length; i++) {
    IProblemLocation problem = locations[i];
    int problemId = problem.getProblemId();

    if (isMissingOverrideAnnotationProblem(problemId)) {
      if (!isMissingOverrideAnnotationInterfaceProblem(problemId)
          || addOverrideInterfaceAnnotation) {
        ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
        if (selectedNode != null) {

          ASTNode declaringNode = getDeclaringNode(selectedNode);
          if (declaringNode instanceof BodyDeclaration) {
            BodyDeclaration declaration = (BodyDeclaration) declaringNode;
            AnnotationRewriteOperation operation =
                new AnnotationRewriteOperation(declaration, OVERRIDE);
            result.add(operation);
          }
        }
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:28,代码来源:Java50Fix.java

示例7: getUnusedName

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
private static SimpleName getUnusedName(
    CompilationUnit compilationUnit, IProblemLocation problem) {
  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);

  if (selectedNode instanceof MethodDeclaration) {
    return ((MethodDeclaration) selectedNode).getName();
  } else if (selectedNode instanceof SimpleName) {
    return (SimpleName) selectedNode;
  }

  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:13,代码来源:UnusedCodeFix.java

示例8: getImportDeclaration

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
private static ImportDeclaration getImportDeclaration(
    IProblemLocation problem, CompilationUnit compilationUnit) {
  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
  if (selectedNode != null) {
    ASTNode node = ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION);
    if (node instanceof ImportDeclaration) {
      return (ImportDeclaration) node;
    }
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:UnusedCodeFix.java

示例9: getParameterizedType

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
private static ParameterizedType getParameterizedType(
    CompilationUnit compilationUnit, IProblemLocation problem) {
  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
  if (selectedNode == null) return null;

  while (!(selectedNode instanceof ParameterizedType) && !(selectedNode instanceof Statement)) {
    selectedNode = selectedNode.getParent();
  }
  if (selectedNode instanceof ParameterizedType) {
    return (ParameterizedType) selectedNode;
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:TypeParametersFix.java

示例10: addUnreachableCatchProposals

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static void addUnreachableCatchProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
  if (selectedNode == null) {
    return;
  }

  QuickAssistProcessor.getCatchClauseToThrowsProposals(context, selectedNode, proposals);
}
 
开发者ID:eclipse,项目名称:che,代码行数:10,代码来源:LocalCorrectionsSubProcessor.java

示例11: addNeedToEmulateProposal

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static void addNeedToEmulateProposal(
    IInvocationContext context,
    IProblemLocation problem,
    Collection<ModifierChangeCorrectionProposal> proposals) {
  ICompilationUnit cu = context.getCompilationUnit();

  ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
  if (!(selectedNode instanceof SimpleName)) {
    return;
  }

  IBinding binding = ((SimpleName) selectedNode).resolveBinding();
  if (binding instanceof IVariableBinding) {
    binding = ((IVariableBinding) binding).getVariableDeclaration();
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    String label =
        Messages.format(
            CorrectionMessages.ModifierCorrectionSubProcessor_changemodifiertofinal_description,
            BasicElementLabels.getJavaElementName(binding.getName()));
    proposals.add(
        new ModifierChangeCorrectionProposal(
            label,
            cu,
            binding,
            selectedNode,
            Modifier.FINAL,
            0,
            IProposalRelevance.CHANGE_MODIFIER_OF_VARIABLE_TO_FINAL,
            image));
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:32,代码来源:ModifierCorrectionSubProcessor.java

示例12: getGenerateForLoopProposals

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static void getGenerateForLoopProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  ASTNode coveringNode = problem.getCoveringNode(context.getASTRoot());
  if (coveringNode != null) {
    QuickAssistProcessor.getGenerateForLoopProposals(context, coveringNode, null, proposals);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:LocalCorrectionsSubProcessor.java

示例13: addUnnecessaryThrownExceptionProposal

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static void addUnnecessaryThrownExceptionProposal(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
  selectedNode = ASTNodes.getNormalizedNode(selectedNode);
  if (selectedNode == null
      || selectedNode.getLocationInParent()
          != MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
    return;
  }
  MethodDeclaration decl = (MethodDeclaration) selectedNode.getParent();
  IMethodBinding binding = decl.resolveBinding();
  if (binding != null) {
    List<Type> thrownExceptions = decl.thrownExceptionTypes();
    int index = thrownExceptions.indexOf(selectedNode);
    if (index == -1) {
      return;
    }
    ChangeDescription[] desc = new ChangeDescription[thrownExceptions.size()];
    desc[index] = new RemoveDescription();

    ICompilationUnit cu = context.getCompilationUnit();
    String label = CorrectionMessages.LocalCorrectionsSubProcessor_unnecessarythrow_description;
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION);

    proposals.add(
        new ChangeMethodSignatureProposal(
            label,
            cu,
            selectedNode,
            binding,
            null,
            desc,
            IProposalRelevance.UNNECESSARY_THROW,
            image));
  }

  JavadocTagsSubProcessor.getUnusedAndUndocumentedParameterOrExceptionProposals(
      context, problem, proposals);
}
 
开发者ID:eclipse,项目名称:che,代码行数:40,代码来源:LocalCorrectionsSubProcessor.java

示例14: getMissingJavadocTagProposals

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static void getMissingJavadocTagProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  ASTNode node = problem.getCoveringNode(context.getASTRoot());
  if (node == null) {
    return;
  }
  node = ASTNodes.getNormalizedNode(node);

  BodyDeclaration bodyDeclaration = ASTResolving.findParentBodyDeclaration(node);
  if (bodyDeclaration == null) {
    return;
  }
  Javadoc javadoc = bodyDeclaration.getJavadoc();
  if (javadoc == null) {
    return;
  }

  String label;
  StructuralPropertyDescriptor location = node.getLocationInParent();
  if (location == SingleVariableDeclaration.NAME_PROPERTY) {
    label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description;
    if (node.getParent().getLocationInParent() != MethodDeclaration.PARAMETERS_PROPERTY) {
      return; // paranoia checks
    }
  } else if (location == TypeParameter.NAME_PROPERTY) {
    label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description;
    StructuralPropertyDescriptor parentLocation = node.getParent().getLocationInParent();
    if (parentLocation != MethodDeclaration.TYPE_PARAMETERS_PROPERTY
        && parentLocation != TypeDeclaration.TYPE_PARAMETERS_PROPERTY) {
      return; // paranoia checks
    }
  } else if (location == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
    label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_returntag_description;
  } else if (location == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
    label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_throwstag_description;
  } else {
    return;
  }
  ASTRewriteCorrectionProposal proposal =
      new AddMissingJavadocTagProposal(
          label,
          context.getCompilationUnit(),
          bodyDeclaration,
          node,
          IProposalRelevance.ADD_MISSING_TAG);
  proposals.add(proposal);

  String label2 = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_allmissing_description;
  ASTRewriteCorrectionProposal addAllMissing =
      new AddAllMissingJavadocTagsProposal(
          label2,
          context.getCompilationUnit(),
          bodyDeclaration,
          IProposalRelevance.ADD_ALL_MISSING_TAGS);
  proposals.add(addAllMissing);
}
 
开发者ID:eclipse,项目名称:che,代码行数:57,代码来源:JavadocTagsSubProcessor.java

示例15: addAddSafeVarargsToDeclarationProposals

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static void addAddSafeVarargsToDeclarationProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  if (!JavaModelUtil.is17OrHigher(context.getCompilationUnit().getJavaProject())) return;

  ASTNode coveringNode = problem.getCoveringNode(context.getASTRoot());
  IMethodBinding methodBinding;
  if (coveringNode instanceof MethodInvocation) {
    methodBinding = ((MethodInvocation) coveringNode).resolveMethodBinding();
  } else if (coveringNode instanceof ClassInstanceCreation) {
    methodBinding = ((ClassInstanceCreation) coveringNode).resolveConstructorBinding();
  } else {
    return;
  }
  if (methodBinding == null) return;

  String label =
      Messages.format(
          CorrectionMessages.VarargsWarningsSubProcessor_add_safevarargs_to_method_label,
          methodBinding.getName());

  ITypeBinding declaringType = methodBinding.getDeclaringClass();
  CompilationUnit astRoot = (CompilationUnit) coveringNode.getRoot();
  if (declaringType != null && declaringType.isFromSource()) {
    try {
      ICompilationUnit targetCu =
          ASTResolving.findCompilationUnitForBinding(
              context.getCompilationUnit(), astRoot, declaringType);
      if (targetCu != null) {
        AddSafeVarargsProposal proposal =
            new AddSafeVarargsProposal(
                label,
                targetCu,
                null,
                methodBinding.getMethodDeclaration(),
                IProposalRelevance.ADD_SAFEVARARGS);
        proposals.add(proposal);
      }
    } catch (JavaModelException e) {
      return;
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:43,代码来源:VarargsWarningsSubProcessor.java


注:本文中的org.eclipse.jdt.ui.text.java.IProblemLocation.getCoveringNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。