diff --git a/java/compiler/impl/src/com/intellij/compiler/server/DefaultMessageHandler.java b/java/compiler/impl/src/com/intellij/compiler/server/DefaultMessageHandler.java index 80c2aaf72fac..da36d742f6b1 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/DefaultMessageHandler.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/DefaultMessageHandler.java @@ -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 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); } }; diff --git a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java index 3fd1161bb0ed..d19ffadb5bda 100644 --- a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java +++ b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java @@ -220,9 +220,10 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{ } @Override - protected Set getStringsToSearch(final PsiElement element) { + protected Set 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.emptySet() : getStringsToSearch(aPackage); } final Set result = new HashSet(); @@ -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); } } diff --git a/java/java-indexing-api/src/com/intellij/psi/search/searches/AllClassesSearch.java b/java/java-indexing-api/src/com/intellij/psi/search/searches/AllClassesSearch.java index 21027204c180..db8c54d08d69 100644 --- a/java/java-indexing-api/src/com/intellij/psi/search/searches/AllClassesSearch.java +++ b/java/java-indexing-api/src/com/intellij/psi/search/searches/AllClassesSearch.java @@ -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 { } + @Override public String toString() { return myName; } diff --git a/platform/indexing-api/src/com/intellij/psi/search/IndexPattern.java b/platform/indexing-api/src/com/intellij/psi/search/IndexPattern.java index 098bd862cab7..fc5de78f9407 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/IndexPattern.java +++ b/platform/indexing-api/src/com/intellij/psi/search/IndexPattern.java @@ -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); diff --git a/platform/indexing-api/src/com/intellij/psi/search/PsiSearchRequest.java b/platform/indexing-api/src/com/intellij/psi/search/PsiSearchRequest.java index 3bb6792653f0..bc4f8c7f0f5e 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/PsiSearchRequest.java +++ b/platform/indexing-api/src/com/intellij/psi/search/PsiSearchRequest.java @@ -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; diff --git a/platform/indexing-api/src/com/intellij/psi/search/TextOccurenceProcessor.java b/platform/indexing-api/src/com/intellij/psi/search/TextOccurenceProcessor.java index bd533a186bc7..929fb543e497 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/TextOccurenceProcessor.java +++ b/platform/indexing-api/src/com/intellij/psi/search/TextOccurenceProcessor.java @@ -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); } diff --git a/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java b/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java index 5b3765930b41..4e94617e7681 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java +++ b/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java @@ -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() { @Override diff --git a/platform/indexing-api/src/com/intellij/psi/search/searches/IndexPatternSearch.java b/platform/indexing-api/src/com/intellij/psi/search/searches/IndexPatternSearch.java index 38044782796d..53f71e882ff7 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/searches/IndexPatternSearch.java +++ b/platform/indexing-api/src/com/intellij/psi/search/searches/IndexPatternSearch.java @@ -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 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 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 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 search(@NotNull PsiFile file, @NotNull IndexPatternProvider patternProvider, int startOffset, int endOffset) { final SearchParameters parameters = new SearchParameters(file, patternProvider, new TextRange(startOffset, endOffset)); diff --git a/platform/indexing-api/src/com/intellij/psi/search/searches/ReferenceDescriptor.java b/platform/indexing-api/src/com/intellij/psi/search/searches/ReferenceDescriptor.java index 7653595d4e2b..153b34b8a46b 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/searches/ReferenceDescriptor.java +++ b/platform/indexing-api/src/com/intellij/psi/search/searches/ReferenceDescriptor.java @@ -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 MAPPER = new Function() { @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; } diff --git a/platform/indexing-api/src/com/intellij/psi/search/searches/ReferencesSearch.java b/platform/indexing-api/src/com/intellij/psi/search/searches/ReferencesSearch.java index fdaea59acd0c..aafb85d529bc 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/searches/ReferencesSearch.java +++ b/platform/indexing-api/src/com/intellij/psi/search/searches/ReferencesSearch.java @@ -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 search(@NotNull PsiElement element) { return search(element, GlobalSearchScope.allScope(element.getProject()), false); } + @NotNull public static Query search(@NotNull PsiElement element, @NotNull SearchScope searchScope) { return search(element, searchScope, false); } + @NotNull public static Query search(@NotNull PsiElement element, @NotNull SearchScope searchScope, boolean ignoreAccessScope) { return search(new SearchParameters(element, searchScope, ignoreAccessScope)); } + @NotNull public static Query search(@NotNull final SearchParameters parameters) { final Query result = INSTANCE.createQuery(parameters); if (parameters.isSharedOptimizer) { @@ -110,7 +115,8 @@ public class ReferencesSearch extends ExtensibleQueryFactory(result, new SearchRequestQuery(element.getProject(), requests))); } - private static UniqueResultsQuery uniqueResults(Query composite) { + @NotNull + private static UniqueResultsQuery uniqueResults(@NotNull Query composite) { return new UniqueResultsQuery(composite, ContainerUtil.canonicalStrategy(), ReferenceDescriptor.MAPPER); } diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java index 5d301599395d..b5c3dd17afb7 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java @@ -104,7 +104,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { @NotNull final Processor 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); diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandler.java b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandler.java index 5152fa8f863b..c98f179aaa82 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandler.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandler.java @@ -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 getStringsToSearch(final PsiElement element) { + protected Collection getStringsToSearch(@NotNull final PsiElement element) { if (element instanceof PsiNamedElement) { return ApplicationManager.getApplication().runReadAction(new Computable>() { @Override diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesOptions.java b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesOptions.java index 39727af430e1..33212071bac3 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesOptions.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesOptions.java @@ -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 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; diff --git a/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java b/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java index 8f391d1947ed..48a4879a7bf4 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java +++ b/platform/lang-impl/src/com/intellij/refactoring/util/TextOccurrencesUtil.java @@ -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 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())) { diff --git a/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/PatternEditorContextMembersProvider.java b/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/PatternEditorContextMembersProvider.java index 0e9a216c441b..e23254da8d1a 100644 --- a/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/PatternEditorContextMembersProvider.java +++ b/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/PatternEditorContextMembersProvider.java @@ -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")) { diff --git a/python/src/com/jetbrains/python/findUsages/PyClassFindUsagesHandler.java b/python/src/com/jetbrains/python/findUsages/PyClassFindUsagesHandler.java index 1185c2707bff..10ddcea15fbe 100644 --- a/python/src/com/jetbrains/python/findUsages/PyClassFindUsagesHandler.java +++ b/python/src/com/jetbrains/python/findUsages/PyClassFindUsagesHandler.java @@ -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 getStringsToSearch(PsiElement element) { + protected Collection getStringsToSearch(@NotNull PsiElement element) { if (element instanceof PyFunction && PyNames.INIT.equals(((PyFunction) element).getName())) { return Collections.emptyList(); } diff --git a/python/src/com/jetbrains/python/magicLiteral/PyMagicLiteralFindUsagesHandlerFactory.java b/python/src/com/jetbrains/python/magicLiteral/PyMagicLiteralFindUsagesHandlerFactory.java index 006f4f3753e7..52091ed899b9 100644 --- a/python/src/com/jetbrains/python/magicLiteral/PyMagicLiteralFindUsagesHandlerFactory.java +++ b/python/src/com/jetbrains/python/magicLiteral/PyMagicLiteralFindUsagesHandlerFactory.java @@ -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 getStringsToSearch(final PsiElement element) { + protected Collection getStringsToSearch(@NotNull final PsiElement element) { return Collections.singleton(((StringLiteralExpression)element).getStringValue()); } }