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


Java IProblemLocation.getCoveredNode方法代码示例

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


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

示例1: removeMismatchedArguments

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static void removeMismatchedArguments(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  ICompilationUnit cu = context.getCompilationUnit();
  ASTNode selectedNode = problem.getCoveredNode(context.getASTRoot());
  if (!(selectedNode instanceof SimpleName)) {
    return;
  }

  ASTNode normalizedNode = ASTNodes.getNormalizedNode(selectedNode);
  if (normalizedNode instanceof ParameterizedType) {
    ASTRewrite rewrite = ASTRewrite.create(normalizedNode.getAST());
    ParameterizedType pt = (ParameterizedType) normalizedNode;
    ASTNode mt = rewrite.createMoveTarget(pt.getType());
    rewrite.replace(pt, mt, null);
    String label = CorrectionMessages.TypeArgumentMismatchSubProcessor_removeTypeArguments;
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal =
        new ASTRewriteCorrectionProposal(
            label, cu, rewrite, IProposalRelevance.REMOVE_TYPE_ARGUMENTS, image);
    proposals.add(proposal);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:TypeArgumentMismatchSubProcessor.java

示例2: getInferDiamondArgumentsProposal

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

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

示例3: getWrongTypeNameProposals

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

  IJavaProject javaProject = cu.getJavaProject();
  String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
  String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);

  CompilationUnit root = context.getASTRoot();

  ASTNode coveredNode = problem.getCoveredNode(root);
  if (!(coveredNode instanceof SimpleName)) return;

  ASTNode parentType = coveredNode.getParent();
  if (!(parentType instanceof AbstractTypeDeclaration)) return;

  String currTypeName = ((SimpleName) coveredNode).getIdentifier();
  String newTypeName = JavaCore.removeJavaLikeExtension(cu.getElementName());

  boolean hasOtherPublicTypeBefore = false;

  boolean found = false;
  List<AbstractTypeDeclaration> types = root.types();
  for (int i = 0; i < types.size(); i++) {
    AbstractTypeDeclaration curr = types.get(i);
    if (parentType != curr) {
      if (newTypeName.equals(curr.getName().getIdentifier())) {
        return;
      }
      if (!found && Modifier.isPublic(curr.getModifiers())) {
        hasOtherPublicTypeBefore = true;
      }
    } else {
      found = true;
    }
  }
  if (!JavaConventions.validateJavaTypeName(newTypeName, sourceLevel, compliance)
      .matches(IStatus.ERROR)) {
    proposals.add(
        new CorrectMainTypeNameProposal(
            cu, context, currTypeName, newTypeName, IProposalRelevance.RENAME_TYPE));
  }

  if (!hasOtherPublicTypeBefore) {
    String newCUName = JavaModelUtil.getRenamedCUName(cu, currTypeName);
    ICompilationUnit newCU = ((IPackageFragment) (cu.getParent())).getCompilationUnit(newCUName);
    if (!newCU.exists()
        && !isLinked
        && !JavaConventions.validateCompilationUnitName(newCUName, sourceLevel, compliance)
            .matches(IStatus.ERROR)) {
      RenameCompilationUnitChange change = new RenameCompilationUnitChange(cu, newCUName);

      // rename CU
      String label =
          Messages.format(
              CorrectionMessages.ReorgCorrectionsSubProcessor_renamecu_description,
              BasicElementLabels.getResourceName(newCUName));
      proposals.add(
          new ChangeCorrectionProposal(
              label,
              change,
              IProposalRelevance.RENAME_CU,
              JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_RENAME)));
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:68,代码来源:ReorgCorrectionsSubProcessor.java

示例4: createProposals

import org.eclipse.jdt.ui.text.java.IProblemLocation; //导入方法依赖的package包/类
public static List<IJavaCompletionProposal> createProposals(IInvocationContext context, IProblemLocation problem)
    throws JavaModelException {
  String syncTypeName = problem.getProblemArguments()[0];
  IJavaProject javaProject = context.getCompilationUnit().getJavaProject();
  IType syncType = JavaModelSearch.findType(javaProject, syncTypeName);
  if (syncType == null || !syncType.isInterface()) {
    return Collections.emptyList();
  }

  CompilationUnit cu = context.getASTRoot();
  ASTNode coveredNode = problem.getCoveredNode(cu);
  TypeDeclaration syncTypeDecl = (TypeDeclaration) coveredNode.getParent();
  assert (cu.getAST().hasResolvedBindings());

  ITypeBinding syncTypeBinding = syncTypeDecl.resolveBinding();
  assert (syncTypeBinding != null);

  String asyncName = RemoteServiceUtilities.computeAsyncTypeName(problem.getProblemArguments()[0]);
  AST ast = context.getASTRoot().getAST();
  Name name = ast.newName(asyncName);

  /*
   * HACK: NewCUUsingWizardProposal wants a name that has a parent expression so we create an
   * assignment so that the name has a valid parent
   */
  ast.newAssignment().setLeftHandSide(name);

  IJavaElement typeContainer = syncType.getParent();
  if (typeContainer.getElementType() == IJavaElement.COMPILATION_UNIT) {
    typeContainer = syncType.getPackageFragment();
  }

  // Add a create async interface proposal
  CreateAsyncInterfaceProposal createAsyncInterfaceProposal = new CreateAsyncInterfaceProposal(
      context.getCompilationUnit(), name, K_INTERFACE, typeContainer, 2, syncTypeBinding);

  // Add the stock create interface proposal
  NewCompilationUnitUsingWizardProposal fallbackProposal = new NewCompilationUnitUsingWizardProposal(
      context.getCompilationUnit(), name, K_INTERFACE, context.getCompilationUnit().getParent(), 1);

  return Arrays.<IJavaCompletionProposal>asList(createAsyncInterfaceProposal, fallbackProposal);
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:43,代码来源:CreateAsyncInterfaceProposal.java


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