Example usage for org.eclipse.jdt.internal.core SearchableEnvironment findExactTypes

List of usage examples for org.eclipse.jdt.internal.core SearchableEnvironment findExactTypes

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core SearchableEnvironment findExactTypes.

Prototype

public void findExactTypes(char[] name, final boolean findMembers, int searchFor,
        final ISearchRequestor storage) 

Source Link

Document

Find the top-level types that are defined in the current environment and whose simple name matches the given name.

Usage

From source file:org.eclipse.recommenders.internal.calls.rcp.templates.TemplatesCompletionProposalComputer.java

License:Open Source License

public Set<IType> findTypesBySimpleName(char[] simpleTypeName) {
    final Set<IType> result = Sets.newHashSet();
    try {//from  w ww.ja  v  a2  s .c  om
        final JavaProject project = (JavaProject) rCtx.getProject();
        SearchableEnvironment environment = project
                .newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY);
        environment.findExactTypes(simpleTypeName, false, IJavaSearchConstants.TYPE, new ISearchRequestor() {
            @Override
            public void acceptConstructor(int modifiers, char[] simpleTypeName, int parameterCount,
                    char[] signature, char[][] parameterTypes, char[][] parameterNames, int typeModifiers,
                    char[] packageName, int extraFlags, String path, AccessRestriction access) {
            }

            @Override
            public void acceptType(char[] packageName, char[] typeName, char[][] enclosingTypeNames,
                    int modifiers, AccessRestriction accessRestriction) {
                IType res;
                try {
                    res = project.findType(String.valueOf(packageName), String.valueOf(typeName));
                    if (res != null) {
                        result.add(res);
                    }
                } catch (JavaModelException e) {
                    log(ERROR_FAILED_TO_FIND_TYPE, e, packageName, typeName);
                }
            }

            @Override
            public void acceptPackage(char[] packageName) {
            }
        });
    } catch (JavaModelException e) {
        Throws.throwUnhandledException(e);
    }
    return result;
}