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); }
@Override public Mirror visitArrayType(ArrayTypeTree arg0, EvaluationContext evaluationContext) { Mirror arrayType = arg0.getType().accept(this, evaluationContext); if (!(arrayType instanceof Type)) { return arrayType; } Type type = (Type) arrayType; String arrayClassName = type.name()+"[]"; ReferenceType aType = getOrLoadClass(type.virtualMachine(), arrayClassName, evaluationContext); if (aType != null) { return aType; } else { Assert.error(arg0, "unknownType", arrayClassName); return null; } }
/** * 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; } }
@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); }
@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; }
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); }
@Override public Void visitArrayType(ArrayTypeTree node, EnumSet<UseTypes> p) { if (node.getType() != null) { handlePossibleIdentifier(new TreePath(getCurrentPath(), node.getType()), EnumSet.of(UseTypes.CLASS_USE)); } return super.visitArrayType(node, p); }
private static Tree normalizeLastLeftTree(Tree lastLeft) { while (lastLeft != null && lastLeft.getKind() == Kind.ARRAY_TYPE) { lastLeft = ((ArrayTypeTree) lastLeft).getType(); } return lastLeft; }
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(); }
@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; }
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; }
private String createType(VariableTree tree) { Tree returnType = tree.getType(); if (returnType instanceof ParameterizedTypeTree || returnType instanceof ArrayTypeTree) { return returnType.toString(); } else { return TreeUtils.getTokenFromIdentifierTree(returnType).getImage(); } }
private String createDataType(Tree returnType) { if (returnType instanceof ParameterizedTypeTree || returnType instanceof ArrayTypeTree) { return returnType.toString(); } else { return TreeUtils.getTokenFromIdentifierTree(returnType).getImage(); } }
private int arrayLevels(Tree node) { int result = 0; while (node.getKind() == Tree.Kind.ARRAY_TYPE) { result++; node = ((ArrayTypeTree) node).getType(); } return result; }
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; }
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" : UtilMDE.binaryNameToFieldDescriptor(typeTree.toString())); break; } }
@Override public Void visitArrayType(ArrayTypeTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (ArrayTypeTreeMatcher matcher : arrayTypeMatchers) { if (!isSuppressed(matcher, state)) { try { reportMatch(matcher.matchArrayType(tree, state), tree, state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitArrayType(tree, state); }
private Description checkArrayDimensions(Tree tree, Tree type, VisitorState state) { if (!(type instanceof ArrayTypeTree)) { return NO_MATCH; } CharSequence source = state.getSourceCode(); for (; type instanceof ArrayTypeTree; type = ((ArrayTypeTree) type).getType()) { Tree elemType = ((ArrayTypeTree) type).getType(); int start = state.getEndPosition(elemType); int end = state.getEndPosition(type); if (start >= end) { continue; } String dim = source.subSequence(start, end).toString(); if (dim.isEmpty()) { continue; } ImmutableList<ErrorProneToken> tokens = ErrorProneTokens.getTokens(dim.trim(), state.context); if (tokens.size() > 2 && tokens.get(0).kind() == TokenKind.IDENTIFIER) { int nonWhitespace = CharMatcher.isNot(' ').indexIn(dim); int idx = dim.indexOf("[]", nonWhitespace); if (idx > nonWhitespace) { String replacement = dim.substring(idx, dim.length()) + dim.substring(0, idx); return describeMatch(tree, SuggestedFix.replace(start, end, replacement)); } } } return NO_MATCH; }
@Override public AnnotatedTypeMirror visitArrayType(ArrayTypeTree node, AnnotatedTypeFactory f) { AnnotatedTypeMirror component = visit(node.getType(), f); AnnotatedTypeMirror result = f.type(node); assert result instanceof AnnotatedArrayType; ((AnnotatedArrayType)result).setComponentType(component); return result; }
@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; }
@Override public Object visitArrayType(ArrayTypeTree node, Object p) { addDependency(node.getType()); return super.visitArrayType(node, p); }
public Boolean visitArrayType(ArrayTypeTree node, ConstructorData p) { super.visitArrayType(node, p); return null; }
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 }
@Override public Boolean visitArrayType(ArrayTypeTree node, Void p) { return super.visitArrayType(node, p); //To change body of generated methods, choose Tools | Templates. }
@Override public List<? extends TypeMirror> visitArrayType(ArrayTypeTree node, Object p) { return null; }
@Override public Void visitArrayType(ArrayTypeTree node, Void unused) { sync(node); visitAnnotatedArrayType(node); return null; }
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; }
private List<SnippetEvent> processVariables(String userSource, List<? extends Tree> units, String compileSource, ParseTask pt) { List<SnippetEvent> allEvents = 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); Snippet snip = new VarSnippet(state.keyMap.keyForVariable(name), userSource, guts, name, subkind, typeName, tds.declareReferences()); DiagList modDiag = modifierDiagnostics(vt.getModifiers(), dis, true); List<SnippetEvent> res1 = declare(snip, modDiag); allEvents.addAll(res1); } return allEvents; }
@Override public R visitArrayType(ArrayTypeTree att, P p) { return null; }
@Override public List<T> visitArrayType(ArrayTypeTree node, T p) { return checkForCriteria(node); }
/** * Finds the start position of a tree. * * @param tree the tree to find the start position. * @return the start position. */ private int findStartPosition(BaseTree tree) { int startPostion = INVALID_POSITION; ModifiersTreeImpl modifiersTree = null; Tree type = null; Token identifier = tree.getToken(); if (tree instanceof ClassTreeImpl) { ClassTreeImpl classTree = ((ClassTreeImpl) tree); modifiersTree = (ModifiersTreeImpl) classTree.getModifiers(); type = classTree.getType(); } else if (tree instanceof MethodTree) { MethodTree methodTree = ((MethodTree) tree); modifiersTree = (ModifiersTreeImpl) methodTree.getModifiers(); type = methodTree.getReturnType(); } else if (tree instanceof VariableTree) { VariableTree variableTree = ((VariableTree) tree); modifiersTree = (ModifiersTreeImpl) variableTree.getModifiers(); type = variableTree.getType(); } else if (tree instanceof BlockTree) { CompoundTree<?> blockTree = ((CompoundTree<?>) tree); startPostion = getTokenPosition(blockTree.getBlockStart()); } if (type instanceof ArrayTypeTree) { type = ((ArrayTypeTree) type).getType(); } if (identifier != null) { startPostion = getTokenPosition(identifier); } if (type != null && type instanceof BaseTree) { startPostion = getTokenPosition(((BaseTree) type).getToken()); } if (modifiersTree != null) { int modifierPosition = getPositionFirstAccessModifier(modifiersTree.getModifiers()); int annotationPosition = getPositionFirstAnnotation(modifiersTree.getAnnotations()); if (modifierPosition != INVALID_POSITION && ((startPostion != INVALID_POSITION && modifierPosition < startPostion) || startPostion == INVALID_POSITION)) { startPostion = modifierPosition; } if (annotationPosition != INVALID_POSITION && ((startPostion != INVALID_POSITION && annotationPosition < startPostion) || startPostion == INVALID_POSITION)) { startPostion = annotationPosition; } } return startPostion; }
@Override public ArrayTypeTree createArrayType(Tree type) { return new ArrayTypeTreeImpl(type); }
@Override public Object visitArrayType(ArrayTypeTree t, Trees p) { info("ArrayTypeTree" + CL + t.getKind() + SP + t); return super.visitArrayType(t, p); }
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; }
@Override public UArrayTypeTree visitArrayType(ArrayTypeTree tree, Void v) { return UArrayTypeTree.create(templateType(tree.getType())); }
@Override @Nullable public Unifier visitArrayType(ArrayTypeTree tree, @Nullable Unifier unifier) { return getType().unify(tree.getType(), unifier); }
@Override @Nullable public Choice<Unifier> visitArrayType(ArrayTypeTree tree, @Nullable Unifier unifier) { return getType().unify(tree.getType(), unifier); }
public ArrayTypeNode(ArrayTypeTree tree) { super(InternalUtils.typeOf(tree)); this.tree = tree; }
@Override public Node visitArrayType(ArrayTypeTree tree, Void p) { return extendWithNode(new ArrayTypeNode(tree)); }