Java Code Examples for org.eclipse.jdt.core.IJavaElement

The following examples show how to use org.eclipse.jdt.core.IJavaElement. These examples are extracted from open source projects. 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
/**
 * @return all java projects which contain the selected elements in the active workbench window
 */
protected IStructuredSelection getSelectedJavaProjects() {
	ISelection currentSelection= JavaPlugin.getActiveWorkbenchWindow().getSelectionService().getSelection();
	if (currentSelection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection= (IStructuredSelection) currentSelection;
		HashSet<IJavaProject> selectedElements= new HashSet<IJavaProject>();
		Iterator<?> iter= structuredSelection.iterator();
		while (iter.hasNext()) {
			Object selectedElement= iter.next();
			if (selectedElement instanceof IJavaElement) {
				IJavaProject javaProject= ((IJavaElement) selectedElement).getJavaProject();
				if (javaProject != null)
					selectedElements.add(javaProject);
			}
		}
		return new StructuredSelection(selectedElements);
	} else
		return StructuredSelection.EMPTY;
}
 
Example 2
/**
 * determines if the delta is a relevant change on a IPackageFragmentRoot
 * 
 * @param delta
 *            the IJavaElementDelta to analyze. the deltas element must be an instance of IPackageFragmentRoot
 */
public boolean isRelevantPackageFragmentRootChange(IJavaElementDelta delta) {
	IJavaElement element = delta.getElement();
	assert (element instanceof IPackageFragmentRoot);
	return delta.getKind() == IJavaElementDelta.REMOVED 
			|| delta.getKind() == IJavaElementDelta.ADDED
			|| (delta.getFlags() & IJavaElementDelta.F_REORDER) != 0
			|| (delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0
			|| (delta.getFlags() & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0
			|| (
					(
						((IPackageFragmentRoot) element).isExternal() 
						|| ((IPackageFragmentRoot) element).isArchive()
					) && 
					(
						delta.getFlags() & // external folders change
						(IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED)
					) == delta.getFlags()
			);
}
 
Example 3
public void helpRequested(HelpEvent e) {
	try {
		Object[] selected= null;
		if (fViewer != null) {
			ISelection selection= fViewer.getSelection();
			if (selection instanceof IStructuredSelection) {
				selected= ((IStructuredSelection)selection).toArray();
			}
		} else if (fEditor != null) {
			IJavaElement input= SelectionConverter.getInput(fEditor);
			if (input != null && ActionUtil.isOnBuildPath(input)) {
				selected= SelectionConverter.codeResolve(fEditor);
			}
		}
		JavadocHelpContext.displayHelp(fContextId, selected);
	} catch (CoreException x) {
		JavaPlugin.log(x);
	}
}
 
Example 4
Source Project: eclipse.jdt.ls   Source File: ReorgPolicyFactory.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public IJavaElement[] getActualJavaElementsToReorg() throws JavaModelException {
	List<IJavaElement> result= new ArrayList<>();
	for (int i= 0; i < fJavaElements.length; i++) {
		IJavaElement element= fJavaElements[i];
		if (element == null) {
			continue;
		}
		if (element instanceof IType) {
			IType type= (IType) element;
			ICompilationUnit cu= type.getCompilationUnit();
			if (cu != null && type.getDeclaringType() == null && cu.exists() && cu.getTypes().length == 1 && !result.contains(cu)) {
				result.add(cu);
			} else if (!result.contains(type)) {
				result.add(type);
			}
		} else if (!result.contains(element)) {
			result.add(element);
		}
	}
	return result.toArray(new IJavaElement[result.size()]);
}
 
Example 5
/**
 * Generates a new setter method for the specified field
 * 
 * @param field the field
 * @param astRewrite the AST rewrite to use
 * @param rewrite the list rewrite to use
 * @throws CoreException if an error occurs
 * @throws OperationCanceledException if the operation has been cancelled
 */
private void generateSetterMethod(final IField field, ASTRewrite astRewrite, final ListRewrite rewrite) throws CoreException, OperationCanceledException {
	final IType type= field.getDeclaringType();
	final String name= GetterSetterUtil.getSetterName(field, null);
	final IMethod existing= JavaModelUtil.findMethod(name, new String[] { field.getTypeSignature()}, false, type);
	if (existing == null || !querySkipExistingMethods(existing)) {
		IJavaElement sibling= null;
		if (existing != null) {
			sibling= StubUtility.findNextSibling(existing);
			removeExistingAccessor(existing, rewrite);
		} else
			sibling= fInsert;
		ASTNode insertion= StubUtility2.getNodeToInsertBefore(rewrite, sibling);
		addNewAccessor(type, field, GetterSetterUtil.getSetterStub(field, name, fSettings.createComments, fVisibility | (field.getFlags() & Flags.AccStatic)), rewrite, insertion);
		if (Flags.isFinal(field.getFlags())) {
			ASTNode fieldDecl= ASTNodes.getParent(NodeFinder.perform(fASTRoot, field.getNameRange()), FieldDeclaration.class);
			if (fieldDecl != null) {
				ModifierRewrite.create(astRewrite, fieldDecl).setModifiers(0, Modifier.FINAL, null);
			}
		}

	}
}
 
Example 6
/**
 * Proposes a getter for this field.
 * 
 * @param context the proposal parameter
 * @param relevance relevance of this proposal
 * @return the proposal if available or null
 */
private static ChangeCorrectionProposal addGetterProposal(ProposalParameter context, int relevance) {
	IMethodBinding method= findGetter(context);
	if (method != null) {
		Expression mi= createMethodInvocation(context, method, null);
		context.astRewrite.replace(context.accessNode, mi, null);

		String label= Messages.format(CorrectionMessages.GetterSetterCorrectionSubProcessor_replacewithgetter_description, BasicElementLabels.getJavaCodeString(ASTNodes.asString(context.accessNode)));
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.compilationUnit, context.astRewrite, relevance, image);
		return proposal;
	} else {
		IJavaElement element= context.variableBinding.getJavaElement();
		if (element instanceof IField) {
			IField field= (IField) element;
			try {
				if (RefactoringAvailabilityTester.isSelfEncapsulateAvailable(field))
					return new SelfEncapsulateFieldProposal(relevance, field);
			} catch (JavaModelException e) {
				JavaPlugin.log(e);
			}
		}
	}
	return null;
}
 
Example 7
/**
 * @see MultiOperation This method delegate to <code>deleteResource</code> or
 * <code>deletePackageFragment</code> depending on the type of <code>element</code>.
 */
protected void processElement(IJavaElement element) throws JavaModelException {
	switch (element.getElementType()) {
		case IJavaElement.CLASS_FILE :
		case IJavaElement.COMPILATION_UNIT :
			deleteResource(element.getResource(), this.force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY);
			break;
		case IJavaElement.PACKAGE_FRAGMENT :
			deletePackageFragment((IPackageFragment) element);
			break;
		default :
			throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element));
	}
	// ensure the element is closed
	if (element instanceof IOpenable) {
		((IOpenable)element).close();
	}
}
 
Example 8
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, int length, MatchLocator locator) {
	PatternLocator closestPattern = null;
	int level = IMPOSSIBLE_MATCH;
	for (int i = 0, pl = this.patternLocators.length; i < pl; i++) {
		PatternLocator patternLocator = this.patternLocators[i];
		int newLevel = patternLocator.referenceType() == 0 ? IMPOSSIBLE_MATCH : patternLocator.resolveLevel(reference);
		if (newLevel > level) {
			closestPattern = patternLocator;
			if (newLevel == ACCURATE_MATCH) break;
			level = newLevel;
		}
	}
	if (closestPattern != null) {
	    return closestPattern.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator);
	}
	// super implementation...
    return locator.newDeclarationMatch(element, elementBinding, accuracy, reference.sourceStart, length);
}
 
Example 9
private boolean containsAsResource(List<Object> list, IResource child) {
	for (Iterator<Object> iter= list.iterator(); iter.hasNext(); ) {
		Object element= iter.next();
		if (child.equals(element))
			return true;
		if (element instanceof IJavaElement) {
			IJavaElement javaChild = (IJavaElement)element;
			try {
				if (child.equals(javaChild.getCorrespondingResource()))
					return true;
			} catch (JavaModelException e) {
				continue;
			}
		}
		
	}
	return false;
}
 
Example 10
/**
 * Returns the type with the given <code>typeName</code>.  Returns inner classes
 * as well.
 */
protected IType getType(String typeName) {
	if (typeName.length() == 0) {
		IJavaElement classFile = this.binaryType.getParent();
		String classFileName = classFile.getElementName();
		StringBuffer newClassFileName = new StringBuffer();
		int lastDollar = classFileName.lastIndexOf('$');
		for (int i = 0; i <= lastDollar; i++)
			newClassFileName.append(classFileName.charAt(i));
		newClassFileName.append(Integer.toString(this.anonymousCounter));
		PackageFragment pkg = (PackageFragment) classFile.getParent();
		return new BinaryType(new ClassFile(pkg, newClassFileName.toString()), typeName);
	} else if (this.binaryType.getElementName().equals(typeName))
		return this.binaryType;
	else
		return this.binaryType.getType(typeName);
}
 
Example 11
private static Location fixLocation(IJavaElement element, Location location, IJavaProject javaProject) {
	if (location == null) {
		return null;
	}
	if (!javaProject.equals(element.getJavaProject()) && element.getJavaProject().getProject().getName().equals(ProjectsManager.DEFAULT_PROJECT_NAME)) {
		// see issue at: https://github.com/eclipse/eclipse.jdt.ls/issues/842 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=541573
		// for jdk classes, jdt will reuse the java model by altering project to share the model between projects
		// so that sometimes the project for `element` is default project and the project is different from the project for `unit`
		// this fix is to replace the project name with non-default ones since default project should be transparent to users.
		if (location.getUri().contains(ProjectsManager.DEFAULT_PROJECT_NAME)) {
			String patched = StringUtils.replaceOnce(location.getUri(), ProjectsManager.DEFAULT_PROJECT_NAME, javaProject.getProject().getName());
			try {
				IClassFile cf = (IClassFile) JavaCore.create(JDTUtils.toURI(patched).getQuery());
				if (cf != null && cf.exists()) {
					location.setUri(patched);
				}
			} catch (Exception ex) {

			}
		}
	}
	return location;
}
 
Example 12
public IJavaElement findPackageFragment(String packageName)
		throws JavaModelException {
	NameLookup lookup = newNameLookup((WorkingCopyOwner)null/*no need to look at working copies for pkgs*/);
	IPackageFragment[] pkgFragments = lookup.findPackageFragments(packageName, false);
	if (pkgFragments == null) {
		return null;

	} else {
		// try to return one that is a child of this project
		for (int i = 0, length = pkgFragments.length; i < length; i++) {

			IPackageFragment pkgFragment = pkgFragments[i];
			if (equals(pkgFragment.getParent().getParent())) {
				return pkgFragment;
			}
		}
		// default to the first one
		return pkgFragments[0];
	}
}
 
Example 13
private String formatLogicalPackageMessage(LogicalPackage logicalPackage) {
	IPackageFragment[] fragments= logicalPackage.getFragments();
	StringBuffer buf= new StringBuffer(logicalPackage.getElementName());
	buf.append(JavaElementLabels.CONCAT_STRING);
	String message= ""; //$NON-NLS-1$
	boolean firstTime= true;
	for (int i= 0; i < fragments.length; i++) {
		IPackageFragment fragment= fragments[i];
		IJavaElement element= fragment.getParent();
		if (element instanceof IPackageFragmentRoot) {
			IPackageFragmentRoot root= (IPackageFragmentRoot) element;
			String label= JavaElementLabels.getElementLabel(root, JavaElementLabels.DEFAULT_QUALIFIED | JavaElementLabels.ROOT_QUALIFIED);
			if (firstTime) {
				buf.append(label);
				firstTime= false;
			}
			else
				message= Messages.format(JavaBrowsingMessages.StatusBar_concat, new String[] {message, label});
		}
	}
	buf.append(message);
	return buf.toString();
}
 
Example 14
public MethodReferenceMatch newMethodReferenceMatch(
		IJavaElement enclosingElement,
		Binding enclosingBinding,
		int accuracy,
		int offset,
		int length,
		boolean isConstructor,
		boolean isSynthetic,
		ASTNode reference) {
	SearchParticipant participant = getParticipant();
	IResource resource = this.currentPossibleMatch.resource;
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
	if (enclosingBinding != null)
		enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
	boolean isOverridden = (accuracy & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0;
	return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, isOverridden, insideDocComment, participant, resource);
}
 
Example 15
public boolean canUpdateQualifiedNames() {
	if (!canEnableQualifiedNameUpdating())
		return false;

	IPackageFragment pack= getDestinationAsPackageFragment();
	if (pack == null)
		return false;

	if (pack.isDefaultPackage())
		return false;

	IJavaElement destination= getJavaElementDestination();
	if (destination instanceof IPackageFragmentRoot && getCus().length > 0) {
		return false;
	}

	return true;
}
 
Example 16
Source Project: eclipse.jdt.ls   Source File: ReorgPolicyFactory.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IJavaElement javaElement) throws JavaModelException {
	Assert.isNotNull(javaElement);
	if (!fCheckDestination) {
		return new RefactoringStatus();
	}
	if (!javaElement.exists()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot1);
	}
	if (javaElement instanceof IJavaModel) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_jmodel);
	}
	if (!(javaElement instanceof IJavaProject)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_src2proj);
	}
	if (javaElement.isReadOnly()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_src2writable);
	}
	if (ReorgUtils.isPackageFragmentRoot(javaElement.getJavaProject())) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_src2nosrc);
	}
	return new RefactoringStatus();
}
 
Example 17
private void acceptPotentialMethodDeclaration(CompletionProposal proposal) {
	try {
		IJavaElement enclosingElement= null;
		if (getContext().isExtended()) {
			enclosingElement= getContext().getEnclosingElement();
		} else if (fCompilationUnit != null) {
			// kept for backward compatibility: CU is not reconciled at this moment, information is missing (bug 70005)
			enclosingElement= fCompilationUnit.getElementAt(proposal.getCompletionLocation() + 1);
		}
		if (enclosingElement == null)
			return;
		IType type= (IType) enclosingElement.getAncestor(IJavaElement.TYPE);
		if (type != null) {
			String prefix= String.valueOf(proposal.getName());
			int completionStart= proposal.getReplaceStart();
			int completionEnd= proposal.getReplaceEnd();
			int relevance= computeRelevance(proposal);

			GetterSetterCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance + 2, fSuggestedMethodNames, fJavaProposals);
			MethodDeclarationCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance, fSuggestedMethodNames, fJavaProposals);
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
}
 
Example 18
/**
 * {@inheritDoc}
 */
@Override
public void setInput(Object information) {
	if (information == null || information instanceof String) {
		inputChanged(null, null);
		return;
	}
	IJavaElement je= (IJavaElement)information;
	ICompilationUnit cu= (ICompilationUnit)je.getAncestor(IJavaElement.COMPILATION_UNIT);
	if (cu != null)
		fInput= cu;
	else
		fInput= je.getAncestor(IJavaElement.CLASS_FILE);

	inputChanged(fInput, information);

	fCategoryFilterActionGroup.setInput(getInputForCategories());
}
 
Example 19
/**
 * Checks if element has an enclosing parent among other selected elements.
 * 
 * @param element the element to be checked for overlap against all elements
 * @param allElements the list of all elements
 * @return <code>true</code> if the element has a parent in the list of all elements
 */
private boolean isElementOverlapping(IJavaElement element, List<?> allElements) {
	element= element.getParent();
	while (element != null) {
		if (element instanceof ISourceReference) {
			if (allElements.contains(element))
				return true;
		} else {
			return false;
		}
		element= element.getParent();
	}
	return false;
}
 
Example 20
/**
 * @param context
 *            an {@link IJavaElement} or <code>null</code>
 * @return a <code>String[]</code> whose <code>[0]</code> is the
 *         {@link JavaCore#COMPILER_SOURCE} and whose <code>[1]</code> is
 *         the {@link JavaCore#COMPILER_COMPLIANCE} level at the given
 *         <code>context</code>.
 */
public static String[] getSourceComplianceLevels(IJavaElement context) {
	if (context != null) {
		IJavaProject javaProject = context.getJavaProject();
		if (javaProject != null) {
			return new String[] { javaProject.getOption(JavaCore.COMPILER_SOURCE, true), javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true) };
		}
	}
	return new String[] { JavaCore.getOption(JavaCore.COMPILER_SOURCE), JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE) };
}
 
Example 21
private static Javadoc getPackageJavadocNode(IJavaElement element, String cuSource) {
	CompilationUnit cu= createAST(element, cuSource);
	if (cu != null) {
		PackageDeclaration packDecl= cu.getPackage();
		if (packDecl != null) {
			return packDecl.getJavadoc();
		}
	}
	return null;
}
 
Example 22
private void collectCompilationUnits(IPackageFragmentRoot root, Collection<IJavaElement> result, String prefix) throws JavaModelException {
	if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
		IJavaElement[] children = root.getChildren();
		for (int i = 0; i < children.length; i++) {
			IPackageFragment pack = (IPackageFragment) children[i];
			if (StringUtils.isBlank(prefix) || pack.getElementName().indexOf(prefix) >= 0) {
				collectCompilationUnits(pack, result);
			}
		}
	}
}
 
Example 23
Source Project: eclipse.jdt.ls   Source File: RenameSupport.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static RenameSupport create(IJavaElement element, String newName, int flags) throws CoreException {
	switch (element.getElementType()) {
		case IJavaElement.JAVA_PROJECT:
			//return RenameSupport.create((IJavaProject) element, newName, flags);
			return null;
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			//return RenameSupport.create((IPackageFragmentRoot) element, newName);
			return null;
		case IJavaElement.PACKAGE_FRAGMENT:
			return RenameSupport.create((IPackageFragment) element, newName, flags);
		case IJavaElement.COMPILATION_UNIT:
			return RenameSupport.create((ICompilationUnit) element, newName, flags);
		case IJavaElement.TYPE:
			return RenameSupport.create((IType) element, newName, flags);
		case IJavaElement.METHOD:
			final IMethod method = (IMethod) element;
			if (method.isConstructor()) {
				return create(method.getDeclaringType(), newName, flags);
			} else {
				return RenameSupport.create((IMethod) element, newName, flags);
			}
		case IJavaElement.FIELD:
			return RenameSupport.create((IField) element, newName, flags);
		case IJavaElement.TYPE_PARAMETER:
			return RenameSupport.create((ITypeParameter) element, newName, flags);
		case IJavaElement.LOCAL_VARIABLE:
			return RenameSupport.create((ILocalVariable) element, newName, flags);
	}
	return null;
}
 
Example 24
/**
 * When executed, this operation sets the raw classpath and output location of the given project.
 */
public SetClasspathOperation(
	JavaProject project,
	IClasspathEntry[] newRawClasspath,
	IClasspathEntry[] referencedEntries,
	IPath newOutputLocation,
	boolean canChangeResource) {

	super(new IJavaElement[] { project }, canChangeResource);
	this.project = project;
	this.newRawClasspath = newRawClasspath;
	this.referencedEntries = referencedEntries;
	this.newOutputLocation = newOutputLocation;
}
 
Example 25
private SymbolInformation[] getOutline(ITypeRoot unit, IProgressMonitor monitor) {
	try {
		IJavaElement[] elements = unit.getChildren();
		ArrayList<SymbolInformation> symbols = new ArrayList<>(elements.length);
		collectChildren(unit, elements, symbols, monitor);
		return symbols.toArray(new SymbolInformation[symbols.size()]);
	} catch (JavaModelException e) {
		JavaLanguageServerPlugin.logException("Problem getting outline for" + unit.getElementName(), e);
	}
	return new SymbolInformation[0];
}
 
Example 26
private boolean javaElementsHaveCommonParent() {
	if (fJavaElements.length == 0)
		return true;
	IJavaElement firstParent= fJavaElements[0].getParent();
	Assert.isNotNull(firstParent); //this should never happen
	for (int i= 1; i < fJavaElements.length; i++) {
		if (! firstParent.equals(fJavaElements[i].getParent()))
			return false;
	}
	return true;
}
 
Example 27
public CopyToClipboardEnablementPolicy(IResource[] resources, IJavaElement[] javaElements, IJarEntryResource[] jarEntryResources) {
	Assert.isNotNull(resources);
	Assert.isNotNull(javaElements);
	Assert.isNotNull(jarEntryResources);
	fResources= resources;
	fJavaElements= javaElements;
	fJarEntryResources= jarEntryResources;
}
 
Example 28
/**
 * @see CreateElementInCUOperation#generateResultHandle()
 */
protected IJavaElement generateResultHandle() {
	IJavaElement parent= getParentElement();
	switch (parent.getElementType()) {
		case IJavaElement.COMPILATION_UNIT:
			return ((ICompilationUnit)parent).getType(getASTNodeName());
		case IJavaElement.TYPE:
			return ((IType)parent).getType(getASTNodeName());
		// Note: creating local/anonymous type is not supported
	}
	return null;
}
 
Example 29
public static boolean isWorkingCopyElement(final IJavaElement element) {
	if (element instanceof ICompilationUnit) {
		return ((ICompilationUnit) element).isWorkingCopy();
	}
	if (ReorgUtils.isInsideCompilationUnit(element)) {
		return ReorgUtils.getCompilationUnit(element).isWorkingCopy();
	}
	return false;
}
 
Example 30
/**
 * 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);
}