コード例 #1
0
  private static List<? extends TypeMirror> computeMethodInvocation(
      Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
    boolean errorInRealArguments = false;

    for (Tree param : nat.getArguments()) {
      errorInRealArguments |= param == error;
    }

    if (errorInRealArguments) {
      TypeMirror[] proposedType = new TypeMirror[1];
      int[] proposedIndex = new int[1];
      ExecutableElement ee =
          org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation(
              info, parent, proposedType, proposedIndex);

      if (ee == null) { // cannot be resolved
        return null;
      }

      types.add(ElementKind.PARAMETER);
      types.add(ElementKind.LOCAL_VARIABLE);
      types.add(ElementKind.FIELD);

      return Collections.singletonList(proposedType[0]);
    }

    return null;
  }
コード例 #2
0
  private static List<? extends TypeMirror> computeNewClass(
      Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    NewClassTree nct = (NewClassTree) parent.getLeaf();
    boolean errorInRealArguments = false;

    for (Tree param : nct.getArguments()) {
      errorInRealArguments |= param == error;
    }

    if (errorInRealArguments) {
      TypeMirror[] proposedType = new TypeMirror[1];
      int[] proposedIndex = new int[1];
      ExecutableElement ee =
          org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation(
              info, parent, proposedType, proposedIndex);

      if (ee == null) { // cannot be resolved
        return null;
      }

      types.add(ElementKind.PARAMETER);
      types.add(ElementKind.LOCAL_VARIABLE);
      types.add(ElementKind.FIELD);

      return Collections.singletonList(proposedType[0]);
    }

    Tree id = nct.getIdentifier();

    if (id.getKind() == Kind.PARAMETERIZED_TYPE) {
      id = ((ParameterizedTypeTree) id).getType();
    }

    if (id == error) {
      return resolveType(
          EnumSet.noneOf(ElementKind.class), info, parent.getParentPath(), nct, offset, null, null);
    }

    return null;
  }