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


Java IInvocationContext.getASTRoot方法代码示例

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


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

示例1: addExtractCheckedLocalProposal

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
/**
 * Fix for {@link IProblem#NullableFieldReference}
 *
 * @param context context
 * @param problem problem to be fixed
 * @param proposals accumulator for computed proposals
 */
public static void addExtractCheckedLocalProposal(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  CompilationUnit compilationUnit = context.getASTRoot();
  ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();

  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);

  SimpleName name = findProblemFieldName(selectedNode, problem.getProblemId());
  if (name == null) return;

  ASTNode method = ASTNodes.getParent(selectedNode, MethodDeclaration.class);
  if (method == null) method = ASTNodes.getParent(selectedNode, Initializer.class);
  if (method == null) return;

  proposals.add(new ExtractToNullCheckedLocalProposal(cu, compilationUnit, name, method));
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:NullAnnotationsCorrectionProcessor.java

示例2: addMakeTypeAbstractProposal

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
private static void addMakeTypeAbstractProposal(
    IInvocationContext context,
    TypeDeclaration parentTypeDecl,
    Collection<ICommandAccess> proposals) {
  MakeTypeAbstractOperation operation =
      new UnimplementedCodeFix.MakeTypeAbstractOperation(parentTypeDecl);

  String label =
      Messages.format(
          CorrectionMessages.ModifierCorrectionSubProcessor_addabstract_description,
          BasicElementLabels.getJavaElementName(parentTypeDecl.getName().getIdentifier()));
  UnimplementedCodeFix fix =
      new UnimplementedCodeFix(
          label, context.getASTRoot(), new CompilationUnitRewriteOperation[] {operation});

  Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
  FixCorrectionProposal proposal =
      new FixCorrectionProposal(
          fix, null, IProposalRelevance.MAKE_TYPE_ABSTRACT_FIX, image, context);
  proposals.add(proposal);
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:ModifierCorrectionSubProcessor.java

示例3: addAbstractTypeProposals

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
public static void addAbstractTypeProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  CompilationUnit astRoot = context.getASTRoot();

  ASTNode selectedNode = problem.getCoveringNode(astRoot);
  if (selectedNode == null) {
    return;
  }

  TypeDeclaration parentTypeDecl = null;
  if (selectedNode instanceof SimpleName) {
    ASTNode parent = selectedNode.getParent();
    if (parent != null) {
      parentTypeDecl = (TypeDeclaration) parent;
    }
  } else if (selectedNode instanceof TypeDeclaration) {
    parentTypeDecl = (TypeDeclaration) selectedNode;
  }

  if (parentTypeDecl == null) {
    return;
  }

  addMakeTypeAbstractProposal(context, parentTypeDecl, proposals);
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:ModifierCorrectionSubProcessor.java

示例4: addReturnAndArgumentTypeProposal

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

  boolean isArgumentProblem = NullAnnotationsFix.isComplainingAboutArgument(selectedNode);
  if (isArgumentProblem || NullAnnotationsFix.isComplainingAboutReturn(selectedNode))
    addNullAnnotationInSignatureProposal(
        context, problem, proposals, changeKind, isArgumentProblem);
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:NullAnnotationsCorrectionProcessor.java

示例5: addMethodRetunsVoidProposals

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
public static void addMethodRetunsVoidProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals)
    throws JavaModelException {
  CompilationUnit astRoot = context.getASTRoot();
  ASTNode selectedNode = problem.getCoveringNode(astRoot);
  if (!(selectedNode instanceof ReturnStatement)) {
    return;
  }
  ReturnStatement returnStatement = (ReturnStatement) selectedNode;
  Expression expression = returnStatement.getExpression();
  if (expression == null) {
    return;
  }
  BodyDeclaration decl = ASTResolving.findParentBodyDeclaration(selectedNode);
  if (decl instanceof MethodDeclaration) {
    MethodDeclaration methDecl = (MethodDeclaration) decl;
    Type retType = methDecl.getReturnType2();
    if (retType == null || retType.resolveBinding() == null) {
      return;
    }
    TypeMismatchSubProcessor.addChangeSenderTypeProposals(
        context,
        expression,
        retType.resolveBinding(),
        false,
        IProposalRelevance.METHOD_RETURNS_VOID,
        proposals);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:30,代码来源:ReturnTypeSubProcessor.java

示例6: getAmbiguosTypeReferenceProposals

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

  IJavaElement[] elements = cu.codeSelect(offset, len);
  for (int i = 0; i < elements.length; i++) {
    IJavaElement curr = elements[i];
    if (curr instanceof IType && !TypeFilter.isFiltered((IType) curr)) {
      String qualifiedTypeName = ((IType) curr).getFullyQualifiedName('.');

      CompilationUnit root = context.getASTRoot();

      String label =
          Messages.format(
              CorrectionMessages.UnresolvedElementsSubProcessor_importexplicit_description,
              BasicElementLabels.getJavaElementName(qualifiedTypeName));
      Image image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
      ASTRewriteCorrectionProposal proposal =
          new ASTRewriteCorrectionProposal(
              label,
              cu,
              ASTRewrite.create(root.getAST()),
              IProposalRelevance.IMPORT_EXPLICIT,
              image);

      ImportRewrite imports = proposal.createImportRewrite(root);
      imports.addImport(qualifiedTypeName);

      proposals.add(proposal);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:36,代码来源:UnresolvedElementsSubProcessor.java

示例7: FixCorrectionProposal

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
public FixCorrectionProposal(
    IProposableFix fix,
    ICleanUp cleanUp,
    int relevance,
    Image image,
    IInvocationContext context) {
  super(fix.getDisplayString(), context.getCompilationUnit(), null, relevance, image);
  fFix = fix;
  fCleanUp = cleanUp;
  fCompilationUnit = context.getASTRoot();
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:FixCorrectionProposal.java

示例8: addUninitializedLocalVariableProposal

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

  ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
  if (!(selectedNode instanceof Name)) {
    return;
  }
  Name name = (Name) selectedNode;
  IBinding binding = name.resolveBinding();
  if (!(binding instanceof IVariableBinding)) {
    return;
  }
  IVariableBinding varBinding = (IVariableBinding) binding;

  CompilationUnit astRoot = context.getASTRoot();
  ASTNode node = astRoot.findDeclaringNode(binding);
  if (node instanceof VariableDeclarationFragment) {
    ASTRewrite rewrite = ASTRewrite.create(node.getAST());

    VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
    if (fragment.getInitializer() != null) {
      return;
    }
    Expression expression =
        ASTNodeFactory.newDefaultExpression(astRoot.getAST(), varBinding.getType());
    if (expression == null) {
      return;
    }
    rewrite.set(fragment, VariableDeclarationFragment.INITIALIZER_PROPERTY, expression, null);

    String label =
        CorrectionMessages.LocalCorrectionsSubProcessor_uninitializedvariable_description;
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);

    LinkedCorrectionProposal proposal =
        new LinkedCorrectionProposal(
            label, cu, rewrite, IProposalRelevance.INITIALIZE_VARIABLE, image);
    proposal.addLinkedPosition(rewrite.track(expression), false, "initializer"); // $NON-NLS-1$
    proposals.add(proposal);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:43,代码来源:LocalCorrectionsSubProcessor.java

示例9: addInvalidVariableNameProposals

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
public static void addInvalidVariableNameProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  // hiding, redefined or future keyword

  CompilationUnit root = context.getASTRoot();
  ASTNode selectedNode = problem.getCoveringNode(root);
  if (selectedNode instanceof MethodDeclaration) {
    selectedNode = ((MethodDeclaration) selectedNode).getName();
  }
  if (!(selectedNode instanceof SimpleName)) {
    return;
  }
  SimpleName nameNode = (SimpleName) selectedNode;
  String valueSuggestion = null;

  String name;
  switch (problem.getProblemId()) {
    case IProblem.LocalVariableHidingLocalVariable:
    case IProblem.LocalVariableHidingField:
      name =
          Messages.format(
              CorrectionMessages.LocalCorrectionsSubProcessor_hiding_local_label,
              BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
      break;
    case IProblem.FieldHidingLocalVariable:
    case IProblem.FieldHidingField:
    case IProblem.DuplicateField:
      name =
          Messages.format(
              CorrectionMessages.LocalCorrectionsSubProcessor_hiding_field_label,
              BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
      break;
    case IProblem.ArgumentHidingLocalVariable:
    case IProblem.ArgumentHidingField:
      name =
          Messages.format(
              CorrectionMessages.LocalCorrectionsSubProcessor_hiding_argument_label,
              BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
      break;
    case IProblem.DuplicateMethod:
      name =
          Messages.format(
              CorrectionMessages.LocalCorrectionsSubProcessor_renaming_duplicate_method,
              BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
      break;

    default:
      name =
          Messages.format(
              CorrectionMessages.LocalCorrectionsSubProcessor_rename_var_label,
              BasicElementLabels.getJavaElementName(nameNode.getIdentifier()));
  }

  if (problem.getProblemId() == IProblem.UseEnumAsAnIdentifier) {
    valueSuggestion = "enumeration"; // $NON-NLS-1$
  } else {
    valueSuggestion = nameNode.getIdentifier() + '1';
  }

  LinkedNamesAssistProposal proposal =
      new LinkedNamesAssistProposal(name, context, nameNode, valueSuggestion);
  proposals.add(proposal);
}
 
开发者ID:eclipse,项目名称:che,代码行数:64,代码来源:LocalCorrectionsSubProcessor.java

示例10: addTypeArgumentsFromContext

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
private static void addTypeArgumentsFromContext(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  // similar to UnresolvedElementsSubProcessor.getTypeProposals(context, problem, proposals);

  ICompilationUnit cu = context.getCompilationUnit();

  CompilationUnit root = context.getASTRoot();
  ASTNode selectedNode = problem.getCoveringNode(root);
  if (selectedNode == null) {
    return;
  }

  while (selectedNode.getLocationInParent() == QualifiedName.NAME_PROPERTY) {
    selectedNode = selectedNode.getParent();
  }

  Name node = null;
  if (selectedNode instanceof SimpleType) {
    node = ((SimpleType) selectedNode).getName();
  } else if (selectedNode instanceof NameQualifiedType) {
    node = ((NameQualifiedType) selectedNode).getName();
  } else if (selectedNode instanceof ArrayType) {
    Type elementType = ((ArrayType) selectedNode).getElementType();
    if (elementType.isSimpleType()) {
      node = ((SimpleType) elementType).getName();
    } else if (elementType.isNameQualifiedType()) {
      node = ((NameQualifiedType) elementType).getName();
    } else {
      return;
    }
  } else if (selectedNode instanceof Name) {
    node = (Name) selectedNode;
  } else {
    return;
  }

  // try to resolve type in context
  ITypeBinding binding = ASTResolving.guessBindingForTypeReference(node);
  if (binding != null) {
    ASTNode parent = node.getParent();
    if (parent instanceof Type
        && parent.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY
        && binding.isInterface()) { // bug 351853
      return;
    }
    ITypeBinding simpleBinding = binding;
    if (simpleBinding.isArray()) {
      simpleBinding = simpleBinding.getElementType();
    }
    simpleBinding = simpleBinding.getTypeDeclaration();

    if (!simpleBinding.isRecovered()) {
      if (binding.isParameterizedType()
          && (node.getParent() instanceof SimpleType
              || node.getParent() instanceof NameQualifiedType)
          && !(node.getParent().getParent() instanceof Type)) {
        proposals.add(
            UnresolvedElementsSubProcessor.createTypeRefChangeFullProposal(
                cu, binding, node, IProposalRelevance.TYPE_ARGUMENTS_FROM_CONTEXT));
      }
    }
  } else {
    ASTNode normalizedNode = ASTNodes.getNormalizedNode(node);
    if (!(normalizedNode.getParent() instanceof Type) && node.getParent() != normalizedNode) {
      ITypeBinding normBinding = ASTResolving.guessBindingForTypeReference(normalizedNode);
      if (normBinding != null && !normBinding.isRecovered()) {
        proposals.add(
            UnresolvedElementsSubProcessor.createTypeRefChangeFullProposal(
                cu, normBinding, normalizedNode, IProposalRelevance.TYPE_ARGUMENTS_FROM_CONTEXT));
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:74,代码来源:LocalCorrectionsSubProcessor.java

示例11: getWrongTypeNameProposals

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的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

示例12: addChangeSenderTypeProposals

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
public static void addChangeSenderTypeProposals(
    IInvocationContext context,
    Expression nodeToCast,
    ITypeBinding castTypeBinding,
    boolean isAssignedNode,
    int relevance,
    Collection<ICommandAccess> proposals)
    throws JavaModelException {
  IBinding callerBinding = Bindings.resolveExpressionBinding(nodeToCast, false);

  ICompilationUnit cu = context.getCompilationUnit();
  CompilationUnit astRoot = context.getASTRoot();

  ICompilationUnit targetCu = null;
  ITypeBinding declaringType = null;
  IBinding callerBindingDecl = callerBinding;
  if (callerBinding instanceof IVariableBinding) {
    IVariableBinding variableBinding = (IVariableBinding) callerBinding;

    if (variableBinding.isEnumConstant()) {
      return;
    }
    if (!variableBinding.isField()) {
      targetCu = cu;
    } else {
      callerBindingDecl = variableBinding.getVariableDeclaration();
      ITypeBinding declaringClass = variableBinding.getDeclaringClass();
      if (declaringClass == null) {
        return; // array length
      }
      declaringType = declaringClass.getTypeDeclaration();
    }
  } else if (callerBinding instanceof IMethodBinding) {
    IMethodBinding methodBinding = (IMethodBinding) callerBinding;
    if (!methodBinding.isConstructor()) {
      declaringType = methodBinding.getDeclaringClass().getTypeDeclaration();
      callerBindingDecl = methodBinding.getMethodDeclaration();
    }
  } else if (callerBinding instanceof ITypeBinding
      && nodeToCast.getLocationInParent() == SingleMemberAnnotation.TYPE_NAME_PROPERTY) {
    declaringType = (ITypeBinding) callerBinding;
    callerBindingDecl =
        Bindings.findMethodInType(declaringType, "value", (String[]) null); // $NON-NLS-1$
    if (callerBindingDecl == null) {
      return;
    }
  }

  if (declaringType != null && declaringType.isFromSource()) {
    targetCu = ASTResolving.findCompilationUnitForBinding(cu, astRoot, declaringType);
  }
  if (targetCu != null
      && ASTResolving.isUseableTypeInContext(castTypeBinding, callerBindingDecl, false)) {
    proposals.add(
        new TypeChangeCorrectionProposal(
            targetCu, callerBindingDecl, astRoot, castTypeBinding, isAssignedNode, relevance));
  }

  // add interface to resulting type
  if (!isAssignedNode) {
    ITypeBinding nodeType = nodeToCast.resolveTypeBinding();
    if (castTypeBinding.isInterface()
        && nodeType != null
        && nodeType.isClass()
        && !nodeType.isAnonymous()
        && nodeType.isFromSource()) {
      ITypeBinding typeDecl = nodeType.getTypeDeclaration();
      ICompilationUnit nodeCu = ASTResolving.findCompilationUnitForBinding(cu, astRoot, typeDecl);
      if (nodeCu != null
          && ASTResolving.isUseableTypeInContext(castTypeBinding, typeDecl, true)) {
        proposals.add(
            new ImplementInterfaceProposal(
                nodeCu, typeDecl, astRoot, castTypeBinding, relevance - 1));
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:78,代码来源:TypeMismatchSubProcessor.java

示例13: addIncompatibleReturnTypeProposals

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
public static void addIncompatibleReturnTypeProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals)
    throws JavaModelException {
  CompilationUnit astRoot = context.getASTRoot();
  ASTNode selectedNode = problem.getCoveringNode(astRoot);
  if (selectedNode == null) {
    return;
  }
  MethodDeclaration decl = ASTResolving.findParentMethodDeclaration(selectedNode);
  if (decl == null) {
    return;
  }
  IMethodBinding methodDeclBinding = decl.resolveBinding();
  if (methodDeclBinding == null) {
    return;
  }

  ITypeBinding returnType = methodDeclBinding.getReturnType();
  IMethodBinding overridden = Bindings.findOverriddenMethod(methodDeclBinding, false);
  if (overridden == null || overridden.getReturnType() == returnType) {
    return;
  }

  ICompilationUnit cu = context.getCompilationUnit();
  IMethodBinding methodDecl = methodDeclBinding.getMethodDeclaration();
  ITypeBinding overriddenReturnType = overridden.getReturnType();
  if (!JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {
    overriddenReturnType = overriddenReturnType.getErasure();
  }
  proposals.add(
      new TypeChangeCorrectionProposal(
          cu,
          methodDecl,
          astRoot,
          overriddenReturnType,
          false,
          IProposalRelevance.CHANGE_RETURN_TYPE));

  ICompilationUnit targetCu = cu;

  IMethodBinding overriddenDecl = overridden.getMethodDeclaration();
  ITypeBinding overridenDeclType = overriddenDecl.getDeclaringClass();

  if (overridenDeclType.isFromSource()) {
    targetCu = ASTResolving.findCompilationUnitForBinding(cu, astRoot, overridenDeclType);
    if (targetCu != null
        && ASTResolving.isUseableTypeInContext(returnType, overriddenDecl, false)) {
      TypeChangeCorrectionProposal proposal =
          new TypeChangeCorrectionProposal(
              targetCu,
              overriddenDecl,
              astRoot,
              returnType,
              false,
              IProposalRelevance.CHANGE_RETURN_TYPE_OF_OVERRIDDEN);
      if (overridenDeclType.isInterface()) {
        proposal.setDisplayName(
            Messages.format(
                CorrectionMessages.TypeMismatchSubProcessor_changereturnofimplemented_description,
                BasicElementLabels.getJavaElementName(overriddenDecl.getName())));
      } else {
        proposal.setDisplayName(
            Messages.format(
                CorrectionMessages.TypeMismatchSubProcessor_changereturnofoverridden_description,
                BasicElementLabels.getJavaElementName(overriddenDecl.getName())));
      }
      proposals.add(proposal);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:71,代码来源:TypeMismatchSubProcessor.java

示例14: getExtractMethodProposal

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
private static boolean getExtractMethodProposal(
    IInvocationContext context,
    ASTNode coveringNode,
    boolean problemsAtLocation,
    Collection<ICommandAccess> proposals)
    throws CoreException {
  if (!(coveringNode instanceof Expression)
      && !(coveringNode instanceof Statement)
      && !(coveringNode instanceof Block)) {
    return false;
  }
  if (coveringNode instanceof Block) {
    List<Statement> statements = ((Block) coveringNode).statements();
    int startIndex = getIndex(context.getSelectionOffset(), statements);
    if (startIndex == -1) return false;
    int endIndex =
        getIndex(context.getSelectionOffset() + context.getSelectionLength(), statements);
    if (endIndex == -1 || endIndex <= startIndex) return false;
  }

  if (proposals == null) {
    return true;
  }

  final ICompilationUnit cu = context.getCompilationUnit();
  final ExtractMethodRefactoring extractMethodRefactoring =
      new ExtractMethodRefactoring(
          context.getASTRoot(), context.getSelectionOffset(), context.getSelectionLength());
  extractMethodRefactoring.setMethodName("extracted"); // $NON-NLS-1$
  if (extractMethodRefactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
    String label = CorrectionMessages.QuickAssistProcessor_extractmethod_description;
    LinkedProposalModel linkedProposalModel = new LinkedProposalModel();
    extractMethodRefactoring.setLinkedProposalModel(linkedProposalModel);

    Image image = JavaPluginImages.get(JavaPluginImages.DESC_MISC_PUBLIC);
    int relevance =
        problemsAtLocation
            ? IProposalRelevance.EXTRACT_METHOD_ERROR
            : IProposalRelevance.EXTRACT_METHOD;
    RefactoringCorrectionProposal proposal =
        new RefactoringCorrectionProposal(label, cu, extractMethodRefactoring, relevance, image);
    proposal.setCommandId(EXTRACT_METHOD_INPLACE_ID);
    proposal.setLinkedProposalModel(linkedProposalModel);
    proposals.add(proposal);
  }
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:48,代码来源:QuickAssistProcessor.java

示例15: getAssignParamToFieldProposals

import org.eclipse.jdt.ui.text.java.IInvocationContext; //导入方法依赖的package包/类
private static boolean getAssignParamToFieldProposals(
    IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
  node = ASTNodes.getNormalizedNode(node);
  ASTNode parent = node.getParent();
  if (!(parent instanceof SingleVariableDeclaration)
      || !(parent.getParent() instanceof MethodDeclaration)) {
    return false;
  }
  SingleVariableDeclaration paramDecl = (SingleVariableDeclaration) parent;
  IVariableBinding binding = paramDecl.resolveBinding();

  MethodDeclaration methodDecl = (MethodDeclaration) parent.getParent();
  if (binding == null || methodDecl.getBody() == null) {
    return false;
  }
  ITypeBinding typeBinding = binding.getType();
  if (typeBinding == null) {
    return false;
  }

  if (resultingCollections == null) {
    return true;
  }

  ITypeBinding parentType = Bindings.getBindingOfParentType(node);
  if (parentType != null) {
    if (parentType.isInterface()) {
      return false;
    }
    // assign to existing fields
    CompilationUnit root = context.getASTRoot();
    IVariableBinding[] declaredFields = parentType.getDeclaredFields();
    boolean isStaticContext = ASTResolving.isInStaticContext(node);
    for (int i = 0; i < declaredFields.length; i++) {
      IVariableBinding curr = declaredFields[i];
      if (isStaticContext == Modifier.isStatic(curr.getModifiers())
          && typeBinding.isAssignmentCompatible(curr.getType())) {
        ASTNode fieldDeclFrag = root.findDeclaringNode(curr);
        if (fieldDeclFrag instanceof VariableDeclarationFragment) {
          VariableDeclarationFragment fragment = (VariableDeclarationFragment) fieldDeclFrag;
          if (fragment.getInitializer() == null) {
            resultingCollections.add(
                new AssignToVariableAssistProposal(
                    context.getCompilationUnit(),
                    paramDecl,
                    fragment,
                    typeBinding,
                    IProposalRelevance.ASSIGN_PARAM_TO_EXISTING_FIELD));
          }
        }
      }
    }
  }

  AssignToVariableAssistProposal fieldProposal =
      new AssignToVariableAssistProposal(
          context.getCompilationUnit(),
          paramDecl,
          null,
          typeBinding,
          IProposalRelevance.ASSIGN_PARAM_TO_NEW_FIELD);
  fieldProposal.setCommandId(ASSIGN_PARAM_TO_FIELD_ID);
  resultingCollections.add(fieldProposal);
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:66,代码来源:QuickAssistProcessor.java


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