org.eclipse.jdt.core.search.TypeNameRequestor Java Examples

The following examples show how to use org.eclipse.jdt.core.search.TypeNameRequestor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void refreshSearchIndices(IProgressMonitor monitor) throws InvocationTargetException {
	try {
		new SearchEngine().searchAllTypeNames(
				null,
				0,
				// make sure we search a concrete name. This is faster according to Kent
				"_______________".toCharArray(), //$NON-NLS-1$
				SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
				IJavaSearchConstants.ENUM,
				SearchEngine.createWorkspaceScope(),
				new TypeNameRequestor() { /* dummy */},
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
				monitor);
	} catch (JavaModelException e) {
		throw new InvocationTargetException(e);
	}
}
 
Example #2
Source File: AbstractJavaModelTests.java    From dacapobench with Apache License 2.0 5 votes vote down vote up
public static void waitUntilIndexesReady() {
  // dummy query for waiting until the indexes are ready
  SearchEngine engine = new SearchEngine();
  IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
  try {
    engine.searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, "!@$#!@".toCharArray(), SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE,
        IJavaSearchConstants.CLASS, scope, new TypeNameRequestor() {
          public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
          }
        }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
  } catch (CoreException e) {
  }
}
 
Example #3
Source File: JdtBasedSimpleTypeScope.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void collectContents(IJavaSearchScope searchScope, TypeNameRequestor nameMatchRequestor) throws JavaModelException {
	new SearchEngine().searchAllTypeNames(
			null, 0, // match all package names
			null, 0, // and all type names,
			IJavaSearchConstants.TYPE, // search for types
			searchScope, // in the scope of the current project
			nameMatchRequestor, 
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, // wait for the jdt index to be ready
			new NullProgressMonitor());
}
 
Example #4
Source File: JdtBasedSimpleTypeScope.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Iterable<IEObjectDescription> internalGetAllElements() {
	IJavaProject javaProject = getTypeProvider().getJavaProject();
	if (javaProject == null)
		return Collections.emptyList();
	final List<IEObjectDescription> allScopedElements = Lists.newArrayListWithExpectedSize(25000);
	try {
		IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
		for(Class<?> clazz: Primitives.ALL_PRIMITIVE_TYPES) {
			IEObjectDescription primitive = createScopedElement(clazz.getName());
			if (primitive != null)
				allScopedElements.add(primitive);
		}
		TypeNameRequestor nameMatchRequestor = new TypeNameRequestor() {
			@Override
			public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
					char[][] enclosingTypeNames, String path) {
				StringBuilder fqName = new StringBuilder(packageName.length + simpleTypeName.length + 1);
				if (packageName.length != 0) {
					fqName.append(packageName);
					fqName.append('.');
				}
				for(char[] enclosingType: enclosingTypeNames) {
					fqName.append(enclosingType);
					fqName.append('.');
				}
				fqName.append(simpleTypeName);
				String fullyQualifiedName = fqName.toString();
				InternalEObject proxy = createProxy(fullyQualifiedName);
				Map<String, String> userData = null;
				if (enclosingTypeNames.length == 0) {
					userData = ImmutableMap.of("flags", String.valueOf(modifiers));
				} else {
					userData = ImmutableMap.of("flags", String.valueOf(modifiers), "inner", "true");
				}
				IEObjectDescription eObjectDescription = EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(fullyQualifiedName), proxy, userData);
				if (eObjectDescription != null)
					allScopedElements.add(eObjectDescription);
			}
		};
		collectContents(searchScope, nameMatchRequestor);
	}
	catch (JavaModelException e) {
		// ignore
	}
	return allScopedElements;
}
 
Example #5
Source File: XtxtUMLReferenceProposalTypeScope.java    From txtUML with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns an appropriate scope consisting of allowed Java class types
 * {@link Boolean}, {@link Double}, {@link Integer} and {@link String}.
 */
@Override
protected Iterable<IEObjectDescription> internalGetAllElements() {
	IJavaProject javaProject = getTypeProvider().getJavaProject();
	if (javaProject == null)
		return Collections.emptyList();
	final List<IEObjectDescription> allScopedElements = Lists.newArrayListWithExpectedSize(25000);
	try {
		IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });

		// don't add primitives, we handle them as keywords

		TypeNameRequestor nameMatchRequestor = new TypeNameRequestor() {
			@Override
			public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
					char[][] enclosingTypeNames, String path) {
				StringBuilder fqName = new StringBuilder(packageName.length + simpleTypeName.length + 1);
				if (packageName.length != 0) {
					fqName.append(packageName);
					fqName.append('.');
				}
				for (char[] enclosingType : enclosingTypeNames) {
					fqName.append(enclosingType);
					fqName.append('.');
				}
				fqName.append(simpleTypeName);
				String fullyQualifiedName = fqName.toString();
				InternalEObject proxy = createProxy(fullyQualifiedName);
				Map<String, String> userData = null;
				if (enclosingTypeNames.length == 0) {
					userData = ImmutableMap.of("flags", String.valueOf(modifiers));
				} else {
					userData = ImmutableMap.of("flags", String.valueOf(modifiers), "inner", "true");
				}
				IEObjectDescription eObjectDescription = EObjectDescription
						.create(getQualifiedNameConverter().toQualifiedName(fullyQualifiedName), proxy, userData);
				if (eObjectDescription != null)
					allScopedElements.add(eObjectDescription);
			}
		};

		// start of modified code

		for (String allowedType : allowedJavaClassTypes) {
			new SearchEngine().searchAllTypeNames("java.lang".toCharArray(), SearchPattern.R_EXACT_MATCH,
					allowedType.toCharArray(), SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.CLASS, searchScope,
					nameMatchRequestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
		}

		// end of modified code

	} catch (JavaModelException e) {
		// ignore
	}
	return allScopedElements;
}
 
Example #6
Source File: TypeNameRequestorWrapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public TypeNameRequestorWrapper(TypeNameRequestor requestor) {
	this.requestor = requestor;
}