Example usage for org.eclipse.jdt.core.dom CompilationUnit PACKAGE_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom CompilationUnit PACKAGE_PROPERTY

Introduction

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

Prototype

ChildPropertyDescriptor PACKAGE_PROPERTY

To view the source code for org.eclipse.jdt.core.dom CompilationUnit PACKAGE_PROPERTY.

Click Source Link

Document

The "package" structural property of this node type (child type: PackageDeclaration ).

Usage

From source file:de.ovgu.cide.language.jdt.SimplePrintVisitor.java

License:Open Source License

public boolean visit(IASTNode node) {
    if (node instanceof ASTStringNode) {
        printToken(((ASTStringNode) node).getValue());
        return false;
    }//  w  w  w  . java2  s. c  o m
    if (node instanceof ASTTextNode) {
        printToken(((ASTTextNode) node).getValue());
        return false;
    }
    if (node instanceof UnifiedASTNode) {
        UnifiedASTNode unode = (UnifiedASTNode) node;

        if (unode.getEclipseASTNodeClass().equals("AnnotationTypeDeclaration")) {

            accept(node, AnnotationTypeDeclaration.JAVADOC_PROPERTY.getId());

        }

        if (unode.getEclipseASTNodeClass().equals(CompilationUnit.class.getSimpleName())) {
            accept(unode, CompilationUnit.PACKAGE_PROPERTY.getId());
            accept(unode, CompilationUnit.IMPORTS_PROPERTY.getId());
            accept(unode, CompilationUnit.TYPES_PROPERTY.getId());
        }

        if (unode.getEclipseASTNodeClass().equals(TypeDeclaration.class.getSimpleName())) {

            accept(node, TypeDeclaration.JAVADOC_PROPERTY.getId());
            accept(node, TypeDeclaration.MODIFIERS2_PROPERTY.getId());
            accept(node, TypeDeclaration.INTERFACE_PROPERTY.getId());
            accept(node, TypeDeclaration.NAME_PROPERTY.getId());
            accept(node, TypeDeclaration.TYPE_PARAMETERS_PROPERTY.getId(), "<", ",", ">", true);
            //            this.buffer.append(" ");//$NON-NLS-1$

            accept(node, TypeDeclaration.SUPERCLASS_TYPE_PROPERTY.getId(), "extends", "", "", false);
            accept(node, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY.getId(), "implements", ",", "", false);
            printToken("{");
            hintNewLine();
            hintIncIndent();

            accept(node, TypeDeclaration.BODY_DECLARATIONS_PROPERTY.getId());

            hintDecIndent();
            printToken("}");
            hintNewLine();
        }

        printToken(unode.getEclipseASTNodeClass());
    }
    return false;
}

From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJCompilationUnit.java

License:Open Source License

@Override
public boolean addChild(ASTJNode<?> child) {
    if (child.getParent() != null) {
        return false;
    }/*w w w.j  a v a 2  s.  c o  m*/

    if (child instanceof ASTJImport) {
        insertLast(child, CompilationUnit.IMPORTS_PROPERTY);
    } else if (child instanceof ASTJAbstractType<?>) {
        insertLast(child, CompilationUnit.TYPES_PROPERTY);
    } else if (child instanceof ASTJPackage) {
        setNodeProperty(getASTNode(), child.getASTNode(), CompilationUnit.PACKAGE_PROPERTY);
    } else {
        return false;
    }
    child.setParent(this);
    return true;
}

From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJCompilationUnit.java

License:Open Source License

@Override
public boolean insertSibling(ASTJNode<?> node, ASTJNode<?> newSibling, boolean before) {
    if (newSibling.getParent() != null) {
        return false;
    }//from  w w  w .j ava  2 s .c  om

    if (newSibling instanceof ASTJImport) {
        if (node instanceof ASTJImport) {
            insert(newSibling, CompilationUnit.IMPORTS_PROPERTY, node, before);
        } else if (node instanceof ASTJPackage) {
            insertFirst(newSibling, CompilationUnit.IMPORTS_PROPERTY);
        } else if (node instanceof ASTJAbstractType<?>) {
            insertLast(newSibling, CompilationUnit.IMPORTS_PROPERTY);
        } else {
            return false;
        }
    } else if (newSibling instanceof ASTJAbstractType<?>) {
        if (node instanceof ASTJAbstractType<?>) {
            insert(newSibling, CompilationUnit.TYPES_PROPERTY, node, before);
        } else if (node instanceof ASTJImport) {
            insertFirst(newSibling, CompilationUnit.TYPES_PROPERTY);
        } else if (node instanceof ASTJPackage) {
            insertFirst(newSibling, CompilationUnit.TYPES_PROPERTY);
        } else {
            return false;
        }
    } else if (newSibling instanceof ASTJPackage) {
        setNodeProperty(getASTNode(), newSibling.getASTNode(), CompilationUnit.PACKAGE_PROPERTY);
    } else {
        return false;
    }
    newSibling.setParent(this);
    return true;
}

From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJCompilationUnit.java

License:Open Source License

/**
 * Removes the given node./*from w w w.  jav a  2 s  . com*/
 * <p>
 * This implementation will not perform moving of the node if the node is inserted after being removed.
 * Hence, the removed node must not be inserted again.
 * 
 * @see org.eclipse.emf.codegen.merge.java.facade.ast.ASTJNode#remove(ASTJNode)
 */
@Override
public boolean remove(ASTJNode<?> node) {
    if (node.getParent() != this) {
        return false;
    }

    if (node instanceof ASTJImport) {
        remove(node, CompilationUnit.IMPORTS_PROPERTY);
    } else if (node instanceof ASTJAbstractType<?>) {
        remove(node, CompilationUnit.TYPES_PROPERTY);
    } else if (node instanceof ASTJPackage) {
        setNodeProperty(getASTNode(), null, CompilationUnit.PACKAGE_PROPERTY);
    } else {
        return false;
    }
    node.setParent(null);
    return true;
}

From source file:org.eclipse.jdt.internal.core.CopyResourceElementsOperation.java

License:Open Source License

private void updatePackageStatement(CompilationUnit astCU, String[] pkgName, ASTRewrite rewriter,
        ICompilationUnit cu) throws JavaModelException {
    boolean defaultPackage = pkgName.length == 0;
    AST ast = astCU.getAST();//from w  w w.j a  v a 2s .  c om
    if (defaultPackage) {
        // remove existing package statement
        PackageDeclaration pkg = astCU.getPackage();
        if (pkg != null) {
            int pkgStart;
            Javadoc javadoc = pkg.getJavadoc();
            if (javadoc != null) {
                pkgStart = javadoc.getStartPosition() + javadoc.getLength() + 1;
            } else {
                pkgStart = pkg.getStartPosition();
            }
            int extendedStart = astCU.getExtendedStartPosition(pkg);
            if (pkgStart != extendedStart) {
                // keep the comments associated with package declaration
                // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=247757
                String commentSource = cu.getSource().substring(extendedStart, pkgStart);
                ASTNode comment = rewriter.createStringPlaceholder(commentSource, ASTNode.PACKAGE_DECLARATION);
                rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, comment, null);
            } else {
                rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, null, null);
            }
        }
    } else {
        org.eclipse.jdt.core.dom.PackageDeclaration pkg = astCU.getPackage();
        if (pkg != null) {
            // rename package statement
            Name name = ast.newName(pkgName);
            rewriter.set(pkg, PackageDeclaration.NAME_PROPERTY, name, null);
        } else {
            // create new package statement
            pkg = ast.newPackageDeclaration();
            pkg.setName(ast.newName(pkgName));
            rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, pkg, null);
        }
    }
}

From source file:org.gw4e.eclipse.facade.JDTManager.java

License:Open Source License

/**
 * @param cu/* w ww  .j av a 2 s .  c  o m*/
 * @param rewrite
 * @param ast
 * @param pkgDeclaration
 */
private static void addPackageDeclaration(CompilationUnit cu, ASTRewrite rewrite, AST ast,
        String[] pkgDeclaration) {
    PackageDeclaration packageDeclaration = ast.newPackageDeclaration();
    Name name = ast.newName(pkgDeclaration);
    packageDeclaration.setName(name);
    rewrite.set(cu, CompilationUnit.PACKAGE_PROPERTY, packageDeclaration, null);

}

From source file:org.moe.natjgen.AbstractUnitManager.java

License:Apache License

/**
 * Update package information/*from w w w.j a  v a  2 s . co  m*/
 */
protected final void updatePackage() {
    PackageDeclaration pkg_decl = (PackageDeclaration) getRewrite().get(getAstRoot(),
            CompilationUnit.PACKAGE_PROPERTY);
    if (pkg_decl == null) {
        pkg_decl = getAST().newPackageDeclaration();
        getRewrite().set(getAstRoot(), CompilationUnit.PACKAGE_PROPERTY, pkg_decl, getEditGroup());
    }

    String pkg_name_value = getPackage();
    Name pkg_name_decl = (Name) getRewrite().get(pkg_decl, PackageDeclaration.NAME_PROPERTY);
    if (pkg_name_decl == null || !pkg_name_decl.getFullyQualifiedName().equals(pkg_name_value)) {
        getRewrite().set(pkg_decl, PackageDeclaration.NAME_PROPERTY, getAST().newName(pkg_name_value),
                getEditGroup());
    }
}