do not search for prefixed properties without JSPs
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Wed, 1 Feb 2012 06:34:01 +0000 (10:34 +0400)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Wed, 1 Feb 2012 09:04:56 +0000 (13:04 +0400)
plugins/properties/src/META-INF/plugin.xml
plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java
plugins/properties/src/com/intellij/lang/properties/findUsages/PropertySearcher.java [new file with mode: 0644]
plugins/properties/src/com/intellij/psi/impl/search/PropertyReferenceViaLastWordSearcher.java [deleted file]
xml/impl/src/com/intellij/xml/util/XmlUtil.java

index bfb9373d6c3b9f509a04f672bbf7ed063c506f3f..b8e9f84ebe60b3b2409a4e7351ec933f2eb86be0 100644 (file)
@@ -45,7 +45,6 @@
     <elementDescriptionProvider implementation="com.intellij.lang.properties.PropertiesDescriptionProvider"/>
     <fileTypeFactory implementation="com.intellij.lang.properties.PropertiesFileTypeFactory"/>
     <fileTypeFactory implementation="com.intellij.lang.properties.editor.ResourceBundleEditorProvider" />
-    <referencesSearch implementation="com.intellij.psi.impl.search.PropertyReferenceViaLastWordSearcher"/>
     <favoriteNodeProvider implementation="com.intellij.ide.favoritesTreeView.ResourcesFavoriteNodeProvider"/>
 
     <localInspection language="Properties" shortName="UnusedProperty" bundle="messages.PropertiesBundle" key="unused.property.inspection.display.name"
index 2d2a48c23244360361cfc64f9735b2fc1cacf3c3..4089e6ca5f3b44303daa8e68c1e167c1165c8ee0 100644 (file)
@@ -19,23 +19,23 @@ import com.intellij.codeInspection.LocalInspectionToolSession;
 import com.intellij.codeInspection.ProblemHighlightType;
 import com.intellij.codeInspection.ProblemsHolder;
 import com.intellij.lang.ASTNode;
+import com.intellij.lang.properties.findUsages.PropertySearcher;
 import com.intellij.lang.properties.psi.Property;
+import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleUtil;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiElementVisitor;
 import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiReference;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.search.PsiSearchHelper;
 import com.intellij.psi.search.searches.ReferencesSearch;
+import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.containers.FilteringIterator;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.List;
-
 /**
  * @author cdr
  */
@@ -50,7 +50,6 @@ public class UnusedPropertyInspection extends PropertySuppressableInspectionBase
     return "UnusedProperty";
   }
 
-
   @NotNull
   @Override
   public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder,
@@ -59,6 +58,9 @@ public class UnusedPropertyInspection extends PropertySuppressableInspectionBase
     final PsiFile file = session.getFile();
     Module module = ModuleUtil.findModuleForPsiElement(file);
     if (module == null) return super.buildVisitor(holder, isOnTheFly, session);
+    Object[] extensions = Extensions.getExtensions("com.intellij.referencesSearch");
+    final PropertySearcher searcher =
+      (PropertySearcher)ContainerUtil.find(extensions, new FilteringIterator.InstanceOf<PropertySearcher>(PropertySearcher.class));
     final GlobalSearchScope searchScope = GlobalSearchScope.moduleWithDependentsScope(module);
     final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject());
     return new PsiElementVisitor() {
@@ -75,22 +77,19 @@ public class UnusedPropertyInspection extends PropertySuppressableInspectionBase
 
         String name = property.getName();
         if (name == null) return;
-        
-        final List<String> words = StringUtil.getWordsIn(name);
-        if (words.isEmpty()) {
-          return;
+        if (searcher != null) {
+          name = searcher.getKeyToSearch(name);
+          if (name == null) return;
         }
 
-        final String lastWord = words.get(words.size() - 1);
-        PsiSearchHelper.SearchCostResult cheapEnough = searchHelper.isCheapEnoughToSearch(lastWord, searchScope, file, original);
-        if (cheapEnough == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) return;
-        
-        cheapEnough = searchHelper.isCheapEnoughToSearch(name, searchScope, file, original);
+        PsiSearchHelper.SearchCostResult cheapEnough = searchHelper.isCheapEnoughToSearch(name, searchScope, file, original);
         if (cheapEnough == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) return;
 
-        final PsiReference usage = cheapEnough == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES ? null :
-                                   ReferencesSearch.search(property, searchScope, false).findFirst();
-        if (usage != null) return;
+        if (cheapEnough != PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES &&
+            ReferencesSearch.search(property, searchScope, false).findFirst() != null) {
+          return;
+        }
+
         final ASTNode propertyNode = property.getNode();
         assert propertyNode != null;
 
diff --git a/plugins/properties/src/com/intellij/lang/properties/findUsages/PropertySearcher.java b/plugins/properties/src/com/intellij/lang/properties/findUsages/PropertySearcher.java
new file mode 100644 (file)
index 0000000..b433826
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2000-2012 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.intellij.lang.properties.findUsages;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Dmitry Avdeev
+ *         Date: 1/31/12
+ */
+public interface PropertySearcher {
+  
+  @Nullable
+  String getKeyToSearch(String propertyName);
+}
diff --git a/plugins/properties/src/com/intellij/psi/impl/search/PropertyReferenceViaLastWordSearcher.java b/plugins/properties/src/com/intellij/psi/impl/search/PropertyReferenceViaLastWordSearcher.java
deleted file mode 100644 (file)
index ad6f6c0..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2000-2009 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.intellij.psi.impl.search;
-
-import com.intellij.lang.properties.IProperty;
-import com.intellij.openapi.application.QueryExecutorBase;
-import com.intellij.openapi.fileTypes.StdFileTypes;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiReference;
-import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.psi.search.SearchScope;
-import com.intellij.psi.search.UsageSearchContext;
-import com.intellij.psi.search.searches.ReferencesSearch;
-import com.intellij.util.Processor;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.List;
-
-/**
- * @author ven
- */
-public class PropertyReferenceViaLastWordSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> {
-  public PropertyReferenceViaLastWordSearcher() {
-    super(true);
-  }
-
-  // add to the search results occurences in JSPs of the last word in the property name, since this stuff is possible:
-  // <bla:bla ref.key="lastWord> (can reference to xxx.lastWord property)
-
-  @Override
-  public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
-    final PsiElement refElement = queryParameters.getElementToSearch();
-    if (!(refElement instanceof IProperty)) return;
-
-    final String name = ((IProperty)refElement).getName();
-    if (name == null) return;
-    final List<String> words = StringUtil.getWordsIn(name);
-    if (words.isEmpty()) return;
-    final String lastWord = words.get(words.size() - 1);
-
-    SearchScope searchScope = queryParameters.getEffectiveSearchScope();
-    if (searchScope instanceof GlobalSearchScope) {
-      searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope)searchScope, StdFileTypes.JSP, StdFileTypes.JSPX);
-    }
-    queryParameters.getOptimizer().searchWord(lastWord, searchScope, UsageSearchContext.IN_FOREIGN_LANGUAGES, false, refElement);
-  }
-}
index 5b9f3dbe0a1bd0edbf7a3630f5540104f167ce0f..348137ad3027f0524df7398920bf42bdd5aaf500 100644 (file)
@@ -110,8 +110,8 @@ public class XmlUtil {
   @NonNls public static final String JSF_HTML_URI = "http://java.sun.com/jsf/html";
   @NonNls public static final String JSF_CORE_URI = "http://java.sun.com/jsf/core";
 
-  @NonNls private static final String JSTL_FORMAT_URI = "http://java.sun.com/jsp/jstl/fmt";
-  @NonNls private static final String JSTL_FORMAT_URI2 = "http://java.sun.com/jstl/fmt";
+  @NonNls public static final String JSTL_FORMAT_URI = "http://java.sun.com/jsp/jstl/fmt";
+  @NonNls public static final String JSTL_FORMAT_URI2 = "http://java.sun.com/jstl/fmt";
   @NonNls private static final String JSTL_FORMAT_URI3 = "http://java.sun.com/jstl/fmt_rt";
   @NonNls public static final String[] JSTL_FORMAT_URIS = {JSTL_FORMAT_URI, JSTL_FORMAT_URI2, JSTL_FORMAT_URI3};