Example usage for org.eclipse.jdt.internal.compiler.env ISourceType getSuperclassName

List of usage examples for org.eclipse.jdt.internal.compiler.env ISourceType getSuperclassName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.env ISourceType getSuperclassName.

Prototype

char[] getSuperclassName();

Source Link

Document

Answer the unresolved name of the receiver's superclass or null if it does not have one.

Usage

From source file:org.eclipse.ajdt.core.javaelements.ITDAwareSourceTypeInfo.java

License:Open Source License

public ITDAwareSourceTypeInfo(ISourceType toCopy, SourceType type) {
    this.handle = createITDAwareType(type, this);

    this.setFlags(toCopy.getModifiers());
    this.setSuperclassName(toCopy.getSuperclassName());
    this.setSuperInterfaceNames(toCopy.getInterfaceNames());
    this.setNameSourceEnd(toCopy.getNameSourceEnd());
    this.setNameSourceStart(toCopy.getNameSourceStart());
    this.setSourceRangeEnd(toCopy.getDeclarationSourceEnd());
    this.setSourceRangeStart(toCopy.getDeclarationSourceStart());
    try {/*from   w  ww. j av  a2s  .c  o m*/
        ITypeParameter[] parameters = type.getTypeParameters();
        if (parameters != null) {
            this.typeParameters = new ITypeParameter[parameters.length];
            System.arraycopy(parameters, 0, this.typeParameters, 0, parameters.length);
        }
    } catch (JavaModelException e) {
    }

    IJavaElement[] children = augmentChildrenAndHierarchy(type);
    if (children != null) {
        this.setChildren(children);
    }

    try {
        // this ensures that itd aware content assist 
        // still works when there are large numbers ofannotations
        Object info = ((JavaElement) handle.getCompilationUnit()).getElementInfo();
        if (info != null && info instanceof CompilationUnitElementInfo) {
            ((CompilationUnitElementInfo) info).annotationNumber = 0;
        }
    } catch (JavaModelException e) {
    }
}

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 w  w  w.j  av a2 s  .c  o 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;
}