Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
 
 package org.eclipse.xtext.ui.search;
 
import  org.eclipse.ui.dialogs.SearchPattern;

Author(s):
Jan Koehnlein - Initial contribution and API
public interface IXtextEObjectSearch {
	Iterable<IEObjectDescriptionfindMatches(String searchPatternString typeSearchPattern);
	public static class Default implements IXtextEObjectSearch {
		public Iterable<IEObjectDescriptionfindMatches(final String searchPatternfinal String typeSearchPattern) {
			return Iterables.filter(getSearchScope(), getSearchPredicate(searchPatterntypeSearchPattern));
		}
		protected Predicate<IEObjectDescriptiongetSearchPredicate(final String stringPattern,
				final String typeStringPattern) {
			final Collection<StringnamespaceDelimiters = IXtextSearchFilter.Registry.allNamespaceDelimiters();			
			final SearchPattern searchPattern = new SearchPattern();
			searchPattern.setPattern(stringPattern);
			final SearchPattern typeSearchPattern = new SearchPattern();
			typeSearchPattern.setPattern(typeStringPattern);
			final Collection<IXtextSearchFilterregisteredFilters = IXtextSearchFilter.Registry.allFilters();
			return new Predicate<IEObjectDescription>() {
				public boolean apply(IEObjectDescription input) {
					if (isNameMatches(searchPatterninputnamespaceDelimiters)
							&& typeSearchPattern.matches(input.getEClass().getName())) {
						for (IXtextSearchFilter xtextSearchFilter : registeredFilters) {
							if (xtextSearchFilter.reject(input)) {
								return false;
							}
						}
						return true;
					}
					return false;
				}
			};
		}
		protected boolean isNameMatches(SearchPattern searchPatternIEObjectDescription eObjectDescriptionCollection<StringnamespaceDelimiters) {
			String qualifiedName = eObjectDescription.getQualifiedName().toString();
			if (qualifiedName!=null) {
				if(searchPattern.matches(qualifiedName)) {
					return true;
				}
				for(String namespaceDelimiter : namespaceDelimiters) {
					int index = qualifiedName.lastIndexOf(namespaceDelimiter); 
					if(index!=-1 && searchPattern.matches(qualifiedName.substring(index+1))) {
						return true;
					}
				}	
			}
			return false;
		}
							return from.getExportedObjects();
						}
					}));
		}
		public void setResourceDescriptions(IResourceDescriptions resourceDescriptions) {
			this. = resourceDescriptions;
		}
		}
	}
New to GrepCode? Check out our FAQ X