/** Tokenizes as little of the {@code tree} as possible to ensure we grab all the annotations. */ private static ImmutableList<ErrorProneToken> annotationTokens( Tree tree, VisitorState state, int annotationEnd) { int endPos; if (tree instanceof JCMethodDecl) { JCMethodDecl methodTree = (JCMethodDecl) tree; endPos = methodTree.getBody() == null ? state.getEndPosition(methodTree) : methodTree.getBody().getStartPosition(); } else if (tree instanceof JCVariableDecl) { endPos = ((JCVariableDecl) tree).getType().getStartPosition(); } else if (tree instanceof JCClassDecl) { JCClassDecl classTree = (JCClassDecl) tree; endPos = classTree.getMembers().isEmpty() ? state.getEndPosition(classTree) : classTree.getMembers().get(0).getStartPosition(); } else { throw new AssertionError(); } return ErrorProneTokens.getTokens( state.getSourceCode().subSequence(annotationEnd, endPos).toString(), state.context); }
if (method.getBody() != null) { boolean skipFirst = false; boolean initialized = false; if (!method.getBody().stats.isEmpty() && method.getBody().stats.get(0).toString().startsWith("this(")) { skipFirst = true; JCMethodInvocation inv = (JCMethodInvocation) ((JCExpressionStatement) method.getBody().stats .get(0)).expr; MethodSymbol ms = Util.findMethodDeclarationInType(context.types, enter(method.getBody()); com.sun.tools.javac.util.List<JCStatement> stats = skipFirst ? method.getBody().stats.tail : method.getBody().stats; if (!stats.isEmpty() && stats.head.toString().startsWith("super(")) { printBlockStatement(stats.head);
return; if (methodDecl.getBody() == null && !(inCoreWrongOverload && !getScope().declareClassScope) || (methodDecl.mods.getFlags().contains(Modifier.DEFAULT) && !getScope().defaultMethodScope)) { if (!getScope().interfaceScope && methodDecl.getModifiers().getFlags().contains(Modifier.ABSTRACT) || (methodDecl.getBody() != null && methodDecl.getBody().getStatements().isEmpty())) { report(methodDecl, methodDecl.name, JSweetProblem.INVALID_METHOD_BODY_IN_INTERFACE, methodDecl.name, parent == null ? "<no class>" : parent.name); if ((method.getBody() == null || (method.mods.getFlags().contains(Modifier.DEFAULT) && !getScope().defaultMethodScope)) && !getScope().interfaceScope && method.getModifiers().getFlags().contains(Modifier.ABSTRACT)) { enter(methodDecl.getBody()); if (!methodDecl.getBody().stats.isEmpty() && methodDecl.getBody().stats.head.toString().startsWith("super(")) { printBlockStatement(methodDecl.getBody().stats.head); if (parent != null) { printInstanceInitialization(parent, methodDecl.sym); printBlockStatements(methodDecl.getBody().stats.tail); } else { if (parent != null) { printInstanceInitialization(parent, methodDecl.sym); printBlockStatements(methodDecl.getBody().stats);
analyzeParsedTree(context, md.getBody()); addMethodNameIndex( src, scope.range.begin.line, scope.range.begin.column, methodName);
utils.make.Try( md.getBody(), List.<JCTree.JCCatch>nil(), utils.block( 0, unlock ) ) );
ConstructorDeclaration cd = new ConstructorDeclaration(); cd.astModifiers((Modifiers) toTree(node.getModifiers())); cd.rawBody(toTree(node.getBody())); fillList(node.getThrows(), cd.rawThrownTypeReferences(), FlagKey.TYPE_REFERENCE); fillList(node.getTypeParameters(), cd.rawTypeVariables()); md.rawBody(toTree(node.getBody())); md.astModifiers((Modifiers) toTree(node.getModifiers())); md.astMethodName(setPos(node, new Identifier().astValue(name)));
ConstructorDeclaration cd = new ConstructorDeclaration(); cd.astModifiers((Modifiers) toTree(node.getModifiers())); cd.rawBody(toTree(node.getBody())); fillList(node.getThrows(), cd.rawThrownTypeReferences(), FlagKey.TYPE_REFERENCE); fillList(node.getTypeParameters(), cd.rawTypeVariables()); md.rawBody(toTree(node.getBody())); md.astModifiers((Modifiers) toTree(node.getModifiers())); md.astMethodName(setPos(node, new Identifier().astValue(name)));
proxyMethodName, utils.voidType, md.getParameters(), md.getThrows(), utils.make.Block( 0, md.getBody().getStatements() ) );
ConstructorDeclaration cd = new ConstructorDeclaration(); cd.astModifiers((Modifiers) toTree(node.getModifiers())); cd.rawBody(toTree(node.getBody())); fillList(node.getThrows(), cd.rawThrownTypeReferences(), FlagKey.TYPE_REFERENCE); fillList(node.getTypeParameters(), cd.rawTypeVariables()); md.rawBody(toTree(node.getBody())); md.astModifiers((Modifiers) toTree(node.getModifiers())); md.astMethodName(setPos(node, new Identifier().astValue(name)));
/** Tokenizes as little of the {@code tree} as possible to ensure we grab all the annotations. */ private static ImmutableList<ErrorProneToken> annotationTokens( Tree tree, VisitorState state, int annotationEnd) { int endPos; if (tree instanceof JCMethodDecl) { JCMethodDecl methodTree = (JCMethodDecl) tree; endPos = methodTree.getBody() == null ? state.getEndPosition(methodTree) : methodTree.getBody().getStartPosition(); } else if (tree instanceof JCVariableDecl) { endPos = ((JCVariableDecl) tree).getType().getStartPosition(); } else if (tree instanceof JCClassDecl) { JCClassDecl classTree = (JCClassDecl) tree; endPos = classTree.getMembers().isEmpty() ? state.getEndPosition(classTree) : classTree.getMembers().get(0).getStartPosition(); } else { throw new AssertionError(); } return ErrorProneTokens.getTokens( state.getSourceCode().subSequence(annotationEnd, endPos).toString(), state.context); }