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

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

Introduction

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

Prototype

public final void setSourceRange(int startPosition, int length) 

Source Link

Document

Sets the source range of the original source file where the source fragment corresponding to this node was found.

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 {//from   ww  w  .  j  a  v  a 2 s.  c o m
        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;
}