This commit is contained in:
Alexey Kudravtsev
2014-06-18 14:59:02 +04:00
parent 2988f383bc
commit bb28346ded
19 changed files with 86 additions and 44 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -308,7 +308,7 @@ public abstract class DefaultMessageHandler implements BuilderMessageHandler {
private static boolean processIdentifiers(PsiSearchHelper helper, @NotNull final PsiElementProcessor<PsiIdentifier> processor, @NotNull final String identifier, @NotNull SearchScope searchScope, short searchContext) {
TextOccurenceProcessor processor1 = new TextOccurenceProcessor() {
@Override
public boolean execute(PsiElement element, int offsetInElement) {
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
return !(element instanceof PsiIdentifier) || processor.execute((PsiIdentifier)element);
}
};
@@ -220,9 +220,10 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
}
@Override
protected Set<String> getStringsToSearch(final PsiElement element) {
protected Set<String> getStringsToSearch(@NotNull final PsiElement element) {
if (element instanceof PsiDirectory) { // normalize a directory to a corresponding package
return getStringsToSearch(JavaDirectoryService.getInstance().getPackage((PsiDirectory)element));
PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element);
return aPackage == null ? Collections.<String>emptySet() : getStringsToSearch(aPackage);
}
final Set<String> result = new HashSet<String>();
@@ -264,7 +265,8 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
}
else if (element instanceof XmlAttributeValue) {
ContainerUtil.addIfNotNull(result, ((XmlAttributeValue)element).getValue());
} else {
}
else {
LOG.error("Unknown element type: " + element);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,7 +58,7 @@ public class AllClassesSearch extends ExtensibleQueryFactory<PsiClass, AllClasse
return myProject;
}
public boolean nameMatches(String name) {
public boolean nameMatches(@NotNull String name) {
return myShortNameCondition.value(name);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ public abstract class SearchScope {
*
* @return hashCode value semantically identical to one from Object but not native
*/
@Override
public int hashCode() {
return myHashCode;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@ public class ExtensionPointName<T> {
}
@Override
public String toString() {
return myName;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,6 +81,7 @@ public class IndexPattern {
}
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -93,6 +94,7 @@ public class IndexPattern {
return true;
}
@Override
public int hashCode() {
int result = myPatternString.hashCode();
result = 29 * result + (myCaseSensitive ? 1 : 0);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@ import org.jetbrains.annotations.NotNull;
* @author peter
*/
public class PsiSearchRequest {
public final SearchScope searchScope;
public final String word;
@NotNull public final SearchScope searchScope;
@NotNull public final String word;
public final short searchContext;
public final boolean caseSensitive;
public final RequestResultProcessor processor;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +17,11 @@
package com.intellij.psi.search;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author ven
*/
public interface TextOccurenceProcessor {
boolean execute (PsiElement element, int offsetInElement);
boolean execute(@NotNull PsiElement element, int offsetInElement);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,16 +63,17 @@ public class DefinitionsScopedSearch extends ExtensibleQueryFactory<PsiElement,
private final SearchScope myScope;
private final boolean myCheckDeep;
public SearchParameters(PsiElement element) {
public SearchParameters(@NotNull PsiElement element) {
this(element, element.getUseScope(), true);
}
public SearchParameters(final PsiElement element, SearchScope scope, final boolean checkDeep) {
public SearchParameters(@NotNull PsiElement element, @NotNull SearchScope scope, final boolean checkDeep) {
myElement = element;
myScope = scope;
myCheckDeep = checkDeep;
}
@NotNull
public PsiElement getElement() {
return myElement;
}
@@ -81,6 +82,7 @@ public class DefinitionsScopedSearch extends ExtensibleQueryFactory<PsiElement,
return myCheckDeep;
}
@NotNull
public SearchScope getScope() {
return ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,6 +64,7 @@ public abstract class IndexPatternSearch extends QueryFactory<IndexPatternOccurr
myPattern = null;
}
@NotNull
public PsiFile getFile() {
return myFile;
}
@@ -92,6 +93,7 @@ public abstract class IndexPatternSearch extends QueryFactory<IndexPatternOccurr
* @param pattern the pattern to search for.
* @return the query instance.
*/
@NotNull
public static Query<IndexPatternOccurrence> search(@NotNull PsiFile file, @NotNull IndexPattern pattern) {
final SearchParameters parameters = new SearchParameters(file, pattern);
return INDEX_PATTERN_SEARCH_INSTANCE.createQuery(parameters);
@@ -107,9 +109,11 @@ public abstract class IndexPatternSearch extends QueryFactory<IndexPatternOccurr
* @param endOffset the end offset of the range to search.
* @return the query instance.
*/
@NotNull
public static Query<IndexPatternOccurrence> search(@NotNull PsiFile file,
@NotNull IndexPattern pattern,
int startOffset, int endOffset) {
int startOffset,
int endOffset) {
final SearchParameters parameters = new SearchParameters(file, pattern, new TextRange(startOffset, endOffset));
return INDEX_PATTERN_SEARCH_INSTANCE.createQuery(parameters);
}
@@ -123,6 +127,7 @@ public abstract class IndexPatternSearch extends QueryFactory<IndexPatternOccurr
* @param patternProvider the provider the patterns from which are searched.
* @return the query instance.
*/
@NotNull
public static Query<IndexPatternOccurrence> search(@NotNull PsiFile file, @NotNull IndexPatternProvider patternProvider) {
final SearchParameters parameters = new SearchParameters(file, patternProvider);
return INDEX_PATTERN_SEARCH_INSTANCE.createQuery(parameters);
@@ -139,6 +144,7 @@ public abstract class IndexPatternSearch extends QueryFactory<IndexPatternOccurr
* @param endOffset the end offset of the range to search.
* @return the query instance.
*/
@NotNull
public static Query<IndexPatternOccurrence> search(@NotNull PsiFile file, @NotNull IndexPatternProvider patternProvider,
int startOffset, int endOffset) {
final SearchParameters parameters = new SearchParameters(file, patternProvider, new TextRange(startOffset, endOffset));
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
* @author max
*/
public class ReferenceDescriptor {
@NotNull
public static final Function<PsiReference, ReferenceDescriptor> MAPPER = new Function<PsiReference, ReferenceDescriptor>() {
@Override
public ReferenceDescriptor fun(PsiReference psiReference) {
@@ -36,7 +37,7 @@ public class ReferenceDescriptor {
private final PsiFile file;
private final int offset;
ReferenceDescriptor(@NotNull PsiFile file, int offset) {
private ReferenceDescriptor(@NotNull PsiFile file, int offset) {
this.file = file;
this.offset = offset;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ public class ReferencesSearch extends ExtensibleQueryFactory<PsiReference, Refer
private final SearchRequestCollector myOptimizer;
private final boolean isSharedOptimizer;
public SearchParameters(@NotNull PsiElement elementToSearch, SearchScope scope, boolean ignoreAccessScope, @Nullable SearchRequestCollector optimizer) {
public SearchParameters(@NotNull PsiElement elementToSearch, @NotNull SearchScope scope, boolean ignoreAccessScope, @Nullable SearchRequestCollector optimizer) {
myElementToSearch = elementToSearch;
myScope = scope;
myIgnoreAccessScope = ignoreAccessScope;
@@ -49,7 +49,7 @@ public class ReferencesSearch extends ExtensibleQueryFactory<PsiReference, Refer
myOptimizer = optimizer == null ? new SearchRequestCollector(new SearchSession()) : optimizer;
}
public SearchParameters(@NotNull final PsiElement elementToSearch, final SearchScope scope, final boolean ignoreAccessScope) {
public SearchParameters(@NotNull PsiElement elementToSearch, @NotNull SearchScope scope, final boolean ignoreAccessScope) {
this(elementToSearch, scope, ignoreAccessScope, null);
}
@@ -62,6 +62,7 @@ public class ReferencesSearch extends ExtensibleQueryFactory<PsiReference, Refer
* Use {@link #getEffectiveSearchScope} instead
*/
@Deprecated()
@NotNull
public SearchScope getScope() {
return myScope;
}
@@ -85,18 +86,22 @@ public class ReferencesSearch extends ExtensibleQueryFactory<PsiReference, Refer
}
}
@NotNull
public static Query<PsiReference> search(@NotNull PsiElement element) {
return search(element, GlobalSearchScope.allScope(element.getProject()), false);
}
@NotNull
public static Query<PsiReference> search(@NotNull PsiElement element, @NotNull SearchScope searchScope) {
return search(element, searchScope, false);
}
@NotNull
public static Query<PsiReference> search(@NotNull PsiElement element, @NotNull SearchScope searchScope, boolean ignoreAccessScope) {
return search(new SearchParameters(element, searchScope, ignoreAccessScope));
}
@NotNull
public static Query<PsiReference> search(@NotNull final SearchParameters parameters) {
final Query<PsiReference> result = INSTANCE.createQuery(parameters);
if (parameters.isSharedOptimizer) {
@@ -110,7 +115,8 @@ public class ReferencesSearch extends ExtensibleQueryFactory<PsiReference, Refer
return uniqueResults(new MergeQuery<PsiReference>(result, new SearchRequestQuery(element.getProject(), requests)));
}
private static UniqueResultsQuery<PsiReference, ReferenceDescriptor> uniqueResults(Query<PsiReference> composite) {
@NotNull
private static UniqueResultsQuery<PsiReference, ReferenceDescriptor> uniqueResults(@NotNull Query<PsiReference> composite) {
return new UniqueResultsQuery<PsiReference, ReferenceDescriptor>(composite, ContainerUtil.<ReferenceDescriptor>canonicalStrategy(), ReferenceDescriptor.MAPPER);
}
@@ -104,7 +104,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
@NotNull final Processor<PsiElement> processor) {
TextOccurenceProcessor occurrenceProcessor = new TextOccurenceProcessor() {
@Override
public boolean execute(PsiElement element, int offsetInElement) {
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
if (CommentUtilCore.isCommentTextElement(element)) {
if (element.findReferenceAt(offsetInElement) == null) {
return processor.process(element);
@@ -846,7 +846,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
final RequestResultProcessor wrapped = singleRequest.processor;
return new TextOccurenceProcessor() {
@Override
public boolean execute(PsiElement element, int offsetInElement) {
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
if (ignoreInjectedPsi && element instanceof PsiLanguageInjectionHost) return true;
return wrapped.processTextOccurrence(element, offsetInElement, consumer);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,7 +81,8 @@ public abstract class FindUsagesHandler {
return PsiElement.EMPTY_ARRAY;
}
public static FindUsagesOptions createFindUsagesOptions(final Project project, @Nullable final DataContext dataContext) {
@NotNull
public static FindUsagesOptions createFindUsagesOptions(@NotNull Project project, @Nullable final DataContext dataContext) {
FindUsagesOptions findUsagesOptions = new FindUsagesOptions(project, dataContext);
findUsagesOptions.isUsages = true;
findUsagesOptions.isSearchForTextOccurrences = true;
@@ -92,6 +93,7 @@ public abstract class FindUsagesHandler {
public FindUsagesOptions getFindUsagesOptions() {
return getFindUsagesOptions(null);
}
@NotNull
public FindUsagesOptions getFindUsagesOptions(@Nullable final DataContext dataContext) {
FindUsagesOptions options = createFindUsagesOptions(getProject(), dataContext);
@@ -185,7 +187,7 @@ public abstract class FindUsagesHandler {
}
@Nullable
protected Collection<String> getStringsToSearch(final PsiElement element) {
protected Collection<String> getStringsToSearch(@NotNull final PsiElement element) {
if (element instanceof PsiNamedElement) {
return ApplicationManager.getApplication().runReadAction(new Computable<Collection<String>>() {
@Override
@@ -32,6 +32,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
public class FindUsagesOptions extends UserDataHolderBase implements Cloneable {
@NotNull
public SearchScope searchScope;
public boolean isSearchForTextOccurrences = true;
@@ -46,15 +47,17 @@ public class FindUsagesOptions extends UserDataHolderBase implements Cloneable {
public FindUsagesOptions(@NotNull Project project, @Nullable final DataContext dataContext) {
String defaultScopeName = FindSettings.getInstance().getDefaultScopeName();
List<SearchScope> predefined = ScopeChooserCombo.getPredefinedScopes(project, dataContext, true, false, false, false);
SearchScope resultScope = null;
for (SearchScope scope : predefined) {
if (scope.getDisplayName().equals(defaultScopeName)) {
searchScope = scope;
resultScope = scope;
break;
}
}
if (searchScope == null) {
searchScope = ProjectScope.getProjectScope(project);
if (resultScope == null) {
resultScope = ProjectScope.getProjectScope(project);
}
searchScope = resultScope;
}
public FindUsagesOptions(@NotNull SearchScope searchScope) {
@@ -66,6 +69,7 @@ public class FindUsagesOptions extends UserDataHolderBase implements Cloneable {
return (FindUsagesOptions)super.clone();
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -74,13 +78,12 @@ public class FindUsagesOptions extends UserDataHolderBase implements Cloneable {
if (isSearchForTextOccurrences != that.isSearchForTextOccurrences) return false;
if (isUsages != that.isUsages) return false;
if (searchScope != null ? !searchScope.equals(that.searchScope) : that.searchScope != null) return false;
return true;
return searchScope.equals(that.searchScope);
}
@Override
public int hashCode() {
int result = searchScope == null ? 0 : searchScope.hashCode();
int result = searchScope.hashCode();
result = 31 * result + (isSearchForTextOccurrences ? 1 : 0);
result = 31 * result + (isUsages ? 1 : 0);
return result;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -99,7 +99,7 @@ public class TextOccurrencesUtil {
private static boolean processStringLiteralsContainingIdentifier(@NotNull String identifier, @NotNull SearchScope searchScope, PsiSearchHelper helper, final Processor<PsiElement> processor) {
TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {
@Override
public boolean execute(PsiElement element, int offsetInElement) {
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
final ASTNode node = element.getNode();
if (definition != null && node != null && definition.getStringLiteralElements().contains(node.getElementType())) {
@@ -146,7 +146,7 @@ public class PatternEditorContextMembersProvider extends NonCodeMembersContribut
GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), StdFileTypes.XML);
final TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {
@Override
public boolean execute(PsiElement element, int offsetInElement) {
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
final String className = tag == null ? null : tag.getAttributeValue("className");
if (className != null && tag.getLocalName().endsWith("patternClass")) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ public class PyClassFindUsagesHandler extends FindUsagesHandler {
}
@Override
protected Collection<String> getStringsToSearch(PsiElement element) {
protected Collection<String> getStringsToSearch(@NotNull PsiElement element) {
if (element instanceof PyFunction && PyNames.INIT.equals(((PyFunction) element).getName())) {
return Collections.emptyList();
}
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python.magicLiteral;
import com.intellij.find.findUsages.FindUsagesHandler;
@@ -34,7 +49,7 @@ public class PyMagicLiteralFindUsagesHandlerFactory extends FindUsagesHandlerFac
@Nullable
@Override
protected Collection<String> getStringsToSearch(final PsiElement element) {
protected Collection<String> getStringsToSearch(@NotNull final PsiElement element) {
return Collections.singleton(((StringLiteralExpression)element).getStringValue());
}
}