Example usage for org.eclipse.jdt.internal.core JavaProject findType

List of usage examples for org.eclipse.jdt.internal.core JavaProject findType

Introduction

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

Prototype

@Override
public IType findType(String fullyQualifiedName, WorkingCopyOwner owner) throws JavaModelException 

Source Link

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