Search in sources :

Example 1 with ConstructorDeclaration

use of org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration in project lombok by rzwitserloot.

the class HandleUtilityClass method changeModifiersAndGenerateConstructor.

private void changeModifiersAndGenerateConstructor(EclipseNode typeNode, EclipseNode annotationNode) {
    TypeDeclaration classDecl = (TypeDeclaration) typeNode.get();
    boolean makeConstructor = true;
    classDecl.modifiers |= ClassFileConstants.AccFinal;
    boolean markStatic = true;
    boolean requiresClInit = false;
    boolean alreadyHasClinit = false;
    if (typeNode.up().getKind() == Kind.COMPILATION_UNIT)
        markStatic = false;
    if (markStatic && typeNode.up().getKind() == Kind.TYPE) {
        TypeDeclaration typeDecl = (TypeDeclaration) typeNode.up().get();
        if ((typeDecl.modifiers & ClassFileConstants.AccInterface) != 0)
            markStatic = false;
    }
    if (markStatic)
        classDecl.modifiers |= ClassFileConstants.AccStatic;
    for (EclipseNode element : typeNode.down()) {
        if (element.getKind() == Kind.FIELD) {
            FieldDeclaration fieldDecl = (FieldDeclaration) element.get();
            if ((fieldDecl.modifiers & ClassFileConstants.AccStatic) == 0) {
                requiresClInit = true;
                fieldDecl.modifiers |= ClassFileConstants.AccStatic;
            }
        } else if (element.getKind() == Kind.METHOD) {
            AbstractMethodDeclaration amd = (AbstractMethodDeclaration) element.get();
            if (amd instanceof ConstructorDeclaration) {
                ConstructorDeclaration constrDecl = (ConstructorDeclaration) element.get();
                if (getGeneratedBy(constrDecl) == null && (constrDecl.bits & ASTNode.IsDefaultConstructor) == 0) {
                    element.addError("@UtilityClasses cannot have declared constructors.");
                    makeConstructor = false;
                    continue;
                }
            } else if (amd instanceof MethodDeclaration) {
                amd.modifiers |= ClassFileConstants.AccStatic;
            } else if (amd instanceof Clinit) {
                alreadyHasClinit = true;
            }
        } else if (element.getKind() == Kind.TYPE) {
            ((TypeDeclaration) element.get()).modifiers |= ClassFileConstants.AccStatic;
        }
    }
    if (makeConstructor)
        createPrivateDefaultConstructor(typeNode, annotationNode);
    if (requiresClInit && !alreadyHasClinit)
        classDecl.addClinit();
}
Also used : Clinit(org.eclipse.jdt.internal.compiler.ast.Clinit) ConstructorDeclaration(org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) AbstractMethodDeclaration(org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) EclipseNode(lombok.eclipse.EclipseNode) TypeDeclaration(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) AbstractMethodDeclaration(org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) FieldDeclaration(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration)

Example 2 with ConstructorDeclaration

use of org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration in project lombok by rzwitserloot.

the class HandleConstructor method generateConstructor.

public void generateConstructor(EclipseNode typeNode, AccessLevel level, List<EclipseNode> fields, boolean allToDefault, String staticName, SkipIfConstructorExists skipIfConstructorExists, List<Annotation> onConstructor, EclipseNode sourceNode) {
    ASTNode source = sourceNode.get();
    boolean staticConstrRequired = staticName != null && !staticName.equals("");
    if (skipIfConstructorExists != SkipIfConstructorExists.NO && constructorExists(typeNode) != MemberExistsResult.NOT_EXISTS)
        return;
    if (skipIfConstructorExists != SkipIfConstructorExists.NO) {
        for (EclipseNode child : typeNode.down()) {
            if (child.getKind() == Kind.ANNOTATION) {
                boolean skipGeneration = (annotationTypeMatches(NoArgsConstructor.class, child) || annotationTypeMatches(AllArgsConstructor.class, child) || annotationTypeMatches(RequiredArgsConstructor.class, child));
                if (!skipGeneration && skipIfConstructorExists == SkipIfConstructorExists.YES) {
                    skipGeneration = annotationTypeMatches(Builder.class, child);
                }
                if (skipGeneration) {
                    if (staticConstrRequired) {
                        // @Data has asked us to generate a constructor, but we're going to skip this instruction, as an explicit 'make a constructor' annotation
                        // will take care of it. However, @Data also wants a specific static name; this will be ignored; the appropriate way to do this is to use
                        // the 'staticName' parameter of the @XArgsConstructor you've stuck on your type.
                        // We should warn that we're ignoring @Data's 'staticConstructor' param.
                        typeNode.addWarning("Ignoring static constructor name: explicit @XxxArgsConstructor annotation present; its `staticName` parameter will be used.", source.sourceStart, source.sourceEnd);
                    }
                    return;
                }
            }
        }
    }
    ConstructorDeclaration constr = createConstructor(staticConstrRequired ? AccessLevel.PRIVATE : level, typeNode, fields, allToDefault, sourceNode, onConstructor);
    injectMethod(typeNode, constr);
    if (staticConstrRequired) {
        MethodDeclaration staticConstr = createStaticConstructor(level, staticName, typeNode, allToDefault ? Collections.<EclipseNode>emptyList() : fields, source);
        injectMethod(typeNode, staticConstr);
    }
}
Also used : NoArgsConstructor(lombok.NoArgsConstructor) AllArgsConstructor(lombok.AllArgsConstructor) ConstructorDeclaration(org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) Builder(lombok.Builder) ASTNode(org.eclipse.jdt.internal.compiler.ast.ASTNode) EclipseNode(lombok.eclipse.EclipseNode)

Example 3 with ConstructorDeclaration

use of org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration in project lombok by rzwitserloot.

the class HandleSneakyThrows method handleMethod.

// private boolean handleField(Node annotation, FieldDeclaration field, List<DeclaredException> exceptions) {
// if (field.initialization == null) {
// annotation.addError("@SneakyThrows can only be used on fields with an initialization statement.");
// return true;
// }
// 
// Expression expression = field.initialization;
// Statement[] content = new Statement[] {new Assignment(
// new SingleNameReference(field.name, 0), expression, 0)};
// field.initialization = null;
// 
// for (DeclaredException exception : exceptions) {
// content = new Statement[] { buildTryCatchBlock(content, exception) };
// }
// 
// Block block = new Block(0);
// block.statements = content;
// 
// Node typeNode = annotation.up().up();
// 
// Initializer initializer = new Initializer(block, field.modifiers & Modifier.STATIC);
// initializer.sourceStart = expression.sourceStart;
// initializer.sourceEnd = expression.sourceEnd;
// initializer.declarationSourceStart = expression.sourceStart;
// initializer.declarationSourceEnd = expression.sourceEnd;
// injectField(typeNode, initializer);
// 
// typeNode.rebuild();
// 
// return true;
// }
public void handleMethod(EclipseNode annotation, AbstractMethodDeclaration method, List<DeclaredException> exceptions) {
    if (method.isAbstract()) {
        annotation.addError("@SneakyThrows can only be used on concrete methods.");
        return;
    }
    if (method.statements == null || method.statements.length == 0) {
        boolean hasConstructorCall = false;
        if (method instanceof ConstructorDeclaration) {
            ExplicitConstructorCall constructorCall = ((ConstructorDeclaration) method).constructorCall;
            hasConstructorCall = constructorCall != null && !constructorCall.isImplicitSuper() && !constructorCall.isImplicitThis();
        }
        if (hasConstructorCall) {
            annotation.addWarning("Calls to sibling / super constructors are always excluded from @SneakyThrows; @SneakyThrows has been ignored because there is no other code in this constructor.");
        } else {
            annotation.addWarning("This method or constructor is empty; @SneakyThrows has been ignored.");
        }
        return;
    }
    Statement[] contents = method.statements;
    for (DeclaredException exception : exceptions) {
        contents = new Statement[] { buildTryCatchBlock(contents, exception, exception.node, method) };
    }
    method.statements = contents;
    annotation.up().rebuild();
}
Also used : ExplicitConstructorCall(org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall) ConstructorDeclaration(org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) ThrowStatement(org.eclipse.jdt.internal.compiler.ast.ThrowStatement) TryStatement(org.eclipse.jdt.internal.compiler.ast.TryStatement)

Example 4 with ConstructorDeclaration

use of org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration in project che by eclipse.

the class CheASTParser method internalCreateASTForKind.

/**
	 * Parses the given source between the bounds specified by the given offset (inclusive)
	 * and the given length and creates and returns a corresponding abstract syntax tree.
	 * <p>
	 * When the parse is successful the result returned includes the ASTs for the
	 * requested source:
	 * <ul>
	 * <li>{@link #K_CLASS_BODY_DECLARATIONS K_CLASS_BODY_DECLARATIONS}: The result node
	 * is a {@link TypeDeclaration TypeDeclaration} whose
	 * {@link TypeDeclaration#bodyDeclarations() bodyDeclarations}
	 * are the new trees. Other aspects of the type declaration are unspecified.</li>
	 * <li>{@link #K_STATEMENTS K_STATEMENTS}: The result node is a
	 * {@link Block Block} whose {@link Block#statements() statements}
	 * are the new trees. Other aspects of the block are unspecified.</li>
	 * <li>{@link #K_EXPRESSION K_EXPRESSION}: The result node is a subclass of
	 * {@link Expression Expression}. Other aspects of the expression are unspecified.</li>
	 * </ul>
	 * The resulting AST node is rooted under an contrived
	 * {@link CompilationUnit CompilationUnit} node, to allow the
	 * client to retrieve the following pieces of information
	 * available there:
	 * <ul>
	 * <li>{@linkplain CompilationUnit#getLineNumber(int) Line number map}. Line
	 * numbers start at 1 and only cover the subrange scanned
	 * (<code>source[offset]</code> through <code>source[offset+length-1]</code>).</li>
	 * <li>{@linkplain CompilationUnit#getMessages() Compiler messages}
	 * and {@linkplain CompilationUnit#getProblems() detailed problem reports}.
	 * Character positions are relative to the start of
	 * <code>source</code>; line positions are for the subrange scanned.</li>
	 * <li>{@linkplain CompilationUnit#getCommentList() Comment list}
	 * for the subrange scanned.</li>
	 * </ul>
	 * The contrived nodes do not have source positions. Other aspects of the
	 * {@link CompilationUnit CompilationUnit} node are unspecified, including
	 * the exact arrangment of intervening nodes.
	 * </p>
	 * <p>
	 * Lexical or syntax errors detected while parsing can result in
	 * a result node being marked as {@link ASTNode#MALFORMED MALFORMED}.
	 * In more severe failure cases where the parser is unable to
	 * recognize the input, this method returns
	 * a {@link CompilationUnit CompilationUnit} node with at least the
	 * compiler messages.
	 * </p>
	 * <p>Each node in the subtree (other than the contrived nodes)
	 * carries source range(s) information relating back
	 * to positions in the given source (the given source itself
	 * is not remembered with the AST).
	 * The source range usually begins at the first character of the first token
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
	 * included. The source range usually extends through the last character of
	 * the last token corresponding to the node; trailing whitespace and
	 * comments are <b>not</b> included. There are a handful of exceptions
	 * (including the various body declarations); the
	 * specification for these node type spells out the details.
	 * Source ranges nest properly: the source range for a child is always
	 * within the source range of its parent, and the source ranges of sibling
	 * nodes never overlap.
	 * </p>
	 * <p>
	 * This method does not compute binding information; all <code>resolveBinding</code>
	 * methods applied to nodes of the resulting AST return <code>null</code>.
	 * </p>
	 *
	 * @return an AST node whose type depends on the kind of parse
	 *  requested, with a fallback to a <code>CompilationUnit</code>
	 *  in the case of severe parsing errors
	 * @see ASTNode#getStartPosition()
	 * @see ASTNode#getLength()
	 */
private ASTNode internalCreateASTForKind() {
    final ASTConverter converter = new ASTConverter(this.compilerOptions, false, null);
    converter.compilationUnitSource = this.rawSource;
    converter.compilationUnitSourceLength = this.rawSource.length;
    converter.scanner.setSource(this.rawSource);
    AST ast = AST.newAST(this.apiLevel);
    ast.setDefaultNodeFlag(ASTNode.ORIGINAL);
    ast.setBindingResolver(new BindingResolver());
    if ((this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0) {
        ast.setFlag(ICompilationUnit.ENABLE_STATEMENTS_RECOVERY);
    }
    converter.setAST(ast);
    CodeSnippetParsingUtil codeSnippetParsingUtil = new CodeSnippetParsingUtil((this.bits & CompilationUnitResolver.IGNORE_METHOD_BODIES) != 0);
    CompilationUnit compilationUnit = ast.newCompilationUnit();
    if (this.sourceLength == -1) {
        this.sourceLength = this.rawSource.length;
    }
    switch(this.astKind) {
        case K_STATEMENTS:
            ConstructorDeclaration constructorDeclaration = codeSnippetParsingUtil.parseStatements(this.rawSource, this.sourceOffset, this.sourceLength, this.compilerOptions, true, (this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0);
            RecoveryScannerData data = constructorDeclaration.compilationResult.recoveryScannerData;
            if (data != null) {
                Scanner scanner = converter.scanner;
                converter.scanner = new RecoveryScanner(scanner, data.removeUnused());
                converter.docParser.scanner = converter.scanner;
                converter.scanner.setSource(scanner.source);
                compilationUnit.setStatementsRecoveryData(data);
            }
            RecordedParsingInformation recordedParsingInformation = codeSnippetParsingUtil.recordedParsingInformation;
            int[][] comments = recordedParsingInformation.commentPositions;
            if (comments != null) {
                converter.buildCommentsTable(compilationUnit, comments);
            }
            compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds);
            Block block = ast.newBlock();
            block.setSourceRange(this.sourceOffset, this.sourceOffset + this.sourceLength);
            org.eclipse.jdt.internal.compiler.ast.Statement[] statements = constructorDeclaration.statements;
            if (statements != null) {
                int statementsLength = statements.length;
                for (int i = 0; i < statementsLength; i++) {
                    if (statements[i] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
                        converter.checkAndAddMultipleLocalDeclaration(statements, i, block.statements());
                    } else {
                        Statement statement = converter.convert(statements[i]);
                        if (statement != null) {
                            block.statements().add(statement);
                        }
                    }
                }
            }
            rootNodeToCompilationUnit(ast, compilationUnit, block, recordedParsingInformation, data);
            ast.setDefaultNodeFlag(0);
            ast.setOriginalModificationCount(ast.modificationCount());
            return block;
        case K_EXPRESSION:
            org.eclipse.jdt.internal.compiler.ast.Expression expression = codeSnippetParsingUtil.parseExpression(this.rawSource, this.sourceOffset, this.sourceLength, this.compilerOptions, true);
            recordedParsingInformation = codeSnippetParsingUtil.recordedParsingInformation;
            comments = recordedParsingInformation.commentPositions;
            if (comments != null) {
                converter.buildCommentsTable(compilationUnit, comments);
            }
            compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds);
            if (expression != null) {
                Expression expression2 = converter.convert(expression);
                rootNodeToCompilationUnit(expression2.getAST(), compilationUnit, expression2, codeSnippetParsingUtil.recordedParsingInformation, null);
                ast.setDefaultNodeFlag(0);
                ast.setOriginalModificationCount(ast.modificationCount());
                return expression2;
            } else {
                CategorizedProblem[] problems = recordedParsingInformation.problems;
                if (problems != null) {
                    compilationUnit.setProblems(problems);
                }
                ast.setDefaultNodeFlag(0);
                ast.setOriginalModificationCount(ast.modificationCount());
                return compilationUnit;
            }
        case K_CLASS_BODY_DECLARATIONS:
            final org.eclipse.jdt.internal.compiler.ast.ASTNode[] nodes = codeSnippetParsingUtil.parseClassBodyDeclarations(this.rawSource, this.sourceOffset, this.sourceLength, this.compilerOptions, true, (this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0);
            recordedParsingInformation = codeSnippetParsingUtil.recordedParsingInformation;
            comments = recordedParsingInformation.commentPositions;
            if (comments != null) {
                converter.buildCommentsTable(compilationUnit, comments);
            }
            compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds);
            if (nodes != null) {
                // source has no syntax error or the statement recovery is enabled
                TypeDeclaration typeDeclaration = converter.convert(nodes);
                typeDeclaration.setSourceRange(this.sourceOffset, this.sourceOffset + this.sourceLength);
                rootNodeToCompilationUnit(typeDeclaration.getAST(), compilationUnit, typeDeclaration, codeSnippetParsingUtil.recordedParsingInformation, null);
                ast.setDefaultNodeFlag(0);
                ast.setOriginalModificationCount(ast.modificationCount());
                return typeDeclaration;
            } else {
                // source has syntax error and the statement recovery is disabled
                CategorizedProblem[] problems = recordedParsingInformation.problems;
                if (problems != null) {
                    compilationUnit.setProblems(problems);
                }
                ast.setDefaultNodeFlag(0);
                ast.setOriginalModificationCount(ast.modificationCount());
                return compilationUnit;
            }
    }
    throw new IllegalStateException();
}
Also used : Scanner(org.eclipse.jdt.internal.compiler.parser.Scanner) RecoveryScanner(org.eclipse.jdt.internal.compiler.parser.RecoveryScanner) ConstructorDeclaration(org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) CodeSnippetParsingUtil(org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) BasicCompilationUnit(org.eclipse.jdt.internal.core.BasicCompilationUnit) RecoveryScanner(org.eclipse.jdt.internal.compiler.parser.RecoveryScanner) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) RecoveryScannerData(org.eclipse.jdt.internal.compiler.parser.RecoveryScannerData) RecordedParsingInformation(org.eclipse.jdt.internal.core.util.RecordedParsingInformation)

Example 5 with ConstructorDeclaration

use of org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration in project che by eclipse.

the class SourceTypeConverter method convert.

/*
	 * Convert a method source element into a parsed method/constructor declaration
	 */
private AbstractMethodDeclaration convert(SourceMethod methodHandle, SourceMethodElementInfo methodInfo, CompilationResult compilationResult) throws JavaModelException {
    AbstractMethodDeclaration method;
    /* only source positions available */
    int start = methodInfo.getNameSourceStart();
    int end = methodInfo.getNameSourceEnd();
    /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, Even when this type is being constructed
		   on behalf of a 1.4 project we must internalize type variables properly in order to be able to
		   recognize usages of them in the method signature, to apply substitutions and thus to be able to
		   detect overriding in the presence of generics. If we simply drop them, when the method signature
		   refers to the type parameter, we won't know it should be bound to the type parameter and perform
		   incorrect lookup and may mistakenly end up with missing types
		 */
    TypeParameter[] typeParams = null;
    char[][] typeParameterNames = methodInfo.getTypeParameterNames();
    if (typeParameterNames != null) {
        int parameterCount = typeParameterNames.length;
        if (parameterCount > 0) {
            // method's type parameters must be null if no type parameter
            char[][][] typeParameterBounds = methodInfo.getTypeParameterBounds();
            typeParams = new TypeParameter[parameterCount];
            for (int i = 0; i < parameterCount; i++) {
                typeParams[i] = createTypeParameter(typeParameterNames[i], typeParameterBounds[i], start, end);
            }
        }
    }
    int modifiers = methodInfo.getModifiers();
    if (methodInfo.isConstructor()) {
        ConstructorDeclaration decl = new ConstructorDeclaration(compilationResult);
        decl.bits &= ~ASTNode.IsDefaultConstructor;
        method = decl;
        decl.typeParameters = typeParams;
    } else {
        MethodDeclaration decl;
        if (methodInfo.isAnnotationMethod()) {
            AnnotationMethodDeclaration annotationMethodDeclaration = new AnnotationMethodDeclaration(compilationResult);
            /* conversion of default value */
            SourceAnnotationMethodInfo annotationMethodInfo = (SourceAnnotationMethodInfo) methodInfo;
            boolean hasDefaultValue = annotationMethodInfo.defaultValueStart != -1 || annotationMethodInfo.defaultValueEnd != -1;
            if ((this.flags & FIELD_INITIALIZATION) != 0) {
                if (hasDefaultValue) {
                    char[] defaultValueSource = CharOperation.subarray(getSource(), annotationMethodInfo.defaultValueStart, annotationMethodInfo.defaultValueEnd + 1);
                    if (defaultValueSource != null) {
                        Expression expression = parseMemberValue(defaultValueSource);
                        if (expression != null) {
                            annotationMethodDeclaration.defaultValue = expression;
                        }
                    } else {
                        // could not retrieve the default value
                        hasDefaultValue = false;
                    }
                }
            }
            if (hasDefaultValue)
                modifiers |= ClassFileConstants.AccAnnotationDefault;
            decl = annotationMethodDeclaration;
        } else {
            decl = new MethodDeclaration(compilationResult);
        }
        // convert return type
        decl.returnType = createTypeReference(methodInfo.getReturnTypeName(), start, end);
        // type parameters
        decl.typeParameters = typeParams;
        method = decl;
    }
    method.selector = methodHandle.getElementName().toCharArray();
    boolean isVarargs = (modifiers & ClassFileConstants.AccVarargs) != 0;
    method.modifiers = modifiers & ~ClassFileConstants.AccVarargs;
    method.sourceStart = start;
    method.sourceEnd = end;
    method.declarationSourceStart = methodInfo.getDeclarationSourceStart();
    method.declarationSourceEnd = methodInfo.getDeclarationSourceEnd();
    // convert 1.5 specific constructs only if compliance is 1.5 or above
    if (this.has1_5Compliance) {
        /* convert annotations */
        method.annotations = convertAnnotations(methodHandle);
    }
    /* convert arguments */
    String[] argumentTypeSignatures = methodHandle.getParameterTypes();
    char[][] argumentNames = methodInfo.getArgumentNames();
    int argumentCount = argumentTypeSignatures == null ? 0 : argumentTypeSignatures.length;
    if (argumentCount > 0) {
        ILocalVariable[] parameters = methodHandle.getParameters();
        long position = ((long) start << 32) + end;
        method.arguments = new Argument[argumentCount];
        for (int i = 0; i < argumentCount; i++) {
            TypeReference typeReference = createTypeReference(argumentTypeSignatures[i], start, end);
            if (isVarargs && i == argumentCount - 1) {
                typeReference.bits |= ASTNode.IsVarArgs;
            }
            method.arguments[i] = new Argument(argumentNames[i], position, typeReference, ClassFileConstants.AccDefault);
            // convert 1.5 specific constructs only if compliance is 1.5 or above
            if (this.has1_5Compliance) {
                /* convert annotations */
                method.arguments[i].annotations = convertAnnotations(parameters[i]);
            }
        }
    }
    /* convert thrown exceptions */
    char[][] exceptionTypeNames = methodInfo.getExceptionTypeNames();
    int exceptionCount = exceptionTypeNames == null ? 0 : exceptionTypeNames.length;
    if (exceptionCount > 0) {
        method.thrownExceptions = new TypeReference[exceptionCount];
        for (int i = 0; i < exceptionCount; i++) {
            method.thrownExceptions[i] = createTypeReference(exceptionTypeNames[i], start, end);
        }
    }
    /* convert local and anonymous types */
    if ((this.flags & LOCAL_TYPE) != 0) {
        IJavaElement[] children = methodInfo.getChildren();
        int typesLength = children.length;
        if (typesLength != 0) {
            Statement[] statements = new Statement[typesLength];
            for (int i = 0; i < typesLength; i++) {
                SourceType type = (SourceType) children[i];
                TypeDeclaration localType = convert(type, compilationResult);
                if ((localType.bits & ASTNode.IsAnonymousType) != 0) {
                    QualifiedAllocationExpression expression = new QualifiedAllocationExpression(localType);
                    expression.type = localType.superclass;
                    localType.superclass = null;
                    localType.superInterfaces = null;
                    localType.allocation = expression;
                    statements[i] = expression;
                } else {
                    statements[i] = localType;
                }
            }
            method.statements = statements;
        }
    }
    return method;
}
Also used : TypeParameter(org.eclipse.jdt.internal.compiler.ast.TypeParameter) Argument(org.eclipse.jdt.internal.compiler.ast.Argument) ISourceType(org.eclipse.jdt.internal.compiler.env.ISourceType) SourceType(org.eclipse.jdt.internal.core.SourceType) ILocalVariable(org.eclipse.jdt.core.ILocalVariable) ConstructorDeclaration(org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) IJavaElement(org.eclipse.jdt.core.IJavaElement) AnnotationMethodDeclaration(org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) AnnotationMethodDeclaration(org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) AbstractMethodDeclaration(org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) Expression(org.eclipse.jdt.internal.compiler.ast.Expression) QualifiedAllocationExpression(org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression) SourceAnnotationMethodInfo(org.eclipse.jdt.internal.core.SourceAnnotationMethodInfo) QualifiedAllocationExpression(org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression) AbstractMethodDeclaration(org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) TypeDeclaration(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration)

Aggregations

ConstructorDeclaration (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration)10 TypeDeclaration (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration)6 EclipseNode (lombok.eclipse.EclipseNode)5 AbstractMethodDeclaration (org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration)4 MethodDeclaration (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)4 ArrayList (java.util.ArrayList)3 ASTNode (org.eclipse.jdt.internal.compiler.ast.ASTNode)3 Argument (org.eclipse.jdt.internal.compiler.ast.Argument)3 ExplicitConstructorCall (org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall)3 FieldDeclaration (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration)3 Statement (org.eclipse.jdt.internal.compiler.ast.Statement)3 Builder (lombok.Builder)2 AllocationExpression (org.eclipse.jdt.internal.compiler.ast.AllocationExpression)2 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)2 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)2 ThrowStatement (org.eclipse.jdt.internal.compiler.ast.ThrowStatement)2 TypeParameter (org.eclipse.jdt.internal.compiler.ast.TypeParameter)2 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)2 AllArgsConstructor (lombok.AllArgsConstructor)1 NoArgsConstructor (lombok.NoArgsConstructor)1