Java Code Examples for org.eclipse.jdt.core.search.SearchPattern#createOrPattern()

The following examples show how to use org.eclipse.jdt.core.search.SearchPattern#createOrPattern() . 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: RefactoringSearchEngine.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static SearchPattern createOrPattern(IJavaElement[] elements, int limitTo) {
	if (elements == null || elements.length == 0) {
		return null;
	}
	Set<IJavaElement> set = new HashSet<>(Arrays.asList(elements));
	Iterator<IJavaElement> iter = set.iterator();
	IJavaElement first = iter.next();
	SearchPattern pattern = SearchPattern.createPattern(first, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	if (pattern == null) {
		throw new IllegalArgumentException("Invalid java element: " + first.getHandleIdentifier() + "\n" + first.toString()); //$NON-NLS-1$ //$NON-NLS-2$
	}
	while (iter.hasNext()) {
		IJavaElement each = iter.next();
		SearchPattern nextPattern = SearchPattern.createPattern(each, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
		if (nextPattern == null) {
			throw new IllegalArgumentException("Invalid java element: " + each.getHandleIdentifier() + "\n" + each.toString()); //$NON-NLS-1$ //$NON-NLS-2$
		}
		pattern = SearchPattern.createOrPattern(pattern, nextPattern);
	}
	return pattern;
}
 
Example 2
Source File: RefactoringSearchEngine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static SearchPattern createOrPattern(IJavaElement[] elements, int limitTo) {
	if (elements == null || elements.length == 0)
		return null;
	Set<IJavaElement> set= new HashSet<IJavaElement>(Arrays.asList(elements));
	Iterator<IJavaElement> iter= set.iterator();
	IJavaElement first= iter.next();
	SearchPattern pattern= SearchPattern.createPattern(first, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	if (pattern == null) // check for bug 90138
		throw new IllegalArgumentException("Invalid java element: " + first.getHandleIdentifier() + "\n" + first.toString()); //$NON-NLS-1$ //$NON-NLS-2$
	while(iter.hasNext()){
		IJavaElement each= iter.next();
		SearchPattern nextPattern= SearchPattern.createPattern(each, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
		if (nextPattern == null) // check for bug 90138
			throw new IllegalArgumentException("Invalid java element: " + each.getHandleIdentifier() + "\n" + each.toString()); //$NON-NLS-1$ //$NON-NLS-2$
		pattern= SearchPattern.createOrPattern(pattern, nextPattern);
	}
	return pattern;
}
 
Example 3
Source File: RefactoringSearchEngine2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets the search pattern to be used during search.
 * <p>
 * This method must be called before {@link RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
 *
 * @param elements the set of elements
 * @param limitTo determines the nature of the expected matches. This is a combination of {@link org.eclipse.jdt.core.search.IJavaSearchConstants}.
 */
public final void setPattern(final IJavaElement[] elements, final int limitTo) {
	Assert.isNotNull(elements);
	Assert.isTrue(elements.length > 0);
	SearchPattern pattern= SearchPattern.createPattern(elements[0], limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	IJavaElement element= null;
	for (int index= 1; index < elements.length; index++) {
		element= elements[index];
		pattern= SearchPattern.createOrPattern(pattern, SearchPattern.createPattern(element, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
	}
	setPattern(pattern);
}
 
Example 4
Source File: CreateCopyOfCompilationUnitChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static SearchPattern createSearchPattern(IType type) throws JavaModelException {
	SearchPattern pattern= SearchPattern.createPattern(type, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	IMethod[] constructors= JavaElementUtil.getAllConstructors(type);
	if (constructors.length == 0) {
		return pattern;
	}
	SearchPattern constructorDeclarationPattern= RefactoringSearchEngine.createOrPattern(constructors, IJavaSearchConstants.DECLARATIONS);
	return SearchPattern.createOrPattern(pattern, constructorDeclarationPattern);
}
 
Example 5
Source File: RefactoringSearchEngine2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the search pattern to be used during search.
 * <p>
 * This method must be called before {@link RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
 *
 * @param elements the set of elements
 * @param limitTo determines the nature of the expected matches. This is a combination of {@link org.eclipse.jdt.core.search.IJavaSearchConstants}.
 */
public final void setPattern(final IJavaElement[] elements, final int limitTo) {
	Assert.isNotNull(elements);
	Assert.isTrue(elements.length > 0);
	SearchPattern pattern= SearchPattern.createPattern(elements[0], limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	IJavaElement element= null;
	for (int index= 1; index < elements.length; index++) {
		element= elements[index];
		pattern= SearchPattern.createOrPattern(pattern, SearchPattern.createPattern(element, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
	}
	setPattern(pattern);
}
 
Example 6
Source File: CreateCopyOfCompilationUnitChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static SearchPattern createSearchPattern(IType type) throws JavaModelException {
	SearchPattern pattern= SearchPattern.createPattern(type, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	IMethod[] constructors= JavaElementUtil.getAllConstructors(type);
	if (constructors.length == 0)
		return pattern;
	SearchPattern constructorDeclarationPattern= RefactoringSearchEngine.createOrPattern(constructors, IJavaSearchConstants.DECLARATIONS);
	return SearchPattern.createOrPattern(pattern, constructorDeclarationPattern);
}
 
Example 7
Source File: RefactoringSearchEngine2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Sets the disjunction of search patterns to be used during search.
 * <p>
 * This method must be called before {@link RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
 *
 * @param first the first search pattern to set
 * @param second the second search pattern to set
 */
public final void setOrPattern(final SearchPattern first, final SearchPattern second) {
	Assert.isNotNull(first);
	Assert.isNotNull(second);
	fPattern= SearchPattern.createOrPattern(first, second);
}
 
Example 8
Source File: RefactoringSearchEngine2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Sets the disjunction of search patterns to be used during search.
 * <p>
 * This method must be called before {@link RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
 *
 * @param first the first search pattern to set
 * @param second the second search pattern to set
 */
public final void setOrPattern(final SearchPattern first, final SearchPattern second) {
	Assert.isNotNull(first);
	Assert.isNotNull(second);
	fPattern= SearchPattern.createOrPattern(first, second);
}