Example usage for org.eclipse.jdt.core IPackageFragment DEFAULT_PACKAGE_NAME

List of usage examples for org.eclipse.jdt.core IPackageFragment DEFAULT_PACKAGE_NAME

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragment DEFAULT_PACKAGE_NAME.

Prototype

String DEFAULT_PACKAGE_NAME

To view the source code for org.eclipse.jdt.core IPackageFragment DEFAULT_PACKAGE_NAME.

Click Source Link

Document

The name of package fragment for the default package (value: the empty string, "").

Usage

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

License:Open Source License

/**
 * Returns the message that is relevant to the code of this status.
 *//*from  w  ww .j a  va  2  s  .  co  m*/
public String getMessage() {
    Throwable exception = getException();
    if (exception == null) {
        switch (getCode()) {
        case CORE_EXCEPTION:
            return Messages.status_coreException;

        case BUILDER_INITIALIZATION_ERROR:
            return Messages.build_initializationError;

        case BUILDER_SERIALIZATION_ERROR:
            return Messages.build_serializationError;

        case DEVICE_PATH:
            return Messages.bind(Messages.status_cannotUseDeviceOnPath, getPath().toString());

        case DOM_EXCEPTION:
            return Messages.status_JDOMError;

        case ELEMENT_DOES_NOT_EXIST:
            return Messages.bind(Messages.element_doesNotExist,
                    ((JavaElement) this.elements[0]).toStringWithAncestors());

        case ELEMENT_NOT_ON_CLASSPATH:
            return Messages.bind(Messages.element_notOnClasspath,
                    ((JavaElement) this.elements[0]).toStringWithAncestors());

        case EVALUATION_ERROR:
            return Messages.bind(Messages.status_evaluationError, this.string);

        case INDEX_OUT_OF_BOUNDS:
            return Messages.status_indexOutOfBounds;

        case INVALID_CONTENTS:
            return Messages.status_invalidContents;

        case INVALID_DESTINATION:
            return Messages.bind(Messages.status_invalidDestination,
                    ((JavaElement) this.elements[0]).toStringWithAncestors());

        case INVALID_ELEMENT_TYPES:
            StringBuffer buff = new StringBuffer(Messages.operation_notSupported);
            for (int i = 0; i < this.elements.length; i++) {
                if (i > 0) {
                    buff.append(", "); //$NON-NLS-1$
                }
                buff.append(((JavaElement) this.elements[i]).toStringWithAncestors());
            }
            return buff.toString();

        case INVALID_NAME:
            return Messages.bind(Messages.status_invalidName, this.string);

        case INVALID_PACKAGE:
            return Messages.bind(Messages.status_invalidPackage, this.string);

        case INVALID_PATH:
            if (this.string != null) {
                return this.string;
            } else {
                return Messages.bind(Messages.status_invalidPath,
                        new String[] { getPath() == null ? "null" : getPath().toString() } //$NON-NLS-1$
                );
            }

        case INVALID_PROJECT:
            return Messages.bind(Messages.status_invalidProject, this.string);

        case INVALID_RESOURCE:
            return Messages.bind(Messages.status_invalidResource, this.string);

        case INVALID_RESOURCE_TYPE:
            return Messages.bind(Messages.status_invalidResourceType, this.string);

        case INVALID_SIBLING:
            if (this.string != null) {
                return Messages.bind(Messages.status_invalidSibling, this.string);
            } else {
                return Messages.bind(Messages.status_invalidSibling,
                        ((JavaElement) this.elements[0]).toStringWithAncestors());
            }

        case IO_EXCEPTION:
            return Messages.status_IOException;

        case NAME_COLLISION:
            if (this.elements != null && this.elements.length > 0) {
                IJavaElement element = this.elements[0];
                if (element instanceof org.eclipse.jdt.internal.core.PackageFragment
                        && ((PackageFragment) element).isDefaultPackage()) {
                    return Messages.operation_cannotRenameDefaultPackage;
                }
            }
            if (this.string != null) {
                return this.string;
            } else {
                return Messages.bind(Messages.status_nameCollision, ""); //$NON-NLS-1$
            }
        case NO_ELEMENTS_TO_PROCESS:
            return Messages.operation_needElements;

        case NULL_NAME:
            return Messages.operation_needName;

        case NULL_PATH:
            return Messages.operation_needPath;

        case NULL_STRING:
            return Messages.operation_needString;

        case PATH_OUTSIDE_PROJECT:
            return Messages.bind(Messages.operation_pathOutsideProject,
                    new String[] { this.string, ((JavaElement) this.elements[0]).toStringWithAncestors() });

        case READ_ONLY:
            IJavaElement element = this.elements[0];
            String name = element.getElementName();
            if (element instanceof IPackageFragment && name.equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) {
                return Messages.status_defaultPackageReadOnly;
            }
            return Messages.bind(Messages.status_readOnly, name);

        case RELATIVE_PATH:
            return Messages.bind(Messages.operation_needAbsolutePath, getPath().toString());

        case TARGET_EXCEPTION:
            return Messages.status_targetException;

        case UPDATE_CONFLICT:
            return Messages.status_updateConflict;

        case NO_LOCAL_CONTENTS:
            return Messages.bind(Messages.status_noLocalContents, getPath().toString());

        case CP_CONTAINER_PATH_UNBOUND:
            IJavaProject javaProject = (IJavaProject) this.elements[0];
            ClasspathContainerInitializer initializer = JavaCore
                    .getClasspathContainerInitializer(this.path.segment(0));
            String description = null;
            if (initializer != null)
                description = initializer.getDescription(this.path, javaProject);
            if (description == null)
                description = this.path.makeRelative().toString();
            return Messages.bind(Messages.classpath_unboundContainerPath,
                    new String[] { description, javaProject.getElementName() });

        case INVALID_CP_CONTAINER_ENTRY:
            javaProject = (IJavaProject) this.elements[0];
            IClasspathContainer container = null;
            description = null;
            try {
                container = JavaCore.getClasspathContainer(this.path, javaProject);
            } catch (JavaModelException e) {
                // project doesn't exist: ignore
            }
            if (container == null) {
                initializer = JavaCore.getClasspathContainerInitializer(this.path.segment(0));
                if (initializer != null)
                    description = initializer.getDescription(this.path, javaProject);
            } else {
                description = container.getDescription();
            }
            if (description == null)
                description = this.path.makeRelative().toString();
            return Messages.bind(Messages.classpath_invalidContainer,
                    new String[] { description, javaProject.getElementName() });

        case CP_VARIABLE_PATH_UNBOUND:
            javaProject = (IJavaProject) this.elements[0];
            return Messages.bind(Messages.classpath_unboundVariablePath,
                    new String[] { this.path.makeRelative().toString(), javaProject.getElementName() });

        case CLASSPATH_CYCLE:
            javaProject = (IJavaProject) this.elements[0];
            return Messages.bind(Messages.classpath_cycle,
                    new String[] { javaProject.getElementName(), this.string });

        case DISABLED_CP_EXCLUSION_PATTERNS:
            javaProject = (IJavaProject) this.elements[0];
            String projectName = javaProject.getElementName();
            IPath newPath = this.path;
            if (this.path.segment(0).toString().equals(projectName)) {
                newPath = this.path.removeFirstSegments(1);
            }
            return Messages.bind(Messages.classpath_disabledInclusionExclusionPatterns,
                    new String[] { newPath.makeRelative().toString(), projectName });

        case DISABLED_CP_MULTIPLE_OUTPUT_LOCATIONS:
            javaProject = (IJavaProject) this.elements[0];
            projectName = javaProject.getElementName();
            newPath = this.path;
            if (this.path.segment(0).toString().equals(projectName)) {
                newPath = this.path.removeFirstSegments(1);
            }
            return Messages.bind(Messages.classpath_disabledMultipleOutputLocations,
                    new String[] { newPath.makeRelative().toString(), projectName });

        case CANNOT_RETRIEVE_ATTACHED_JAVADOC:
            if (this.elements != null && this.elements.length == 1) {
                if (this.string != null) {
                    return Messages.bind(Messages.status_cannot_retrieve_attached_javadoc,
                            ((JavaElement) this.elements[0]).toStringWithAncestors(), this.string);
                }
                return Messages.bind(Messages.status_cannot_retrieve_attached_javadoc,
                        ((JavaElement) this.elements[0]).toStringWithAncestors(), ""); //$NON-NLS-1$
            }
            if (this.string != null) {
                return Messages.bind(Messages.status_cannot_retrieve_attached_javadoc, this.string, "");//$NON-NLS-1$
            }
            break;

        case CANNOT_RETRIEVE_ATTACHED_JAVADOC_TIMEOUT:
            if (this.elements != null && this.elements.length == 1) {
                if (this.string != null) {
                    return Messages.bind(Messages.status_timeout_javadoc,
                            ((JavaElement) this.elements[0]).toStringWithAncestors(), this.string);
                }
                return Messages.bind(Messages.status_timeout_javadoc,
                        ((JavaElement) this.elements[0]).toStringWithAncestors(), ""); //$NON-NLS-1$
            }
            if (this.string != null) {
                return Messages.bind(Messages.status_timeout_javadoc, this.string, "");//$NON-NLS-1$
            }
            break;

        case UNKNOWN_JAVADOC_FORMAT:
            return Messages.bind(Messages.status_unknown_javadoc_format,
                    ((JavaElement) this.elements[0]).toStringWithAncestors());

        case DEPRECATED_VARIABLE:
            javaProject = (IJavaProject) this.elements[0];
            return Messages.bind(Messages.classpath_deprecated_variable, new String[] {
                    this.path.segment(0).toString(), javaProject.getElementName(), this.string });
        }
        if (this.string != null) {
            return this.string;
        } else {
            return ""; //$NON-NLS-1$
        }
    } else {
        String message = exception.getMessage();
        if (message != null) {
            return message;
        } else {
            return exception.toString();
        }
    }
}

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

License:Open Source License

public String getFullyQualifiedName(char enclosingTypeSeparator, boolean showParameters)
        throws JavaModelException {
    String packageName = getPackageFragment().getElementName();
    if (packageName.equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) {
        return getTypeQualifiedName(enclosingTypeSeparator, showParameters);
    }/*from  ww w.  ja va 2  s.  co m*/
    return packageName + '.' + getTypeQualifiedName(enclosingTypeSeparator, showParameters);
}

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

License:Open Source License

/**
 * Find type. Considering secondary types and waiting for indexes depends on given corresponding parameters.
 *//*from w  w  w . j a  v  a2 s.  c  om*/
public Answer findType(String typeName, String packageName, boolean partialMatch, int acceptFlags,
        boolean considerSecondaryTypes, boolean waitForIndexes, boolean checkRestrictions,
        IProgressMonitor monitor) {
    if (packageName == null || packageName.length() == 0) {
        packageName = IPackageFragment.DEFAULT_PACKAGE_NAME;
    } else if (typeName.length() > 0 && ScannerHelper.isLowerCase(typeName.charAt(0))) {
        // see if this is a known package and not a type
        if (findPackageFragments(packageName + "." + typeName, false) != null) //$NON-NLS-1$
            return null;
    }

    // Look for concerned package fragments
    JavaElementRequestor elementRequestor = new JavaElementRequestor();
    seekPackageFragments(packageName, false, elementRequestor);
    IPackageFragment[] packages = elementRequestor.getPackageFragments();

    // Try to find type in package fragments list
    IType type = null;
    int length = packages.length;
    HashSet projects = null;
    IJavaProject javaProject = null;
    Answer suggestedAnswer = null;
    for (int i = 0; i < length; i++) {
        type = findType(typeName, packages[i], partialMatch, acceptFlags, waitForIndexes,
                considerSecondaryTypes);
        if (type != null) {
            AccessRestriction accessRestriction = null;
            if (checkRestrictions) {
                accessRestriction = getViolatedRestriction(typeName, packageName, type, accessRestriction);
            }
            Answer answer = new Answer(type, accessRestriction);
            if (!answer.ignoreIfBetter()) {
                if (answer.isBetter(suggestedAnswer))
                    return answer;
            } else if (answer.isBetter(suggestedAnswer))
                // remember suggestion and keep looking
                suggestedAnswer = answer;
        } else if (suggestedAnswer == null && considerSecondaryTypes) {
            if (javaProject == null) {
                javaProject = packages[i].getJavaProject();
            } else if (projects == null) {
                if (!javaProject.equals(packages[i].getJavaProject())) {
                    projects = new HashSet(3);
                    projects.add(javaProject);
                    projects.add(packages[i].getJavaProject());
                }
            } else {
                projects.add(packages[i].getJavaProject());
            }
        }
    }
    if (suggestedAnswer != null)
        // no better answer was found
        return suggestedAnswer;

    // If type was not found, try to find it as secondary in source folders
    if (considerSecondaryTypes && javaProject != null) {
        if (projects == null) {
            type = findSecondaryType(packageName, typeName, javaProject, waitForIndexes, monitor);
        } else {
            Iterator allProjects = projects.iterator();
            while (type == null && allProjects.hasNext()) {
                type = findSecondaryType(packageName, typeName, (IJavaProject) allProjects.next(),
                        waitForIndexes, monitor);
            }
        }
    }
    if (type != null) {
        ICompilationUnit unit = type.getCompilationUnit();
        if (unit != null && unit.isWorkingCopy()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421902
            IType[] types = null;
            try {
                types = unit.getTypes();
            } catch (JavaModelException e) {
                return null;
            }
            boolean typeFound = false;
            for (int i = 0, typesLength = types == null ? 0 : types.length; i < typesLength; i++) {
                if (types[i].getElementName().equals(typeName)) {
                    typeFound = true;
                    break;
                }
            }
            if (!typeFound)
                type = null;
        }
    }
    return type == null ? null : new Answer(type, null);
}

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

License:Open Source License

public Answer findType(String name, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes,
        boolean waitForIndexes, boolean checkRestrictions, IProgressMonitor monitor) {
    int index = name.lastIndexOf('.');
    if (index == 0) {
        return null; // bug 377710 - e.g. ".Foo" (no package, but not "default" package)
    }//w ww. jav a  2s  . c  om
    String className = null, packageName = null;
    if (index == -1) {
        packageName = IPackageFragment.DEFAULT_PACKAGE_NAME;
        className = name;
    } else {
        packageName = name.substring(0, index);
        className = name.substring(index + 1);
    }
    return findType(className, packageName, partialMatch, acceptFlags, considerSecondaryTypes, waitForIndexes,
            checkRestrictions, monitor);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected IType lookupType(ReferenceBinding typeBinding) {
    if (typeBinding == null || !typeBinding.isValidBinding())
        return null;

    char[] packageName = typeBinding.qualifiedPackageName();
    IPackageFragment[] pkgs = this.nameLookup.findPackageFragments(
            (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME
                    : new String(packageName),
            false);/*from   www  .  ja  v  a 2s .com*/

    // iterate type lookup in each package fragment
    char[] sourceName = typeBinding.qualifiedSourceName();
    String typeName = new String(sourceName);
    int acceptFlag = 0;
    if (typeBinding.isAnnotationType()) {
        acceptFlag = NameLookup.ACCEPT_ANNOTATIONS;
    } else if (typeBinding.isEnum()) {
        acceptFlag = NameLookup.ACCEPT_ENUMS;
    } else if (typeBinding.isInterface()) {
        acceptFlag = NameLookup.ACCEPT_INTERFACES;
    } else if (typeBinding.isClass()) {
        acceptFlag = NameLookup.ACCEPT_CLASSES;
    }
    if (pkgs != null) {
        for (int i = 0, length = pkgs.length; i < length; i++) {
            IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag,
                    true/*consider secondary types*/);
            if (type != null)
                return type;
        }
    }

    // search inside enclosing element
    char[][] qualifiedName = CharOperation.splitOn('.', sourceName);
    int length = qualifiedName.length;
    if (length == 0)
        return null;

    IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type
    if (type == null)
        return null;

    for (int i = 1; i < length; i++) {
        type = type.getType(new String(qualifiedName[i]));
        if (type == null)
            return null;
    }
    if (type.exists())
        return type;
    return null;
}

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

License:Open Source License

/**
 * Returns the given type in the the given package if it exists,
 * otherwise <code>null</code>.
 *//*from  ww  w . ja  v  a  2 s  . com*/
protected NameEnvironmentAnswer find(String typeName, String packageName) {
    if (packageName == null)
        packageName = IPackageFragment.DEFAULT_PACKAGE_NAME;
    if (this.owner != null) {
        String source = this.owner.findSource(typeName, packageName);
        if (source != null) {
            ICompilationUnit cu = new BasicCompilationUnit(source.toCharArray(),
                    CharOperation.splitOn('.', packageName.toCharArray()),
                    typeName + Util.defaultJavaExtension());
            return new NameEnvironmentAnswer(cu, null);
        }
    }
    NameLookup.Answer answer = this.nameLookup.findType(typeName, packageName, false/*exact match*/,
            NameLookup.ACCEPT_ALL, this.checkAccessRestrictions);
    if (answer != null) {
        // construct name env answer
        if (answer.type instanceof BinaryType) { // BinaryType
            try {
                return new NameEnvironmentAnswer((IBinaryType) ((BinaryType) answer.type).getElementInfo(),
                        answer.restriction);
            } catch (JavaModelException npe) {
                // fall back to using owner
            }
        } else { //SourceType
            try {
                // retrieve the requested type
                SourceTypeElementInfo sourceType = (SourceTypeElementInfo) ((SourceType) answer.type)
                        .getElementInfo();
                ISourceType topLevelType = sourceType;
                while (topLevelType.getEnclosingType() != null) {
                    topLevelType = topLevelType.getEnclosingType();
                }
                // find all siblings (other types declared in same unit, since may be used for name resolution)
                IType[] types = sourceType.getHandle().getCompilationUnit().getTypes();
                ISourceType[] sourceTypes = new ISourceType[types.length];

                // in the resulting collection, ensure the requested type is the first one
                sourceTypes[0] = sourceType;
                int length = types.length;
                for (int i = 0, index = 1; i < length; i++) {
                    ISourceType otherType = (ISourceType) ((JavaElement) types[i]).getElementInfo();
                    if (!otherType.equals(topLevelType) && index < length) // check that the index is in bounds (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=62861)
                        sourceTypes[index++] = otherType;
                }
                return new NameEnvironmentAnswer(sourceTypes, answer.restriction);
            } catch (JavaModelException jme) {
                if (jme.isDoesNotExist() && String.valueOf(TypeConstants.PACKAGE_INFO_NAME).equals(typeName)) {
                    // in case of package-info.java the type doesn't exist in the model,
                    // but the CU may still help in order to fetch package level annotations.
                    return new NameEnvironmentAnswer((ICompilationUnit) answer.type.getParent(),
                            answer.restriction);
                }
                // no usable answer
            }
        }
    }
    return null;
}

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

License:Open Source License

public static PackageFragment getParentPackage(IFile ajFile) {
    IJavaProject jp = JavaCore.create(ajFile.getProject());
    IJavaElement elem = JavaModelManager.determineIfOnClasspath(ajFile, jp);
    if (elem == null) {
        //not on classpath -> default package
        IPackageFragmentRoot root = jp.getPackageFragmentRoot(ajFile.getParent());
        elem = root.getPackageFragment(IPackageFragment.DEFAULT_PACKAGE_NAME);
    }/* w  w w  .  ja  v a2  s. c o m*/
    if (elem instanceof PackageFragment) {
        return (PackageFragment) elem;
    }
    //should never happen

    return null;
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected IType lookupType(ReferenceBinding typeBinding) {
    if (typeBinding == null || !typeBinding.isValidBinding())
        return null;

    char[] packageName = typeBinding.qualifiedPackageName();
    IPackageFragment[] pkgs = this.nameLookup.findPackageFragments(
            (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME
                    : new String(packageName),
            false);/*from w  ww.j  av a  2 s  .c o  m*/

    // iterate type lookup in each package fragment
    char[] sourceName = typeBinding.qualifiedSourceName();
    String typeName = new String(sourceName);
    int acceptFlag = 0;
    if (typeBinding.isAnnotationType()) {
        acceptFlag = NameLookup.ACCEPT_ANNOTATIONS;
    } else if (typeBinding.isEnum()) {
        acceptFlag = NameLookup.ACCEPT_ENUMS;
    } else if (typeBinding.isInterface()) {
        acceptFlag = NameLookup.ACCEPT_INTERFACES;
    } else if (typeBinding.isClass()) {
        acceptFlag = NameLookup.ACCEPT_CLASSES;
    }
    if (pkgs != null) {
        for (int i = 0, length = pkgs.length; i < length; i++) {
            IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag, false,
                    true/*consider secondary types*/);
            if (type != null)
                return type;
        }
    }

    // search inside enclosing element
    char[][] qualifiedName = CharOperation.splitOn('.', sourceName);
    int length = qualifiedName.length;
    if (length == 0)
        return null;

    IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type
    if (type == null)
        return null;

    for (int i = 1; i < length; i++) {
        type = type.getType(new String(qualifiedName[i]));
        if (type == null)
            return null;
    }
    if (type.exists())
        return type;
    return null;
}

From source file:org.eclipse.che.jdt.internal.core.search.Util.java

License:Open Source License

/**
 * Converts the given relative path into a package name.
 * Returns null if the path is not a valid package name.
 * @param pkgPath the package path/*from w  w  w.  j av a 2 s. com*/
 * @param sourceLevel the source level
 * @param complianceLevel the compliance level
 */
public static String packageName(IPath pkgPath, String sourceLevel, String complianceLevel) {
    StringBuffer pkgName = new StringBuffer(IPackageFragment.DEFAULT_PACKAGE_NAME);
    for (int j = 0, max = pkgPath.segmentCount(); j < max; j++) {
        String segment = pkgPath.segment(j);
        if (!isValidFolderNameForPackage(segment, sourceLevel, complianceLevel)) {
            return null;
        }
        pkgName.append(segment);
        if (j < pkgPath.segmentCount() - 1) {
            pkgName.append("."); //$NON-NLS-1$
        }
    }
    return pkgName.toString();
}

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected IType lookupType(ReferenceBinding typeBinding) {
    if (typeBinding == null)
        return null;

    char[] packageName = typeBinding.qualifiedPackageName();
    IPackageFragment[] pkgs = this.nameLookup.findPackageFragments(
            (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME
                    : new String(packageName),
            false);//w ww  .j  a  v  a 2 s.  c o  m

    // iterate type lookup in each package fragment
    char[] sourceName = typeBinding.qualifiedSourceName();
    String typeName = new String(sourceName);
    int acceptFlag = 0;
    if (typeBinding.isAnnotationType()) {
        acceptFlag = NameLookup.ACCEPT_ANNOTATIONS;
    } else if (typeBinding.isEnum()) {
        acceptFlag = NameLookup.ACCEPT_ENUMS;
    } else if (typeBinding.isInterface()) {
        acceptFlag = NameLookup.ACCEPT_INTERFACES;
    } else if (typeBinding.isClass()) {
        acceptFlag = NameLookup.ACCEPT_CLASSES;
    }
    if (pkgs != null) {
        for (int i = 0, length = pkgs.length; i < length; i++) {
            IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag,
                    true/*consider secondary types*/);
            if (type != null)
                return type;
        }
    }

    // search inside enclosing element
    char[][] qualifiedName = CharOperation.splitOn('.', sourceName);
    int length = qualifiedName.length;
    if (length == 0)
        return null;

    IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type
    if (type == null)
        return null;

    for (int i = 1; i < length; i++) {
        type = type.getType(new String(qualifiedName[i]));
        if (type == null)
            return null;
    }
    if (type.exists())
        return type;
    return null;
}