Example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccDefault

List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccDefault

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccDefault.

Prototype

int AccDefault

To view the source code for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccDefault.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.compiler.parser.SourceTypeConverter.java

License:Open Source License

private CompilationUnitDeclaration convert(ISourceType[] sourceTypes, CompilationResult compilationResult)
        throws JavaModelException {
    this.unit = new CompilationUnitDeclaration(this.problemReporter, compilationResult, 0);
    // not filled at this point

    if (sourceTypes.length == 0)
        return this.unit;
    SourceTypeElementInfo topLevelTypeInfo = (SourceTypeElementInfo) sourceTypes[0];
    org.eclipse.jdt.core.ICompilationUnit cuHandle = topLevelTypeInfo.getHandle().getCompilationUnit();
    this.cu = (ICompilationUnit) cuHandle;

    final CompilationUnitElementInfo compilationUnitElementInfo = (CompilationUnitElementInfo) ((JavaElement) this.cu)
            .getElementInfo();// ww  w  .  j  a  va2 s .  c om
    if (this.has1_5Compliance
            && (compilationUnitElementInfo.annotationNumber >= CompilationUnitElementInfo.ANNOTATION_THRESHOLD_FOR_DIET_PARSE
                    || (compilationUnitElementInfo.hasFunctionalTypes && (this.flags & LOCAL_TYPE) != 0))) {
        // If more than 10 annotations, diet parse as this is faster, but not if
        // the client wants local and anonymous types to be converted (https://bugs.eclipse.org/bugs/show_bug.cgi?id=254738)
        // Also see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=405843
        if ((this.flags & LOCAL_TYPE) == 0) {
            return new Parser(this.problemReporter, true).dietParse(this.cu, compilationResult);
        } else {
            return new Parser(this.problemReporter, true).parse(this.cu, compilationResult);
        }
    }

    /* only positions available */
    int start = topLevelTypeInfo.getNameSourceStart();
    int end = topLevelTypeInfo.getNameSourceEnd();

    /* convert package and imports */
    String[] packageName = ((PackageFragment) cuHandle.getParent()).names;
    if (packageName.length > 0)
        // if its null then it is defined in the default package
        this.unit.currentPackage = createImportReference(packageName, start, end, false,
                ClassFileConstants.AccDefault);
    IImportDeclaration[] importDeclarations = topLevelTypeInfo.getHandle().getCompilationUnit().getImports();
    int importCount = importDeclarations.length;
    this.unit.imports = new ImportReference[importCount];
    for (int i = 0; i < importCount; i++) {
        ImportDeclaration importDeclaration = (ImportDeclaration) importDeclarations[i];
        ISourceImport sourceImport = (ISourceImport) importDeclaration.getElementInfo();
        String nameWithoutStar = importDeclaration.getNameWithoutStar();
        this.unit.imports[i] = createImportReference(
                Util.splitOn('.', nameWithoutStar, 0, nameWithoutStar.length()),
                sourceImport.getDeclarationSourceStart(), sourceImport.getDeclarationSourceEnd(),
                importDeclaration.isOnDemand(), sourceImport.getModifiers());
    }
    /* convert type(s) */
    try {
        int typeCount = sourceTypes.length;
        final TypeDeclaration[] types = new TypeDeclaration[typeCount];
        /*
         * We used a temporary types collection to prevent this.unit.types from being null during a call to
         * convert(...) when the source is syntactically incorrect and the parser is flushing the unit's types.
         * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97466
         */
        for (int i = 0; i < typeCount; i++) {
            SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) sourceTypes[i];
            types[i] = convert((SourceType) typeInfo.getHandle(), compilationResult);
        }
        this.unit.types = types;
        return this.unit;
    } catch (AnonymousMemberFound e) {
        return new Parser(this.problemReporter, true).parse(this.cu, compilationResult);
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.compiler.parser.SourceTypeConverter.java

License:Open Source License

private Initializer convert(InitializerElementInfo initializerInfo, CompilationResult compilationResult)
        throws JavaModelException {

    Block block = new Block(0);
    Initializer initializer = new Initializer(block, ClassFileConstants.AccDefault);

    int start = initializerInfo.getDeclarationSourceStart();
    int end = initializerInfo.getDeclarationSourceEnd();

    initializer.sourceStart = initializer.declarationSourceStart = start;
    initializer.sourceEnd = initializer.declarationSourceEnd = end;
    initializer.modifiers = initializerInfo.getModifiers();

    /* convert local and anonymous types */
    IJavaElement[] children = initializerInfo.getChildren();
    int typesLength = children.length;
    if (typesLength > 0) {
        Statement[] statements = new Statement[typesLength];
        for (int i = 0; i < typesLength; i++) {
            SourceType type = (SourceType) children[i];
            TypeDeclaration localType = convert(type, compilationResult);
            if ((localType.bits & ASTNode.IsAnonymousType) != 0) {
                QualifiedAllocationExpression expression = new QualifiedAllocationExpression(localType);
                expression.type = localType.superclass;
                localType.superclass = null;
                localType.superInterfaces = null;
                localType.allocation = expression;
                statements[i] = expression;
            } else {
                statements[i] = localType;
            }/*from   w  w  w  . j a  v a  2s .  c  o m*/
        }
        block.statements = statements;
    }

    return initializer;
}

From source file:com.codenvy.ide.ext.java.server.internal.compiler.parser.SourceTypeConverter.java

License:Open Source License

private AbstractMethodDeclaration convert(SourceMethod methodHandle, SourceMethodElementInfo methodInfo,
        CompilationResult compilationResult) throws JavaModelException {
    AbstractMethodDeclaration method;/*w ww  .j ava2 s.  c o m*/

    /* only source positions available */
    int start = methodInfo.getNameSourceStart();
    int end = methodInfo.getNameSourceEnd();

    /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, Even when this type is being constructed
       on behalf of a 1.4 project we must internalize type variables properly in order to be able to
       recognize usages of them in the method signature, to apply substitutions and thus to be able to
       detect overriding in the presence of generics. If we simply drop them, when the method signature
       refers to the type parameter, we won't know it should be bound to the type parameter and perform
       incorrect lookup and may mistakenly end up with missing types
     */
    TypeParameter[] typeParams = null;
    char[][] typeParameterNames = methodInfo.getTypeParameterNames();
    if (typeParameterNames != null) {
        int parameterCount = typeParameterNames.length;
        if (parameterCount > 0) { // method's type parameters must be null if no type parameter
            char[][][] typeParameterBounds = methodInfo.getTypeParameterBounds();
            typeParams = new TypeParameter[parameterCount];
            for (int i = 0; i < parameterCount; i++) {
                typeParams[i] = createTypeParameter(typeParameterNames[i], typeParameterBounds[i], start, end);
            }
        }
    }

    int modifiers = methodInfo.getModifiers();
    if (methodInfo.isConstructor()) {
        ConstructorDeclaration decl = new ConstructorDeclaration(compilationResult);
        decl.bits &= ~ASTNode.IsDefaultConstructor;
        method = decl;
        decl.typeParameters = typeParams;
    } else {
        MethodDeclaration decl;
        if (methodInfo.isAnnotationMethod()) {
            AnnotationMethodDeclaration annotationMethodDeclaration = new AnnotationMethodDeclaration(
                    compilationResult);

            /* conversion of default value */
            SourceAnnotationMethodInfo annotationMethodInfo = (SourceAnnotationMethodInfo) methodInfo;
            boolean hasDefaultValue = annotationMethodInfo.defaultValueStart != -1
                    || annotationMethodInfo.defaultValueEnd != -1;
            if ((this.flags & FIELD_INITIALIZATION) != 0) {
                if (hasDefaultValue) {
                    char[] defaultValueSource = CharOperation.subarray(getSource(),
                            annotationMethodInfo.defaultValueStart, annotationMethodInfo.defaultValueEnd + 1);
                    if (defaultValueSource != null) {
                        Expression expression = parseMemberValue(defaultValueSource);
                        if (expression != null) {
                            annotationMethodDeclaration.defaultValue = expression;
                        }
                    } else {
                        // could not retrieve the default value
                        hasDefaultValue = false;
                    }
                }
            }
            if (hasDefaultValue)
                modifiers |= ClassFileConstants.AccAnnotationDefault;
            decl = annotationMethodDeclaration;
        } else {
            decl = new MethodDeclaration(compilationResult);
        }

        // convert return type
        decl.returnType = createTypeReference(methodInfo.getReturnTypeName(), start, end);

        // type parameters
        decl.typeParameters = typeParams;

        method = decl;
    }
    method.selector = methodHandle.getElementName().toCharArray();
    boolean isVarargs = (modifiers & ClassFileConstants.AccVarargs) != 0;
    method.modifiers = modifiers & ~ClassFileConstants.AccVarargs;
    method.sourceStart = start;
    method.sourceEnd = end;
    method.declarationSourceStart = methodInfo.getDeclarationSourceStart();
    method.declarationSourceEnd = methodInfo.getDeclarationSourceEnd();

    // convert 1.5 specific constructs only if compliance is 1.5 or above
    if (this.has1_5Compliance) {
        /* convert annotations */
        method.annotations = convertAnnotations(methodHandle);
    }

    /* convert arguments */
    String[] argumentTypeSignatures = methodHandle.getParameterTypes();
    char[][] argumentNames = methodInfo.getArgumentNames();
    int argumentCount = argumentTypeSignatures == null ? 0 : argumentTypeSignatures.length;
    if (argumentCount > 0) {
        ILocalVariable[] parameters = methodHandle.getParameters();
        long position = ((long) start << 32) + end;
        method.arguments = new Argument[argumentCount];
        for (int i = 0; i < argumentCount; i++) {
            TypeReference typeReference = createTypeReference(argumentTypeSignatures[i], start, end);
            if (isVarargs && i == argumentCount - 1) {
                typeReference.bits |= ASTNode.IsVarArgs;
            }
            method.arguments[i] = new Argument(argumentNames[i], position, typeReference,
                    ClassFileConstants.AccDefault);
            // do not care whether was final or not
            // convert 1.5 specific constructs only if compliance is 1.5 or above
            if (this.has1_5Compliance) {
                /* convert annotations */
                method.arguments[i].annotations = convertAnnotations(parameters[i]);
            }
        }
    }

    /* convert thrown exceptions */
    char[][] exceptionTypeNames = methodInfo.getExceptionTypeNames();
    int exceptionCount = exceptionTypeNames == null ? 0 : exceptionTypeNames.length;
    if (exceptionCount > 0) {
        method.thrownExceptions = new TypeReference[exceptionCount];
        for (int i = 0; i < exceptionCount; i++) {
            method.thrownExceptions[i] = createTypeReference(exceptionTypeNames[i], start, end);
        }
    }

    /* convert local and anonymous types */
    if ((this.flags & LOCAL_TYPE) != 0) {
        IJavaElement[] children = methodInfo.getChildren();
        int typesLength = children.length;
        if (typesLength != 0) {
            Statement[] statements = new Statement[typesLength];
            for (int i = 0; i < typesLength; i++) {
                SourceType type = (SourceType) children[i];
                TypeDeclaration localType = convert(type, compilationResult);
                if ((localType.bits & ASTNode.IsAnonymousType) != 0) {
                    QualifiedAllocationExpression expression = new QualifiedAllocationExpression(localType);
                    expression.type = localType.superclass;
                    localType.superclass = null;
                    localType.superInterfaces = null;
                    localType.allocation = expression;
                    statements[i] = expression;
                } else {
                    statements[i] = localType;
                }
            }
            method.statements = statements;
        }
    }

    return method;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryTypeConverter.java

License:Open Source License

/**
 * Convert a binary type into an AST type declaration and put it in the given compilation unit.
 *//*from   w w  w . j a va 2 s . c o  m*/
public TypeDeclaration buildTypeDeclaration(IType type, CompilationUnitDeclaration compilationUnit)
        throws JavaModelException {
    PackageFragment pkg = (PackageFragment) type.getPackageFragment();
    char[][] packageName = Util.toCharArrays(pkg.names);

    if (packageName.length > 0) {
        compilationUnit.currentPackage = new ImportReference(packageName, new long[] { 0 }, false,
                ClassFileConstants.AccDefault);
    }

    /* convert type */
    TypeDeclaration typeDeclaration = convert(type, null, null);

    IType alreadyComputedMember = type;
    IType parent = type.getDeclaringType();
    TypeDeclaration previousDeclaration = typeDeclaration;
    while (parent != null) {
        TypeDeclaration declaration = convert(parent, alreadyComputedMember, previousDeclaration);

        alreadyComputedMember = parent;
        previousDeclaration = declaration;
        parent = parent.getDeclaringType();
    }

    compilationUnit.types = new TypeDeclaration[] { previousDeclaration };

    return typeDeclaration;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryTypeConverter.java

License:Open Source License

private AbstractMethodDeclaration convert(IMethod method, IType type) throws JavaModelException {

    AbstractMethodDeclaration methodDeclaration;

    org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParams = null;

    // convert 1.5 specific constructs only if compliance is 1.5 or above
    if (this.has1_5Compliance) {
        /* convert type parameters */
        ITypeParameter[] typeParameters = method.getTypeParameters();
        if (typeParameters != null && typeParameters.length > 0) {
            int parameterCount = typeParameters.length;
            typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount];
            for (int i = 0; i < parameterCount; i++) {
                ITypeParameter typeParameter = typeParameters[i];
                typeParams[i] = createTypeParameter(typeParameter.getElementName().toCharArray(),
                        stringArrayToCharArray(typeParameter.getBounds()), 0, 0);
            }//  www.  jav  a2 s  .  c o  m
        }
    }

    if (method.isConstructor()) {
        ConstructorDeclaration decl = new ConstructorDeclaration(this.compilationResult);
        decl.bits &= ~ASTNode.IsDefaultConstructor;
        decl.typeParameters = typeParams;
        methodDeclaration = decl;
    } else {
        MethodDeclaration decl = type.isAnnotation() ? new AnnotationMethodDeclaration(this.compilationResult)
                : new MethodDeclaration(this.compilationResult);
        /* convert return type */
        TypeReference typeReference = createTypeReference(method.getReturnType());
        if (typeReference == null)
            return null;
        decl.returnType = typeReference;
        decl.typeParameters = typeParams;
        methodDeclaration = decl;
    }
    methodDeclaration.selector = method.getElementName().toCharArray();
    int flags = method.getFlags();
    boolean isVarargs = Flags.isVarargs(flags);
    methodDeclaration.modifiers = flags & ~Flags.AccVarargs;

    /* convert arguments */
    String[] argumentTypeNames = method.getParameterTypes();
    String[] argumentNames = method.getParameterNames();
    int argumentCount = argumentTypeNames == null ? 0 : argumentTypeNames.length;
    // Ignore synthetic arguments (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=212224)
    int startIndex = (method.isConstructor() && type.isMember() && !Flags.isStatic(type.getFlags())) ? 1 : 0;
    argumentCount -= startIndex;
    methodDeclaration.arguments = new Argument[argumentCount];
    for (int i = 0; i < argumentCount; i++) {
        String argumentTypeName = argumentTypeNames[startIndex + i];
        TypeReference typeReference = createTypeReference(argumentTypeName);
        if (typeReference == null)
            return null;
        if (isVarargs && i == argumentCount - 1) {
            typeReference.bits |= ASTNode.IsVarArgs;
        }
        methodDeclaration.arguments[i] = new Argument(argumentNames[i].toCharArray(), 0, typeReference,
                ClassFileConstants.AccDefault);
        // do not care whether was final or not
    }

    /* convert thrown exceptions */
    String[] exceptionTypeNames = method.getExceptionTypes();
    int exceptionCount = exceptionTypeNames == null ? 0 : exceptionTypeNames.length;
    if (exceptionCount > 0) {
        methodDeclaration.thrownExceptions = new TypeReference[exceptionCount];
        for (int i = 0; i < exceptionCount; i++) {
            TypeReference typeReference = createTypeReference(exceptionTypeNames[i]);
            if (typeReference == null)
                return null;
            methodDeclaration.thrownExceptions[i] = typeReference;
        }
    }
    return methodDeclaration;
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java

License:Open Source License

protected void createImports(ModuleNode moduleNode) {
    List<ImportNode> importNodes = moduleNode.getImports();
    List<ImportNode> importPackages = ImportNodeCompatibilityWrapper.getStarImports(moduleNode);
    Map<String, ImportNode> importStatics = ImportNodeCompatibilityWrapper.getStaticImports(moduleNode);
    Map<String, ImportNode> importStaticStars = ImportNodeCompatibilityWrapper.getStaticStarImports(moduleNode);
    if (importNodes.size() > 0 || importPackages.size() > 0 || importStatics.size() > 0
            || importStaticStars.size() > 0) {
        List<ImportReference> importReferences = new ArrayList<ImportReference>();
        for (ImportNode importNode : importNodes) {
            char[][] splits = CharOperation.splitOn('.', importNode.getClassName().toCharArray());
            ImportReference ref = null;//from w ww.  j ava 2s .  c  om
            ClassNode type = importNode.getType();
            int typeStartOffset = startOffset(type);
            int typeEndOffset = endOffset(type);
            if (typeStartOffset == 0) {
                // not a real import, a fake one created during recovery
                continue;
            }
            if (importNode.getAlias() != null && importNode.getAlias().length() > 0) {
                // FIXASC will need extra positional info for the 'as' and the alias
                ref = new AliasImportReference(importNode.getAlias().toCharArray(), splits,
                        positionsFor(splits, typeStartOffset, typeEndOffset), false,
                        ClassFileConstants.AccDefault);
            } else {
                ref = new ImportReference(splits, positionsFor(splits, typeStartOffset, typeEndOffset), false,
                        ClassFileConstants.AccDefault);
            }
            ref.sourceEnd = Math.max(typeEndOffset - 1, ref.sourceStart); // For error reporting, Eclipse wants -1
            int start = importNode.getStart();
            ref.declarationSourceStart = start;
            int end = importNode.getEnd();
            ref.declarationSourceEnd = end;

            ref.declarationEnd = ref.sourceEnd;
            importReferences.add(ref);
        }

        for (ImportNode importPackage : importPackages) {
            String importText = importPackage.getText();

            // when calculating these offsets, assume no extraneous whitespace
            int packageStartOffset = importPackage.getStart() + "import ".length();
            int packageEndOffset = packageStartOffset + importText.length() - "import ".length()
                    - ".*".length();

            char[][] splits = CharOperation.splitOn('.', importPackage.getPackageName()
                    .substring(0, importPackage.getPackageName().length() - 1).toCharArray());
            ImportReference ref = new ImportReference(splits,
                    positionsFor(splits, packageStartOffset, packageEndOffset), true,
                    ClassFileConstants.AccDefault);
            // import * style only have slocs for the entire ImportNode and not for the embedded type
            ref.sourceEnd = packageEndOffset;
            ref.declarationSourceStart = importPackage.getStart();
            ref.declarationSourceEnd = importPackage.getEnd();
            ref.declarationEnd = ref.sourceEnd;
            importReferences.add(ref);
        }
        for (Map.Entry<String, ImportNode> importStatic : importStatics.entrySet()) {
            ImportNode importNode = importStatic.getValue();
            String importName = importNode.getClassName() + "." + importStatic.getKey();
            char[][] splits = CharOperation.splitOn('.', importName.toCharArray());

            ImportReference ref = null;
            ClassNode type = importNode.getType();
            int typeStartOffset = startOffset(type);
            int typeEndOffset = endOffset(type);
            if (importNode.getAlias() != null && importNode.getAlias().length() > 0) {
                // FIXASC will need extra positional info for the 'as' and the alias
                ref = new AliasImportReference(importNode.getAlias().toCharArray(), splits,
                        positionsFor(splits, typeStartOffset, typeEndOffset), false,
                        ClassFileConstants.AccDefault | ClassFileConstants.AccStatic);
            } else {
                ref = new ImportReference(splits, positionsFor(splits, typeStartOffset, typeEndOffset), false,
                        ClassFileConstants.AccDefault | ClassFileConstants.AccStatic);
            }
            ref.sourceEnd = Math.max(typeEndOffset - 1, ref.sourceStart); // For error reporting, Eclipse wants -1
            ref.declarationSourceStart = importNode.getStart();
            ref.declarationSourceEnd = importNode.getEnd();
            ref.declarationEnd = ref.sourceEnd;
            importReferences.add(ref);
        }
        for (Map.Entry<String, ImportNode> importStaticStar : importStaticStars.entrySet()) {
            String classname = importStaticStar.getKey();
            ImportNode importNode = importStaticStar.getValue();
            ClassNode importedType = importNode.getType();
            int typeStartOffset = importedType != null ? startOffset(importedType) : 0;
            int typeEndOffset = importedType != null ? endOffset(importedType) : 0;
            char[][] splits = CharOperation.splitOn('.', classname.toCharArray());
            ImportReference ref = new ImportReference(splits,
                    positionsFor(splits, typeStartOffset, typeEndOffset), true,
                    ClassFileConstants.AccDefault | ClassFileConstants.AccStatic);
            ref.sourceEnd = Math.max(typeEndOffset - 1, ref.sourceStart); // For error reporting, Eclipse wants -1
            ref.declarationSourceStart = importNode.getStart();
            ref.declarationSourceEnd = importNode.getEnd();
            ref.declarationEnd = ref.sourceEnd;
            importReferences.add(ref);
        }

        // ensure proper lexical order
        if (importReferences.size() != 0) {
            imports = importReferences.toArray(new ImportReference[importReferences.size()]);
            Arrays.sort(imports, new Comparator<ImportReference>() {
                public int compare(ImportReference left, ImportReference right) {
                    return left.sourceStart - right.sourceStart;
                }
            });
            for (ImportReference ref : imports) {
                if (ref.declarationSourceStart > 0
                        && (ref.declarationEnd - ref.declarationSourceStart + 1) < 0) {
                    throw new IllegalStateException(
                            "Import reference alongside class " + moduleNode.getClasses().get(0)
                                    + " will trigger later failure: " + ref.toString() + " declSourceStart="
                                    + ref.declarationSourceStart + " declEnd=" + +ref.declarationEnd);
                }

            }
        }
    }
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java

License:Open Source License

/**
 * Build a JDT package declaration based on the groovy one
 *//*from   ww w. j  ava  2 s  .com*/
private void createPackageDeclaration(ModuleNode moduleNode) {
    if (moduleNode.hasPackageName()) {
        PackageNode packageNode = moduleNode.getPackage();// Node();
        String packageName = moduleNode.getPackageName();
        if (packageName.endsWith(".")) {
            packageName = packageName.substring(0, packageName.length() - 1);
        }
        long start = startOffset(packageNode);
        long end = endOffset(packageNode);
        char[][] packageReference = CharOperation.splitOn('.', packageName.toCharArray());
        currentPackage = new ImportReference(packageReference, positionsFor(packageReference, start, end), true,
                ClassFileConstants.AccDefault);
        currentPackage.declarationSourceStart = currentPackage.sourceStart;
        currentPackage.declarationSourceEnd = currentPackage.sourceEnd;
        currentPackage.declarationEnd = currentPackage.sourceEnd;

        // FIXASC (M3) not right, there may be spaces between package keyword and decl. Just the first example of position
        // problems
        currentPackage.declarationSourceStart = currentPackage.sourceStart - "package ".length();
        currentPackage.declarationEnd = currentPackage.declarationSourceEnd = currentPackage.sourceEnd;
    }
}

From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementParser2.java

License:Open Source License

protected void consumeSingleStaticImportDeclarationName() {
    // SingleTypeImportDeclarationName ::= 'import' 'static' Name
    ImportReference impt;//w  ww  .j av  a2  s  .c o m
    int length;
    char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
    this.identifierPtr -= length;
    long[] positions = new long[length];
    System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
    System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
    pushOnAstStack(impt = newImportReference(tokens, positions, false, ClassFileConstants.AccStatic));

    this.modifiers = ClassFileConstants.AccDefault;
    this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)

    if (this.currentToken == TokenNameSEMICOLON) {
        impt.declarationSourceEnd = this.scanner.currentPosition - 1;
    } else {
        impt.declarationSourceEnd = impt.sourceEnd;
    }
    impt.declarationEnd = impt.declarationSourceEnd;
    //this.endPosition is just before the ;
    impt.declarationSourceStart = this.intStack[this.intPtr--];

    if (!this.statementRecoveryActivated && this.options.sourceLevel < ClassFileConstants.JDK1_5
            && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
        impt.modifiers = ClassFileConstants.AccDefault; // convert the static import reference to a non-static importe reference
        this.problemReporter().invalidUsageOfStaticImports(impt);
    }

    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = impt.declarationSourceEnd + 1;
        this.currentElement = this.currentElement.add(impt, 0);
        this.lastIgnoredToken = -1;
        this.restartRecovery = true; // used to avoid branching back into the regular automaton      
    }
    if (reportReferenceInfo) {
        // Name for static import is TypeName '.' Identifier
        // => accept unknown ref on identifier
        int tokensLength = impt.tokens.length - 1;
        int start = (int) (impt.sourcePositions[tokensLength] >>> 32);
        char[] last = impt.tokens[tokensLength];
        // accept all possible kind for last name, index users will have to select the right one...
        // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=86901
        requestor.acceptFieldReference(last, start);
        requestor.acceptMethodReference(last, 0, start);
        requestor.acceptTypeReference(last, start);
        // accept type name
        if (tokensLength > 0) {
            char[][] compoundName = new char[tokensLength][];
            System.arraycopy(impt.tokens, 0, compoundName, 0, tokensLength);
            int end = (int) impt.sourcePositions[tokensLength - 1];
            requestor.acceptTypeReference(compoundName, impt.sourceStart, end);
        }
    }
}

From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementParser2.java

License:Open Source License

protected void consumeSingleTypeImportDeclarationName() {
    // SingleTypeImportDeclarationName ::= 'import' Name
    /* push an ImportRef build from the last name 
    stored in the identifier stack. */

    ImportReference impt;/*from  w  ww . j  a  va  2  s .c o  m*/
    int length;
    char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
    this.identifierPtr -= length;
    long[] positions = new long[length];
    System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
    System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
    pushOnAstStack(impt = newImportReference(tokens, positions, false, ClassFileConstants.AccDefault));

    if (this.currentToken == TokenNameSEMICOLON) {
        impt.declarationSourceEnd = this.scanner.currentPosition - 1;
    } else {
        impt.declarationSourceEnd = impt.sourceEnd;
    }
    impt.declarationEnd = impt.declarationSourceEnd;
    //this.endPosition is just before the ;
    impt.declarationSourceStart = this.intStack[this.intPtr--];

    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = impt.declarationSourceEnd + 1;
        this.currentElement = this.currentElement.add(impt, 0);
        this.lastIgnoredToken = -1;
        this.restartRecovery = true; // used to avoid branching back into the regular automaton      
    }
    if (reportReferenceInfo) {
        requestor.acceptTypeReference(impt.tokens, impt.sourceStart, impt.sourceEnd);
    }
}

From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementParser2.java

License:Open Source License

protected void consumeStaticImportOnDemandDeclarationName() {
    // TypeImportOnDemandDeclarationName ::= 'import' 'static' Name '.' '*'
    /* push an ImportRef build from the last name 
    stored in the identifier stack. */

    ImportReference impt;/*from   ww w  .jav a  2s.c o m*/
    int length;
    char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
    this.identifierPtr -= length;
    long[] positions = new long[length];
    System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
    System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
    pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic));

    this.modifiers = ClassFileConstants.AccDefault;
    this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)

    if (this.currentToken == TokenNameSEMICOLON) {
        impt.declarationSourceEnd = this.scanner.currentPosition - 1;
    } else {
        impt.declarationSourceEnd = impt.sourceEnd;
    }
    impt.declarationEnd = impt.declarationSourceEnd;
    //this.endPosition is just before the ;
    impt.declarationSourceStart = this.intStack[this.intPtr--];

    if (!this.statementRecoveryActivated && options.sourceLevel < ClassFileConstants.JDK1_5
            && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
        impt.modifiers = ClassFileConstants.AccDefault; // convert the static import reference to a non-static importe reference
        this.problemReporter().invalidUsageOfStaticImports(impt);
    }

    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = impt.declarationSourceEnd + 1;
        this.currentElement = this.currentElement.add(impt, 0);
        this.lastIgnoredToken = -1;
        this.restartRecovery = true; // used to avoid branching back into the regular automaton      
    }
    if (reportReferenceInfo) {
        requestor.acceptTypeReference(impt.tokens, impt.sourceStart, impt.sourceEnd);
    }
}