Example usage for org.eclipse.jdt.core.dom PackageDeclaration PackageDeclaration

List of usage examples for org.eclipse.jdt.core.dom PackageDeclaration PackageDeclaration

Introduction

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

Prototype

PackageDeclaration(AST ast) 

Source Link

Document

Creates a new AST node for a package declaration owned by the given AST.

Usage

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

License:Open Source License

public PackageDeclaration convertPackage(
        org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration compilationUnitDeclaration) {
    org.eclipse.jdt.internal.compiler.ast.ImportReference importReference = compilationUnitDeclaration.currentPackage;
    final PackageDeclaration packageDeclaration = new PackageDeclaration(this.ast);
    final char[][] tokens = importReference.tokens;
    final int length = importReference.tokens.length;
    long[] positions = importReference.sourcePositions;
    if (length > 1) {
        packageDeclaration.setName(setQualifiedNameNameAndSourceRanges(tokens, positions, importReference));
    } else {/*  w  ww.  j a  v a2s. c om*/
        final SimpleName name = new SimpleName(this.ast);
        name.internalSetIdentifier(new String(tokens[0]));
        int start = (int) (positions[0] >>> 32);
        int end = (int) (positions[length - 1] & 0xFFFFFFFF);
        name.setSourceRange(start, end - start + 1);
        name.index = 1;
        packageDeclaration.setName(name);
        if (this.resolveBindings) {
            recordNodes(name, compilationUnitDeclaration);
        }
    }
    packageDeclaration.setSourceRange(importReference.declarationSourceStart,
            importReference.declarationEnd - importReference.declarationSourceStart + 1);
    org.eclipse.jdt.internal.compiler.ast.Annotation[] annotations = importReference.annotations;
    if (annotations != null) {
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            packageDeclaration.setFlags(packageDeclaration.getFlags() & ASTNode.MALFORMED);
            break;
        default:
            for (int i = 0, max = annotations.length; i < max; i++) {
                packageDeclaration.annotations().add(convert(annotations[i]));
            }
        }
    }
    if (this.resolveBindings) {
        recordNodes(packageDeclaration, importReference);
    }
    // Set javadoc
    convert(compilationUnitDeclaration.javadoc, packageDeclaration);
    return packageDeclaration;
}