Example usage for org.eclipse.jdt.core IType isAnonymous

List of usage examples for org.eclipse.jdt.core IType isAnonymous

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IType isAnonymous.

Prototype

boolean isAnonymous() throws JavaModelException;

Source Link

Document

Returns whether this type represents an anonymous type.

Usage

From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java

License:Open Source License

private void computeSubstitutions(IType instantiatedType, IType instantiatingType, String[] typeArguments)
        throws JavaModelException {
    Substitutions s = new Substitutions();
    fTypeVariableSubstitutions.put(instantiatedType, s);

    ITypeParameter[] typeParameters = instantiatedType.getTypeParameters();

    if (instantiatingType == null) { // the focus type
        for (int i = 0; i < typeParameters.length; i++) {
            ITypeParameter curr = typeParameters[i];
            // use star to make type variables different from type refs
            s.addSubstitution(curr.getElementName(), '*' + curr.getElementName(),
                    getTypeParameterErasure(curr, instantiatedType));
        }/*from w w  w.java2  s.  c om*/
    } else {
        if (typeParameters.length == typeArguments.length) {
            for (int i = 0; i < typeParameters.length; i++) {
                ITypeParameter curr = typeParameters[i];
                String substString = getSubstitutedTypeName(typeArguments[i], instantiatingType); // substitute in the context of the instantiatingType
                String erasure = getErasedTypeName(typeArguments[i], instantiatingType); // get the erasure from the type argument
                s.addSubstitution(curr.getElementName(), substString, erasure);
            }
        } else if (typeArguments.length == 0) { // raw type reference
            for (int i = 0; i < typeParameters.length; i++) {
                ITypeParameter curr = typeParameters[i];
                String erasure = getTypeParameterErasure(curr, instantiatedType);
                s.addSubstitution(curr.getElementName(), erasure, erasure);
            }
        } else {
            // code with errors
        }
    }
    String superclassTypeSignature = instantiatedType.getSuperclassTypeSignature();
    if (superclassTypeSignature != null) {
        String[] superTypeArguments = Signature.getTypeArguments(superclassTypeSignature);
        IType superclass = fHierarchy.getSuperclass(instantiatedType);
        if (superclass != null && !fTypeVariableSubstitutions.containsKey(superclass)) {
            computeSubstitutions(superclass, instantiatedType, superTypeArguments);
        }
    }
    String[] superInterfacesTypeSignature;
    if (instantiatedType.isAnonymous()) {
        // special case: superinterface is also returned by IType#getSuperclassTypeSignature()
        superInterfacesTypeSignature = new String[] { superclassTypeSignature };
    } else {
        superInterfacesTypeSignature = instantiatedType.getSuperInterfaceTypeSignatures();
    }
    int nInterfaces = superInterfacesTypeSignature.length;
    if (nInterfaces > 0) {
        IType[] superInterfaces = fHierarchy.getSuperInterfaces(instantiatedType);
        if (superInterfaces.length == nInterfaces) {
            for (int i = 0; i < nInterfaces; i++) {
                String[] superTypeArguments = Signature.getTypeArguments(superInterfacesTypeSignature[i]);
                IType superInterface = superInterfaces[i];
                if (!fTypeVariableSubstitutions.containsKey(superInterface)) {
                    computeSubstitutions(superInterface, instantiatedType, superTypeArguments);
                }
            }
        }
    }
}

From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java

License:Open Source License

/**
 * Appends the label for a type. Considers the T_* flags.
 *
 * @param type the element to render/*w  w w  . jav  a2 s  . co  m*/
 * @param flags the rendering flags. Flags with names starting with 'T_' are considered.
 */
public void appendTypeLabel(IType type, long flags) {

    if (getFlag(flags, JavaElementLabels.T_FULLY_QUALIFIED)) {
        IPackageFragment pack = type.getPackageFragment();
        if (!pack.isDefaultPackage()) {
            appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS));
            fBuffer.append('.');
        }
    }
    IJavaElement parent = type.getParent();
    if (getFlag(flags, JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.T_CONTAINER_QUALIFIED)) {
        IType declaringType = type.getDeclaringType();
        if (declaringType != null) {
            appendTypeLabel(declaringType, JavaElementLabels.T_CONTAINER_QUALIFIED | (flags & QUALIFIER_FLAGS));
            fBuffer.append('.');
        }
        int parentType = parent.getElementType();
        if (parentType == IJavaElement.METHOD || parentType == IJavaElement.FIELD
                || parentType == IJavaElement.INITIALIZER) { // anonymous or local
            appendElementLabel(parent, 0);
            fBuffer.append('.');
        }
    }

    String typeName;
    boolean isAnonymous = false;
    if (type.isLambda()) {
        typeName = "() -> {...}"; //$NON-NLS-1$
        try {
            String[] superInterfaceSignatures = type.getSuperInterfaceTypeSignatures();
            if (superInterfaceSignatures.length > 0) {
                typeName = typeName + ' ' + getSimpleTypeName(type, superInterfaceSignatures[0]);
            }
        } catch (JavaModelException e) {
            //ignore
        }

    } else {
        typeName = getElementName(type);
        try {
            isAnonymous = type.isAnonymous();
        } catch (JavaModelException e1) {
            // should not happen, but let's play safe:
            isAnonymous = typeName.length() == 0;
        }
        if (isAnonymous) {
            try {
                if (parent instanceof IField && type.isEnum()) {
                    typeName = '{' + JavaElementLabels.ELLIPSIS_STRING + '}';
                } else {
                    String supertypeName = null;
                    String[] superInterfaceSignatures = type.getSuperInterfaceTypeSignatures();
                    if (superInterfaceSignatures.length > 0) {
                        supertypeName = getSimpleTypeName(type, superInterfaceSignatures[0]);
                    } else {
                        String supertypeSignature = type.getSuperclassTypeSignature();
                        if (supertypeSignature != null) {
                            supertypeName = getSimpleTypeName(type, supertypeSignature);
                        }
                    }
                    if (supertypeName == null) {
                        typeName = JavaUIMessages.JavaElementLabels_anonym;
                    } else {
                        typeName = Messages.format(JavaUIMessages.JavaElementLabels_anonym_type, supertypeName);
                    }
                }
            } catch (JavaModelException e) {
                //ignore
                typeName = JavaUIMessages.JavaElementLabels_anonym;
            }
        }
    }
    fBuffer.append(typeName);

    if (getFlag(flags, JavaElementLabels.T_TYPE_PARAMETERS)) {
        if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && type.isResolved()) {
            BindingKey key = new BindingKey(type.getKey());
            if (key.isParameterizedType()) {
                String[] typeArguments = key.getTypeArguments();
                appendTypeArgumentSignaturesLabel(type, typeArguments, flags);
            } else {
                String[] typeParameters = Signature.getTypeParameters(key.toSignature());
                appendTypeParameterSignaturesLabel(typeParameters, flags);
            }
        } else if (type.exists()) {
            try {
                appendTypeParametersLabels(type.getTypeParameters(), flags);
            } catch (JavaModelException e) {
                // ignore
            }
        }
    }

    // category
    if (getFlag(flags, JavaElementLabels.T_CATEGORY) && type.exists()) {
        try {
            appendCategoryLabel(type, flags);
        } catch (JavaModelException e) {
            // ignore
        }
    }

    // post qualification
    if (getFlag(flags, JavaElementLabels.T_POST_QUALIFIED)) {
        int offset = fBuffer.length();
        fBuffer.append(JavaElementLabels.CONCAT_STRING);
        IType declaringType = type.getDeclaringType();
        if (declaringType == null && type.isBinary() && isAnonymous) {
            // workaround for Bug 87165: [model] IType#getDeclaringType() does not work for anonymous binary type
            String tqn = type.getTypeQualifiedName();
            int lastDollar = tqn.lastIndexOf('$');
            if (lastDollar != 1) {
                String declaringTypeCF = tqn.substring(0, lastDollar) + ".class"; //$NON-NLS-1$
                declaringType = type.getPackageFragment().getClassFile(declaringTypeCF).getType();
                try {
                    ISourceRange typeSourceRange = type.getSourceRange();
                    if (declaringType.exists() && SourceRange.isAvailable(typeSourceRange)) {
                        IJavaElement realParent = declaringType.getTypeRoot()
                                .getElementAt(typeSourceRange.getOffset() - 1);
                        if (realParent != null) {
                            parent = realParent;
                        }
                    }
                } catch (JavaModelException e) {
                    // ignore
                }
            }
        }
        if (declaringType != null) {
            appendTypeLabel(declaringType, JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
            int parentType = parent.getElementType();
            if (parentType == IJavaElement.METHOD || parentType == IJavaElement.FIELD
                    || parentType == IJavaElement.INITIALIZER) { // anonymous or local
                fBuffer.append('.');
                appendElementLabel(parent, 0);
            }
        } else {
            appendPackageFragmentLabel(type.getPackageFragment(), flags & QUALIFIER_FLAGS);
        }
        //         if (getFlag(flags, JavaElementLabels.COLORIZE)) {
        //            fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
        //         }
    }
}

From source file:ca.uvic.chisel.javasketch.internal.JavaSearchUtils.java

License:Open Source License

/**
 * @param scope// www  .java  2s .  c o  m
 * @param monitor
 * @param classSignature
 * @param methodName
 * @param signature
 * @return
 * @throws CoreException
 * @throws InterruptedException
 */
public static IJavaElement searchForMethod(IJavaSearchScope scope, IProgressMonitor monitor,
        String classSignature, String methodName, String signature) throws CoreException, InterruptedException {

    SubProgressMonitor typeMonitor = new SubProgressMonitor(monitor, 100);
    SubProgressMonitor hierarchyMonitor = new SubProgressMonitor(monitor, 100);
    IType foundType = (IType) searchForType(classSignature, scope, typeMonitor);
    if (foundType == null)
        return null;
    boolean isConstructor = false;
    if (methodName.startsWith("<init")) {
        isConstructor = true;
        boolean i = isConstructor;
        boolean isAnonymous = false;
        if (!foundType.exists()) {
            //check anonymity using the dollar sign
            String elementName = foundType.getElementName();
            if (elementName.length() > 0 && Character.isDigit(elementName.charAt(0))) {
                isAnonymous = true;
            }
        } else {
            isAnonymous = foundType.isAnonymous();
        }
        if (isAnonymous) {
            methodName = "";
        } else {
            methodName = foundType.getElementName();
        }
    }
    String[] methodParamTypes = Signature.getParameterTypes(signature);
    IMethod searchMethod = foundType.getMethod(methodName, methodParamTypes);
    IMethod[] methods = foundType.getMethods();
    for (IMethod checkMethod : methods) {
        if (isSimilar(searchMethod, checkMethod)) {
            return checkMethod;
        }
    }
    return searchMethod;
}

From source file:ca.uvic.chisel.javasketch.internal.JavaSearchUtils.java

License:Open Source License

public static String getFullyQualifiedName(IType type, boolean includeOccurrenceCount) {
    IType declaring = type;
    String qualifiedName = "";
    try {//from w  w w.  j  a  v  a  2s  .c  o m
        while (declaring != null) {
            if (declaring.isAnonymous()) {
                qualifiedName = declaring.getOccurrenceCount() + "" + qualifiedName;
            } else {
                qualifiedName = declaring.getElementName() + qualifiedName;
                if (includeOccurrenceCount) {
                    IJavaElement parent = declaring.getParent();
                    if (parent instanceof IMember && !(parent instanceof IType)) {
                        qualifiedName = type.getOccurrenceCount() + qualifiedName;
                    }
                }
            }
            IJavaElement parent = declaring.getParent();
            while (parent != null) {
                if (parent instanceof IType) {
                    declaring = (IType) parent;
                    break;
                }
                parent = parent.getParent();
            }
            if (parent != null) {
                qualifiedName = "$" + qualifiedName;
            } else {
                declaring = null;
            }
        }
    } catch (JavaModelException e) {
        return type.getFullyQualifiedName();
    }
    String pack = type.getPackageFragment().getElementName();
    if (!"".equals(pack))
        pack = pack + ".";
    qualifiedName = pack + qualifiedName;
    return qualifiedName;
}

From source file:ca.uvic.chisel.javasketch.ui.internal.presentation.TraceThreadLabelProvider.java

License:Open Source License

@Override
public String getText(Object element) {
    try {//from   ww w .  j  a va 2s . c o m
        IJavaElement je = null;

        if (element instanceof ICall) {
            IMessage target = ((ICall) element).getTarget();
            if (target != null) {
                je = JavaSearchUtils.findElement(target.getActivation(), new NullProgressMonitor());
            }
        } else if (element instanceof IThrow) {
            return "Exception";
        } else if (element instanceof IReply) {
            String sig = ((IReply) element).getActivation().getMethod().getSignature();
            return Signature.getSimpleName(Signature.toString(Signature.getReturnType(sig)));
        } else if (element instanceof ITraceModel) {
            je = JavaSearchUtils.findElement((ITraceModel) element, new NullProgressMonitor());
        }
        if (je != null) {
            if (je instanceof IType) {
                IType type = (IType) je;
                //qualify with all the parent type names
                String name = type.getElementName();

                if (type.isAnonymous()) {
                    name = type.getTypeQualifiedName();
                } else if (type.getOccurrenceCount() > 1) {
                    name = type.getOccurrenceCount() + name;
                }
                IJavaElement parent = type.getParent();
                while (parent != null) {
                    if (parent instanceof IType) {
                        IType pt = (IType) parent;
                        int occurrence = pt.getOccurrenceCount();
                        if (pt.isAnonymous()) {
                            name = occurrence + "$" + name;
                        } else {
                            name = ((occurrence > 1) ? occurrence : "") + pt.getElementName() + "$" + name;
                        }
                    }
                    parent = parent.getParent();
                }
                return name;
            }
            return workbenchLabelProvider.getText(je);
        } else if (element instanceof ITraceModel) {
            return uresolvedModelElement((ITraceModel) element);
        }
    } catch (InterruptedException e) {
    } catch (CoreException e) {
    } catch (Exception e) {
    }
    return (element != null) ? element.toString() : "";
}

From source file:ch.qos.logback.beagle.util.EditorUtil.java

License:Open Source License

private static String getFullyQualifiedName(IType type) {
    try {/*from   ww w. ja v a2 s  .  com*/
        if (type.isBinary() && !type.isAnonymous()) {
            IType declaringType = type.getDeclaringType();
            if (declaringType != null) {
                return getFullyQualifiedName(declaringType) + '.' + type.getElementName();
            }
        }
    } catch (JavaModelException e) {
        // ignore
    }
    return type.getFullyQualifiedName('.');
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.CustomViewFinder.java

License:Open Source License

/**
 * Determines whether the given member is a valid android.view.View to be added to the
 * list of custom views or third party views. It checks that the view is public and
 * not abstract for example./*from   w  w  w.java  2  s  . c  o m*/
 */
private static boolean isValidView(IType type, boolean layoutsOnly) throws JavaModelException {
    // Skip anonymous classes
    if (type.isAnonymous()) {
        return false;
    }
    int flags = type.getFlags();
    if (Flags.isAbstract(flags) || !Flags.isPublic(flags)) {
        return false;
    }

    // TODO: if (layoutsOnly) perhaps try to filter out AdapterViews and other ViewGroups
    // not willing to accept children via XML

    // See if the class has one of the acceptable constructors
    // needed for XML instantiation:
    //    View(Context context)
    //    View(Context context, AttributeSet attrs)
    //    View(Context context, AttributeSet attrs, int defStyle)
    // We don't simply do three direct checks via type.getMethod() because the types
    // are not resolved, so we don't know for each parameter if we will get the
    // fully qualified or the unqualified class names.
    // Instead, iterate over the methods and look for a match.
    String typeName = type.getElementName();
    for (IMethod method : type.getMethods()) {
        // Only care about constructors
        if (!method.getElementName().equals(typeName)) {
            continue;
        }

        String[] parameterTypes = method.getParameterTypes();
        if (parameterTypes == null || parameterTypes.length < 1 || parameterTypes.length > 3) {
            continue;
        }

        String first = parameterTypes[0];
        // Look for the parameter type signatures -- produced by
        // JDT's Signature.createTypeSignature("Context", false /*isResolved*/);.
        // This is not a typo; they were copy/pasted from the actual parameter names
        // observed in the debugger examining these data structures.
        if (first.equals("QContext;") //$NON-NLS-1$
                || first.equals("Qandroid.content.Context;")) { //$NON-NLS-1$
            if (parameterTypes.length == 1) {
                return true;
            }
            String second = parameterTypes[1];
            if (second.equals("QAttributeSet;") //$NON-NLS-1$
                    || second.equals("Qandroid.util.AttributeSet;")) { //$NON-NLS-1$
                if (parameterTypes.length == 2) {
                    return true;
                }
                String third = parameterTypes[2];
                if (third.equals("I")) { //$NON-NLS-1$
                    if (parameterTypes.length == 3) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}

From source file:com.android.ide.eclipse.cheatsheets.actions.SetBreakpoint.java

License:Open Source License

/**
 * Prunes out all naming occurrences of anonymous inner types, since these types have no names
 * and cannot be derived visiting an AST (no positive type name matching while visiting ASTs)
 * @param type//from w w  w  .  j  a  v a  2  s.  c  o  m
 * @return the compiled type name from the given {@link IType} with all occurrences of anonymous inner types removed
 * @since 3.4
 */
private String pruneAnonymous(IType type) {
    StringBuffer buffer = new StringBuffer();
    IJavaElement parent = type;
    while (parent != null) {
        if (parent.getElementType() == IJavaElement.TYPE) {
            IType atype = (IType) parent;
            try {
                if (!atype.isAnonymous()) {
                    if (buffer.length() > 0) {
                        buffer.insert(0, '$');
                    }
                    buffer.insert(0, atype.getElementName());
                }
            } catch (JavaModelException jme) {
            }
        }
        parent = parent.getParent();
    }
    return buffer.toString();
}

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java

License:Open Source License

/**
 * Asks the engine to compute the selection of the given type
 * from the given context//from   www  . j a  v a2  s.c o m
 *
 *  @param typeName char[]
 *      a type name which is to be resolved in the context of a compilation unit.
 *      NOTE: the type name is supposed to be correctly reduced (no whitespaces, no unicodes left)
 *
 *  @param context org.eclipse.jdt.core.IType
 *      the context in which code assist is invoked.
 */
public void selectType(char[] typeName, IType context) throws JavaModelException {
    try {
        this.acceptedAnswer = false;

        // only the type erasure are returned by IType.resolvedType(...)
        if (CharOperation.indexOf('<', typeName) != -1) {
            char[] typeSig = Signature.createCharArrayTypeSignature(typeName, false/*not resolved*/);
            typeSig = Signature.getTypeErasure(typeSig);
            typeName = Signature.toCharArray(typeSig);
        }

        CompilationUnitDeclaration parsedUnit = null;
        TypeDeclaration typeDeclaration = null;
        org.eclipse.jdt.core.ICompilationUnit cu = context.getCompilationUnit();
        if (cu != null) {
            IType[] topLevelTypes = cu.getTypes();
            int length = topLevelTypes.length;
            SourceTypeElementInfo[] topLevelInfos = new SourceTypeElementInfo[length];
            for (int i = 0; i < length; i++) {
                topLevelInfos[i] = (SourceTypeElementInfo) ((SourceType) topLevelTypes[i]).getElementInfo();
            }
            CompilationResult result = new CompilationResult(
                    (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) cu, 1, 1,
                    this.compilerOptions.maxProblemsPerUnit);
            int flags = SourceTypeConverter.FIELD_AND_METHOD | SourceTypeConverter.MEMBER_TYPE;
            if (context.isAnonymous() || context.isLocal())
                flags |= SourceTypeConverter.LOCAL_TYPE;
            parsedUnit = SourceTypeConverter.buildCompilationUnit(topLevelInfos, flags,
                    this.parser.problemReporter(), result);
            if (parsedUnit != null && parsedUnit.types != null) {
                if (DEBUG) {
                    System.out.println("SELECTION - Diet AST :"); //$NON-NLS-1$
                    System.out.println(parsedUnit.toString());
                }
                // find the type declaration that corresponds to the original source type
                typeDeclaration = new ASTNodeFinder(parsedUnit).findType(context);
            }
        } else { // binary type
            ClassFile classFile = (ClassFile) context.getClassFile();
            ClassFileReader reader = (ClassFileReader) classFile.getBinaryTypeInfo(
                    (IFile) null/*classFile.resource()*/,
                    false/*don't fully initialize so as to keep constant pool (used below)*/);
            CompilationResult result = new CompilationResult(reader.getFileName(), 1, 1,
                    this.compilerOptions.maxProblemsPerUnit);
            parsedUnit = new CompilationUnitDeclaration(this.parser.problemReporter(), result, 0);
            HashSetOfCharArrayArray typeNames = new HashSetOfCharArrayArray();

            BinaryTypeConverter converter = new BinaryTypeConverter(this.parser.problemReporter(), result,
                    typeNames);
            typeDeclaration = converter.buildTypeDeclaration(context, parsedUnit);
            parsedUnit.imports = converter.buildImports(reader);
        }

        if (typeDeclaration != null) {

            // add fake field with the type we're looking for
            // note: since we didn't ask for fields above, there is no field defined yet
            FieldDeclaration field = new FieldDeclaration();
            int dot;
            if ((dot = CharOperation.lastIndexOf('.', typeName)) == -1) {
                this.selectedIdentifier = typeName;
                field.type = new SelectionOnSingleTypeReference(typeName, -1);
                // position not used
            } else {
                char[][] previousIdentifiers = CharOperation.splitOn('.', typeName, 0, dot);
                char[] selectionIdentifier = CharOperation.subarray(typeName, dot + 1, typeName.length);
                this.selectedIdentifier = selectionIdentifier;
                field.type = new SelectionOnQualifiedTypeReference(previousIdentifiers, selectionIdentifier,
                        new long[previousIdentifiers.length + 1]);
            }
            field.name = "<fakeField>".toCharArray(); //$NON-NLS-1$
            typeDeclaration.fields = new FieldDeclaration[] { field };

            // build bindings
            this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/);
            if ((this.unitScope = parsedUnit.scope) != null) {
                try {
                    // build fields
                    // note: this builds fields only in the parsed unit (the buildFieldsAndMethods flag is not passed along)
                    this.lookupEnvironment.completeTypeBindings(parsedUnit, true);

                    // resolve
                    parsedUnit.scope.faultInTypes();
                    parsedUnit.resolve();
                } catch (SelectionNodeFound e) {
                    if (e.binding != null) {
                        if (DEBUG) {
                            System.out.println("SELECTION - Selection binding :"); //$NON-NLS-1$
                            System.out.println(e.binding.toString());
                        }
                        // if null then we found a problem in the selection node
                        selectFrom(e.binding, parsedUnit, e.isDeclaration);
                    }
                }
            }
        }
        if (this.noProposal && this.problem != null) {
            this.requestor.acceptError(this.problem);
        }
    } catch (AbortCompilation e) { // ignore this exception for now since it typically means we cannot find java.lang.Object
    } finally {
        reset(true);
    }
}

From source file:com.codenvy.ide.ext.java.server.javadoc.JavaElementLabelComposer.java

License:Open Source License

/**
 * Appends the label for a type. Considers the T_* flags.
 *
 * @param type the element to render/*w  w  w  .  j av  a2  s.com*/
 * @param flags the rendering flags. Flags with names starting with 'T_' are considered.
 */
public void appendTypeLabel(IType type, long flags) {

    if (getFlag(flags, JavaElementLabels.T_FULLY_QUALIFIED)) {
        IPackageFragment pack = type.getPackageFragment();
        if (!pack.isDefaultPackage()) {
            appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS));
            fBuffer.append('.');
        }
    }
    IJavaElement parent = type.getParent();
    if (getFlag(flags, JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.T_CONTAINER_QUALIFIED)) {
        IType declaringType = type.getDeclaringType();
        if (declaringType != null) {
            appendTypeLabel(declaringType, JavaElementLabels.T_CONTAINER_QUALIFIED | (flags & QUALIFIER_FLAGS));
            fBuffer.append('.');
        }
        int parentType = parent.getElementType();
        if (parentType == IJavaElement.METHOD || parentType == IJavaElement.FIELD
                || parentType == IJavaElement.INITIALIZER) { // anonymous or local
            appendElementLabel(parent, 0);
            fBuffer.append('.');
        }
    }

    String typeName;
    boolean isAnonymous = false;
    if (type.isLambda()) {
        typeName = "() -> {...}"; //$NON-NLS-1$
        try {
            String[] superInterfaceSignatures = type.getSuperInterfaceTypeSignatures();
            if (superInterfaceSignatures.length > 0) {
                typeName = typeName + ' ' + getSimpleTypeName(type, superInterfaceSignatures[0]);
            }
        } catch (JavaModelException e) {
            //ignore
        }

    } else {
        typeName = getElementName(type);
        try {
            isAnonymous = type.isAnonymous();
        } catch (JavaModelException e1) {
            // should not happen, but let's play safe:
            isAnonymous = typeName.length() == 0;
        }
        if (isAnonymous) {
            try {
                if (parent instanceof IField && type.isEnum()) {
                    typeName = '{' + JavaElementLabels.ELLIPSIS_STRING + '}';
                } else {
                    String supertypeName;
                    String[] superInterfaceSignatures = type.getSuperInterfaceTypeSignatures();
                    if (superInterfaceSignatures.length > 0) {
                        supertypeName = getSimpleTypeName(type, superInterfaceSignatures[0]);
                    } else {
                        supertypeName = getSimpleTypeName(type, type.getSuperclassTypeSignature());
                    }
                    typeName = MessageFormat.format("new {0}() '{'...}", supertypeName);
                }
            } catch (JavaModelException e) {
                //ignore
                typeName = "new Anonymous";
            }
        }
    }
    fBuffer.append(typeName);

    if (getFlag(flags, JavaElementLabels.T_TYPE_PARAMETERS)) {
        if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && type.isResolved()) {
            BindingKey key = new BindingKey(type.getKey());
            if (key.isParameterizedType()) {
                String[] typeArguments = key.getTypeArguments();
                appendTypeArgumentSignaturesLabel(type, typeArguments, flags);
            } else {
                String[] typeParameters = Signature.getTypeParameters(key.toSignature());
                appendTypeParameterSignaturesLabel(typeParameters, flags);
            }
        } else if (type.exists()) {
            try {
                appendTypeParametersLabels(type.getTypeParameters(), flags);
            } catch (JavaModelException e) {
                // ignore
            }
        }
    }

    // category
    if (getFlag(flags, JavaElementLabels.T_CATEGORY) && type.exists()) {
        try {
            appendCategoryLabel(type, flags);
        } catch (JavaModelException e) {
            // ignore
        }
    }

    // post qualification
    if (getFlag(flags, JavaElementLabels.T_POST_QUALIFIED)) {
        int offset = fBuffer.length();
        fBuffer.append(JavaElementLabels.CONCAT_STRING);
        IType declaringType = type.getDeclaringType();
        if (declaringType == null && type.isBinary() && isAnonymous) {
            // workaround for Bug 87165: [model] IType#getDeclaringType() does not work for anonymous binary type
            String tqn = type.getTypeQualifiedName();
            int lastDollar = tqn.lastIndexOf('$');
            if (lastDollar != 1) {
                String declaringTypeCF = tqn.substring(0, lastDollar) + ".class"; //$NON-NLS-1$
                declaringType = type.getPackageFragment().getClassFile(declaringTypeCF).getType();
                try {
                    ISourceRange typeSourceRange = type.getSourceRange();
                    if (declaringType.exists() && SourceRange.isAvailable(typeSourceRange)) {
                        IJavaElement realParent = declaringType.getTypeRoot()
                                .getElementAt(typeSourceRange.getOffset() - 1);
                        if (realParent != null) {
                            parent = realParent;
                        }
                    }
                } catch (JavaModelException e) {
                    // ignore
                }
            }
        }
        if (declaringType != null) {
            appendTypeLabel(declaringType, JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
            int parentType = parent.getElementType();
            if (parentType == IJavaElement.METHOD || parentType == IJavaElement.FIELD
                    || parentType == IJavaElement.INITIALIZER) { // anonymous or local
                fBuffer.append('.');
                appendElementLabel(parent, 0);
            }
        } else {
            appendPackageFragmentLabel(type.getPackageFragment(), flags & QUALIFIER_FLAGS);
        }
        //         if (getFlag(flags, JavaElementLabels.COLORIZE)) {
        //            fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
        //         }
    }
}