Example usage for org.eclipse.jdt.internal.compiler.lookup TypeConstants CharArray_JAVA_LANG_ANNOTATION_ANNOTATION

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeConstants CharArray_JAVA_LANG_ANNOTATION_ANNOTATION

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup TypeConstants CharArray_JAVA_LANG_ANNOTATION_ANNOTATION.

Prototype

null CharArray_JAVA_LANG_ANNOTATION_ANNOTATION

To view the source code for org.eclipse.jdt.internal.compiler.lookup TypeConstants CharArray_JAVA_LANG_ANNOTATION_ANNOTATION.

Click Source Link

Usage

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

License:Open Source License

protected void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence,
        TypeDeclaration declaringType) {

    if (CharOperation.equals(TypeConstants.PACKAGE_INFO_NAME, typeDeclaration.name))
        return;/* w  ww.j  a v  a  2s .c  om*/

    //   AspectJ change begin
    boolean isAspect = false;
    org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration ajtypeDeclaration = new org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration(
            new org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult(
                    typeDeclaration.compilationResult.fileName, typeDeclaration.compilationResult.unitIndex,
                    typeDeclaration.compilationResult.totalUnitsKnown, 500));
    if (ajtypeDeclaration instanceof AspectDeclaration) {
        isAspect = true;
    }
    //   AspectJ change end

    // range check
    boolean isInRange = initialPosition <= typeDeclaration.declarationSourceStart
            && eofPosition >= typeDeclaration.declarationSourceEnd;

    FieldDeclaration[] fields = typeDeclaration.fields;
    AbstractMethodDeclaration[] methods = typeDeclaration.methods;
    TypeDeclaration[] memberTypes = typeDeclaration.memberTypes;
    int fieldCounter = fields == null ? 0 : fields.length;
    int methodCounter = methods == null ? 0 : methods.length;
    int memberTypeCounter = memberTypes == null ? 0 : memberTypes.length;
    int fieldIndex = 0;
    int methodIndex = 0;
    int memberTypeIndex = 0;

    if (notifyTypePresence) {
        char[][] interfaceNames = getInterfaceNames(typeDeclaration);
        int kind = TypeDeclaration.kind(typeDeclaration.modifiers);
        char[] implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_OBJECT;
        if (isInRange) {
            int currentModifiers = typeDeclaration.modifiers;

            // remember deprecation so as to not lose it below
            boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0
                    || hasDeprecatedAnnotation(typeDeclaration.annotations);

            boolean isEnumInit = typeDeclaration.allocation != null
                    && typeDeclaration.allocation.enumConstant != null;
            char[] superclassName;
            if (isEnumInit) {
                currentModifiers |= ClassFileConstants.AccEnum;
                superclassName = declaringType.name;
            } else {
                superclassName = getSuperclassName(typeDeclaration);
            }
            ISourceElementRequestor.TypeInfo typeInfo = new ISourceElementRequestor.TypeInfo();
            if (typeDeclaration.allocation == null) {
                typeInfo.declarationStart = typeDeclaration.declarationSourceStart;
            } else if (isEnumInit) {
                typeInfo.declarationStart = typeDeclaration.allocation.enumConstant.sourceStart;
            } else {
                typeInfo.declarationStart = typeDeclaration.allocation.sourceStart;
            }
            typeInfo.modifiers = deprecated
                    ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated
                    : currentModifiers & ExtraCompilerModifiers.AccJustFlag;
            typeInfo.name = typeDeclaration.name;
            typeInfo.nameSourceStart = isEnumInit ? typeDeclaration.allocation.enumConstant.sourceStart
                    : typeDeclaration.sourceStart;
            typeInfo.nameSourceEnd = sourceEnd(typeDeclaration);
            typeInfo.superclass = superclassName;
            typeInfo.superinterfaces = interfaceNames;
            typeInfo.typeParameters = getTypeParameterInfos(typeDeclaration.typeParameters);
            typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration);
            typeInfo.secondary = typeDeclaration.isSecondary();
            typeInfo.anonymousMember = typeDeclaration.allocation != null
                    && typeDeclaration.allocation.enclosingInstance != null;
            typeInfo.annotations = typeDeclaration.annotations;
            typeInfo.node = typeDeclaration;
            requestor.enterType(typeInfo, isAspect,
                    (isAspect ? ((AspectDeclaration) ajtypeDeclaration).isPrivileged : false)); // AspectJ change
            switch (kind) {
            case TypeDeclaration.CLASS_DECL:
                if (superclassName != null)
                    implicitSuperclassName = superclassName;
                break;
            case TypeDeclaration.INTERFACE_DECL:
                implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_OBJECT;
                break;
            case TypeDeclaration.ENUM_DECL:
                implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_ENUM;
                break;
            case TypeDeclaration.ANNOTATION_TYPE_DECL:
                implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_ANNOTATION_ANNOTATION;
                break;
            }
        }
        if (this.nestedTypeIndex == this.typeNames.length) {
            // need a resize
            System.arraycopy(this.typeNames, 0, (this.typeNames = new char[this.nestedTypeIndex * 2][]), 0,
                    this.nestedTypeIndex);
            System.arraycopy(this.superTypeNames, 0,
                    (this.superTypeNames = new char[this.nestedTypeIndex * 2][]), 0, this.nestedTypeIndex);
        }
        this.typeNames[this.nestedTypeIndex] = typeDeclaration.name;
        this.superTypeNames[this.nestedTypeIndex++] = implicitSuperclassName;
    }
    while ((fieldIndex < fieldCounter) || (memberTypeIndex < memberTypeCounter)
            || (methodIndex < methodCounter)) {
        FieldDeclaration nextFieldDeclaration = null;
        AbstractMethodDeclaration nextMethodDeclaration = null;
        TypeDeclaration nextMemberDeclaration = null;

        int position = Integer.MAX_VALUE;
        int nextDeclarationType = -1;
        if (fieldIndex < fieldCounter) {
            nextFieldDeclaration = fields[fieldIndex];
            if (nextFieldDeclaration.declarationSourceStart < position) {
                position = nextFieldDeclaration.declarationSourceStart;
                nextDeclarationType = 0; // FIELD
            }
        }
        if (methodIndex < methodCounter) {
            nextMethodDeclaration = methods[methodIndex];
            if (nextMethodDeclaration.declarationSourceStart < position) {
                position = nextMethodDeclaration.declarationSourceStart;
                nextDeclarationType = 1; // METHOD
            }
        }
        if (memberTypeIndex < memberTypeCounter) {
            nextMemberDeclaration = memberTypes[memberTypeIndex];
            if (nextMemberDeclaration.declarationSourceStart < position) {
                position = nextMemberDeclaration.declarationSourceStart;
                nextDeclarationType = 2; // MEMBER
            }
        }
        switch (nextDeclarationType) {
        case 0:
            fieldIndex++;
            notifySourceElementRequestor(nextFieldDeclaration, typeDeclaration);
            break;
        case 1:
            methodIndex++;
            notifySourceElementRequestor(nextMethodDeclaration);
            break;
        case 2:
            memberTypeIndex++;
            notifySourceElementRequestor(nextMemberDeclaration, true, null);
        }
    }
    if (notifyTypePresence) {
        if (isInRange) {
            requestor.exitType(typeDeclaration.declarationSourceEnd);
        }
        nestedTypeIndex--;
    }
}

From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.java

License:Open Source License

private IType[] findSuperInterfaces(IGenericType type, ReferenceBinding typeBinding) {
    char[][] superInterfaceNames;
    char separator;
    if (type instanceof IBinaryType) {
        superInterfaceNames = ((IBinaryType) type).getInterfaceNames();
        separator = '/';
    } else if (type instanceof ISourceType) {
        ISourceType sourceType = (ISourceType) type;
        if (sourceType.getName().length == 0) { // if anonymous type
            if (typeBinding.superInterfaces() != null && typeBinding.superInterfaces().length > 0) {
                superInterfaceNames = new char[][] { sourceType.getSuperclassName() };
            } else {
                superInterfaceNames = sourceType.getInterfaceNames();
            }/*from ww w.  j a v a2 s.  co m*/
        } else {
            if (TypeDeclaration.kind(sourceType.getModifiers()) == TypeDeclaration.ANNOTATION_TYPE_DECL)
                superInterfaceNames = new char[][] { TypeConstants.CharArray_JAVA_LANG_ANNOTATION_ANNOTATION };
            else
                superInterfaceNames = sourceType.getInterfaceNames();
        }
        separator = '.';
    } else if (type instanceof HierarchyType) {
        HierarchyType hierarchyType = (HierarchyType) type;
        if (hierarchyType.name.length == 0) { // if anonymous type
            if (typeBinding.superInterfaces() != null && typeBinding.superInterfaces().length > 0) {
                superInterfaceNames = new char[][] { hierarchyType.superclassName };
            } else {
                superInterfaceNames = hierarchyType.superInterfaceNames;
            }
        } else {
            superInterfaceNames = hierarchyType.superInterfaceNames;
        }
        separator = '.';
    } else {
        return null;
    }

    ReferenceBinding[] interfaceBindings = typeBinding.superInterfaces();
    int bindingIndex = 0;
    int bindingLength = interfaceBindings == null ? 0 : interfaceBindings.length;
    int length = superInterfaceNames == null ? 0 : superInterfaceNames.length;
    IType[] superinterfaces = new IType[length];
    int index = 0;
    next: for (int i = 0; i < length; i++) {
        char[] superInterfaceName = superInterfaceNames[i];
        int end = superInterfaceName.length;

        // find the end of simple name
        int genericStart = CharOperation.indexOf(Signature.C_GENERIC_START, superInterfaceName);
        if (genericStart != -1)
            end = genericStart;

        // find the start of simple name
        int lastSeparator = CharOperation.lastIndexOf(separator, superInterfaceName, 0, end);
        int start = lastSeparator + 1;

        // case of binary inner type -> take the last part
        int lastDollar = CharOperation.lastIndexOf('$', superInterfaceName, start);
        if (lastDollar != -1)
            start = lastDollar + 1;

        char[] simpleName = CharOperation.subarray(superInterfaceName, start, end);

        if (bindingIndex < bindingLength) {
            ReferenceBinding interfaceBinding = (ReferenceBinding) interfaceBindings[bindingIndex].erasure();

            // ensure that the binding corresponds to the interface defined by the user
            if (CharOperation.equals(simpleName, interfaceBinding.sourceName)) {
                bindingIndex++;
                for (int t = this.typeIndex; t >= 0; t--) {
                    if (this.typeBindings[t] == interfaceBinding) {
                        IType handle = this.builder.getHandle(this.typeModels[t], interfaceBinding);
                        if (handle != null) {
                            superinterfaces[index++] = handle;
                            continue next;
                        }
                    }
                }
            }
        }
        this.builder.hierarchy.missingTypes.add(new String(simpleName));
    }
    if (index != length)
        System.arraycopy(superinterfaces, 0, superinterfaces = new IType[index], 0, index);
    return superinterfaces;
}