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


Java NewArrayTree类代码示例

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


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

示例1: rewriteNewArrayTree

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
private void rewriteNewArrayTree(WorkingCopy copy, TreeMaker mk, TreePath natPath, TypeMirror compType) {
    NewArrayTree nat = (NewArrayTree)natPath.getLeaf();
    TypeMirror existing = copy.getTrees().getTypeMirror(natPath);
    int existingDim = numberOfDimensions(existing);
    int newDim = numberOfDimensions(compType);
    
    if (existingDim == newDim + 1 /* newDim is counted from component type, lacks the enclosing array */) {
        // simple, number of dimensions does not change
        copy.rewrite(nat.getType(), mk.Type(compType));
        return;
    }
    List<ExpressionTree> l = new ArrayList<ExpressionTree>(nat.getDimensions().subList(
            0, Math.min(newDim + 1, nat.getDimensions().size())));
    Tree replacement = mk.NewArray(mk.Type(compType), l, null);
    GeneratorUtilities.get(copy).copyComments(nat, replacement, true);
    GeneratorUtilities.get(copy).copyComments(nat, replacement, false);
    
    copy.rewrite(nat, replacement);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SuspiciousToArray.java

示例2: 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

示例3: 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

示例4: getArrayType

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
private ArrayType getArrayType(NewArrayTree arg0, Type type, int depth, EvaluationContext evaluationContext) {
    String arrayClassName;
    if (depth < BRACKETS.length()/2) {
        arrayClassName = type.name() + BRACKETS.substring(0, 2*depth);
    } else {
        arrayClassName = type.name() + BRACKETS;
        for (int i = BRACKETS.length()/2; i < depth; i++) {
            arrayClassName += "[]"; // NOI18N
        }
    }
    ReferenceType rt = getOrLoadClass(type.virtualMachine(), arrayClassName, evaluationContext);
    if (rt == null) {
        Assert.error(arg0, "unknownType", arrayClassName);
    }
    return (ArrayType) rt;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:EvaluatorVisitor.java

示例5: 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

示例6: 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

示例7: annotationsFromArrayCreation

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
public final static List<? extends AnnotationMirror> annotationsFromArrayCreation(NewArrayTree node, int level) {

        assert node instanceof JCNewArray;
        final JCNewArray newArray = ((JCNewArray) node);

        if (level == -1) {
            return annotationsFromTypeAnnotationTrees(newArray.annotations);
        }

        if (newArray.dimAnnotations.length() > 0
                && (level >= 0)
                && (level < newArray.dimAnnotations.size()))
            return annotationsFromTypeAnnotationTrees(newArray.dimAnnotations.get(level));

        return Collections.emptyList();
    }
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:17,代码来源:InternalUtils.java

示例8: visitNewArray

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
@Override
public Void visitNewArray(NewArrayTree node, Void p) {
    AnnotatedArrayType type = atypeFactory.getAnnotatedType(node);
    AnnotatedTypeMirror componentType = type.getComponentType();
    if (componentType.hasEffectiveAnnotation(NONNULL)
            && !isNewArrayAllZeroDims(node)
            && !isNewArrayInToArray(node)
            && !TypesUtils.isPrimitive(componentType.getUnderlyingType())
            && checker.getLintOption("arrays:forbidnonnullcomponents",
                    false)) {
        checker.report(
                Result.failure("new.array.type.invalid",
                        componentType.getAnnotations(), type.toString()),
                node);
    }

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

示例9: isNewArrayAllZeroDims

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
/**
 * Determine whether all dimensions given in a new array expression have
 * zero as length. For example "new Object[0][0];". Also true for empty
 * dimensions, as in "new Object[] {...}".
 */
private static boolean isNewArrayAllZeroDims(NewArrayTree node) {
    boolean isAllZeros = true;
    for (ExpressionTree dim : node.getDimensions()) {
        if (dim instanceof LiteralTree) {
            Object val = ((LiteralTree) dim).getValue();
            if (!(val instanceof Number) || !(new Integer(0).equals(val))) {
                isAllZeros = false;
                break;
            }
        } else {
            isAllZeros = false;
            break;
        }
    }
    return isAllZeros;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:22,代码来源:NullnessVisitor.java

示例10: annotateArrayAsArray

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
private void annotateArrayAsArray(AnnotatedArrayType result, NewArrayTree node, AnnotatedTypeFactory f) {
    // Copy annotations from the type.
    AnnotatedTypeMirror treeElem = f.fromTypeTree(node.getType());
    boolean hasInit = node.getInitializers() != null;
    AnnotatedTypeMirror typeElem = descendBy(result,
            hasInit ? 1 : node.getDimensions().size());
    while (true) {
        typeElem.addAnnotations(treeElem.getAnnotations());
        if (!(treeElem instanceof AnnotatedArrayType)) break;
        assert typeElem instanceof AnnotatedArrayType;
        treeElem = ((AnnotatedArrayType)treeElem).getComponentType();
        typeElem = ((AnnotatedArrayType)typeElem).getComponentType();
    }
    // Add all dimension annotations.
    int idx = 0;
    AnnotatedTypeMirror level = result;
    while (level.getKind() == TypeKind.ARRAY) {
        AnnotatedArrayType array = (AnnotatedArrayType)level;
        List<? extends AnnotationMirror> annos = InternalUtils.annotationsFromArrayCreation(node, idx++);
        array.addAnnotations(annos);
        level = array.getComponentType();
    }

    // Add top-level annotations.
    result.addAnnotations(InternalUtils.annotationsFromArrayCreation(node, -1));
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:27,代码来源:TypeFromTree.java

示例11: annotationsFromArrayCreation

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
public static final List<? extends AnnotationMirror> annotationsFromArrayCreation(
        NewArrayTree node, int level) {

    assert node instanceof JCNewArray;
    final JCNewArray newArray = ((JCNewArray) node);

    if (level == -1) {
        return annotationsFromTypeAnnotationTrees(newArray.annotations);
    }

    if (newArray.dimAnnotations.length() > 0
            && (level >= 0)
            && (level < newArray.dimAnnotations.size()))
        return annotationsFromTypeAnnotationTrees(newArray.dimAnnotations.get(level));

    return Collections.emptyList();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:18,代码来源:InternalUtils.java

示例12: visitNewArray

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
@Override
public Tree visitNewArray(NewArrayTree tree, Void p) {
    NewArrayTree n = make.NewArray(tree.getType(), tree.getDimensions(), tree.getInitializers());
    model.setType(n, model.getType(tree));
    comments.copyComments(tree, n);
    model.setPos(n, model.getPos(tree));
    return n;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:TreeDuplicator.java

示例13: visitNewArray

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
public Boolean visitNewArray(NewArrayTree node, TreePath p) {
    if (p == null)
        return super.visitNewArray(node, p);

    NewArrayTree t = (NewArrayTree) p.getLeaf();

    if (!checkLists(node.getDimensions(), t.getDimensions(), p))
        return false;

    if (!checkLists(node.getInitializers(), t.getInitializers(), p))
        return false;

    return scan(node.getType(), t.getType(), p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:CopyFinder.java

示例14: test120768

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
public void test120768() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "    byte[] test = new byte[10000];\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "    byte[] test = new byte[WHAT_A_F];\n" +
        "}\n";
    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            VariableTree var = (VariableTree) clazz.getMembers().get(1);
            NewArrayTree nat = (NewArrayTree) var.getInitializer();
            workingCopy.rewrite(nat.getDimensions().get(0), make.Identifier("WHAT_A_F"));
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:ArraysTest.java

示例15: test162485a

import com.sun.source.tree.NewArrayTree; //导入依赖的package包/类
public void test162485a() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "    Object test = new int[2];\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "    Object test = {{1}};\n" +
        "}\n";
    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            VariableTree var = (VariableTree) clazz.getMembers().get(1);
            NewArrayTree nat = (NewArrayTree) var.getInitializer();
            NewArrayTree dim2 = make.NewArray(null, Collections.<ExpressionTree>emptyList(), Collections.singletonList(make.Literal(Integer.valueOf(1))));
            NewArrayTree newTree = make.NewArray(null, Collections.<ExpressionTree>emptyList(), Collections.<ExpressionTree>singletonList(dim2));
            workingCopy.rewrite(nat, newTree);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:ArraysTest.java


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