List of usage examples for org.eclipse.jdt.internal.core.search BasicSearchEngine VERBOSE
boolean VERBOSE
To view the source code for org.eclipse.jdt.internal.core.search BasicSearchEngine VERBOSE.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaWorkspaceScope.java
License:Open Source License
public IPath[] enclosingProjectsAndJars() { IPath[] result = this.enclosingPaths; if (result != null) { return result; }/*from ww w .ja v a 2 s. co m*/ long start = BasicSearchEngine.VERBOSE ? System.currentTimeMillis() : -1; try { IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); // use a linked set to preserve the order during search: see bug 348507 Set paths = new LinkedHashSet(projects.length * 2); for (int i = 0, length = projects.length; i < length; i++) { JavaProject javaProject = (JavaProject) projects[i]; // Add project full path IPath projectPath = javaProject.getProject().getFullPath(); paths.add(projectPath); } // add the project source paths first in a separate loop above // to ensure source files always get higher precedence during search. // see bug 348507 for (int i = 0, length = projects.length; i < length; i++) { JavaProject javaProject = (JavaProject) projects[i]; // Add project libraries paths IClasspathEntry[] entries = javaProject.getResolvedClasspath(); for (int j = 0, eLength = entries.length; j < eLength; j++) { IClasspathEntry entry = entries[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = entry.getPath(); Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); paths.add(entry.getPath()); } } } result = new IPath[paths.size()]; paths.toArray(result); return this.enclosingPaths = result; } catch (JavaModelException e) { Util.log(e, "Exception while computing workspace scope's enclosing projects and jars"); //$NON-NLS-1$ return new IPath[0]; } finally { if (BasicSearchEngine.VERBOSE) { long time = System.currentTimeMillis() - start; int length = result == null ? 0 : result.length; Util.verbose("JavaWorkspaceScope.enclosingProjectsAndJars: " + length + " paths computed in " + time //$NON-NLS-1$//$NON-NLS-2$ + "ms."); //$NON-NLS-1$ } } }
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTModelLoader.java
License:Open Source License
public void createLookupEnvironment() { try {//from w ww. j a va 2 s. c o m lookupEnvironment = new LookupEnvironment(new ITypeRequestor() { private Parser basicParser; @Override public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) { // case of SearchableEnvironment of an IJavaProject is used ISourceType sourceType = sourceTypes[0]; while (sourceType.getEnclosingType() != null) sourceType = sourceType.getEnclosingType(); if (sourceType instanceof SourceTypeElementInfo) { // get source SourceTypeElementInfo elementInfo = (SourceTypeElementInfo) sourceType; IType type = elementInfo.getHandle(); ICompilationUnit sourceUnit = (ICompilationUnit) type.getCompilationUnit(); accept(sourceUnit, accessRestriction); } else { CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, 0); CompilationUnitDeclaration unit = SourceTypeConverter.buildCompilationUnit(sourceTypes, SourceTypeConverter.FIELD_AND_METHOD // need field and methods | SourceTypeConverter.MEMBER_TYPE, // need member types // no need for field initialization lookupEnvironment.problemReporter, result); lookupEnvironment.buildTypeBindings(unit, accessRestriction); lookupEnvironment.completeTypeBindings(unit, true); } } @Override public void accept(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) { lookupEnvironment.createBinaryTypeFrom(binaryType, packageBinding, accessRestriction); } @Override public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) { // Switch the current policy and compilation result for this unit to the requested one. CompilationResult unitResult = new CompilationResult(sourceUnit, 1, 1, compilerOptions.maxProblemsPerUnit); try { CompilationUnitDeclaration parsedUnit = basicParser().dietParse(sourceUnit, unitResult); lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction); lookupEnvironment.completeTypeBindings(parsedUnit, true); } catch (AbortCompilationUnit e) { // at this point, currentCompilationUnitResult may not be sourceUnit, but some other // one requested further along to resolve sourceUnit. if (unitResult.compilationUnit == sourceUnit) { // only report once //requestor.acceptResult(unitResult.tagAsAccepted()); } else { throw e; // want to abort enclosing request to compile } } // Display unit error in debug mode if (BasicSearchEngine.VERBOSE) { if (unitResult.problemCount > 0) { System.out.println(unitResult); } } } private Parser basicParser() { if (this.basicParser == null) { ProblemReporter problemReporter = new ProblemReporter( DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, new DefaultProblemFactory()); this.basicParser = new Parser(problemReporter, false); this.basicParser.reportOnlyOneSyntaxError = true; } return this.basicParser; } }, compilerOptions, problemReporter, ((JavaProject) javaProject).newSearchableNameEnvironment((WorkingCopyOwner) null)); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.eclipse.che.jdt.internal.core.search.JavaWorkspaceScope.java
License:Open Source License
public IPath[] enclosingProjectsAndJars() { IPath[] result = this.enclosingPaths; if (result != null) { return result; }//from ww w. ja v a 2 s . c om long start = org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE ? System.currentTimeMillis() : -1; try { IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); // use a linked set to preserve the order during search: see bug 348507 Set paths = new LinkedHashSet(projects.length * 2); for (int i = 0, length = projects.length; i < length; i++) { JavaProject javaProject = (JavaProject) projects[i]; // Add project full path IPath projectPath = javaProject.getProject().getFullPath(); paths.add(projectPath); } // add the project source paths first in a separate loop above // to ensure source files always get higher precedence during search. // see bug 348507 for (int i = 0, length = projects.length; i < length; i++) { JavaProject javaProject = (JavaProject) projects[i]; // Add project libraries paths IClasspathEntry[] entries = javaProject.getResolvedClasspath(); for (int j = 0, eLength = entries.length; j < eLength; j++) { IClasspathEntry entry = entries[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = entry.getPath(); Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); paths.add(entry.getPath()); } } } result = new IPath[paths.size()]; paths.toArray(result); return this.enclosingPaths = result; } catch (JavaModelException e) { Util.log(e, "Exception while computing workspace scope's enclosing projects and jars"); //$NON-NLS-1$ return new IPath[0]; } finally { if (BasicSearchEngine.VERBOSE) { long time = System.currentTimeMillis() - start; int length = result == null ? 0 : result.length; Util.verbose("JavaWorkspaceScope.enclosingProjectsAndJars: " + length + " paths computed in " + time //$NON-NLS-1$//$NON-NLS-2$ + "ms."); //$NON-NLS-1$ } } }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
/** * Configure the plugin with respect to option settings defined in ".options" file *//*from ww w .j a va2s .co m*/ public void configurePluginDebugOptions() { if (JavaCore.getPlugin().isDebugging()) { String option = Platform.getDebugOption(BUFFER_MANAGER_DEBUG); if (option != null) BufferManager.VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(BUILDER_DEBUG); if (option != null) JavaBuilder.DEBUG = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(COMPILER_DEBUG); if (option != null) Compiler.DEBUG = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(BUILDER_STATS_DEBUG); if (option != null) JavaBuilder.SHOW_STATS = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(COMPLETION_DEBUG); if (option != null) CompletionEngine.DEBUG = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(CP_RESOLVE_DEBUG); if (option != null) JavaModelManager.CP_RESOLVE_VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(CP_RESOLVE_ADVANCED_DEBUG); if (option != null) JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(CP_RESOLVE_FAILURE_DEBUG); if (option != null) JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(DELTA_DEBUG); if (option != null) DeltaProcessor.DEBUG = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(DELTA_DEBUG_VERBOSE); if (option != null) DeltaProcessor.VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(HIERARCHY_DEBUG); if (option != null) TypeHierarchy.DEBUG = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(INDEX_MANAGER_DEBUG); if (option != null) JobManager.VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(INDEX_MANAGER_ADVANCED_DEBUG); if (option != null) IndexManager.DEBUG = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(JAVAMODEL_DEBUG); if (option != null) JavaModelManager.VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(JAVAMODELCACHE_DEBUG); if (option != null) JavaModelCache.VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(POST_ACTION_DEBUG); if (option != null) JavaModelOperation.POST_ACTION_VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(RESOLUTION_DEBUG); if (option != null) NameLookup.VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(SEARCH_DEBUG); if (option != null) BasicSearchEngine.VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(SELECTION_DEBUG); if (option != null) SelectionEngine.DEBUG = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(ZIP_ACCESS_DEBUG); if (option != null) JavaModelManager.ZIP_ACCESS_VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(SOURCE_MAPPER_DEBUG_VERBOSE); if (option != null) SourceMapper.VERBOSE = option.equalsIgnoreCase(TRUE); option = Platform.getDebugOption(FORMATTER_DEBUG); if (option != null) DefaultCodeFormatter.DEBUG = option.equalsIgnoreCase(TRUE); } // configure performance options if (PerformanceStats.ENABLED) { CompletionEngine.PERF = PerformanceStats.isEnabled(COMPLETION_PERF); SelectionEngine.PERF = PerformanceStats.isEnabled(SELECTION_PERF); DeltaProcessor.PERF = PerformanceStats.isEnabled(DELTA_LISTENER_PERF); JavaModelManager.PERF_VARIABLE_INITIALIZER = PerformanceStats.isEnabled(VARIABLE_INITIALIZER_PERF); JavaModelManager.PERF_CONTAINER_INITIALIZER = PerformanceStats.isEnabled(CONTAINER_INITIALIZER_PERF); ReconcileWorkingCopyOperation.PERF = PerformanceStats.isEnabled(RECONCILE_PERF); } }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
private Map secondaryTypesSearching(IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor, final PerProjectInfo projectInfo) throws JavaModelException { if (VERBOSE || BasicSearchEngine.VERBOSE) { StringBuffer buffer = new StringBuffer("JavaModelManager.secondaryTypesSearch("); //$NON-NLS-1$ buffer.append(project.getElementName()); buffer.append(','); buffer.append(waitForIndexes);//from www . ja v a 2 s . c o m buffer.append(')'); Util.verbose(buffer.toString()); } final Hashtable secondaryTypes = new Hashtable(3); IRestrictedAccessTypeRequestor nameRequestor = new IRestrictedAccessTypeRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { String key = packageName == null ? "" : new String(packageName); //$NON-NLS-1$ HashMap types = (HashMap) secondaryTypes.get(key); if (types == null) types = new HashMap(3); types.put(new String(simpleTypeName), path); secondaryTypes.put(key, types); } }; // Build scope using prereq projects but only source folders IPackageFragmentRoot[] allRoots = project.getAllPackageFragmentRoots(); int length = allRoots.length, size = 0; IPackageFragmentRoot[] allSourceFolders = new IPackageFragmentRoot[length]; for (int i = 0; i < length; i++) { if (allRoots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { allSourceFolders[size++] = allRoots[i]; } } if (size < length) { System.arraycopy(allSourceFolders, 0, allSourceFolders = new IPackageFragmentRoot[size], 0, size); } // Search all secondary types on scope new BasicSearchEngine().searchAllSecondaryTypeNames(allSourceFolders, nameRequestor, waitForIndexes, monitor); // Build types from paths Iterator packages = secondaryTypes.values().iterator(); while (packages.hasNext()) { HashMap types = (HashMap) packages.next(); Iterator names = types.entrySet().iterator(); while (names.hasNext()) { Map.Entry entry = (Map.Entry) names.next(); String typeName = (String) entry.getKey(); String path = (String) entry.getValue(); if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(path)) { IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null); IType type = unit.getType(typeName); types.put(typeName, type); // replace stored path with type itself } else { names.remove(); } } } // Store result in per project info cache if still null or there's still an indexing cache (may have been set by another thread...) if (projectInfo.secondaryTypes == null || projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES) != null) { projectInfo.secondaryTypes = secondaryTypes; if (VERBOSE || BasicSearchEngine.VERBOSE) { System.out.print(Thread.currentThread() + " -> secondary paths stored in cache: "); //$NON-NLS-1$ System.out.println(); Iterator entries = secondaryTypes.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); String qualifiedName = (String) entry.getKey(); Util.verbose(" - " + qualifiedName + '-' + entry.getValue()); //$NON-NLS-1$ } } } return projectInfo.secondaryTypes; }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Add an additional compilation unit into the loop * -> build compilation unit declarations, their bindings and record their results. *///w w w. j a va 2 s . c o m public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) { // Switch the current policy and compilation result for this unit to the requested one. CompilationResult unitResult = new CompilationResult(sourceUnit, 1, 1, this.options.maxProblemsPerUnit); try { CompilationUnitDeclaration parsedUnit = basicParser().dietParse(sourceUnit, unitResult); this.lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction); this.lookupEnvironment.completeTypeBindings(parsedUnit, true); } catch (AbortCompilationUnit e) { // at this point, currentCompilationUnitResult may not be sourceUnit, but some other // one requested further along to resolve sourceUnit. if (unitResult.compilationUnit == sourceUnit) { // only report once //requestor.acceptResult(unitResult.tagAsAccepted()); } else { throw e; // want to abort enclosing request to compile } } // Display unit error in debug mode if (BasicSearchEngine.VERBOSE) { if (unitResult.problemCount > 0) { System.out.println(unitResult); } } }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Creates an IMethod from the given method declaration and type. *//* w ww .ja v a2 s . co m*/ protected IJavaElement createHandle(AbstractMethodDeclaration method, IJavaElement parent) { if (!(parent instanceof IType)) return parent; IType type = (IType) parent; Argument[] arguments = method.arguments; int argCount = arguments == null ? 0 : arguments.length; if (type.isBinary()) { // don't cache the methods of the binary type // fall thru if its a constructor with a synthetic argument... find it the slower way ClassFileReader reader = classFileReader(type); if (reader != null) { // build arguments names boolean firstIsSynthetic = false; if (reader.isMember() && method.isConstructor() && !Flags.isStatic(reader.getModifiers())) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=48261 firstIsSynthetic = true; argCount++; } char[][] argumentTypeNames = new char[argCount][]; for (int i = 0; i < argCount; i++) { char[] typeName = null; if (i == 0 && firstIsSynthetic) { typeName = type.getDeclaringType().getFullyQualifiedName().toCharArray(); } else if (arguments != null) { TypeReference typeRef = arguments[firstIsSynthetic ? i - 1 : i].type; typeName = CharOperation.concatWith(typeRef.getTypeName(), '.'); for (int k = 0, dim = typeRef.dimensions(); k < dim; k++) typeName = CharOperation.concat(typeName, new char[] { '[', ']' }); } if (typeName == null) { // invalid type name return null; } argumentTypeNames[i] = typeName; } // return binary method IMethod binaryMethod = createBinaryMethodHandle(type, method.selector, argumentTypeNames); if (binaryMethod == null) { // when first attempt fails, try with similar matches if any... PossibleMatch similarMatch = this.currentPossibleMatch.getSimilarMatch(); while (similarMatch != null) { type = ((ClassFile) similarMatch.openable).getType(); binaryMethod = createBinaryMethodHandle(type, method.selector, argumentTypeNames); if (binaryMethod != null) { return binaryMethod; } similarMatch = similarMatch.getSimilarMatch(); } } return binaryMethod; } if (BasicSearchEngine.VERBOSE) { System.out.println("Not able to createHandle for the method " + //$NON-NLS-1$ CharOperation.charToString(method.selector) + " May miss some results"); //$NON-NLS-1$ } return null; } String[] parameterTypeSignatures = new String[argCount]; if (arguments != null) { for (int i = 0; i < argCount; i++) { TypeReference typeRef = arguments[i].type; char[] typeName = CharOperation.concatWith(typeRef.getParameterizedTypeName(), '.'); parameterTypeSignatures[i] = Signature.createTypeSignature(typeName, false); } } return createMethodHandle(type, new String(method.selector), parameterTypeSignatures); }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Locate the matches in the given files and report them using the search requestor. *//*from www.j a v a2 s .c om*/ public void locateMatches(SearchDocument[] searchDocuments) throws CoreException { if (this.patternLocator == null) return; int docsLength = searchDocuments.length; int progressLength = docsLength; if (BasicSearchEngine.VERBOSE) { System.out.println("Locating matches in documents ["); //$NON-NLS-1$ for (int i = 0; i < docsLength; i++) System.out.println("\t" + searchDocuments[i]); //$NON-NLS-1$ System.out.println("]"); //$NON-NLS-1$ } IJavaProject[] javaModelProjects = null; if (this.searchPackageDeclaration) { javaModelProjects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); progressLength += javaModelProjects.length; } // init infos for progress increasing int n = progressLength < 1000 ? Math.min(Math.max(progressLength / 200 + 1, 2), 4) : 5 * (progressLength / 1000); this.progressStep = progressLength < n ? 1 : progressLength / n; // step should not be 0 this.progressWorked = 0; // extract working copies ArrayList copies = new ArrayList(); for (int i = 0; i < docsLength; i++) { SearchDocument document = searchDocuments[i]; if (document instanceof WorkingCopyDocument) { copies.add(((WorkingCopyDocument) document).workingCopy); } } int copiesLength = copies.size(); this.workingCopies = new org.eclipse.jdt.core.ICompilationUnit[copiesLength]; copies.toArray(this.workingCopies); JavaModelManager manager = JavaModelManager.getJavaModelManager(); this.bindings = new SimpleLookupTable(); try { // optimize access to zip files during search operation manager.cacheZipFiles(this); // initialize handle factory (used as a cache of handles so as to optimize space) if (this.handleFactory == null) this.handleFactory = new HandleFactory(); if (this.progressMonitor != null) { this.progressMonitor.beginTask("", searchDocuments.length); //$NON-NLS-1$ } // initialize pattern for polymorphic search (i.e. method reference pattern) this.patternLocator.initializePolymorphicSearch(this); JavaProject previousJavaProject = null; PossibleMatchSet matchSet = new PossibleMatchSet(); Util.sort(searchDocuments, new Util.Comparer() { public int compare(Object a, Object b) { return ((SearchDocument) a).getPath().compareTo(((SearchDocument) b).getPath()); } }); int displayed = 0; // progress worked displayed String previousPath = null; SearchParticipant searchParticipant = null; for (int i = 0; i < docsLength; i++) { if (this.progressMonitor != null && this.progressMonitor.isCanceled()) { throw new OperationCanceledException(); } // skip duplicate paths SearchDocument searchDocument = searchDocuments[i]; if (searchParticipant == null) { searchParticipant = searchDocument.getParticipant(); } searchDocuments[i] = null; // free current document String pathString = searchDocument.getPath(); if (i > 0 && pathString.equals(previousPath)) { if (this.progressMonitor != null) { this.progressWorked++; if ((this.progressWorked % this.progressStep) == 0) this.progressMonitor.worked(this.progressStep); } displayed++; continue; } previousPath = pathString; Openable openable; org.eclipse.jdt.core.ICompilationUnit workingCopy = null; if (searchDocument instanceof WorkingCopyDocument) { workingCopy = ((WorkingCopyDocument) searchDocument).workingCopy; openable = (Openable) workingCopy; } else { openable = this.handleFactory.createOpenable(pathString, this.scope); } if (openable == null) { if (this.progressMonitor != null) { this.progressWorked++; if ((this.progressWorked % this.progressStep) == 0) this.progressMonitor.worked(this.progressStep); } displayed++; continue; // match is outside classpath } // create new parser and lookup environment if this is a new project IResource resource = null; JavaProject javaProject = (JavaProject) openable.getJavaProject(); resource = workingCopy != null ? workingCopy.getResource() : openable.getResource(); if (resource == null) resource = javaProject.getProject(); // case of a file in an external jar or external folder if (!javaProject.equals(previousJavaProject)) { // locate matches in previous project if (previousJavaProject != null) { try { locateMatches(previousJavaProject, matchSet, i - displayed); displayed = i; } catch (JavaModelException e) { // problem with classpath in this project -> skip it } matchSet.reset(); } previousJavaProject = javaProject; } matchSet.add(new PossibleMatch(this, resource, openable, searchDocument, this.pattern.mustResolve)); } // last project if (previousJavaProject != null) { try { locateMatches(previousJavaProject, matchSet, docsLength - displayed); } catch (JavaModelException e) { // problem with classpath in last project -> ignore } } if (this.searchPackageDeclaration) { locatePackageDeclarations(searchParticipant, javaModelProjects); } } finally { if (this.progressMonitor != null) this.progressMonitor.done(); if (this.nameEnvironment != null) this.nameEnvironment.cleanup(); manager.flushZipFiles(this); this.bindings = null; } }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Add the possibleMatch to the loop/*from w w w . j ava 2s . com*/ * -> build compilation unit declarations, their bindings and record their results. */ protected boolean parseAndBuildBindings(PossibleMatch possibleMatch, boolean mustResolve) throws CoreException { if (this.progressMonitor != null && this.progressMonitor.isCanceled()) throw new OperationCanceledException(); try { if (BasicSearchEngine.VERBOSE) System.out.println("Parsing " + possibleMatch.openable.toStringWithAncestors()); //$NON-NLS-1$ this.parser.nodeSet = possibleMatch.nodeSet; CompilationResult unitResult = new CompilationResult(possibleMatch, 1, 1, this.options.maxProblemsPerUnit); CompilationUnitDeclaration parsedUnit = this.parser.dietParse(possibleMatch, unitResult); if (parsedUnit != null) { if (!parsedUnit.isEmpty()) { if (mustResolve) { this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); } if (hasAlreadyDefinedType(parsedUnit)) return false; // skip type has it is hidden so not visible // GROOVY Start // old // getMethodBodies(parsedUnit, possibleMatch.nodeSet); // new // Only getMethodBodies for Java files if (!LanguageSupportFactory.isInterestingSourceFile(new String(parsedUnit.getFileName()))) { getMethodBodies(parsedUnit, possibleMatch.nodeSet); } // GROOVY End if (this.patternLocator.mayBeGeneric && !mustResolve && possibleMatch.nodeSet.mustResolve) { // special case: possible match node set force resolution although pattern does not // => we need to build types for this compilation unit this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); } } // add the possibleMatch with its parsedUnit to matchesToProcess possibleMatch.parsedUnit = parsedUnit; int size = this.matchesToProcess.length; if (this.numberOfMatches == size) System.arraycopy(this.matchesToProcess, 0, this.matchesToProcess = new PossibleMatch[size == 0 ? 1 : size * 2], 0, this.numberOfMatches); this.matchesToProcess[this.numberOfMatches++] = possibleMatch; } } finally { this.parser.nodeSet = null; } return true; }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected void process(PossibleMatch possibleMatch, boolean bindingsWereCreated) throws CoreException { // GROOVY Start // Do not process non-Java files. They use a separate delegated search if (LanguageSupportFactory.isInterestingSourceFile(new String(possibleMatch.getFileName()))) { try {//w w w . ja v a 2s. c o m this.lookupEnvironment.buildTypeBindings(possibleMatch.parsedUnit, null /*no access restriction*/); } catch (Throwable t) { t.printStackTrace(); } possibleMatch.parsedUnit.resolve(); return; } // GROOVY End this.currentPossibleMatch = possibleMatch; CompilationUnitDeclaration unit = possibleMatch.parsedUnit; try { if (unit.isEmpty()) { if (this.currentPossibleMatch.openable instanceof ClassFile) { ClassFile classFile = (ClassFile) this.currentPossibleMatch.openable; IBinaryType info = null; try { info = getBinaryInfo(classFile, classFile.resource()); } catch (CoreException ce) { // Do nothing } if (info != null) { boolean mayBeGeneric = this.patternLocator.mayBeGeneric; this.patternLocator.mayBeGeneric = false; // there's no longer generic in class files try { new ClassFileMatchLocator().locateMatches(this, classFile, info); } finally { this.patternLocator.mayBeGeneric = mayBeGeneric; } } } return; } if (hasAlreadyDefinedType(unit)) return; // skip type has it is hidden so not visible // Move getMethodBodies to #parseAndBuildings(...) method to allow possible match resolution management //getMethodBodies(unit); boolean mustResolve = (this.pattern.mustResolve || possibleMatch.nodeSet.mustResolve); if (bindingsWereCreated && mustResolve) { if (unit.types != null) { if (BasicSearchEngine.VERBOSE) System.out .println("Resolving " + this.currentPossibleMatch.openable.toStringWithAncestors()); //$NON-NLS-1$ this.lookupEnvironment.unitBeingCompleted = unit; reduceParseTree(unit); if (unit.scope != null) { // fault in fields & methods unit.scope.faultInTypes(); } unit.resolve(); } else if (unit.isPackageInfo()) { if (BasicSearchEngine.VERBOSE) System.out .println("Resolving " + this.currentPossibleMatch.openable.toStringWithAncestors()); //$NON-NLS-1$ unit.resolve(); } } reportMatching(unit, mustResolve); } catch (AbortCompilation e) { // could not resolve: report inaccurate matches reportMatching(unit, false); // do not resolve when cu has errors if (!(e instanceof AbortCompilationUnit)) { // problem with class path throw e; } } finally { this.lookupEnvironment.unitBeingCompleted = null; this.currentPossibleMatch = null; } }