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

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

Introduction

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

Prototype

public SearchableEnvironment newSearchableNameEnvironment(WorkingCopyOwner owner) throws JavaModelException 

Source Link

Usage

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

License:Open Source License

/**
 * @see IType#resolveType(String, org.eclipse.jdt.core.WorkingCopyOwner)
 *///from  w ww  .j  a  v a  2 s .  co  m
public String[][] resolveType(String typeName, WorkingCopyOwner owner) throws JavaModelException {
    JavaProject project = (JavaProject) getJavaProject();
    SearchableEnvironment environment = project.newSearchableNameEnvironment(owner);

    class TypeResolveRequestor implements ISelectionRequestor {
        String[][] answers = null;

        public void acceptType(char[] packageName, char[] tName, int modifiers, boolean isDeclaration,
                char[] uniqueKey, int start, int end) {
            String[] answer = new String[] { new String(packageName), new String(tName) };
            if (this.answers == null) {
                this.answers = new String[][] { answer };
            } else {
                // grow
                int length = this.answers.length;
                System.arraycopy(this.answers, 0, this.answers = new String[length + 1][], 0, length);
                this.answers[length] = answer;
            }
        }

        public void acceptError(CategorizedProblem error) {
            // ignore
        }

        public void acceptField(char[] declaringTypePackageName, char[] declaringTypeName, char[] fieldName,
                boolean isDeclaration, char[] uniqueKey, int start, int end) {
            // ignore
        }

        public void acceptMethod(char[] declaringTypePackageName, char[] declaringTypeName,
                String enclosingDeclaringTypeSignature, char[] selector, char[][] parameterPackageNames,
                char[][] parameterTypeNames, String[] parameterSignatures, char[][] typeParameterNames,
                char[][][] typeParameterBoundNames, boolean isConstructor, boolean isDeclaration,
                char[] uniqueKey, int start, int end) {
            // ignore
        }

        public void acceptPackage(char[] packageName) {
            // ignore
        }

        public void acceptTypeParameter(char[] declaringTypePackageName, char[] declaringTypeName,
                char[] typeParameterName, boolean isDeclaration, int start, int end) {
            // ignore
        }

        public void acceptMethodTypeParameter(char[] declaringTypePackageName, char[] declaringTypeName,
                char[] selector, int selectorStart, int selcetorEnd, char[] typeParameterName,
                boolean isDeclaration, int start, int end) {
            // ignore
        }

    }
    TypeResolveRequestor requestor = new TypeResolveRequestor();
    SelectionEngine engine = new SelectionEngine(environment, requestor, project.getOptions(true), owner,
            project.getIndexManager(), project);

    engine.selectType(typeName.toCharArray(), (IType) this);
    if (NameLookup.VERBOSE) {
        System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " //$NON-NLS-1$
                + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$
        System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " //$NON-NLS-1$
                + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$
    }
    return requestor.answers;
}

From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyBuilder.java

License:Open Source License

public HierarchyBuilder(TypeHierarchy hierarchy) throws JavaModelException {

    this.hierarchy = hierarchy;
    JavaProject project = (JavaProject) hierarchy.javaProject();

    IType focusType = hierarchy.getType();
    org.eclipse.jdt.core.ICompilationUnit unitToLookInside = focusType == null ? null
            : focusType.getCompilationUnit();
    org.eclipse.jdt.core.ICompilationUnit[] workingCopies = this.hierarchy.workingCopies;
    org.eclipse.jdt.core.ICompilationUnit[] unitsToLookInside;
    if (unitToLookInside != null) {
        int wcLength = workingCopies == null ? 0 : workingCopies.length;
        if (wcLength == 0) {
            unitsToLookInside = new org.eclipse.jdt.core.ICompilationUnit[] { unitToLookInside };
        } else {/*from  w w w  . j a v a2  s  .c o m*/
            unitsToLookInside = new org.eclipse.jdt.core.ICompilationUnit[wcLength + 1];
            unitsToLookInside[0] = unitToLookInside;
            System.arraycopy(workingCopies, 0, unitsToLookInside, 1, wcLength);
        }
    } else {
        unitsToLookInside = workingCopies;
    }
    if (project != null) {
        // GROOVY start - pulled out of the call
        Map optionMap = project.getOptions(true);
        CompilerUtils.configureOptionsBasedOnNature(optionMap, project);
        // GROOVY end
        SearchableEnvironment searchableEnvironment = project.newSearchableNameEnvironment(unitsToLookInside);
        this.nameLookup = searchableEnvironment.nameLookup;
        this.hierarchyResolver = new HierarchyResolver(searchableEnvironment,
                // GROOVY start
                /* old {
                project.getOptions(true),
                } new */
                optionMap,
                // GROOVY end
                this, new DefaultProblemFactory());
    }
    this.infoToHandle = new HashMap(5);
    this.focusQualifiedName = focusType == null ? null : focusType.getFullyQualifiedName();
}

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

License:Open Source License

/**
 * Create a new parser for the given project, as well as a lookup environment.
 *///from w ww.j  ava  2 s  . co m
public void initialize(JavaProject project, int possibleMatchSize) throws JavaModelException {
    // clean up name environment only if there are several possible match as it is reused
    // when only one possible match (bug 58581)
    if (this.nameEnvironment != null && possibleMatchSize != 1)
        this.nameEnvironment.cleanup();

    SearchableEnvironment searchableEnvironment = project.newSearchableNameEnvironment(this.workingCopies);

    // if only one possible match, a file name environment costs too much,
    // so use the existing searchable  environment which will populate the java model
    // only for this possible match and its required types.
    this.nameEnvironment = possibleMatchSize == 1 ? (INameEnvironment) searchableEnvironment
            : (INameEnvironment) new JavaSearchNameEnvironment(project, this.workingCopies);

    // create lookup environment
    Map map = project.getOptions(true);
    map.put(CompilerOptions.OPTION_TaskTags, org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING);
    this.options = new CompilerOptions(map);
    ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            this.options, new DefaultProblemFactory());
    this.lookupEnvironment = new LookupEnvironment(this, this.options, problemReporter, this.nameEnvironment);

    this.parser = MatchLocatorParser.createParser(problemReporter, this);

    // basic parser needs also to be reset as project options may have changed
    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=163072
    this.basicParser = null;

    // remember project's name lookup
    this.nameLookup = searchableEnvironment.nameLookup;

    // initialize queue of units
    this.numberOfMatches = 0;
    this.matchesToProcess = new PossibleMatch[possibleMatchSize];
}

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 {/* w  ww . ja v  a  2 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;
}