com.sun.source.tree.ArrayTypeTree Java Examples
The following examples show how to use
com.sun.source.tree.ArrayTypeTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DimensionHelpers.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Accumulates a flattened list of array dimensions specifiers with type annotations, and returns * the base type. * <p> * <p>Given {@code int @A @B [][] @C []}, adds {@code [[@A, @B], [@C]]} to dims and returns {@code * int}. */ private static Tree extractDims(Deque<List<AnnotationTree>> dims, Tree node) { switch (node.getKind()) { case ARRAY_TYPE: return extractDims(dims, ((ArrayTypeTree) node).getType()); // TODO: 22-Jul-17 missing type /* case ANNOTATED_TYPE: AnnotatedTypeTree annotatedTypeTree = (AnnotatedTypeTree) node; if (annotatedTypeTree.getUnderlyingType().getKind() != Tree.Kind.ARRAY_TYPE) { return node; } node = extractDims(dims, annotatedTypeTree.getUnderlyingType()); dims.addFirst(ImmutableList.<AnnotationTree>copyOf(annotatedTypeTree.getAnnotations())); return node;*/ default: return node; } }
Example #2
Source File: DimensionHelpers.java From google-java-format with Apache License 2.0 | 6 votes |
/** * Accumulates a flattened list of array dimensions specifiers with type annotations, and returns * the base type. * * <p>Given {@code int @A @B [][] @C []}, adds {@code [[@A, @B], [@C]]} to dims and returns {@code * int}. */ private static Tree extractDims(Deque<List<AnnotationTree>> dims, Tree node) { switch (node.getKind()) { case ARRAY_TYPE: return extractDims(dims, ((ArrayTypeTree) node).getType()); case ANNOTATED_TYPE: AnnotatedTypeTree annotatedTypeTree = (AnnotatedTypeTree) node; if (annotatedTypeTree.getUnderlyingType().getKind() != Tree.Kind.ARRAY_TYPE) { return node; } node = extractDims(dims, annotatedTypeTree.getUnderlyingType()); dims.addFirst(ImmutableList.copyOf(annotatedTypeTree.getAnnotations())); return node; default: return node; } }
Example #3
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 6 votes |
@Override public Void visitAnnotatedType(AnnotatedTypeTree node, Void unused) { sync(node); ExpressionTree base = node.getUnderlyingType(); if (base instanceof MemberSelectTree) { MemberSelectTree selectTree = (MemberSelectTree) base; scan(selectTree.getExpression(), null); token("."); visitAnnotations(node.getAnnotations(), BreakOrNot.NO, BreakOrNot.NO); builder.breakToFill(" "); visit(selectTree.getIdentifier()); } else if (base instanceof ArrayTypeTree) { visitAnnotatedArrayType(node); } else { visitAnnotations(node.getAnnotations(), BreakOrNot.NO, BreakOrNot.NO); builder.breakToFill(" "); scan(base, null); } return null; }
Example #4
Source File: TokenList.java From netbeans with Apache License 2.0 | 6 votes |
public void moveToEnd(Tree t) { if (t == null) { return ; } long end = sourcePositions.getEndPosition(info.getCompilationUnit(), t); if (end == (-1)) return ; if (t.getKind() == Kind.ARRAY_TYPE) { moveToEnd(((ArrayTypeTree) t).getType()); return ; } moveToOffset(end); }
Example #5
Source File: TreeFinder.java From annotation-tools with MIT License | 6 votes |
@Override public Pair<ASTRecord, Integer> visitArrayType(ArrayTypeTree node, Insertion ins) { dbug.debug("TypePositionFinder.visitArrayType(%s)%n", node); JCArrayTypeTree att = (JCArrayTypeTree) node; dbug.debug("TypePositionFinder.visitArrayType(%s) preferred = %s%n", node, att.getPreferredPosition()); // If the code has a type like "String[][][]", then this gets called // three times: for String[][][], String[][], and String[] // respectively. For each of the three, call String[][][] "largest". ArrayTypeTree largest = largestContainingArray(node); int largestLevels = arrayLevels(largest); int levels = arrayLevels(node); int start = arrayContentType(att).getPreferredPosition() + 1; int end = att.getEndPosition(tree.endPositions); int pos = arrayInsertPos(start, end); dbug.debug(" levels=%d largestLevels=%d%n", levels, largestLevels); for (int i=levels; i<largestLevels; i++) { pos = getFirstInstanceAfter('[', pos+1); dbug.debug(" pos %d at i=%d%n", pos, i); } return Pair.of(astRecord(node), pos); }
Example #6
Source File: DimensionHelpers.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Accumulates a flattened list of array dimensions specifiers with type annotations, and returns * the base type. * <p> * <p>Given {@code int @A @B [][] @C []}, adds {@code [[@A, @B], [@C]]} to dims and returns {@code * int}. */ private static Tree extractDims(Deque<List<AnnotationTree>> dims, Tree node) { switch (node.getKind()) { case ARRAY_TYPE: return extractDims(dims, ((ArrayTypeTree) node).getType()); // TODO: 22-Jul-17 missing type /* case ANNOTATED_TYPE: AnnotatedTypeTree annotatedTypeTree = (AnnotatedTypeTree) node; if (annotatedTypeTree.getUnderlyingType().getKind() != Tree.Kind.ARRAY_TYPE) { return node; } node = extractDims(dims, annotatedTypeTree.getUnderlyingType()); dims.addFirst(ImmutableList.<AnnotationTree>copyOf(annotatedTypeTree.getAnnotations())); return node;*/ default: return node; } }
Example #7
Source File: TreeDiffer.java From compile-testing with Apache License 2.0 | 5 votes |
@Override public Void visitArrayType(ArrayTypeTree expected, Tree actual) { Optional<ArrayTypeTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getType(), other.get().getType()); return null; }
Example #8
Source File: JVMNames.java From annotation-tools with MIT License | 5 votes |
@SuppressWarnings("signature") // com.sun.source.tree.Tree is not yet annotated private static void treeToJVMLString(Tree typeTree, StringBuilder builder) { // FIXME: not robust in presence of comments switch (typeTree.getKind()) { case ARRAY_TYPE: builder.append('['); treeToJVMLString(((ArrayTypeTree) typeTree).getType(), builder); break; default: String str = typeTree.toString(); builder.append("void".equals(str) ? "V" : Signatures.binaryNameToFieldDescriptor(typeTree.toString())); break; } }
Example #9
Source File: ASTPathCriterion.java From annotation-tools with MIT License | 5 votes |
private boolean checkTypePath(int i, Tree typeTree) { try { loop: while (typeTree != null && i < astPath.size()) { ASTPath.ASTEntry entry = astPath.get(i); Tree.Kind kind = entry.getTreeKind(); switch (kind) { case ANNOTATED_TYPE: typeTree = ((AnnotatedTypeTree) typeTree) .getUnderlyingType(); continue; case ARRAY_TYPE: typeTree = ((ArrayTypeTree) typeTree).getType(); break; case MEMBER_SELECT: typeTree = ((MemberSelectTree) typeTree).getExpression(); break; case PARAMETERIZED_TYPE: if (entry.childSelectorIs(ASTPath.TYPE_ARGUMENT)) { int arg = entry.getArgument(); typeTree = ((ParameterizedTypeTree) typeTree) .getTypeArguments().get(arg); } else { // TYPE typeTree = ((ParameterizedTypeTree) typeTree).getType(); } break; default: if (isWildcard(kind)) { return ++i == astPath.size(); // ??? } break loop; } ++i; } } catch (RuntimeException ex) {} return false; }
Example #10
Source File: TreeFinder.java From annotation-tools with MIT License | 5 votes |
private int arrayLevels(Tree node) { int result = 0; while (node.getKind() == Tree.Kind.ARRAY_TYPE) { result++; node = ((ArrayTypeTree) node).getType(); } return result; }
Example #11
Source File: Move.java From netbeans with Apache License 2.0 | 5 votes |
private ExpressionTree transformInitializer(ExpressionTree initializer, Tree type, TreeMaker make) { if(initializer.getKind() == Tree.Kind.NEW_ARRAY) { NewArrayTree nat = (NewArrayTree) initializer; if(nat.getType() == null) { if(type.getKind() == Tree.Kind.ARRAY_TYPE) { ArrayTypeTree arrayTypeTree = (ArrayTypeTree) type; type = arrayTypeTree.getType(); } return make.NewArray(type, nat.getDimensions(), nat.getInitializers()); } } return initializer; }
Example #12
Source File: TreeNode.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Void visitArrayType(ArrayTypeTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingElement(below); addCorrespondingType(below); addCorrespondingComments(below); super.visitArrayType(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
Example #13
Source File: TreeDuplicator.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Tree visitArrayType(ArrayTypeTree tree, Void p) { ArrayTypeTree n = make.ArrayType(tree.getType()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
Example #14
Source File: CopyFinder.java From netbeans with Apache License 2.0 | 5 votes |
public Boolean visitArrayType(ArrayTypeTree node, TreePath p) { if (p == null) { super.visitArrayType(node, p); return false; } ArrayTypeTree at = (ArrayTypeTree) p.getLeaf(); return scan(node.getType(), at.getType(), p); }
Example #15
Source File: ReplaceConstructorWithBuilderUI.java From netbeans with Apache License 2.0 | 5 votes |
private ReplaceConstructorWithBuilderUI(TreePathHandle constructor, CompilationInfo info) { this.refactoring = new ReplaceConstructorWithBuilderRefactoring(constructor); ExecutableElement contructorElement = (ExecutableElement) constructor.resolveElement(info); this.name = contructorElement.getSimpleName().toString(); MethodTree constTree = (MethodTree) constructor.resolve(info).getLeaf(); paramaterNames = new ArrayList<String>(); parameterTypes = new ArrayList<String>(); parameterTypeVars = new ArrayList<Boolean>(); boolean varargs = contructorElement.isVarArgs(); List<? extends VariableElement> parameterElements = contructorElement.getParameters(); List<? extends VariableTree> parameters = constTree.getParameters(); for (int i = 0; i < parameters.size(); i++) { VariableTree var = parameters.get(i); paramaterNames.add(var.getName().toString()); String type = contructorElement.getParameters().get(i).asType().toString(); if(varargs && i+1 == parameters.size()) { if(var.getType().getKind() == Tree.Kind.ARRAY_TYPE) { ArrayTypeTree att = (ArrayTypeTree) var.getType(); type = att.getType().toString(); type += "..."; //NOI18N } } parameterTypes.add(type); parameterTypeVars.add(parameterElements.get(i).asType().getKind() == TypeKind.TYPEVAR); } TypeElement typeEl = (TypeElement) contructorElement.getEnclosingElement(); if(typeEl.getNestingKind() != NestingKind.TOP_LEVEL) { PackageElement packageOf = info.getElements().getPackageOf(typeEl); builderFQN = packageOf.toString() + "." + typeEl.getSimpleName().toString(); } else { builderFQN = typeEl.getQualifiedName().toString(); } buildMethodName = "create" + typeEl.getSimpleName(); }
Example #16
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
private static Tree normalizeLastLeftTree(Tree lastLeft) { while (lastLeft != null && lastLeft.getKind() == Kind.ARRAY_TYPE) { lastLeft = ((ArrayTypeTree) lastLeft).getType(); } return lastLeft; }
Example #17
Source File: JavaInputAstVisitor.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
@Override public Void visitArrayType(ArrayTypeTree node, Void unused) { sync(node); visitAnnotatedArrayType(node); return null; }
Example #18
Source File: Utilities.java From netbeans with Apache License 2.0 | 4 votes |
private String simpleName(Tree t) { if (t == null) { return Bundle.DisplayName_Unknown(); } if (t.getKind() == Kind.IDENTIFIER) { return ((IdentifierTree) t).getName().toString(); } if (t.getKind() == Kind.MEMBER_SELECT) { return ((MemberSelectTree) t).getIdentifier().toString(); } if (t.getKind() == Kind.METHOD_INVOCATION) { return scan(t, null); } if (t.getKind() == Kind.PARAMETERIZED_TYPE) { return simpleName(((ParameterizedTypeTree) t).getType()) + "<...>"; // NOI18N } if (t.getKind() == Kind.ARRAY_ACCESS) { return simpleName(((ArrayAccessTree) t).getExpression()) + "[]"; //NOI18N } if (t.getKind() == Kind.PARENTHESIZED) { return "(" + simpleName(((ParenthesizedTree)t).getExpression()) + ")"; //NOI18N } if (t.getKind() == Kind.TYPE_CAST) { return simpleName(((TypeCastTree)t).getType()); } if (t.getKind() == Kind.ARRAY_TYPE) { return simpleName(((ArrayTypeTree)t).getType()); } if (t.getKind() == Kind.PRIMITIVE_TYPE) { return ((PrimitiveTypeTree) t).getPrimitiveTypeKind().name().toLowerCase(); } throw new IllegalStateException("Currently unsupported kind of tree: " + t.getKind()); // NOI18N }
Example #19
Source File: UArrayTypeTree.java From Refaster with Apache License 2.0 | 4 votes |
@Override @Nullable public Unifier visitArrayType(ArrayTypeTree tree, @Nullable Unifier unifier) { return getType().unify(tree.getType(), unifier); }
Example #20
Source File: UTemplater.java From Refaster with Apache License 2.0 | 4 votes |
@Override public UArrayTypeTree visitArrayType(ArrayTypeTree tree, Void v) { return UArrayTypeTree.create(templateType(tree.getType())); }
Example #21
Source File: Translator.java From groovy-cps with Apache License 2.0 | 4 votes |
@Override public JType visitArrayType(ArrayTypeTree at, Void __) { return visit(at.getType()).array(); }
Example #22
Source File: TreeConverter.java From j2objc with Apache License 2.0 | 4 votes |
private TreeNode convertArrayType(ArrayTypeTree node, TreePath parent) { TreePath path = getTreePath(parent, node); ArrayType newNode = new ArrayType(); Type componentType = Type.newType(getTypeMirror(getTreePath(path, node.getType()))); return newNode.setComponentType(componentType).setTypeMirror(getTypeMirror(path)); }
Example #23
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 4 votes |
@Override public Void visitArrayType(ArrayTypeTree node, Void unused) { sync(node); visitAnnotatedArrayType(node); return null; }
Example #24
Source File: TreeFinder.java From annotation-tools with MIT License | 4 votes |
private ArrayTypeTree largestContainingArray(Tree node) { TreePath p = getPath(node); Tree result = TreeFinder.largestContainingArray(p).getLeaf(); assert result.getKind() == Tree.Kind.ARRAY_TYPE; return (ArrayTypeTree) result; }
Example #25
Source File: DependencyCollector.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Object visitArrayType(ArrayTypeTree node, Object p) { addDependency(node.getType()); return super.visitArrayType(node, p); }
Example #26
Source File: Eval.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private List<Snippet> processVariables(String userSource, List<? extends Tree> units, String compileSource, ParseTask pt) { List<Snippet> snippets = new ArrayList<>(); TreeDissector dis = TreeDissector.createByFirstClass(pt); for (Tree unitTree : units) { VariableTree vt = (VariableTree) unitTree; String name = vt.getName().toString(); String typeName = EvalPretty.prettyExpr((JCTree) vt.getType(), false); Tree baseType = vt.getType(); TreeDependencyScanner tds = new TreeDependencyScanner(); tds.scan(baseType); // Not dependent on initializer StringBuilder sbBrackets = new StringBuilder(); while (baseType instanceof ArrayTypeTree) { //TODO handle annotations too baseType = ((ArrayTypeTree) baseType).getType(); sbBrackets.append("[]"); } Range rtype = dis.treeToRange(baseType); Range runit = dis.treeToRange(vt); runit = new Range(runit.begin, runit.end - 1); ExpressionTree it = vt.getInitializer(); Range rinit = null; int nameMax = runit.end - 1; SubKind subkind; if (it != null) { subkind = SubKind.VAR_DECLARATION_WITH_INITIALIZER_SUBKIND; rinit = dis.treeToRange(it); nameMax = rinit.begin - 1; } else { subkind = SubKind.VAR_DECLARATION_SUBKIND; } int nameStart = compileSource.lastIndexOf(name, nameMax); if (nameStart < 0) { throw new AssertionError("Name '" + name + "' not found"); } int nameEnd = nameStart + name.length(); Range rname = new Range(nameStart, nameEnd); Wrap guts = Wrap.varWrap(compileSource, rtype, sbBrackets.toString(), rname, rinit); DiagList modDiag = modifierDiagnostics(vt.getModifiers(), dis, true); Snippet snip = new VarSnippet(state.keyMap.keyForVariable(name), userSource, guts, name, subkind, typeName, tds.declareReferences(), modDiag); snippets.add(snip); } return snippets; }
Example #27
Source File: JavaInputAstVisitor.java From javaide with GNU General Public License v3.0 | 4 votes |
@Override public Void visitArrayType(ArrayTypeTree node, Void unused) { sync(node); visitAnnotatedArrayType(node); return null; }
Example #28
Source File: Flow.java From netbeans with Apache License 2.0 | 4 votes |
public Boolean visitArrayType(ArrayTypeTree node, ConstructorData p) { super.visitArrayType(node, p); return null; }
Example #29
Source File: ExpectedTypeResolver.java From netbeans with Apache License 2.0 | 4 votes |
@Override public List<? extends TypeMirror> visitArrayType(ArrayTypeTree node, Object p) { return null; }
Example #30
Source File: Utilities.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Boolean visitArrayType(ArrayTypeTree node, Void p) { return super.visitArrayType(node, p); //To change body of generated methods, choose Tools | Templates. }