Example usage for org.eclipse.jdt.internal.compiler.ast AbstractMethodDeclaration isDefaultConstructor

List of usage examples for org.eclipse.jdt.internal.compiler.ast AbstractMethodDeclaration isDefaultConstructor

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast AbstractMethodDeclaration isDefaultConstructor.

Prototype

public boolean isDefaultConstructor() 

Source Link

Usage

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration enumDeclaration2,
        EnumDeclaration enumDeclaration) {
    // add body declaration in the lexical order
    org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = enumDeclaration2.memberTypes;
    org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = enumDeclaration2.fields;
    org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration[] methods = enumDeclaration2.methods;

    int fieldsLength = fields == null ? 0 : fields.length;
    int methodsLength = methods == null ? 0 : methods.length;
    int membersLength = members == null ? 0 : members.length;
    int fieldsIndex = 0;
    int methodsIndex = 0;
    int membersIndex = 0;

    while ((fieldsIndex < fieldsLength) || (membersIndex < membersLength) || (methodsIndex < methodsLength)) {
        org.eclipse.jdt.internal.compiler.ast.FieldDeclaration nextFieldDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration nextMethodDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = null;

        int position = Integer.MAX_VALUE;
        int nextDeclarationType = -1;
        if (fieldsIndex < fieldsLength) {
            nextFieldDeclaration = fields[fieldsIndex];
            if (nextFieldDeclaration.declarationSourceStart < position) {
                position = nextFieldDeclaration.declarationSourceStart;
                nextDeclarationType = 0; // FIELD
            }/*w ww  .j  a v a2 s  .  com*/
        }
        if (methodsIndex < methodsLength) {
            nextMethodDeclaration = methods[methodsIndex];
            if (nextMethodDeclaration.declarationSourceStart < position) {
                position = nextMethodDeclaration.declarationSourceStart;
                nextDeclarationType = 1; // METHOD
            }
        }
        if (membersIndex < membersLength) {
            nextMemberDeclaration = members[membersIndex];
            if (nextMemberDeclaration.declarationSourceStart < position) {
                position = nextMemberDeclaration.declarationSourceStart;
                nextDeclarationType = 2; // MEMBER
            }
        }
        switch (nextDeclarationType) {
        case 0:
            if (nextFieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                enumDeclaration.enumConstants().add(convert(nextFieldDeclaration));
            } else {
                checkAndAddMultipleFieldDeclaration(fields, fieldsIndex, enumDeclaration.bodyDeclarations());
            }
            fieldsIndex++;
            break;
        case 1:
            methodsIndex++;
            if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
                enumDeclaration.bodyDeclarations().add(convert(false, nextMethodDeclaration));
            }
            break;
        case 2:
            membersIndex++;
            enumDeclaration.bodyDeclarations().add(convert(nextMemberDeclaration));
            break;
        }
    }
    convert(enumDeclaration2.javadoc, enumDeclaration);
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration expression,
        AnonymousClassDeclaration anonymousClassDeclaration) {
    // add body declaration in the lexical order
    org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = expression.memberTypes;
    org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = expression.fields;
    org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration[] methods = expression.methods;

    int fieldsLength = fields == null ? 0 : fields.length;
    int methodsLength = methods == null ? 0 : methods.length;
    int membersLength = members == null ? 0 : members.length;
    int fieldsIndex = 0;
    int methodsIndex = 0;
    int membersIndex = 0;

    while ((fieldsIndex < fieldsLength) || (membersIndex < membersLength) || (methodsIndex < methodsLength)) {
        org.eclipse.jdt.internal.compiler.ast.FieldDeclaration nextFieldDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration nextMethodDeclaration = null;
        org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = null;

        int position = Integer.MAX_VALUE;
        int nextDeclarationType = -1;
        if (fieldsIndex < fieldsLength) {
            nextFieldDeclaration = fields[fieldsIndex];
            if (nextFieldDeclaration.declarationSourceStart < position) {
                position = nextFieldDeclaration.declarationSourceStart;
                nextDeclarationType = 0; // FIELD
            }/*  w ww .  j  a va 2 s. c o m*/
        }
        if (methodsIndex < methodsLength) {
            nextMethodDeclaration = methods[methodsIndex];
            if (nextMethodDeclaration.declarationSourceStart < position) {
                position = nextMethodDeclaration.declarationSourceStart;
                nextDeclarationType = 1; // METHOD
            }
        }
        if (membersIndex < membersLength) {
            nextMemberDeclaration = members[membersIndex];
            if (nextMemberDeclaration.declarationSourceStart < position) {
                position = nextMemberDeclaration.declarationSourceStart;
                nextDeclarationType = 2; // MEMBER
            }
        }
        switch (nextDeclarationType) {
        case 0:
            if (nextFieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                anonymousClassDeclaration.bodyDeclarations().add(convert(nextFieldDeclaration));
            } else {
                checkAndAddMultipleFieldDeclaration(fields, fieldsIndex,
                        anonymousClassDeclaration.bodyDeclarations());
            }
            fieldsIndex++;
            break;
        case 1:
            methodsIndex++;
            if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
                anonymousClassDeclaration.bodyDeclarations().add(convert(false, nextMethodDeclaration));
            }
            break;
        case 2:
            membersIndex++;
            ASTNode node = convert(nextMemberDeclaration);
            if (node == null) {
                anonymousClassDeclaration.setFlags(anonymousClassDeclaration.getFlags() | ASTNode.MALFORMED);
            } else {
                anonymousClassDeclaration.bodyDeclarations().add(node);
            }
        }
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public TypeDeclaration convert(org.eclipse.jdt.internal.compiler.ast.ASTNode[] nodes) {
    final TypeDeclaration typeDecl = new TypeDeclaration(this.ast);
    typeDecl.setInterface(false);/*w  w  w.j a  va2s  .  c  o  m*/
    int nodesLength = nodes.length;
    for (int i = 0; i < nodesLength; i++) {
        org.eclipse.jdt.internal.compiler.ast.ASTNode node = nodes[i];
        if (node instanceof org.eclipse.jdt.internal.compiler.ast.Initializer) {
            org.eclipse.jdt.internal.compiler.ast.Initializer oldInitializer = (org.eclipse.jdt.internal.compiler.ast.Initializer) node;
            Initializer initializer = new Initializer(this.ast);
            initializer.setBody(convert(oldInitializer.block));
            setModifiers(initializer, oldInitializer);
            initializer.setSourceRange(oldInitializer.declarationSourceStart,
                    oldInitializer.sourceEnd - oldInitializer.declarationSourceStart + 1);
            //            setJavaDocComment(initializer);
            //            initializer.setJavadoc(convert(oldInitializer.javadoc));
            convert(oldInitializer.javadoc, initializer);
            typeDecl.bodyDeclarations().add(initializer);
        } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
            org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
            if (i > 0 && (nodes[i - 1] instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration)
                    && ((org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) nodes[i
                            - 1]).declarationSourceStart == fieldDeclaration.declarationSourceStart) {
                // we have a multiple field declaration
                // We retrieve the existing fieldDeclaration to add the new VariableDeclarationFragment
                FieldDeclaration currentFieldDeclaration = (FieldDeclaration) typeDecl.bodyDeclarations()
                        .get(typeDecl.bodyDeclarations().size() - 1);
                currentFieldDeclaration.fragments().add(convertToVariableDeclarationFragment(fieldDeclaration));
            } else {
                // we can create a new FieldDeclaration
                typeDecl.bodyDeclarations().add(convertToFieldDeclaration(fieldDeclaration));
            }
        } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) {
            AbstractMethodDeclaration nextMethodDeclaration = (AbstractMethodDeclaration) node;
            if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
                typeDecl.bodyDeclarations().add(convert(false, nextMethodDeclaration));
            }
        } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
            ASTNode nextMemberDeclarationNode = convert(nextMemberDeclaration);
            if (nextMemberDeclarationNode == null) {
                typeDecl.setFlags(typeDecl.getFlags() | ASTNode.MALFORMED);
            } else {
                typeDecl.bodyDeclarations().add(nextMemberDeclarationNode);
            }
        }
    }
    return typeDecl;
}