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


Java NewArrayTree.getInitializers方法代码示例

本文整理汇总了Java中com.sun.source.tree.NewArrayTree.getInitializers方法的典型用法代码示例。如果您正苦于以下问题:Java NewArrayTree.getInitializers方法的具体用法?Java NewArrayTree.getInitializers怎么用?Java NewArrayTree.getInitializers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.source.tree.NewArrayTree的用法示例。


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

示例1: findArrayValue

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
public static List<AnnotationTree> findArrayValue(AnnotationTree at, String name) {
    ExpressionTree fixesArray = findValue(at, name);
    List<AnnotationTree> fixes = new LinkedList<AnnotationTree>();

    if (fixesArray != null && fixesArray.getKind() == Kind.NEW_ARRAY) {
        NewArrayTree trees = (NewArrayTree) fixesArray;

        for (ExpressionTree fix : trees.getInitializers()) {
            if (fix.getKind() == Kind.ANNOTATION) {
                fixes.add((AnnotationTree) fix);
            }
        }
    }

    if (fixesArray != null && fixesArray.getKind() == Kind.ANNOTATION) {
        fixes.add((AnnotationTree) fixesArray);
    }
    
    return fixes;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Utilities.java

示例2: checkZeroSizeArray

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
private static boolean checkZeroSizeArray(CompilationInfo info, TreePath val) {
    if (val.getLeaf().getKind() != Tree.Kind.VARIABLE) {
        return false;
    }
    VariableTree vt = (VariableTree)val.getLeaf();
    ExpressionTree xpr = vt.getInitializer();
    if (xpr == null) {
        return false;
    }
    if (xpr.getKind() == Tree.Kind.NEW_ARRAY) {
        NewArrayTree nat = (NewArrayTree)xpr;
        List<? extends ExpressionTree> dims = nat.getDimensions();
        if (dims != null && !dims.isEmpty()) {
            Object size = ArithmeticUtilities.compute(info, 
                    new TreePath(
                        new TreePath(val, xpr),
                        dims.get(dims.size() -1)), 
                    true);
            return ArithmeticUtilities.isRealValue(size) && Integer.valueOf(0).equals(size);
        } else {
            return nat.getInitializers() != null && nat.getInitializers().isEmpty();
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ConstantNameHint.java

示例3: rowLength

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
static int rowLength(List<? extends ExpressionTree> row) {
    int size = 0;
    for (ExpressionTree tree : row) {
        if (tree.getKind() != NEW_ARRAY) {
            size++;
            continue;
        }
        NewArrayTree array = (NewArrayTree) tree;
        if (array.getInitializers() == null) {
            size++;
            continue;
        }
        size += rowLength(array.getInitializers());
    }
    return size;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:JavaInputAstVisitor.java

示例4: matches

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
@Override
public boolean matches(AnnotationTree annotationTree, VisitorState state) {
  ExpressionTree expressionTree = AnnotationMatcherUtils.getArgument(annotationTree, element);
  if (expressionTree == null) {
    return false;
  }

  expressionTree = ASTHelpers.stripParentheses(expressionTree);

  if (expressionTree instanceof NewArrayTree) {
    NewArrayTree arrayTree = (NewArrayTree) expressionTree;
    for (ExpressionTree elementTree : arrayTree.getInitializers()) {
      if (valueMatcher.matches(elementTree, state)) {
        return true;
      }
    }
    return false;
  }

  return valueMatcher.matches(expressionTree, state);
}
 
开发者ID:google,项目名称:error-prone,代码行数:22,代码来源:AnnotationHasArgumentWithValue.java

示例5: computeNewArray

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeNewArray(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    NewArrayTree nat = (NewArrayTree) parent.getLeaf();
    
    if (nat.getType() == error) {
        types.add(ElementKind.CLASS);
        types.add(ElementKind.ENUM);
        types.add(ElementKind.INTERFACE);
        
        return null;
    }
    
    for (Tree dimension : nat.getDimensions()) {
        if (dimension == error) {
            types.add(ElementKind.PARAMETER);
            types.add(ElementKind.LOCAL_VARIABLE);
            types.add(ElementKind.FIELD);
            
            return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.INT));
        }
    }
    
    for (Tree init : nat.getInitializers()) {
        if (init == error) {
            TypeMirror whole = info.getTrees().getTypeMirror(parent);
            
            if (whole == null || whole.getKind() != TypeKind.ARRAY)
                return null;
            
            types.add(ElementKind.PARAMETER);
            types.add(ElementKind.LOCAL_VARIABLE);
            types.add(ElementKind.FIELD);
            
            return Collections.singletonList(((ArrayType) whole).getComponentType());
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:CreateElementUtilities.java

示例6: after

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
@TriggerPattern(value="$mods$ $type[] $name = $init$;")
public static ErrorDescription after(HintContext ctx) {
    VariableElement var = testElement(ctx);

    if (var == null) return null;

    Tree parent = ctx.getPath().getParentPath().getLeaf();

    if (parent.getKind() == Kind.ENHANCED_FOR_LOOP
        && ((EnhancedForLoopTree) parent).getVariable() == ctx.getPath().getLeaf()) {
        return null;
    }
    
    TreePath init = ctx.getVariables().get("$init$");

    if (init != null) {
        boolean asWrite = true;
        
        if (init.getLeaf().getKind() == Kind.NEW_ARRAY) {
            NewArrayTree nat = (NewArrayTree) init.getLeaf();

            if (nat.getInitializers() == null || nat.getInitializers().isEmpty()) {
                asWrite = false;
            }
        }
        
        if (asWrite) {
            record(ctx.getInfo(), var, State.WRITE);
        }
    }

    return produceWarning(ctx, "ERR_UnbalancedArray");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:Unbalanced.java

示例7: performRewrite

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath path = ctx.getPath();
    TypeMirror compType = ctype.resolve(wc);
    if (compType == null) {
        return;
    }
    TreeMaker mk = wc.getTreeMaker();
    Tree l = path.getLeaf();
    if (l.getKind() == Tree.Kind.NEW_ARRAY) {
        NewArrayTree nat = (NewArrayTree)l;
        // if there are some initializers, we should probably rewrite the whole expression.
        if (nat.getInitializers() == null) {
            rewriteNewArrayTree(wc, mk, path, compType);
            return;
        }
    }
    // replace the entire tree
    TreePath colRef = null;
    if (colReference != null) {
        colRef = colReference.resolve(wc);
        if (colRef == null) {
            return;
        }
    }
    GeneratorUtilities gu = GeneratorUtilities.get(wc);
    Tree lc = gu.importComments(l, wc.getCompilationUnit());
    Tree newArrayTree = mk.NewArray(mk.Type(compType), Collections.<ExpressionTree>singletonList(
            mk.MethodInvocation(Collections.<ExpressionTree>emptyList(), 
                colRef == null ? mk.Identifier("size") :
                mk.MemberSelect((ExpressionTree)colRef.getLeaf(), "size"), // NOI18N
                Collections.<ExpressionTree>emptyList())),
            null);
    gu.copyComments(lc, newArrayTree, true);
    gu.copyComments(lc, newArrayTree, false);
    wc.rewrite(lc, newArrayTree);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:SuspiciousToArray.java

示例8: visitNewArray

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
@Override
public Boolean visitNewArray(NewArrayTree node, Void p) {
    if (node.getInitializers() != null) {
        for (ExpressionTree et : node.getInitializers()) {
            if (scan(et, p) == Boolean.TRUE) {
                assignedToArray = true;
                break;
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ReplaceBufferByString.java

示例9: visitNewArray

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
@Override
    public Void visitNewArray(NewArrayTree node, Void unused) {
        if (node.getType() != null) {
            builder.open(plusFour);
            token("new");
            builder.space();

            TypeWithDims extractedDims = DimensionHelpers.extractDims(node.getType(), SortedDims.YES);
            Tree base = extractedDims.node;

            Deque<ExpressionTree> dimExpressions = new ArrayDeque<>(node.getDimensions());

            Deque<List<AnnotationTree>> annotations = new ArrayDeque<>();
            // TODO: 22-Jul-17 missing method java8
//            annotations.add(ImmutableList.copyOf(node.getAnnotations()));
//            annotations.addAll((List<List<AnnotationTree>>) node.getDimAnnotations());
            annotations.addAll(extractedDims.dims);

            scan(base, null);
            builder.open(ZERO);
            maybeAddDims(dimExpressions, annotations);
            builder.close();
            builder.close();
        }
        if (node.getInitializers() != null) {
            if (node.getType() != null) {
                builder.space();
            }
            visitArrayInitializer(node.getInitializers());
        }
        return null;
    }
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:33,代码来源:JavaInputAstVisitor.java

示例10: getSuggestedFix

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
protected final Fix getSuggestedFix(AnnotationTree annotationTree) {
  List<String> values = new ArrayList<>();
  for (ExpressionTree argumentTree : annotationTree.getArguments()) {
    AssignmentTree assignmentTree = (AssignmentTree) argumentTree;
    if (assignmentTree.getVariable().toString().equals("value")) {
      ExpressionTree expressionTree = assignmentTree.getExpression();
      switch (expressionTree.getKind()) {
        case STRING_LITERAL:
          values.add(((String) ((JCTree.JCLiteral) expressionTree).value));
          break;
        case NEW_ARRAY:
          NewArrayTree newArrayTree = (NewArrayTree) expressionTree;
          for (ExpressionTree elementTree : newArrayTree.getInitializers()) {
            values.add((String) ((JCTree.JCLiteral) elementTree).value);
          }
          break;
        default:
          throw new AssertionError("Unknown kind: " + expressionTree.getKind());
      }
      processSuppressWarningsValues(values);
    } else {
      throw new AssertionError("SuppressWarnings has an element other than value=");
    }
  }

  if (values.isEmpty()) {
    return SuggestedFix.delete(annotationTree);
  } else if (values.size() == 1) {
    return SuggestedFix.replace(annotationTree, "@SuppressWarnings(\"" + values.get(0) + "\")");
  } else {
    return SuggestedFix.replace(
        annotationTree, "@SuppressWarnings({\"" + Joiner.on("\", \"").join(values) + "\"})");
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:35,代码来源:AbstractSuppressWarningsMatcher.java

示例11: matches

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
@Override
public boolean matches(AnnotationTree annotationTree, VisitorState state) {
  for (ExpressionTree argumentTree : annotationTree.getArguments()) {
    if (argumentTree.getKind() == Tree.Kind.ASSIGNMENT) {
      AssignmentTree assignmentTree = (AssignmentTree) argumentTree;
      if (assignmentTree.getVariable().toString().equals(element)) {
        ExpressionTree expressionTree = assignmentTree.getExpression();
        while (expressionTree instanceof ParenthesizedTree) {
          expressionTree = ((ParenthesizedTree) expressionTree).getExpression();
        }

        if (expressionTree instanceof NewArrayTree) {
          NewArrayTree arrayTree = (NewArrayTree) expressionTree;
          for (ExpressionTree elementTree : arrayTree.getInitializers()) {
            if (valueMatcher.matches(elementTree, state)) {
              return true;
            }
          }
          return false;
        }

        return valueMatcher.matches(expressionTree, state);
      }
    }
  }
  return false;
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:28,代码来源:AnnotationHasArgumentWithValue.java

示例12: getSuggestedFix

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
protected final Fix getSuggestedFix(AnnotationTree annotationTree) {
  List<String> values = new ArrayList<String>();
  for (ExpressionTree argumentTree : annotationTree.getArguments()) {
    AssignmentTree assignmentTree = (AssignmentTree) argumentTree;
    if (assignmentTree.getVariable().toString().equals("value")) {
      ExpressionTree expressionTree = assignmentTree.getExpression();
      switch (expressionTree.getKind()) {
        case STRING_LITERAL:
          values.add(((String) ((JCTree.JCLiteral) expressionTree).value));
          break;
        case NEW_ARRAY:
          NewArrayTree newArrayTree = (NewArrayTree) expressionTree;
          for (ExpressionTree elementTree : newArrayTree.getInitializers()) {
            values.add((String) ((JCTree.JCLiteral) elementTree).value);
          }
          break;
        default:
          throw new AssertionError("Unknown kind: " + expressionTree.getKind());
      }
      processSuppressWarningsValues(values);
    } else {
      throw new AssertionError("SuppressWarnings has an element other than value=");
    }
  }

  if (values.size() == 0) {
    return new SuggestedFix().delete(annotationTree);
  } else if (values.size() == 1) {
    return new SuggestedFix()
        .replace(annotationTree, "@SuppressWarnings(\"" + values.get(0) + "\")");
  } else {
    StringBuilder sb = new StringBuilder("@SuppressWarnings({\"" + values.get(0) + "\"");
    for (int i = 1; i < values.size(); i++) {
      sb.append(", ");
      sb.append("\"" + values.get(i) + "\"");
    }
    sb.append("})");
    return new SuggestedFix().replace(annotationTree, sb.toString());
  }
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:41,代码来源:AbstractSuppressWarningsMatcher.java

示例13: visitNewArray

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
@Override
public Node visitNewArray(NewArrayTree tree, Void p) {
    // see JLS 15.10

    ArrayType type = (ArrayType)InternalUtils.typeOf(tree);
    TypeMirror elemType = type.getComponentType();

    List<? extends ExpressionTree> dimensions = tree.getDimensions();
    List<? extends ExpressionTree> initializers = tree
            .getInitializers();

    List<Node> dimensionNodes = new ArrayList<Node>();
    if (dimensions != null) {
        for (ExpressionTree dim : dimensions) {
            dimensionNodes.add(unaryNumericPromotion(scan(dim, p)));
        }
    }

    List<Node> initializerNodes = new ArrayList<Node>();
    if (initializers != null) {
        for (ExpressionTree init : initializers) {
            initializerNodes.add(assignConvert(scan(init, p), elemType));
        }
    }

    Node node = new ArrayCreationNode(tree, type, dimensionNodes,
            initializerNodes);
    return extendWithNode(node);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:30,代码来源:CFGBuilder.java

示例14: visitNewArray

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
@Override
public Void visitNewArray(NewArrayTree node, Void p) {
    boolean valid = validateTypeOf(node);
    if (valid && node.getType() != null && node.getInitializers() != null) {
        AnnotatedArrayType arrayType = atypeFactory.getAnnotatedType(node);
        checkArrayInitialization(arrayType.getComponentType(),
                node.getInitializers());
    }

    return super.visitNewArray(node, p);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:12,代码来源:BaseTypeVisitor.java

示例15: visitNewArray

import com.sun.source.tree.NewArrayTree; //导入方法依赖的package包/类
@Override
public Node visitNewArray(NewArrayTree tree, Void p) {
    // see JLS 15.10

    ArrayType type = (ArrayType) InternalUtils.typeOf(tree);
    TypeMirror elemType = type.getComponentType();

    List<? extends ExpressionTree> dimensions = tree.getDimensions();
    List<? extends ExpressionTree> initializers = tree.getInitializers();

    List<Node> dimensionNodes = new ArrayList<Node>();
    if (dimensions != null) {
        for (ExpressionTree dim : dimensions) {
            dimensionNodes.add(unaryNumericPromotion(scan(dim, p)));
        }
    }

    List<Node> initializerNodes = new ArrayList<Node>();
    if (initializers != null) {
        for (ExpressionTree init : initializers) {
            initializerNodes.add(assignConvert(scan(init, p), elemType));
        }
    }

    Node node = new ArrayCreationNode(tree, type, dimensionNodes, initializerNodes);
    return extendWithNode(node);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:28,代码来源:CFGBuilder.java


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