Example usage for org.eclipse.jdt.core.dom ASTNode SUPER_CONSTRUCTOR_INVOCATION

List of usage examples for org.eclipse.jdt.core.dom ASTNode SUPER_CONSTRUCTOR_INVOCATION

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ASTNode SUPER_CONSTRUCTOR_INVOCATION.

Prototype

int SUPER_CONSTRUCTOR_INVOCATION

To view the source code for org.eclipse.jdt.core.dom ASTNode SUPER_CONSTRUCTOR_INVOCATION.

Click Source Link

Document

Node type constant indicating a node of type SuperConstructorInvocation.

Usage

From source file:ca.uvic.chisel.diver.sequencediagrams.sc.java.model.JavaActivation.java

License:Open Source License

@Override
public List<JavaMessage> getMessages() {
    if (this.messages == null) {
        this.messages = new ArrayList<JavaMessage>();
        if (getAST() == null) {
            return messages;
        }//from  w  ww .j  ava 2 s.  c o  m
        MessageFinder finder = new MessageFinder();
        getAST().accept(finder);
        for (ASTNode node : finder.messages) {
            IMethodBinding binding = null;
            switch (node.getNodeType()) {
            case ASTNode.METHOD_INVOCATION:
                binding = ((MethodInvocation) node).resolveMethodBinding();
                break;
            case ASTNode.SUPER_METHOD_INVOCATION:
                binding = ((SuperMethodInvocation) node).resolveMethodBinding();
                break;
            case ASTNode.CONSTRUCTOR_INVOCATION:
                binding = ((ConstructorInvocation) node).resolveConstructorBinding();
                break;
            case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
                binding = ((SuperConstructorInvocation) node).resolveConstructorBinding();
                break;
            case ASTNode.CLASS_INSTANCE_CREATION:
                binding = ((ClassInstanceCreation) node).resolveConstructorBinding();
                break;
            }
            if (binding != null) {
                IMethod target = (IMethod) binding.getJavaElement();
                if (target != null) {
                    JavaActivation targetActivation = new JavaActivation(tree, target);
                    JavaMessage message = new JavaMessage(tree, node, this, targetActivation);
                    //add catches
                    targetActivation.setCallingMessage(message);
                    message.setTries(finder.invocationTries.get(node));
                    messages.add(message);
                }
            } else if (node instanceof ThrowStatement) {
                ThrowStatement statement = (ThrowStatement) node;
                List<IType> throwns = finder.thrownTypes.get(statement);
                for (IType thrown : throwns) {
                    JavaMessage parentMessage = getCallingMessage();
                    IJavaActivation root = this;
                    JavaMessage message = null;
                    while (parentMessage != null) {
                        root = parentMessage.getSource();
                        if (parentMessage.catches(thrown)) {
                            break;
                        }
                        parentMessage = root.getCallingMessage();
                    }
                    if (root != null && root != this) {
                        message = new JavaMessage(tree, statement, this, root);
                        message.setType(thrown);
                        message.setException(true);
                        messages.add(message);
                    }
                }
            } else if (node instanceof ReturnStatement) {
                if (getCallingMessage() != null) {
                    JavaMessage message = new JavaMessage(tree, node, this, getCallingMessage().getSource());
                    IJavaProject project = getJavaElement().getJavaProject();
                    if (project != null) {
                        String returnType;
                        try {
                            returnType = ((IMethod) getJavaElement()).getReturnType();
                            if (returnType != null) {
                                message.setType(returnType);
                            }
                        } catch (JavaModelException e) {
                        }

                    }
                    messages.add(message);

                }
            }
        }
    }
    return messages;
}

From source file:com.ashigeru.eclipse.util.jdt.internal.ui.handlers.InsertAssertionHandler.java

License:Apache License

private TextEdit createEdit(CompilationUnit ast, MethodDeclaration method, IDocument target) {
    assert ast != null;
    assert method != null;
    assert target != null;
    List<String> objectParams = new ArrayList<String>();
    for (Object o : method.parameters()) {
        SingleVariableDeclaration var = (SingleVariableDeclaration) o;
        if (var.getType().getNodeType() != ASTNode.PRIMITIVE_TYPE) {
            objectParams.add(var.getName().getIdentifier());
        }// w  w  w .  j  a va  2s. com
    }
    if (objectParams.isEmpty()) {
        return null;
    }
    AST factory = ast.getAST();
    ast.recordModifications();
    List<Statement> toInsert = new ArrayList<Statement>();
    for (String name : objectParams) {
        AssertStatement assertion = createAssertion(factory, name);
        toInsert.add(assertion);
    }

    Block body = method.getBody();
    @SuppressWarnings("unchecked")
    List<Statement> statements = body.statements();

    int offset = 0;
    if (statements.isEmpty() == false) {
        Statement first = statements.get(0);
        int type = first.getNodeType();
        if (type == ASTNode.CONSTRUCTOR_INVOCATION || type == ASTNode.SUPER_CONSTRUCTOR_INVOCATION) {
            offset++;
        }
    }

    statements.addAll(offset, toInsert);

    return ast.rewrite(target, null);
}

From source file:com.google.devtools.j2objc.ast.TreeConverter.java

License:Apache License

public static TreeNode convertInner(ASTNode jdtNode) {
    switch (jdtNode.getNodeType()) {
    case ASTNode.ANNOTATION_TYPE_DECLARATION:
        return new AnnotationTypeDeclaration((org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) jdtNode);
    case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
        return new AnnotationTypeMemberDeclaration(
                (org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration) jdtNode);
    case ASTNode.ANONYMOUS_CLASS_DECLARATION:
        return new AnonymousClassDeclaration((org.eclipse.jdt.core.dom.AnonymousClassDeclaration) jdtNode);
    case ASTNode.ARRAY_ACCESS:
        return new ArrayAccess((org.eclipse.jdt.core.dom.ArrayAccess) jdtNode);
    case ASTNode.ARRAY_CREATION:
        return new ArrayCreation((org.eclipse.jdt.core.dom.ArrayCreation) jdtNode);
    case ASTNode.ARRAY_INITIALIZER:
        return new ArrayInitializer((org.eclipse.jdt.core.dom.ArrayInitializer) jdtNode);
    case ASTNode.ARRAY_TYPE:
        return new ArrayType((org.eclipse.jdt.core.dom.ArrayType) jdtNode);
    case ASTNode.ASSERT_STATEMENT:
        return new AssertStatement((org.eclipse.jdt.core.dom.AssertStatement) jdtNode);
    case ASTNode.ASSIGNMENT:
        return new Assignment((org.eclipse.jdt.core.dom.Assignment) jdtNode);
    case ASTNode.BLOCK:
        return new Block((org.eclipse.jdt.core.dom.Block) jdtNode);
    case ASTNode.BLOCK_COMMENT:
        return new BlockComment((org.eclipse.jdt.core.dom.BlockComment) jdtNode);
    case ASTNode.BOOLEAN_LITERAL:
        return new BooleanLiteral((org.eclipse.jdt.core.dom.BooleanLiteral) jdtNode);
    case ASTNode.BREAK_STATEMENT:
        return new BreakStatement((org.eclipse.jdt.core.dom.BreakStatement) jdtNode);
    case ASTNode.CAST_EXPRESSION:
        return new CastExpression((org.eclipse.jdt.core.dom.CastExpression) jdtNode);
    case ASTNode.CATCH_CLAUSE:
        return new CatchClause((org.eclipse.jdt.core.dom.CatchClause) jdtNode);
    case ASTNode.CHARACTER_LITERAL:
        return new CharacterLiteral((org.eclipse.jdt.core.dom.CharacterLiteral) jdtNode);
    case ASTNode.CLASS_INSTANCE_CREATION:
        return new ClassInstanceCreation((org.eclipse.jdt.core.dom.ClassInstanceCreation) jdtNode);
    case ASTNode.CONDITIONAL_EXPRESSION:
        return new ConditionalExpression((org.eclipse.jdt.core.dom.ConditionalExpression) jdtNode);
    case ASTNode.CONSTRUCTOR_INVOCATION:
        return new ConstructorInvocation((org.eclipse.jdt.core.dom.ConstructorInvocation) jdtNode);
    case ASTNode.CONTINUE_STATEMENT:
        return new ContinueStatement((org.eclipse.jdt.core.dom.ContinueStatement) jdtNode);
    case ASTNode.DO_STATEMENT:
        return new DoStatement((org.eclipse.jdt.core.dom.DoStatement) jdtNode);
    case ASTNode.EMPTY_STATEMENT:
        return new EmptyStatement((org.eclipse.jdt.core.dom.EmptyStatement) jdtNode);
    case ASTNode.ENHANCED_FOR_STATEMENT:
        return new EnhancedForStatement((org.eclipse.jdt.core.dom.EnhancedForStatement) jdtNode);
    case ASTNode.ENUM_CONSTANT_DECLARATION:
        return new EnumConstantDeclaration((org.eclipse.jdt.core.dom.EnumConstantDeclaration) jdtNode);
    case ASTNode.ENUM_DECLARATION:
        return new EnumDeclaration((org.eclipse.jdt.core.dom.EnumDeclaration) jdtNode);
    case ASTNode.EXPRESSION_STATEMENT:
        return new ExpressionStatement((org.eclipse.jdt.core.dom.ExpressionStatement) jdtNode);
    case ASTNode.FIELD_ACCESS:
        return new FieldAccess((org.eclipse.jdt.core.dom.FieldAccess) jdtNode);
    case ASTNode.FIELD_DECLARATION:
        return new FieldDeclaration((org.eclipse.jdt.core.dom.FieldDeclaration) jdtNode);
    case ASTNode.FOR_STATEMENT:
        return new ForStatement((org.eclipse.jdt.core.dom.ForStatement) jdtNode);
    case ASTNode.IF_STATEMENT:
        return new IfStatement((org.eclipse.jdt.core.dom.IfStatement) jdtNode);
    case ASTNode.INFIX_EXPRESSION:
        return new InfixExpression((org.eclipse.jdt.core.dom.InfixExpression) jdtNode);
    case ASTNode.INITIALIZER:
        return new Initializer((org.eclipse.jdt.core.dom.Initializer) jdtNode);
    case ASTNode.INSTANCEOF_EXPRESSION:
        return new InstanceofExpression((org.eclipse.jdt.core.dom.InstanceofExpression) jdtNode);
    case ASTNode.JAVADOC:
        return new Javadoc((org.eclipse.jdt.core.dom.Javadoc) jdtNode);
    case ASTNode.LABELED_STATEMENT:
        return new LabeledStatement((org.eclipse.jdt.core.dom.LabeledStatement) jdtNode);
    case ASTNode.LINE_COMMENT:
        return new LineComment((org.eclipse.jdt.core.dom.LineComment) jdtNode);
    case ASTNode.MARKER_ANNOTATION:
        return new MarkerAnnotation((org.eclipse.jdt.core.dom.MarkerAnnotation) jdtNode);
    case ASTNode.MEMBER_VALUE_PAIR:
        return new MemberValuePair((org.eclipse.jdt.core.dom.MemberValuePair) jdtNode);
    case ASTNode.METHOD_DECLARATION:
        return new MethodDeclaration((org.eclipse.jdt.core.dom.MethodDeclaration) jdtNode);
    case ASTNode.METHOD_INVOCATION:
        return new MethodInvocation((org.eclipse.jdt.core.dom.MethodInvocation) jdtNode);
    case ASTNode.NORMAL_ANNOTATION:
        return new NormalAnnotation((org.eclipse.jdt.core.dom.NormalAnnotation) jdtNode);
    case ASTNode.NULL_LITERAL:
        return new NullLiteral((org.eclipse.jdt.core.dom.NullLiteral) jdtNode);
    case ASTNode.NUMBER_LITERAL:
        return new NumberLiteral((org.eclipse.jdt.core.dom.NumberLiteral) jdtNode);
    case ASTNode.PACKAGE_DECLARATION:
        return new PackageDeclaration((org.eclipse.jdt.core.dom.PackageDeclaration) jdtNode);
    case ASTNode.PARAMETERIZED_TYPE:
        return new ParameterizedType((org.eclipse.jdt.core.dom.ParameterizedType) jdtNode);
    case ASTNode.PARENTHESIZED_EXPRESSION:
        return new ParenthesizedExpression((org.eclipse.jdt.core.dom.ParenthesizedExpression) jdtNode);
    case ASTNode.POSTFIX_EXPRESSION:
        return new PostfixExpression((org.eclipse.jdt.core.dom.PostfixExpression) jdtNode);
    case ASTNode.PREFIX_EXPRESSION:
        return new PrefixExpression((org.eclipse.jdt.core.dom.PrefixExpression) jdtNode);
    case ASTNode.PRIMITIVE_TYPE:
        return new PrimitiveType((org.eclipse.jdt.core.dom.PrimitiveType) jdtNode);
    case ASTNode.QUALIFIED_NAME:
        return new QualifiedName((org.eclipse.jdt.core.dom.QualifiedName) jdtNode);
    case ASTNode.QUALIFIED_TYPE:
        return new QualifiedType((org.eclipse.jdt.core.dom.QualifiedType) jdtNode);
    case ASTNode.RETURN_STATEMENT:
        return new ReturnStatement((org.eclipse.jdt.core.dom.ReturnStatement) jdtNode);
    case ASTNode.SIMPLE_NAME:
        return new SimpleName((org.eclipse.jdt.core.dom.SimpleName) jdtNode);
    case ASTNode.SIMPLE_TYPE:
        return new SimpleType((org.eclipse.jdt.core.dom.SimpleType) jdtNode);
    case ASTNode.SINGLE_MEMBER_ANNOTATION:
        return new SingleMemberAnnotation((org.eclipse.jdt.core.dom.SingleMemberAnnotation) jdtNode);
    case ASTNode.SINGLE_VARIABLE_DECLARATION:
        return new SingleVariableDeclaration((org.eclipse.jdt.core.dom.SingleVariableDeclaration) jdtNode);
    case ASTNode.STRING_LITERAL:
        return new StringLiteral((org.eclipse.jdt.core.dom.StringLiteral) jdtNode);
    case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
        return new SuperConstructorInvocation((org.eclipse.jdt.core.dom.SuperConstructorInvocation) jdtNode);
    case ASTNode.SUPER_FIELD_ACCESS:
        return new SuperFieldAccess((org.eclipse.jdt.core.dom.SuperFieldAccess) jdtNode);
    case ASTNode.SUPER_METHOD_INVOCATION:
        return new SuperMethodInvocation((org.eclipse.jdt.core.dom.SuperMethodInvocation) jdtNode);
    case ASTNode.SWITCH_CASE:
        return new SwitchCase((org.eclipse.jdt.core.dom.SwitchCase) jdtNode);
    case ASTNode.SWITCH_STATEMENT:
        return new SwitchStatement((org.eclipse.jdt.core.dom.SwitchStatement) jdtNode);
    case ASTNode.SYNCHRONIZED_STATEMENT:
        return new SynchronizedStatement((org.eclipse.jdt.core.dom.SynchronizedStatement) jdtNode);
    case ASTNode.TAG_ELEMENT:
        return new TagElement((org.eclipse.jdt.core.dom.TagElement) jdtNode);
    case ASTNode.TEXT_ELEMENT:
        return new TextElement((org.eclipse.jdt.core.dom.TextElement) jdtNode);
    case ASTNode.THIS_EXPRESSION:
        return new ThisExpression((org.eclipse.jdt.core.dom.ThisExpression) jdtNode);
    case ASTNode.THROW_STATEMENT:
        return new ThrowStatement((org.eclipse.jdt.core.dom.ThrowStatement) jdtNode);
    case ASTNode.TRY_STATEMENT:
        return new TryStatement((org.eclipse.jdt.core.dom.TryStatement) jdtNode);
    case ASTNode.TYPE_DECLARATION:
        return new TypeDeclaration((org.eclipse.jdt.core.dom.TypeDeclaration) jdtNode);
    case ASTNode.TYPE_DECLARATION_STATEMENT:
        return new TypeDeclarationStatement((org.eclipse.jdt.core.dom.TypeDeclarationStatement) jdtNode);
    case ASTNode.TYPE_LITERAL:
        return new TypeLiteral((org.eclipse.jdt.core.dom.TypeLiteral) jdtNode);
    case ASTNode.UNION_TYPE:
        return new UnionType((org.eclipse.jdt.core.dom.UnionType) jdtNode);
    case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
        return new VariableDeclarationExpression(
                (org.eclipse.jdt.core.dom.VariableDeclarationExpression) jdtNode);
    case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
        return new VariableDeclarationFragment((org.eclipse.jdt.core.dom.VariableDeclarationFragment) jdtNode);
    case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        return new VariableDeclarationStatement(
                (org.eclipse.jdt.core.dom.VariableDeclarationStatement) jdtNode);
    case ASTNode.WHILE_STATEMENT:
        return new WhileStatement((org.eclipse.jdt.core.dom.WhileStatement) jdtNode);
    // These nodes only appear in comments and J2ObjC doens't need any
    // information from their subtree so we just convert them to TextElement.
    case ASTNode.MEMBER_REF:
    case ASTNode.METHOD_REF:
    case ASTNode.METHOD_REF_PARAMETER:
        return new TextElement(jdtNode);
    case ASTNode.COMPILATION_UNIT:
        throw new AssertionError("CompilationUnit must be converted using convertCompilationUnit()");
    default:/* ww w .  j a  v a2  s . c  om*/
        throw new AssertionError("Unknown node type: " + jdtNode.getClass().getName());
    }
}

From source file:com.google.devtools.j2objc.jdt.TreeConverter.java

License:Apache License

private static TreeNode convertInner(ASTNode jdtNode) {
    switch (jdtNode.getNodeType()) {
    case ASTNode.ANNOTATION_TYPE_DECLARATION:
        return convertAnnotationTypeDeclaration((org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) jdtNode);
    case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
        return convertAnnotationTypeMemberDeclaration(
                (org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration) jdtNode);
    case ASTNode.ARRAY_ACCESS:
        return convertArrayAccess((org.eclipse.jdt.core.dom.ArrayAccess) jdtNode);
    case ASTNode.ARRAY_CREATION:
        return convertArrayCreation((org.eclipse.jdt.core.dom.ArrayCreation) jdtNode);
    case ASTNode.ARRAY_INITIALIZER:
        return convertArrayInitializer((org.eclipse.jdt.core.dom.ArrayInitializer) jdtNode);
    case ASTNode.ARRAY_TYPE:
        return convertArrayType((org.eclipse.jdt.core.dom.ArrayType) jdtNode);
    case ASTNode.ASSERT_STATEMENT:
        return convertAssertStatement((org.eclipse.jdt.core.dom.AssertStatement) jdtNode);
    case ASTNode.ASSIGNMENT:
        return convertAssignment((org.eclipse.jdt.core.dom.Assignment) jdtNode);
    case ASTNode.BLOCK:
        return convertBlock((org.eclipse.jdt.core.dom.Block) jdtNode);
    case ASTNode.BLOCK_COMMENT:
        return new BlockComment();
    case ASTNode.BOOLEAN_LITERAL:
        return convertBooleanLiteral((org.eclipse.jdt.core.dom.BooleanLiteral) jdtNode);
    case ASTNode.BREAK_STATEMENT:
        return convertBreakStatement((org.eclipse.jdt.core.dom.BreakStatement) jdtNode);
    case ASTNode.CAST_EXPRESSION:
        return convertCastExpression((org.eclipse.jdt.core.dom.CastExpression) jdtNode);
    case ASTNode.CATCH_CLAUSE:
        return convertCatchClause((org.eclipse.jdt.core.dom.CatchClause) jdtNode);
    case ASTNode.CHARACTER_LITERAL:
        return convertCharacterLiteral((org.eclipse.jdt.core.dom.CharacterLiteral) jdtNode);
    case ASTNode.CLASS_INSTANCE_CREATION:
        return convertClassInstanceCreation((org.eclipse.jdt.core.dom.ClassInstanceCreation) jdtNode);
    case ASTNode.CONDITIONAL_EXPRESSION:
        return convertConditionalExpression((org.eclipse.jdt.core.dom.ConditionalExpression) jdtNode);
    case ASTNode.CONSTRUCTOR_INVOCATION:
        return convertConstructorInvocation((org.eclipse.jdt.core.dom.ConstructorInvocation) jdtNode);
    case ASTNode.CONTINUE_STATEMENT:
        return convertContinueStatement((org.eclipse.jdt.core.dom.ContinueStatement) jdtNode);
    case ASTNode.CREATION_REFERENCE:
        return convertCreationReference((org.eclipse.jdt.core.dom.CreationReference) jdtNode);
    case ASTNode.DIMENSION:
        return convertDimension((org.eclipse.jdt.core.dom.Dimension) jdtNode);
    case ASTNode.DO_STATEMENT:
        return convertDoStatement((org.eclipse.jdt.core.dom.DoStatement) jdtNode);
    case ASTNode.EMPTY_STATEMENT:
        return new EmptyStatement();
    case ASTNode.ENHANCED_FOR_STATEMENT:
        return convertEnhancedForStatement((org.eclipse.jdt.core.dom.EnhancedForStatement) jdtNode);
    case ASTNode.ENUM_CONSTANT_DECLARATION:
        return convertEnumConstantDeclaration((org.eclipse.jdt.core.dom.EnumConstantDeclaration) jdtNode);
    case ASTNode.ENUM_DECLARATION:
        return convertEnumDeclaration((org.eclipse.jdt.core.dom.EnumDeclaration) jdtNode);
    case ASTNode.EXPRESSION_METHOD_REFERENCE:
        return convertExpressionMethodReference((org.eclipse.jdt.core.dom.ExpressionMethodReference) jdtNode);
    case ASTNode.EXPRESSION_STATEMENT:
        return convertExpressionStatement((org.eclipse.jdt.core.dom.ExpressionStatement) jdtNode);
    case ASTNode.FIELD_ACCESS:
        return convertFieldAccess((org.eclipse.jdt.core.dom.FieldAccess) jdtNode);
    case ASTNode.FIELD_DECLARATION:
        return convertFieldDeclaration((org.eclipse.jdt.core.dom.FieldDeclaration) jdtNode);
    case ASTNode.FOR_STATEMENT:
        return convertForStatement((org.eclipse.jdt.core.dom.ForStatement) jdtNode);
    case ASTNode.IF_STATEMENT:
        return convertIfStatement((org.eclipse.jdt.core.dom.IfStatement) jdtNode);
    case ASTNode.INFIX_EXPRESSION:
        return convertInfixExpression((org.eclipse.jdt.core.dom.InfixExpression) jdtNode);
    case ASTNode.INTERSECTION_TYPE:
        return convertIntersectionType((org.eclipse.jdt.core.dom.IntersectionType) jdtNode);
    case ASTNode.INITIALIZER:
        return convertInitializer((org.eclipse.jdt.core.dom.Initializer) jdtNode);
    case ASTNode.INSTANCEOF_EXPRESSION:
        return convertInstanceofExpression((org.eclipse.jdt.core.dom.InstanceofExpression) jdtNode);
    case ASTNode.JAVADOC:
        return convertJavadoc((org.eclipse.jdt.core.dom.Javadoc) jdtNode);
    case ASTNode.LABELED_STATEMENT:
        return convertLabeledStatement((org.eclipse.jdt.core.dom.LabeledStatement) jdtNode);
    case ASTNode.LAMBDA_EXPRESSION:
        return convertLambdaExpression((org.eclipse.jdt.core.dom.LambdaExpression) jdtNode);
    case ASTNode.LINE_COMMENT:
        return new LineComment();
    case ASTNode.MARKER_ANNOTATION:
        return convertMarkerAnnotation((org.eclipse.jdt.core.dom.MarkerAnnotation) jdtNode);
    case ASTNode.MEMBER_VALUE_PAIR:
        return convertMemberValuePair((org.eclipse.jdt.core.dom.MemberValuePair) jdtNode);
    case ASTNode.METHOD_DECLARATION:
        return convertMethodDeclaration((org.eclipse.jdt.core.dom.MethodDeclaration) jdtNode);
    case ASTNode.METHOD_INVOCATION:
        return convertMethodInvocation((org.eclipse.jdt.core.dom.MethodInvocation) jdtNode);
    case ASTNode.NAME_QUALIFIED_TYPE:
        return convertNameQualifiedType((org.eclipse.jdt.core.dom.NameQualifiedType) jdtNode);
    case ASTNode.NORMAL_ANNOTATION:
        return convertNormalAnnotation((org.eclipse.jdt.core.dom.NormalAnnotation) jdtNode);
    case ASTNode.NULL_LITERAL:
        return new NullLiteral(BindingConverter.NULL_TYPE);
    case ASTNode.NUMBER_LITERAL:
        return convertNumberLiteral((org.eclipse.jdt.core.dom.NumberLiteral) jdtNode);
    case ASTNode.PACKAGE_DECLARATION:
        return convertPackageDeclaration((org.eclipse.jdt.core.dom.PackageDeclaration) jdtNode);
    case ASTNode.PARAMETERIZED_TYPE:
        return convertParameterizedType((org.eclipse.jdt.core.dom.ParameterizedType) jdtNode);
    case ASTNode.PARENTHESIZED_EXPRESSION:
        return convertParenthesizedExpression((org.eclipse.jdt.core.dom.ParenthesizedExpression) jdtNode);
    case ASTNode.POSTFIX_EXPRESSION:
        return convertPostfixExpression((org.eclipse.jdt.core.dom.PostfixExpression) jdtNode);
    case ASTNode.PREFIX_EXPRESSION:
        return convertPrefixExpression((org.eclipse.jdt.core.dom.PrefixExpression) jdtNode);
    case ASTNode.PRIMITIVE_TYPE:
        return convertPrimitiveType((org.eclipse.jdt.core.dom.PrimitiveType) jdtNode);
    case ASTNode.QUALIFIED_NAME:
        return convertQualifiedName((org.eclipse.jdt.core.dom.QualifiedName) jdtNode);
    case ASTNode.QUALIFIED_TYPE:
        return convertQualifiedType((org.eclipse.jdt.core.dom.QualifiedType) jdtNode);
    case ASTNode.RETURN_STATEMENT:
        return convertReturnStatement((org.eclipse.jdt.core.dom.ReturnStatement) jdtNode);
    case ASTNode.SIMPLE_NAME:
        return convertSimpleName((org.eclipse.jdt.core.dom.SimpleName) jdtNode);
    case ASTNode.SIMPLE_TYPE:
        return convertSimpleType((org.eclipse.jdt.core.dom.SimpleType) jdtNode);
    case ASTNode.SINGLE_MEMBER_ANNOTATION:
        return convertSingleMemberAnnotation((org.eclipse.jdt.core.dom.SingleMemberAnnotation) jdtNode);
    case ASTNode.SINGLE_VARIABLE_DECLARATION:
        return convertSingleVariableDeclaration((org.eclipse.jdt.core.dom.SingleVariableDeclaration) jdtNode);
    case ASTNode.STRING_LITERAL:
        return convertStringLiteral((org.eclipse.jdt.core.dom.StringLiteral) jdtNode);
    case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
        return convertSuperConstructorInvocation((org.eclipse.jdt.core.dom.SuperConstructorInvocation) jdtNode);
    case ASTNode.SUPER_FIELD_ACCESS:
        return convertSuperFieldAccess((org.eclipse.jdt.core.dom.SuperFieldAccess) jdtNode);
    case ASTNode.SUPER_METHOD_INVOCATION:
        return convertSuperMethodInvocation((org.eclipse.jdt.core.dom.SuperMethodInvocation) jdtNode);
    case ASTNode.SUPER_METHOD_REFERENCE:
        return convertSuperMethodReference((org.eclipse.jdt.core.dom.SuperMethodReference) jdtNode);
    case ASTNode.SWITCH_CASE:
        return convertSwitchCase((org.eclipse.jdt.core.dom.SwitchCase) jdtNode);
    case ASTNode.SWITCH_STATEMENT:
        return convertSwitchStatement((org.eclipse.jdt.core.dom.SwitchStatement) jdtNode);
    case ASTNode.SYNCHRONIZED_STATEMENT:
        return convertSynchronizedStatement((org.eclipse.jdt.core.dom.SynchronizedStatement) jdtNode);
    case ASTNode.TAG_ELEMENT:
        return convertTagElement((org.eclipse.jdt.core.dom.TagElement) jdtNode);
    case ASTNode.TEXT_ELEMENT:
        return convertTextElement(((org.eclipse.jdt.core.dom.TextElement) jdtNode).getText());
    case ASTNode.THIS_EXPRESSION:
        return convertThisExpression((org.eclipse.jdt.core.dom.ThisExpression) jdtNode);
    case ASTNode.THROW_STATEMENT:
        return convertThrowStatement((org.eclipse.jdt.core.dom.ThrowStatement) jdtNode);
    case ASTNode.TRY_STATEMENT:
        return convertTryStatement((org.eclipse.jdt.core.dom.TryStatement) jdtNode);
    case ASTNode.TYPE_DECLARATION:
        return convertTypeDeclaration((org.eclipse.jdt.core.dom.TypeDeclaration) jdtNode);
    case ASTNode.TYPE_DECLARATION_STATEMENT:
        return convertTypeDeclarationStatement((org.eclipse.jdt.core.dom.TypeDeclarationStatement) jdtNode);
    case ASTNode.TYPE_LITERAL:
        return convertTypeLiteral((org.eclipse.jdt.core.dom.TypeLiteral) jdtNode);
    case ASTNode.TYPE_METHOD_REFERENCE:
        return convertTypeMethodReference((org.eclipse.jdt.core.dom.TypeMethodReference) jdtNode);
    case ASTNode.UNION_TYPE:
        return convertUnionType((org.eclipse.jdt.core.dom.UnionType) jdtNode);
    case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
        return convertVariableDeclarationExpression(
                (org.eclipse.jdt.core.dom.VariableDeclarationExpression) jdtNode);
    case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
        return convertVariableDeclarationFragment(
                (org.eclipse.jdt.core.dom.VariableDeclarationFragment) jdtNode);
    case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        return convertVariableDeclarationStatement(
                (org.eclipse.jdt.core.dom.VariableDeclarationStatement) jdtNode);
    case ASTNode.WHILE_STATEMENT:
        return convertWhileStatement((org.eclipse.jdt.core.dom.WhileStatement) jdtNode);
    // These nodes only appear in comments and J2ObjC doens't need any
    // information from their subtree so we just convert them to TextElement.
    case ASTNode.MEMBER_REF:
    case ASTNode.METHOD_REF:
    case ASTNode.METHOD_REF_PARAMETER:
        return convertTextElement(jdtNode.toString());
    case ASTNode.COMPILATION_UNIT:
        throw new AssertionError("CompilationUnit must be converted using convertCompilationUnit()");
    default://from w w w . j a v  a 2  s .com
        throw new AssertionError("Unknown node type: " + jdtNode.getClass().getName());
    }
}

From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java

License:Open Source License

public static void getConstructorProposals(IInvocationContext context, IProblemLocation problem,
        Map<String, Map> missingConstructorsMap) throws CoreException {
    ICompilationUnit cu = context.getCompilationUnit();

    CompilationUnit astRoot = context.getASTRoot();
    ASTNode selectedNode = problem.getCoveringNode(astRoot);
    if (selectedNode == null) {
        return;//from w w  w. ja  va2  s.com
    }

    ITypeBinding targetBinding = null;
    List<Expression> arguments = null;
    IMethodBinding recursiveConstructor = null;

    int type = selectedNode.getNodeType();
    if (type == ASTNode.CLASS_INSTANCE_CREATION) {
        ClassInstanceCreation creation = (ClassInstanceCreation) selectedNode;

        IBinding binding = creation.getType().resolveBinding();
        if (binding instanceof ITypeBinding) {
            targetBinding = (ITypeBinding) binding;
            arguments = creation.arguments();
        }
    } else if (type == ASTNode.SUPER_CONSTRUCTOR_INVOCATION) {
        ITypeBinding typeBinding = Bindings.getBindingOfParentType(selectedNode);
        if (typeBinding != null && !typeBinding.isAnonymous()) {
            targetBinding = typeBinding.getSuperclass();
            arguments = ((SuperConstructorInvocation) selectedNode).arguments();
        }
    } else if (type == ASTNode.CONSTRUCTOR_INVOCATION) {
        ITypeBinding typeBinding = Bindings.getBindingOfParentType(selectedNode);
        if (typeBinding != null && !typeBinding.isAnonymous()) {
            targetBinding = typeBinding;
            arguments = ((ConstructorInvocation) selectedNode).arguments();
            recursiveConstructor = ASTResolving.findParentMethodDeclaration(selectedNode).resolveBinding();
        }
    }
    if (targetBinding == null) {
        return;
    }
    IMethodBinding[] methods = targetBinding.getDeclaredMethods();
    ArrayList<IMethodBinding> similarElements = new ArrayList<IMethodBinding>();
    for (int i = 0; i < methods.length; i++) {
        IMethodBinding curr = methods[i];
        if (curr.isConstructor() && recursiveConstructor != curr) {
            similarElements.add(curr); // similar elements can contain a implicit default constructor
        }
    }

    if (targetBinding.isFromSource()) {
        ITypeBinding targetDecl = targetBinding.getTypeDeclaration();

        Map<String, LinkedCorrectionProposal> map = missingConstructorsMap.get(targetDecl.getQualifiedName());
        if (map == null)
            return;
        ICompilationUnit targetCU = ASTResolving.findCompilationUnitForBinding(cu, astRoot, targetDecl);
        if (targetCU != null) {
            String arg = ASTResolving.getMethodSignature(ASTResolving.getTypeSignature(targetDecl),
                    getParameterTypes(arguments), false);
            String label = Messages.format(
                    CorrectionMessages.UnresolvedElementsSubProcessor_createconstructor_description, arg);
            Image image = JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_MISC_PUBLIC,
                    JavaElementImageDescriptor.CONSTRUCTOR, JavaElementImageProvider.SMALL_SIZE);
            /**
             * Make sure constructor of a certain signature is created only once. 
             */
            String key = arg;
            map.put(key, new NewMethodCorrectionProposal(label, targetCU, selectedNode, arguments, targetDecl,
                    IProposalRelevance.CREATE_CONSTRUCTOR, image));
        }
    }
}

From source file:com.j2swift.ast.TreeConverter.java

License:Apache License

public static TreeNode convertInner(ASTNode jdtNode) {
    switch (jdtNode.getNodeType()) {
    case ASTNode.ANNOTATION_TYPE_DECLARATION:
        return new AnnotationTypeDeclaration((org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) jdtNode);
    case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
        return new AnnotationTypeMemberDeclaration(
                (org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration) jdtNode);
    case ASTNode.ANONYMOUS_CLASS_DECLARATION:
        return new AnonymousClassDeclaration((org.eclipse.jdt.core.dom.AnonymousClassDeclaration) jdtNode);
    case ASTNode.ARRAY_ACCESS:
        return new ArrayAccess((org.eclipse.jdt.core.dom.ArrayAccess) jdtNode);
    case ASTNode.ARRAY_CREATION:
        return new ArrayCreation((org.eclipse.jdt.core.dom.ArrayCreation) jdtNode);
    case ASTNode.ARRAY_INITIALIZER:
        return new ArrayInitializer((org.eclipse.jdt.core.dom.ArrayInitializer) jdtNode);
    case ASTNode.ARRAY_TYPE:
        return new ArrayType((org.eclipse.jdt.core.dom.ArrayType) jdtNode);
    case ASTNode.ASSERT_STATEMENT:
        return new AssertStatement((org.eclipse.jdt.core.dom.AssertStatement) jdtNode);
    case ASTNode.ASSIGNMENT:
        return new Assignment((org.eclipse.jdt.core.dom.Assignment) jdtNode);
    case ASTNode.BLOCK:
        return new Block((org.eclipse.jdt.core.dom.Block) jdtNode);
    case ASTNode.BLOCK_COMMENT:
        return new BlockComment((org.eclipse.jdt.core.dom.BlockComment) jdtNode);
    case ASTNode.BOOLEAN_LITERAL:
        return new BooleanLiteral((org.eclipse.jdt.core.dom.BooleanLiteral) jdtNode);
    case ASTNode.BREAK_STATEMENT:
        return new BreakStatement((org.eclipse.jdt.core.dom.BreakStatement) jdtNode);
    case ASTNode.CAST_EXPRESSION:
        return new CastExpression((org.eclipse.jdt.core.dom.CastExpression) jdtNode);
    case ASTNode.CATCH_CLAUSE:
        return new CatchClause((org.eclipse.jdt.core.dom.CatchClause) jdtNode);
    case ASTNode.CHARACTER_LITERAL:
        return new CharacterLiteral((org.eclipse.jdt.core.dom.CharacterLiteral) jdtNode);
    case ASTNode.CLASS_INSTANCE_CREATION:
        return new ClassInstanceCreation((org.eclipse.jdt.core.dom.ClassInstanceCreation) jdtNode);
    case ASTNode.CONDITIONAL_EXPRESSION:
        return new ConditionalExpression((org.eclipse.jdt.core.dom.ConditionalExpression) jdtNode);
    case ASTNode.CONSTRUCTOR_INVOCATION:
        return new ConstructorInvocation((org.eclipse.jdt.core.dom.ConstructorInvocation) jdtNode);
    case ASTNode.CONTINUE_STATEMENT:
        return new ContinueStatement((org.eclipse.jdt.core.dom.ContinueStatement) jdtNode);
    case ASTNode.CREATION_REFERENCE:
        return new CreationReference((org.eclipse.jdt.core.dom.CreationReference) jdtNode);
    case ASTNode.DIMENSION:
        return new Dimension((org.eclipse.jdt.core.dom.Dimension) jdtNode);
    case ASTNode.DO_STATEMENT:
        return new DoStatement((org.eclipse.jdt.core.dom.DoStatement) jdtNode);
    case ASTNode.EMPTY_STATEMENT:
        return new EmptyStatement((org.eclipse.jdt.core.dom.EmptyStatement) jdtNode);
    case ASTNode.ENHANCED_FOR_STATEMENT:
        return new EnhancedForStatement((org.eclipse.jdt.core.dom.EnhancedForStatement) jdtNode);
    case ASTNode.ENUM_CONSTANT_DECLARATION:
        return new EnumConstantDeclaration((org.eclipse.jdt.core.dom.EnumConstantDeclaration) jdtNode);
    case ASTNode.ENUM_DECLARATION:
        return new EnumDeclaration((org.eclipse.jdt.core.dom.EnumDeclaration) jdtNode);
    case ASTNode.EXPRESSION_METHOD_REFERENCE:
        return new ExpressionMethodReference((org.eclipse.jdt.core.dom.ExpressionMethodReference) jdtNode);
    case ASTNode.EXPRESSION_STATEMENT:
        return new ExpressionStatement((org.eclipse.jdt.core.dom.ExpressionStatement) jdtNode);
    case ASTNode.FIELD_ACCESS:
        return new FieldAccess((org.eclipse.jdt.core.dom.FieldAccess) jdtNode);
    case ASTNode.FIELD_DECLARATION:
        return new FieldDeclaration((org.eclipse.jdt.core.dom.FieldDeclaration) jdtNode);
    case ASTNode.FOR_STATEMENT:
        return new ForStatement((org.eclipse.jdt.core.dom.ForStatement) jdtNode);
    case ASTNode.IF_STATEMENT:
        return new IfStatement((org.eclipse.jdt.core.dom.IfStatement) jdtNode);
    case ASTNode.INFIX_EXPRESSION:
        return new InfixExpression((org.eclipse.jdt.core.dom.InfixExpression) jdtNode);
    case ASTNode.INTERSECTION_TYPE:
        return new IntersectionType((org.eclipse.jdt.core.dom.IntersectionType) jdtNode);
    case ASTNode.INITIALIZER:
        return new Initializer((org.eclipse.jdt.core.dom.Initializer) jdtNode);
    case ASTNode.INSTANCEOF_EXPRESSION:
        return new InstanceofExpression((org.eclipse.jdt.core.dom.InstanceofExpression) jdtNode);
    case ASTNode.JAVADOC:
        return new Javadoc((org.eclipse.jdt.core.dom.Javadoc) jdtNode);
    case ASTNode.LABELED_STATEMENT:
        return new LabeledStatement((org.eclipse.jdt.core.dom.LabeledStatement) jdtNode);
    case ASTNode.LAMBDA_EXPRESSION:
        return new LambdaExpression((org.eclipse.jdt.core.dom.LambdaExpression) jdtNode);
    case ASTNode.LINE_COMMENT:
        return new LineComment((org.eclipse.jdt.core.dom.LineComment) jdtNode);
    case ASTNode.MARKER_ANNOTATION:
        return MarkerAnnotation.convert((org.eclipse.jdt.core.dom.MarkerAnnotation) jdtNode);
    case ASTNode.MEMBER_VALUE_PAIR:
        return new MemberValuePair((org.eclipse.jdt.core.dom.MemberValuePair) jdtNode);
    case ASTNode.METHOD_DECLARATION:
        return new MethodDeclaration((org.eclipse.jdt.core.dom.MethodDeclaration) jdtNode);
    case ASTNode.METHOD_INVOCATION:
        return new MethodInvocation((org.eclipse.jdt.core.dom.MethodInvocation) jdtNode);
    case ASTNode.NAME_QUALIFIED_TYPE:
        return new NameQualifiedType((org.eclipse.jdt.core.dom.NameQualifiedType) jdtNode);
    case ASTNode.NORMAL_ANNOTATION:
        return new NormalAnnotation((org.eclipse.jdt.core.dom.NormalAnnotation) jdtNode);
    case ASTNode.NULL_LITERAL:
        return new NullLiteral((org.eclipse.jdt.core.dom.NullLiteral) jdtNode);
    case ASTNode.NUMBER_LITERAL:
        return new NumberLiteral((org.eclipse.jdt.core.dom.NumberLiteral) jdtNode);
    case ASTNode.PACKAGE_DECLARATION:
        return new PackageDeclaration((org.eclipse.jdt.core.dom.PackageDeclaration) jdtNode);
    case ASTNode.PARAMETERIZED_TYPE:
        return new ParameterizedType((org.eclipse.jdt.core.dom.ParameterizedType) jdtNode);
    case ASTNode.PARENTHESIZED_EXPRESSION:
        return new ParenthesizedExpression((org.eclipse.jdt.core.dom.ParenthesizedExpression) jdtNode);
    case ASTNode.POSTFIX_EXPRESSION:
        return new PostfixExpression((org.eclipse.jdt.core.dom.PostfixExpression) jdtNode);
    case ASTNode.PREFIX_EXPRESSION:
        return new PrefixExpression((org.eclipse.jdt.core.dom.PrefixExpression) jdtNode);
    case ASTNode.PRIMITIVE_TYPE:
        return new PrimitiveType((org.eclipse.jdt.core.dom.PrimitiveType) jdtNode);
    case ASTNode.QUALIFIED_NAME:
        return new QualifiedName((org.eclipse.jdt.core.dom.QualifiedName) jdtNode);
    case ASTNode.QUALIFIED_TYPE:
        return new QualifiedType((org.eclipse.jdt.core.dom.QualifiedType) jdtNode);
    case ASTNode.RETURN_STATEMENT:
        return new ReturnStatement((org.eclipse.jdt.core.dom.ReturnStatement) jdtNode);
    case ASTNode.SIMPLE_NAME:
        return new SimpleName((org.eclipse.jdt.core.dom.SimpleName) jdtNode);
    case ASTNode.SIMPLE_TYPE:
        return new SimpleType((org.eclipse.jdt.core.dom.SimpleType) jdtNode);
    case ASTNode.SINGLE_MEMBER_ANNOTATION:
        return SingleMemberAnnotation.convert((org.eclipse.jdt.core.dom.SingleMemberAnnotation) jdtNode);
    case ASTNode.SINGLE_VARIABLE_DECLARATION:
        return new SingleVariableDeclaration((org.eclipse.jdt.core.dom.SingleVariableDeclaration) jdtNode);
    case ASTNode.STRING_LITERAL:
        return new StringLiteral((org.eclipse.jdt.core.dom.StringLiteral) jdtNode);
    case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
        return new SuperConstructorInvocation((org.eclipse.jdt.core.dom.SuperConstructorInvocation) jdtNode);
    case ASTNode.SUPER_FIELD_ACCESS:
        return new SuperFieldAccess((org.eclipse.jdt.core.dom.SuperFieldAccess) jdtNode);
    case ASTNode.SUPER_METHOD_INVOCATION:
        return new SuperMethodInvocation((org.eclipse.jdt.core.dom.SuperMethodInvocation) jdtNode);
    case ASTNode.SUPER_METHOD_REFERENCE:
        return new SuperMethodReference((org.eclipse.jdt.core.dom.SuperMethodReference) jdtNode);
    case ASTNode.SWITCH_CASE:
        return new SwitchCase((org.eclipse.jdt.core.dom.SwitchCase) jdtNode);
    case ASTNode.SWITCH_STATEMENT:
        return new SwitchStatement((org.eclipse.jdt.core.dom.SwitchStatement) jdtNode);
    case ASTNode.SYNCHRONIZED_STATEMENT:
        return new SynchronizedStatement((org.eclipse.jdt.core.dom.SynchronizedStatement) jdtNode);
    case ASTNode.TAG_ELEMENT:
        return new TagElement((org.eclipse.jdt.core.dom.TagElement) jdtNode);
    case ASTNode.TEXT_ELEMENT:
        return new TextElement((org.eclipse.jdt.core.dom.TextElement) jdtNode);
    case ASTNode.THIS_EXPRESSION:
        return new ThisExpression((org.eclipse.jdt.core.dom.ThisExpression) jdtNode);
    case ASTNode.THROW_STATEMENT:
        return new ThrowStatement((org.eclipse.jdt.core.dom.ThrowStatement) jdtNode);
    case ASTNode.TRY_STATEMENT:
        return new TryStatement((org.eclipse.jdt.core.dom.TryStatement) jdtNode);
    case ASTNode.TYPE_DECLARATION:
        return new TypeDeclaration((org.eclipse.jdt.core.dom.TypeDeclaration) jdtNode);
    case ASTNode.TYPE_DECLARATION_STATEMENT:
        return new TypeDeclarationStatement((org.eclipse.jdt.core.dom.TypeDeclarationStatement) jdtNode);
    case ASTNode.TYPE_LITERAL:
        return new TypeLiteral((org.eclipse.jdt.core.dom.TypeLiteral) jdtNode);
    case ASTNode.TYPE_METHOD_REFERENCE:
        return new TypeMethodReference((org.eclipse.jdt.core.dom.TypeMethodReference) jdtNode);
    case ASTNode.UNION_TYPE:
        return new UnionType((org.eclipse.jdt.core.dom.UnionType) jdtNode);
    case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
        return new VariableDeclarationExpression(
                (org.eclipse.jdt.core.dom.VariableDeclarationExpression) jdtNode);
    case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
        return new VariableDeclarationFragment((org.eclipse.jdt.core.dom.VariableDeclarationFragment) jdtNode);
    case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        return new VariableDeclarationStatement(
                (org.eclipse.jdt.core.dom.VariableDeclarationStatement) jdtNode);
    case ASTNode.WHILE_STATEMENT:
        return new WhileStatement((org.eclipse.jdt.core.dom.WhileStatement) jdtNode);
    // These nodes only appear in comments and J2ObjC doens't need any
    // information from their subtree so we just convert them to TextElement.
    case ASTNode.MEMBER_REF:
    case ASTNode.METHOD_REF:
    case ASTNode.METHOD_REF_PARAMETER:
        return new TextElement(jdtNode);
    case ASTNode.COMPILATION_UNIT:
        throw new AssertionError("CompilationUnit must be converted using convertCompilationUnit()");
    default:/*from   w ww.  j  a v a2  s.  c  o m*/
        throw new AssertionError("Unknown node type: " + jdtNode.getClass().getName());
    }
}

From source file:edu.illinois.jflow.core.transformations.code.ExtractClosureAnalyzer.java

License:Open Source License

@Override
public void endVisit(CompilationUnit node) {
    RefactoringStatus status = getStatus();
    superCall: {/*from   ww w .  j av  a 2 s.  co m*/
        if (status.hasFatalError())
            break superCall;
        if (!hasSelectedNodes()) {
            ASTNode coveringNode = getLastCoveringNode();
            if (coveringNode instanceof Block && coveringNode.getParent() instanceof MethodDeclaration) {
                MethodDeclaration methodDecl = (MethodDeclaration) coveringNode.getParent();
                Message[] messages = ASTNodes.getMessages(methodDecl, ASTNodes.NODE_ONLY);
                if (messages.length > 0) {
                    status.addFatalError(
                            Messages.format(JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_compile_errors,
                                    BasicElementLabels
                                            .getJavaElementName(methodDecl.getName().getIdentifier())),
                            JavaStatusContext.create(fCUnit, methodDecl));
                    break superCall;
                }
            }
            status.addFatalError(JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_only_method_body);
            break superCall;
        }
        fEnclosingBodyDeclaration = (BodyDeclaration) ASTNodes.getParent(getFirstSelectedNode(),
                BodyDeclaration.class);
        if (fEnclosingBodyDeclaration == null
                || (fEnclosingBodyDeclaration.getNodeType() != ASTNode.METHOD_DECLARATION
                        && fEnclosingBodyDeclaration.getNodeType() != ASTNode.FIELD_DECLARATION
                        && fEnclosingBodyDeclaration.getNodeType() != ASTNode.INITIALIZER)) {
            status.addFatalError(JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_only_method_body);
            break superCall;
        } else if (ASTNodes.getEnclosingType(fEnclosingBodyDeclaration) == null) {
            status.addFatalError(
                    JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_compile_errors_no_parent_binding);
            break superCall;
        } else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) {
            fEnclosingMethodBinding = ((MethodDeclaration) fEnclosingBodyDeclaration).resolveBinding();
        }
        if (!isSingleExpressionOrStatementSet()) {
            status.addFatalError(JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_single_expression_or_set);
            break superCall;
        }
        if (isExpressionSelected()) {
            ASTNode expression = getFirstSelectedNode();
            if (expression instanceof Name) {
                Name name = (Name) expression;
                if (name.resolveBinding() instanceof ITypeBinding) {
                    status.addFatalError(
                            JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_type_reference);
                    break superCall;
                }
                if (name.resolveBinding() instanceof IMethodBinding) {
                    status.addFatalError(
                            JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_method_name_reference);
                    break superCall;
                }
                if (name.resolveBinding() instanceof IVariableBinding) {
                    StructuralPropertyDescriptor locationInParent = name.getLocationInParent();
                    if (locationInParent == QualifiedName.NAME_PROPERTY
                            || (locationInParent == FieldAccess.NAME_PROPERTY
                                    && !(((FieldAccess) name.getParent())
                                            .getExpression() instanceof ThisExpression))) {
                        status.addFatalError(
                                JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_part_of_qualified_name);
                        break superCall;
                    }
                }
                if (name.isSimpleName() && ((SimpleName) name).isDeclaration()) {
                    status.addFatalError(
                            JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_name_in_declaration);
                    break superCall;
                }
            }
            fForceStatic = ASTNodes.getParent(expression, ASTNode.SUPER_CONSTRUCTOR_INVOCATION) != null
                    || ASTNodes.getParent(expression, ASTNode.CONSTRUCTOR_INVOCATION) != null;
        }
        status.merge(LocalTypeAnalyzer.perform(fEnclosingBodyDeclaration, getSelection()));
        computeLastStatementSelected();
    }
    super.endVisit(node);
}

From source file:org.autorefactor.refactoring.ASTHelper.java

License:Open Source License

/**
 * Returns whether the two provided nodes structurally match.
 *
 * @param matcher the AST matcher//from   w w w  . j  a va2s.  c o m
 * @param node1 the first node to compare
 * @param node2 the second node to compare
 * @return true if the two provided nodes structurally match, false otherwise
 */
public static boolean match(ASTMatcher matcher, ASTNode node1, ASTNode node2) {
    if (sameClass(node1, node2)) {
        // FIXME JNR implement all expressions
        // TODO JNR
        // can we match "this.ast" and the unqualified "ast" for example?
        // can we match "MyClass.CONSTANT" and the unqualified "CONSTANT" for example?
        // can we use IVariableBindings to compare them?
        switch (node1.getNodeType()) {
        case ASTNode.ANNOTATION_TYPE_DECLARATION:
            return matcher.match((AnnotationTypeDeclaration) node1, node2);
        case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
            return matcher.match((AnnotationTypeMemberDeclaration) node1, node2);
        case ASTNode.ANONYMOUS_CLASS_DECLARATION:
            return matcher.match((AnonymousClassDeclaration) node1, node2);
        case ASTNode.ARRAY_ACCESS:
            return matcher.match((ArrayAccess) node1, node2);
        case ASTNode.ARRAY_CREATION:
            return matcher.match((ArrayCreation) node1, node2);
        case ASTNode.ARRAY_INITIALIZER:
            return matcher.match((ArrayInitializer) node1, node2);
        case ASTNode.ARRAY_TYPE:
            return matcher.match((ArrayType) node1, node2);
        case ASTNode.ASSERT_STATEMENT:
            return matcher.match((AssertStatement) node1, node2);
        case ASTNode.ASSIGNMENT:
            return matcher.match((Assignment) node1, node2);
        case ASTNode.BLOCK:
            return matcher.match((Block) node1, node2);
        case ASTNode.BLOCK_COMMENT:
            return matcher.match((BlockComment) node1, node2);
        case ASTNode.BOOLEAN_LITERAL:
            return matcher.match((BooleanLiteral) node1, node2);
        case ASTNode.BREAK_STATEMENT:
            return matcher.match((BreakStatement) node1, node2);
        case ASTNode.CAST_EXPRESSION:
            return matcher.match((CastExpression) node1, node2);
        case ASTNode.CATCH_CLAUSE:
            return matcher.match((CatchClause) node1, node2);
        case ASTNode.CHARACTER_LITERAL:
            return matcher.match((CharacterLiteral) node1, node2);
        case ASTNode.CLASS_INSTANCE_CREATION:
            return matcher.match((ClassInstanceCreation) node1, node2);
        case ASTNode.COMPILATION_UNIT:
            return matcher.match((CompilationUnit) node1, node2);
        case ASTNode.CONDITIONAL_EXPRESSION:
            return matcher.match((ConditionalExpression) node1, node2);
        case ASTNode.CONSTRUCTOR_INVOCATION:
            return matcher.match((ConstructorInvocation) node1, node2);
        case ASTNode.CONTINUE_STATEMENT:
            return matcher.match((ContinueStatement) node1, node2);
        case ASTNode.DO_STATEMENT:
            return matcher.match((DoStatement) node1, node2);
        case ASTNode.EMPTY_STATEMENT:
            return matcher.match((EmptyStatement) node1, node2);
        case ASTNode.ENHANCED_FOR_STATEMENT:
            return matcher.match((EnhancedForStatement) node1, node2);
        case ASTNode.ENUM_DECLARATION:
            return matcher.match((EnumDeclaration) node1, node2);
        case ASTNode.ENUM_CONSTANT_DECLARATION:
            return matcher.match((EnumConstantDeclaration) node1, node2);
        case ASTNode.EXPRESSION_STATEMENT:
            return matcher.match((ExpressionStatement) node1, node2);
        case ASTNode.FIELD_ACCESS:
            return matcher.match((FieldAccess) node1, node2);
        case ASTNode.FIELD_DECLARATION:
            return matcher.match((FieldDeclaration) node1, node2);
        case ASTNode.FOR_STATEMENT:
            return matcher.match((ForStatement) node1, node2);
        case ASTNode.IF_STATEMENT:
            return matcher.match((IfStatement) node1, node2);
        case ASTNode.IMPORT_DECLARATION:
            return matcher.match((ImportDeclaration) node1, node2);
        case ASTNode.INFIX_EXPRESSION:
            return matcher.match((InfixExpression) node1, node2);
        case ASTNode.INITIALIZER:
            return matcher.match((Initializer) node1, node2);
        case ASTNode.INSTANCEOF_EXPRESSION:
            return matcher.match((InstanceofExpression) node1, node2);
        case ASTNode.JAVADOC:
            return matcher.match((Javadoc) node1, node2);
        case ASTNode.LABELED_STATEMENT:
            return matcher.match((LabeledStatement) node1, node2);
        case ASTNode.LINE_COMMENT:
            return matcher.match((LineComment) node1, node2);
        case ASTNode.MARKER_ANNOTATION:
            return matcher.match((MarkerAnnotation) node1, node2);
        case ASTNode.MEMBER_REF:
            return matcher.match((MemberRef) node1, node2);
        case ASTNode.MEMBER_VALUE_PAIR:
            return matcher.match((MemberValuePair) node1, node2);
        case ASTNode.METHOD_DECLARATION:
            return matcher.match((MethodDeclaration) node1, node2);
        case ASTNode.METHOD_INVOCATION:
            return matcher.match((MethodInvocation) node1, node2);
        case ASTNode.METHOD_REF:
            return matcher.match((MethodRef) node1, node2);
        case ASTNode.METHOD_REF_PARAMETER:
            return matcher.match((MethodRefParameter) node1, node2);
        case ASTNode.MODIFIER:
            return matcher.match((Modifier) node1, node2);
        case ASTNode.NORMAL_ANNOTATION:
            return matcher.match((NormalAnnotation) node1, node2);
        case ASTNode.NULL_LITERAL:
            return matcher.match((NullLiteral) node1, node2);
        case ASTNode.NUMBER_LITERAL:
            return matcher.match((NumberLiteral) node1, node2);
        case ASTNode.PACKAGE_DECLARATION:
            return matcher.match((PackageDeclaration) node1, node2);
        case ASTNode.PARAMETERIZED_TYPE:
            return matcher.match((ParameterizedType) node1, node2);
        case ASTNode.PARENTHESIZED_EXPRESSION:
            return matcher.match((ParenthesizedExpression) node1, node2);
        case ASTNode.POSTFIX_EXPRESSION:
            return matcher.match((PostfixExpression) node1, node2);
        case ASTNode.PREFIX_EXPRESSION:
            return matcher.match((PrefixExpression) node1, node2);
        case ASTNode.PRIMITIVE_TYPE:
            return matcher.match((PrimitiveType) node1, node2);
        case ASTNode.QUALIFIED_NAME:
            return matcher.match((QualifiedName) node1, node2);
        case ASTNode.QUALIFIED_TYPE:
            return matcher.match((QualifiedType) node1, node2);
        case ASTNode.RETURN_STATEMENT:
            return matcher.match((ReturnStatement) node1, node2);
        case ASTNode.SIMPLE_NAME:
            return matcher.match((SimpleName) node1, node2);
        case ASTNode.SIMPLE_TYPE:
            return matcher.match((SimpleType) node1, node2);
        case ASTNode.SINGLE_MEMBER_ANNOTATION:
            return matcher.match((SingleMemberAnnotation) node1, node2);
        case ASTNode.SINGLE_VARIABLE_DECLARATION:
            return matcher.match((SingleVariableDeclaration) node1, node2);
        case ASTNode.STRING_LITERAL:
            return matcher.match((StringLiteral) node1, node2);
        case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
            return matcher.match((SuperConstructorInvocation) node1, node2);
        case ASTNode.SUPER_FIELD_ACCESS:
            return matcher.match((SuperFieldAccess) node1, node2);
        case ASTNode.SUPER_METHOD_INVOCATION:
            return matcher.match((SuperMethodInvocation) node1, node2);
        case ASTNode.SWITCH_CASE:
            return matcher.match((SwitchCase) node1, node2);
        case ASTNode.SWITCH_STATEMENT:
            return matcher.match((SwitchStatement) node1, node2);
        case ASTNode.SYNCHRONIZED_STATEMENT:
            return matcher.match((SynchronizedStatement) node1, node2);
        case ASTNode.TAG_ELEMENT:
            return matcher.match((TagElement) node1, node2);
        case ASTNode.TEXT_ELEMENT:
            return matcher.match((TextElement) node1, node2);
        case ASTNode.THIS_EXPRESSION:
            return matcher.match((ThisExpression) node1, node2);
        case ASTNode.THROW_STATEMENT:
            return matcher.match((ThrowStatement) node1, node2);
        case ASTNode.TRY_STATEMENT:
            return matcher.match((TryStatement) node1, node2);
        case ASTNode.TYPE_DECLARATION:
            return matcher.match((TypeDeclaration) node1, node2);
        case ASTNode.TYPE_DECLARATION_STATEMENT:
            return matcher.match((TypeDeclarationStatement) node1, node2);
        case ASTNode.TYPE_LITERAL:
            return matcher.match((TypeLiteral) node1, node2);
        case ASTNode.TYPE_PARAMETER:
            return matcher.match((TypeParameter) node1, node2);
        case ASTNode.UNION_TYPE:
            return matcher.match((UnionType) node1, node2);
        case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
            return matcher.match((VariableDeclarationExpression) node1, node2);
        case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
            return matcher.match((VariableDeclarationFragment) node1, node2);
        case ASTNode.VARIABLE_DECLARATION_STATEMENT:
            return matcher.match((VariableDeclarationStatement) node1, node2);
        case ASTNode.WHILE_STATEMENT:
            return matcher.match((WhileStatement) node1, node2);
        case ASTNode.WILDCARD_TYPE:
            return matcher.match((WildcardType) node1, node2);
        default:
            throw new NotImplementedException(node1);
        }
    }
    return false;
}

From source file:org.eclipse.ajdt.internal.ui.editor.quickfix.UnresolvedElementsSubProcessor.java

License:Open Source License

public static void getConstructorProposals(IInvocationContext context, IProblemLocation problem,
        Collection proposals) throws CoreException {
    ICompilationUnit cu = context.getCompilationUnit();

    CompilationUnit astRoot = context.getASTRoot();
    ASTNode selectedNode = problem.getCoveringNode(astRoot);
    if (selectedNode == null) {
        return;/* w  w w  .j  a  v a  2s.  c  o  m*/
    }

    ITypeBinding targetBinding = null;
    List arguments = null;
    IMethodBinding recursiveConstructor = null;

    int type = selectedNode.getNodeType();
    if (type == ASTNode.CLASS_INSTANCE_CREATION) {
        ClassInstanceCreation creation = (ClassInstanceCreation) selectedNode;

        targetBinding = creation.getType().resolveBinding();
        arguments = creation.arguments();
    } else if (type == ASTNode.SUPER_CONSTRUCTOR_INVOCATION) {
        ITypeBinding typeBinding = Bindings.getBindingOfParentType(selectedNode);
        if (typeBinding != null && !typeBinding.isAnonymous()) {
            targetBinding = typeBinding.getSuperclass();
            arguments = ((SuperConstructorInvocation) selectedNode).arguments();
        }
    } else if (type == ASTNode.CONSTRUCTOR_INVOCATION) {
        ITypeBinding typeBinding = Bindings.getBindingOfParentType(selectedNode);
        if (typeBinding != null && !typeBinding.isAnonymous()) {
            targetBinding = typeBinding;
            arguments = ((ConstructorInvocation) selectedNode).arguments();
            recursiveConstructor = ASTResolving.findParentMethodDeclaration(selectedNode).resolveBinding();
        }
    }
    if (targetBinding == null) {
        return;
    }
    IMethodBinding[] methods = targetBinding.getDeclaredMethods();
    ArrayList similarElements = new ArrayList();
    for (int i = 0; i < methods.length; i++) {
        IMethodBinding curr = methods[i];
        if (curr.isConstructor() && recursiveConstructor != curr) {
            similarElements.add(curr); // similar elements can contain a implicit default constructor
        }
    }

    addParameterMissmatchProposals(context, problem, similarElements, selectedNode, arguments, proposals);

    if (targetBinding.isFromSource()) {
        ITypeBinding targetDecl = targetBinding.getTypeDeclaration();

        ICompilationUnit targetCU = ASTResolving.findCompilationUnitForBinding(cu, astRoot, targetDecl);
        if (targetCU != null) {
            String[] args = new String[] { ASTResolving.getMethodSignature(
                    ASTResolving.getTypeSignature(targetDecl), getParameterTypes(arguments), false) };
            String label = Messages.format(
                    CorrectionMessages.UnresolvedElementsSubProcessor_createconstructor_description, args);
            Image image = JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_MISC_PUBLIC,
                    JavaElementImageDescriptor.CONSTRUCTOR, JavaElementImageProvider.SMALL_SIZE);
            proposals.add(new NewMethodCorrectionProposal(label, targetCU, selectedNode, arguments, targetDecl,
                    5, image));
        }
    }
}

From source file:org.eclipse.emf.test.tools.merger.ASTTest.java

License:Open Source License

@Test
public void testRead() {
    String content = TestUtil.readFile(CLASS_FILE, false);

    ASTParser astParser = CodeGenUtil.EclipseUtil.newASTParser();
    astParser.setSource(content.toCharArray());
    CompilationUnit compilationUnit = (CompilationUnit) astParser.createAST(null);

    {// w  w  w. j a v a 2 s .com
        Javadoc javadoc = (Javadoc) compilationUnit.getCommentList().get(0);
        assertEquals(1, javadoc.tags().size());
        TagElement tagElement = (TagElement) javadoc.tags().get(0);
        assertEquals(7, tagElement.fragments().size());
        //     for (Iterator i = tagElement.fragments().iterator(); i.hasNext();)
        //    {
        //      TextElement element = (TextElement)i.next();
        //      System.out.println(element.getText());
        //    }
    }

    //** Package
    PackageDeclaration packageDeclaration = compilationUnit.getPackage();
    assertNotNull(packageDeclaration);
    assertTrue(packageDeclaration.getName().isQualifiedName());
    assertEquals("org.eclipse.emf.test.tools.merger", packageDeclaration.getName().getFullyQualifiedName());

    //** Imports
    List<?> importDeclarations = compilationUnit.imports();
    assertEquals(6, importDeclarations.size());
    assertEquals("java.util.Collections",
            ((ImportDeclaration) importDeclarations.get(0)).getName().getFullyQualifiedName());
    assertFalse(((ImportDeclaration) importDeclarations.get(0)).isOnDemand());
    assertEquals("java.util.List",
            ((ImportDeclaration) importDeclarations.get(1)).getName().getFullyQualifiedName());
    assertFalse(((ImportDeclaration) importDeclarations.get(1)).isOnDemand());
    assertEquals("java.util.Map",
            ((ImportDeclaration) importDeclarations.get(2)).getName().getFullyQualifiedName());
    assertFalse(((ImportDeclaration) importDeclarations.get(2)).isOnDemand());
    assertEquals("org.eclipse.emf.common",
            ((ImportDeclaration) importDeclarations.get(3)).getName().getFullyQualifiedName());
    assertTrue(((ImportDeclaration) importDeclarations.get(3)).isOnDemand());
    assertEquals("org.eclipse.emf.common.notify.Notification",
            ((ImportDeclaration) importDeclarations.get(4)).getName().getFullyQualifiedName());
    assertFalse(((ImportDeclaration) importDeclarations.get(4)).isOnDemand());
    assertEquals("org.eclipse.emf.ecore.impl.EObjectImpl",
            ((ImportDeclaration) importDeclarations.get(5)).getName().getFullyQualifiedName());
    assertFalse(((ImportDeclaration) importDeclarations.get(5)).isOnDemand());

    //** Types
    List<?> typeDeclarations = compilationUnit.types();
    assertEquals(2, typeDeclarations.size());

    //** Class Example1
    TypeDeclaration exampleClass = (TypeDeclaration) typeDeclarations.get(1);
    assertEquals("Example1", exampleClass.getName().getFullyQualifiedName());
    assertFalse(exampleClass.isInterface());
    //Javadoc
    {
        Javadoc typeJavadoc = exampleClass.getJavadoc();
        assertEquals(4, typeJavadoc.tags().size());
        @SuppressWarnings("unchecked")
        TagElement[] tagElements = (TagElement[]) typeJavadoc.tags()
                .toArray(new TagElement[typeJavadoc.tags().size()]);
        //Tag[0]: " This is an example to be parsed by the ASTTests.\n Not really important"
        assertNull(tagElements[0].getTagName());
        assertEquals(2, tagElements[0].fragments().size());
        assertEquals("This is an example of a fairly complete Java file.",
                ((TextElement) tagElements[0].fragments().get(0)).getText());
        assertEquals("Its content is not really important",
                ((TextElement) tagElements[0].fragments().get(1)).getText());
        //Tag[1]: "@author EMF team"
        assertEquals("@author", tagElements[1].getTagName());
        assertEquals(1, tagElements[1].fragments().size());
        assertEquals(" EMF team", ((TextElement) tagElements[1].fragments().get(0)).getText());
        //Tag[2]: "@generated"
        assertEquals("@generated", tagElements[2].getTagName());
        assertTrue(tagElements[2].fragments().isEmpty());
        //Tag[3]: "@generated NOT"
        assertEquals("@generated", tagElements[3].getTagName());
        assertEquals(1, tagElements[3].fragments().size());
        assertEquals(" NOT", ((TextElement) tagElements[3].fragments().get(0)).getText());
    }
    //Super Class
    assertTrue(exampleClass.getSuperclassType().isSimpleType());
    assertEquals("EObjectImpl",
            ((SimpleType) exampleClass.getSuperclassType()).getName().getFullyQualifiedName());
    //Interfaces
    assertTrue(exampleClass.superInterfaceTypes().isEmpty());
    //Modifiers
    assertEquals(Modifier.PUBLIC, exampleClass.getModifiers());

    //** Content of the Example1 class
    assertEquals(19, exampleClass.bodyDeclarations().size());
    assertEquals(2, exampleClass.getTypes().length);
    assertEquals(7, exampleClass.getFields().length);
    assertEquals(7, exampleClass.getMethods().length);

    // Tests the order of the contents
    List<?> bodyDeclarations = exampleClass.bodyDeclarations();
    assertTrue(bodyDeclarations.get(0).toString(), bodyDeclarations.get(0) instanceof TypeDeclaration);
    assertTrue(bodyDeclarations.get(1).toString(), bodyDeclarations.get(1) instanceof Initializer);
    assertTrue(bodyDeclarations.get(2).toString(), bodyDeclarations.get(2) instanceof FieldDeclaration);
    assertTrue(bodyDeclarations.get(3).toString(), bodyDeclarations.get(3) instanceof TypeDeclaration);
    assertTrue(bodyDeclarations.get(4).toString(), bodyDeclarations.get(4) instanceof FieldDeclaration);
    assertTrue(bodyDeclarations.get(5).toString(), bodyDeclarations.get(5) instanceof FieldDeclaration);
    assertTrue(bodyDeclarations.get(6).toString(), bodyDeclarations.get(6) instanceof FieldDeclaration);
    assertTrue(bodyDeclarations.get(7).toString(), bodyDeclarations.get(7) instanceof Initializer);
    assertTrue(bodyDeclarations.get(8).toString(), bodyDeclarations.get(8) instanceof MethodDeclaration);
    assertTrue(bodyDeclarations.get(8).toString(), bodyDeclarations.get(9) instanceof MethodDeclaration);
    assertTrue(bodyDeclarations.get(8).toString(), bodyDeclarations.get(10) instanceof MethodDeclaration);
    assertTrue(bodyDeclarations.get(9).toString(), bodyDeclarations.get(11) instanceof MethodDeclaration);
    assertTrue(bodyDeclarations.get(10).toString(), bodyDeclarations.get(12) instanceof FieldDeclaration);
    assertTrue(bodyDeclarations.get(11).toString(), bodyDeclarations.get(13) instanceof MethodDeclaration);
    assertTrue(bodyDeclarations.get(12).toString(), bodyDeclarations.get(14) instanceof MethodDeclaration);
    assertTrue(bodyDeclarations.get(13).toString(), bodyDeclarations.get(15) instanceof MethodDeclaration);
    assertTrue(bodyDeclarations.get(14).toString(), bodyDeclarations.get(16) instanceof Initializer);

    //** Initializers
    {
        Initializer initializer = (Initializer) bodyDeclarations.get(1);
        assertFalse(Modifier.isStatic(initializer.getModifiers()));
        assertNull(initializer.getJavadoc());
    }
    //
    {
        Initializer initializer = (Initializer) bodyDeclarations.get(7);
        assertTrue(Modifier.isStatic(initializer.getModifiers()));
        assertNotNull(initializer.getJavadoc());
        Javadoc javadoc = initializer.getJavadoc();
        assertEquals(1, javadoc.tags().size());
        assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size());
        assertEquals("An static initializer",
                ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText());
    }
    //
    {
        Initializer initializer = (Initializer) bodyDeclarations.get(16);
        assertFalse(Modifier.isStatic(initializer.getModifiers()));
        assertNotNull(initializer.getJavadoc());
        Javadoc javadoc = initializer.getJavadoc();
        assertEquals(1, javadoc.tags().size());
        assertEquals(2, ((TagElement) javadoc.tags().get(0)).fragments().size());
        assertEquals("Another initializer with 2 lines",
                ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText());
        assertEquals("of javadoc.",
                ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(1)).getText());
    }

    //** Inner Class
    TypeDeclaration innerClass = exampleClass.getTypes()[0];
    assertFalse(innerClass.isInterface());
    assertTrue(innerClass.bodyDeclarations().isEmpty());
    assertEquals(Modifier.PUBLIC | Modifier.ABSTRACT, innerClass.getModifiers());
    assertNull(innerClass.getSuperclassType());
    assertEquals(2, innerClass.superInterfaceTypes().size());
    assertTrue(((Type) innerClass.superInterfaceTypes().get(0)).isSimpleType());
    assertEquals("Notification",
            ((SimpleType) innerClass.superInterfaceTypes().get(0)).getName().getFullyQualifiedName());
    assertTrue(((Type) innerClass.superInterfaceTypes().get(1)).isSimpleType());
    assertEquals("org.eclipse.emf.common.notify.Notifier",
            ((SimpleType) innerClass.superInterfaceTypes().get(1)).getName().getFullyQualifiedName());
    assertNull(innerClass.getJavadoc());

    //** Inner Interface
    TypeDeclaration innerInterface = exampleClass.getTypes()[1];
    assertTrue(innerInterface.isInterface());
    assertTrue(innerInterface.bodyDeclarations().isEmpty());
    assertEquals(Modifier.PRIVATE | Modifier.STATIC, innerInterface.getModifiers());
    assertNull(innerInterface.getSuperclassType());
    assertEquals(1, innerInterface.superInterfaceTypes().size());
    assertTrue(((Type) innerInterface.superInterfaceTypes().get(0)).isSimpleType());
    assertEquals("Notification",
            ((SimpleType) innerInterface.superInterfaceTypes().get(0)).getName().getFullyQualifiedName());
    assertNull(innerClass.getJavadoc());

    //** Fields
    FieldDeclaration[] fieldDeclarations = exampleClass.getFields();
    //fieldDeclarations[0]: public static final String STR_CONST = "something"
    {
        Javadoc javadoc = fieldDeclarations[0].getJavadoc();
        assertEquals(1, javadoc.tags().size());
        assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size());
        assertEquals("public String constant.",
                ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText());
        //
        assertEquals(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL, fieldDeclarations[0].getModifiers());
        //
        assertTrue(fieldDeclarations[0].getType().isSimpleType());
        assertEquals("String", ((SimpleType) fieldDeclarations[0].getType()).getName().getFullyQualifiedName());
        //
        assertEquals(1, fieldDeclarations[0].fragments().size());
        @SuppressWarnings("unchecked")
        VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[0]
                .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[0].fragments().size()]);
        assertEquals(0, variableDeclarationFragments[0].getExtraDimensions());
        assertEquals("STR_CONST", variableDeclarationFragments[0].getName().getFullyQualifiedName());
        //
        assertNotNull(variableDeclarationFragments[0].getInitializer());
        assertTrue(variableDeclarationFragments[0].getInitializer().getClass().getName(),
                variableDeclarationFragments[0].getInitializer() instanceof InfixExpression);
        InfixExpression infixExpression = (InfixExpression) variableDeclarationFragments[0].getInitializer();
        assertTrue(infixExpression.getLeftOperand() instanceof StringLiteral);
        assertEquals("something is ; different \"//; /*;*/",
                ((StringLiteral) infixExpression.getLeftOperand()).getLiteralValue());
        assertTrue(infixExpression.getRightOperand() instanceof StringLiteral);
        assertEquals(" !!;;", ((StringLiteral) infixExpression.getRightOperand()).getLiteralValue());
        assertEquals("+", infixExpression.getOperator().toString());
    }
    //fieldDeclarations[1]: protected static long longStatic = 1l
    {
        Javadoc javadoc = fieldDeclarations[1].getJavadoc();
        assertEquals(1, javadoc.tags().size());
        assertEquals(2, ((TagElement) javadoc.tags().get(0)).fragments().size());
        assertEquals("protected static long field.",
                ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText());
        assertEquals("This is a multiline comment.",
                ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(1)).getText());
        //
        assertEquals(Modifier.PROTECTED | Modifier.STATIC, fieldDeclarations[1].getModifiers());
        //
        assertTrue(fieldDeclarations[1].getType().isPrimitiveType());
        assertEquals(PrimitiveType.LONG,
                ((PrimitiveType) fieldDeclarations[1].getType()).getPrimitiveTypeCode());
        //
        assertEquals(1, fieldDeclarations[1].fragments().size());
        @SuppressWarnings("unchecked")
        VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[1]
                .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[1].fragments().size()]);
        assertEquals(0, variableDeclarationFragments[0].getExtraDimensions());
        assertEquals("longStatic", variableDeclarationFragments[0].getName().getFullyQualifiedName());
        //
        assertNotNull(variableDeclarationFragments[0].getInitializer());
        assertTrue(variableDeclarationFragments[0].getInitializer() instanceof NumberLiteral);
        assertEquals("1l", ((NumberLiteral) variableDeclarationFragments[0].getInitializer()).getToken());
    }
    //fieldDeclarations[2]: Boolean booleanInstance
    {
        assertNull(fieldDeclarations[2].getJavadoc());
        //
        assertEquals(0, fieldDeclarations[2].getModifiers());
        //
        assertTrue(fieldDeclarations[2].getType().isSimpleType());
        assertEquals("Boolean",
                ((SimpleType) fieldDeclarations[2].getType()).getName().getFullyQualifiedName());
        //
        assertEquals(1, fieldDeclarations[2].fragments().size());
        @SuppressWarnings("unchecked")
        VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[2]
                .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[2].fragments().size()]);
        assertEquals(0, variableDeclarationFragments[0].getExtraDimensions());
        assertEquals("booleanInstance", variableDeclarationFragments[0].getName().getFullyQualifiedName());
        //
        assertNull(variableDeclarationFragments[0].getInitializer());
    }
    //fieldDeclarations[3]: private Map.Entry myEntry
    {
        assertNull(fieldDeclarations[3].getJavadoc());
        //
        assertEquals(Modifier.PRIVATE, fieldDeclarations[3].getModifiers());
        //
        assertTrue(fieldDeclarations[3].getType().isSimpleType());
        assertEquals("Map.Entry",
                ((SimpleType) fieldDeclarations[3].getType()).getName().getFullyQualifiedName());
        //
        assertEquals(1, fieldDeclarations[3].fragments().size());
        @SuppressWarnings("unchecked")
        VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[3]
                .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[3].fragments().size()]);
        assertEquals(0, variableDeclarationFragments[0].getExtraDimensions());
        assertEquals("myEntry", variableDeclarationFragments[0].getName().getFullyQualifiedName());
        //
        assertNull(variableDeclarationFragments[0].getInitializer());
    }
    //fieldDeclarations[4]: private int[][] myMatrix = new int[4][5]
    {
        assertNull(fieldDeclarations[4].getJavadoc());
        //
        assertEquals(Modifier.PRIVATE, fieldDeclarations[4].getModifiers());
        //
        assertTrue(fieldDeclarations[4].getType().isArrayType());
        assertEquals(2, ((ArrayType) fieldDeclarations[4].getType()).getDimensions());
        assertTrue(((ArrayType) fieldDeclarations[4].getType()).getElementType().isPrimitiveType());
        assertEquals(PrimitiveType.INT,
                ((PrimitiveType) ((ArrayType) fieldDeclarations[4].getType()).getElementType())
                        .getPrimitiveTypeCode());
        //
        assertEquals(1, fieldDeclarations[4].fragments().size());
        @SuppressWarnings("unchecked")
        VariableDeclarationFragment[] variableDeclarationFragments = (VariableDeclarationFragment[]) fieldDeclarations[4]
                .fragments().toArray(new VariableDeclarationFragment[fieldDeclarations[4].fragments().size()]);
        assertEquals(0, variableDeclarationFragments[0].getExtraDimensions());
        assertEquals("myMatrix", variableDeclarationFragments[0].getName().getFullyQualifiedName());
        //
        assertNotNull(variableDeclarationFragments[0].getInitializer());
        assertTrue(variableDeclarationFragments[0].getInitializer() instanceof ArrayCreation);
        ArrayCreation arrayCreation = (ArrayCreation) variableDeclarationFragments[0].getInitializer();
        assertEquals(2, arrayCreation.dimensions().size());
        assertEquals("4", ((NumberLiteral) arrayCreation.dimensions().get(0)).getToken());
        assertEquals("5", ((NumberLiteral) arrayCreation.dimensions().get(1)).getToken());
    }

    //** Methods
    MethodDeclaration[] methodDeclarations = exampleClass.getMethods();
    //methodDeclarations[0]: public Example1()
    {
        Javadoc javadoc = methodDeclarations[0].getJavadoc();
        assertEquals(1, javadoc.tags().size());
        assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size());
        assertEquals("This is a contructor",
                ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText());
        //
        assertTrue(methodDeclarations[0].isConstructor());
        //
        assertEquals(Modifier.PUBLIC, methodDeclarations[0].getModifiers());
        //
        assertNull(methodDeclarations[0].getReturnType2());
        //
        assertEquals("Example1", methodDeclarations[0].getName().getFullyQualifiedName());
        //
        assertTrue(methodDeclarations[0].parameters().isEmpty());
        //
        assertNotNull(methodDeclarations[0].getBody());
        assertEquals(1, methodDeclarations[0].getBody().statements().size());
        Statement statement = (Statement) methodDeclarations[0].getBody().statements().get(0);
        assertEquals(ASTNode.SUPER_CONSTRUCTOR_INVOCATION, statement.getNodeType());
        assertTrue(((SuperConstructorInvocation) statement).arguments().isEmpty());
    }
    //methodDeclarations[2]: public void setBooleanInstance(Boolean b)
    {
        Javadoc javadoc = methodDeclarations[2].getJavadoc();
        assertEquals(3, javadoc.tags().size());
        assertNull(((TagElement) javadoc.tags().get(0)).getTagName());
        assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size());
        assertEquals("Sets the boolean instance.",
                ((TextElement) ((TagElement) javadoc.tags().get(0)).fragments().get(0)).getText());
        assertEquals("@param", ((TagElement) javadoc.tags().get(1)).getTagName());
        assertEquals(1, ((TagElement) javadoc.tags().get(0)).fragments().size());
        assertEquals("b",
                ((SimpleName) ((TagElement) javadoc.tags().get(1)).fragments().get(0)).getFullyQualifiedName());
        assertEquals("@generated", ((TagElement) javadoc.tags().get(2)).getTagName());
        assertTrue(((TagElement) javadoc.tags().get(2)).fragments().isEmpty());
        //
        assertFalse(methodDeclarations[2].isConstructor());
        //
        assertEquals(Modifier.PUBLIC, methodDeclarations[2].getModifiers());
        //
        assertNotNull(methodDeclarations[2].getReturnType2());
        assertTrue(methodDeclarations[2].getReturnType2().isPrimitiveType());
        assertEquals(PrimitiveType.VOID,
                ((PrimitiveType) methodDeclarations[2].getReturnType2()).getPrimitiveTypeCode());
        //
        assertEquals("setBooleanInstance", methodDeclarations[2].getName().getFullyQualifiedName());
        //
        assertEquals(1, methodDeclarations[2].parameters().size());
        assertTrue(((SingleVariableDeclaration) methodDeclarations[2].parameters().get(0)).getType()
                .isSimpleType());
        assertEquals("Boolean",
                ((SimpleType) ((SingleVariableDeclaration) methodDeclarations[2].parameters().get(0)).getType())
                        .getName().getFullyQualifiedName());
        assertEquals("b", ((SingleVariableDeclaration) methodDeclarations[2].parameters().get(0)).getName()
                .getFullyQualifiedName());
        //
        assertNotNull(methodDeclarations[2].getBody());
        assertEquals(1, methodDeclarations[2].getBody().statements().size());
    }
}