Example usage for org.eclipse.jdt.core.dom Initializer getJavadoc

List of usage examples for org.eclipse.jdt.core.dom Initializer getJavadoc

Introduction

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

Prototype

public Javadoc getJavadoc() 

Source Link

Document

Returns the doc comment node.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(Initializer node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }//from   www .  j a va  2s.c  om
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
    }
    node.getBody().accept(this);
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(Initializer node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }/* www.  jav  a  2s.  co m*/
    if (node.getAST().apiLevel() >= AST.JLS3) {
        printModifiers(node.modifiers());
    }
    node.getBody().accept(this);
    return false;
}

From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes:// www.  j a  va 2  s. c o  m
 * <ul>
 *   <li>Initializer entity to <code>IEntityWriter</code>
 *   <ul>
 *     <li>Inside relation to <code>IRelationWriter</code></li>
 *   </ul></li>
 * </ul>
 * 
 * Enum constant fully qualified names (FQNs) adhere to the following format:<br> 
 * parent fqn + . + simple name
 */
@Override
public boolean visit(Initializer node) {
    // Get the fqn
    String fqn = fqnStack.peek(EnclosingDeclaredType.class).getInitializerFqn();

    String parentFqn = fqnStack.getFqn();

    // Visit the children
    fqnStack.push(fqn, Entity.INITIALIZER);
    accept(node.getJavadoc());
    accept(node.modifiers());
    accept(node.getBody());

    // Write the entity
    entityWriter.writeEntity(Entity.INITIALIZER, fqn, node.getModifiers(), createMetrics(node),
            createLocation(node));

    // Write the contains relation
    relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, createUnknownLocation());

    fqnStack.pop();

    return false;
}

From source file:net.sf.j2s.core.astvisitors.ASTJ2SDocVisitor.java

License:Open Source License

public boolean visit(Block node) {
    blockLevel++;/*  w  w w  .j  a  v  a 2s. co  m*/
    buffer.append("{\r\n");
    ASTNode parent = node.getParent();
    if (parent instanceof MethodDeclaration) {
        MethodDeclaration method = (MethodDeclaration) parent;
        Javadoc javadoc = method.getJavadoc();
        /*
         * if comment contains "@j2sNative", then output the given native 
         * JavaScript codes directly. 
         */
        if (visitNativeJavadoc(javadoc, node, true) == false) {
            return false;
        }
        IMethodBinding methodBinding = method.resolveBinding();
        if (methodBinding != null) {
            ITypeBinding superclass = methodBinding.getDeclaringClass().getSuperclass();
            boolean containsSuperPrivateMethod = false;
            while (superclass != null) {
                IMethodBinding[] methods = superclass.getDeclaredMethods();
                for (int i = 0; i < methods.length; i++) {
                    if (methods[i].getName().equals(methodBinding.getName())
                            && (methods[i].getModifiers() & Modifier.PRIVATE) != 0) {
                        containsSuperPrivateMethod = true;
                        break;
                    }
                }
                if (containsSuperPrivateMethod) {
                    break;
                }
                superclass = superclass.getSuperclass();
            }
            if (containsSuperPrivateMethod) {
                buffer.append("var $private = Clazz.checkPrivateMethod (arguments);\r\n");
                buffer.append("if ($private != null) {\r\n");
                buffer.append("return $private.apply (this, arguments);\r\n");
                buffer.append("}\r\n");
            }
        }
    } else if (parent instanceof Initializer) {
        Initializer initializer = (Initializer) parent;
        Javadoc javadoc = initializer.getJavadoc();
        /*
         * if comment contains "@j2sNative", then output the given native 
         * JavaScript codes directly. 
         */
        if (visitNativeJavadoc(javadoc, node, true) == false) {
            return false;
        }
    }
    int blockStart = node.getStartPosition();
    int previousStart = getPreviousStartPosition(node);
    ASTNode root = node.getRoot();
    checkJavadocs(root);
    //for (int i = 0; i < nativeJavadoc.length; i++) {
    for (int i = nativeJavadoc.length - 1; i >= 0; i--) {
        Javadoc javadoc = nativeJavadoc[i];
        int commentStart = javadoc.getStartPosition();
        if (commentStart > previousStart && commentStart < blockStart) {
            /*
             * if the block's leading comment contains "@j2sNative", 
             * then output the given native JavaScript codes directly. 
             */
            if (visitNativeJavadoc(javadoc, node, true) == false) {
                return false;
            }
        }
    }
    return super.visit(node);
}

From source file:net.sf.j2s.core.astvisitors.DependencyASTVisitor.java

License:Open Source License

public boolean visit(Block node) {
    ASTNode parent = node.getParent();//  w w  w .j a  v a2s.c  om
    if (parent instanceof MethodDeclaration) {
        MethodDeclaration method = (MethodDeclaration) parent;
        Javadoc javadoc = method.getJavadoc();
        /*
         * if comment contains "@j2sNative", then output the given native 
         * JavaScript codes directly. 
         */
        if (visitNativeJavadoc(javadoc, node, true) == false) {
            return false;
        }
    } else if (parent instanceof Initializer) {
        Initializer initializer = (Initializer) parent;
        Javadoc javadoc = initializer.getJavadoc();
        /*
         * if comment contains "@j2sNative", then output the given native 
         * JavaScript codes directly. 
         */
        if (visitNativeJavadoc(javadoc, node, true) == false) {
            return false;
        }
    }
    int blockStart = node.getStartPosition();
    int previousStart = getPreviousStartPosition(node);
    ASTNode root = node.getRoot();
    checkJavadocs(root);
    //for (int i = 0; i < nativeJavadoc.length; i++) {
    for (int i = nativeJavadoc.length - 1; i >= 0; i--) {
        Javadoc javadoc = nativeJavadoc[i];
        int commentStart = javadoc.getStartPosition();
        if (commentStart > previousStart && commentStart < blockStart) {
            /*
             * if the block's leading comment contains "@j2sNative", 
             * then output the given native JavaScript codes directly. 
             */
            if (visitNativeJavadoc(javadoc, node, true) == false) {
                return false;
            }
        }
    }
    return super.visit(node);
}

From source file:org.codemucker.jmutate.ast.JAstFlattener.java

License:Open Source License

public boolean visit(Initializer node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }//from   w w w.  j  ava  2 s.c o  m
    if (node.getAST().apiLevel() == JLS2) {
        printModifiers(node.getModifiers());
    }
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
    }
    node.getBody().accept(this);
    return false;
}

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  ww.  ja v  a  2s .c om*/
        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());
    }
}

From source file:org.eclipse.xtend.core.javaconverter.JavaASTFlattener.java

License:Open Source License

@Override
public boolean visit(final Initializer it) {
    Javadoc _javadoc = it.getJavadoc();
    boolean _tripleNotEquals = (_javadoc != null);
    if (_tripleNotEquals) {
        it.getJavadoc().accept(this);
    }//from  ww w.j a va  2s  .co m
    this.appendModifiers(it, it.modifiers());
    boolean _isStatic = this._aSTFlattenerUtils.isStatic(it.modifiers());
    if (_isStatic) {
        if (((it.getParent() instanceof TypeDeclaration)
                && IterableExtensions.<FieldDeclaration>forall(IterableExtensions.<FieldDeclaration>filter(
                        ((Iterable<FieldDeclaration>) Conversions
                                .doWrapArray(((TypeDeclaration) it.getParent()).getFields())),
                        ((Function1<FieldDeclaration, Boolean>) (FieldDeclaration it_1) -> {
                            return Boolean.valueOf((this._aSTFlattenerUtils.isStatic(it_1.modifiers())
                                    && this._aSTFlattenerUtils.isFinal(it_1.modifiers())));
                        })), ((Function1<FieldDeclaration, Boolean>) (FieldDeclaration f) -> {
                            final Function1<VariableDeclarationFragment, Boolean> _function = (
                                    VariableDeclarationFragment fragment) -> {
                                Boolean _isAssignedInBody = this._aSTFlattenerUtils
                                        .isAssignedInBody(it.getBody(), fragment);
                                return Boolean.valueOf((!(_isAssignedInBody).booleanValue()));
                            };
                            return Boolean.valueOf(IterableExtensions
                                    .<VariableDeclarationFragment>forall(f.fragments(), _function));
                        })))) {
            this.appendToBuffer(" final Void static_initializer = {");
            this.appendLineWrapToBuffer();
            it.getBody().accept(this);
            this.appendToBuffer("null }");
            this.appendLineWrapToBuffer();
        } else {
            this.addProblem(it, "Static initializer is not fully supported");
            this.appendToBuffer("{/*FIXME ");
            it.getBody().accept(this);
            this.appendToBuffer("*/}");
        }
    } else {
        ASTNode _parent = it.getParent();
        if ((_parent instanceof AnonymousClassDeclaration)) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("Initializer is not supported in ");
            String _simpleName = ASTNode.nodeClassForType(it.getParent().getNodeType()).getSimpleName();
            _builder.append(_simpleName);
            this.addProblem(it, _builder.toString());
        }
        it.getBody().accept(this);
    }
    return false;
}

From source file:org.whole.lang.java.util.JDTTransformerVisitor.java

License:Open Source License

@Override
public boolean visit(Initializer node) {
    org.whole.lang.java.model.Initializer initializer;
    appendBodyDeclaration(initializer = lf.create(JavaEntityDescriptorEnum.Initializer));

    if (acceptChild(node.getJavadoc()))
        initializer.setJavadoc(this.javadoc);

    List<?> modifiers = node.modifiers();
    if (!modifiers.isEmpty()) {
        initializer.setModifiers(lf.create(JavaEntityDescriptorEnum.ExtendedModifiers));
        setExtendedModifiers(initializer.getModifiers(), modifiers);
    }/*  w w w .j av  a 2  s  .c  om*/

    acceptChild(node.getBody());
    initializer.setBody((org.whole.lang.java.model.Block) stm);

    return false;
}

From source file:ptolemy.backtrack.eclipse.ast.ASTFormatter.java

License:Open Source License

/** Visit an ast node, and return whether its children should be further
 *  visited.//www. j  a va 2s. c  o m
 *
 *  @param node The AST node.
 *  @return Whether its children should be further visited.
 */
public boolean visit(Initializer node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }

    _outputModifiers(node.modifiers());

    _output(_indent);
    node.getBody().accept(this);
    _output("\n");
    return false;
}