From d8ef503a2303bdc70f564ea004876c4b0072e7f1 Mon Sep 17 00:00:00 2001 From: Peter Gromov Date: Fri, 25 Apr 2008 20:19:40 +0400 Subject: [PATCH] IDEADEV-26249 Freemarker "Cannot resolve variable" should respect the list tag --- .../DefaultFindUsagesHandlerFactory.java | 31 ++++++++++ .../find/findUsages/FindUsagesHandler.java | 2 +- .../find/findUsages/FindUsagesHandlerFactory.java | 9 ++- .../find/findUsages/FindUsagesManager.java | 34 +++++------ .../src/META-INF/LangExtensionPoints.xml | 2 + platform-resources/src/META-INF/LangExtensions.xml | 2 + .../find/findUsages/JavaFindUsagesHandler.java | 52 +--------------- .../findUsages/JavaFindUsagesHandlerFactory.java | 70 ++++++++++++++++++++++ .../com/intellij/psi/impl/JavaPsiFacadeImpl.java | 1 - ui-designer/impl/META-INF/plugin.xml | 2 +- 10 files changed, 129 insertions(+), 76 deletions(-) create mode 100644 lang-impl/src/com/intellij/find/findUsages/DefaultFindUsagesHandlerFactory.java create mode 100644 source/com/intellij/find/findUsages/JavaFindUsagesHandlerFactory.java diff --git a/lang-impl/src/com/intellij/find/findUsages/DefaultFindUsagesHandlerFactory.java b/lang-impl/src/com/intellij/find/findUsages/DefaultFindUsagesHandlerFactory.java new file mode 100644 index 0000000000..c3c891398d --- /dev/null +++ b/lang-impl/src/com/intellij/find/findUsages/DefaultFindUsagesHandlerFactory.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved. + * Use is subject to license terms. + */ +package com.intellij.find.findUsages; + +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.lang.findUsages.LanguageFindUsages; + +/** + * @author peter +*/ +public class DefaultFindUsagesHandlerFactory extends FindUsagesHandlerFactory { + public boolean canFindUsages(final PsiElement element) { + if (element instanceof PsiFile) { + if (((PsiFile)element).getVirtualFile() == null) return false; + } + else if (!LanguageFindUsages.INSTANCE.forLanguage(element.getLanguage()).canFindUsagesFor(element)) { + return false; + } + return true; + } + + public FindUsagesHandler createFindUsagesHandler(final PsiElement element, final boolean forHighlightUsages) { + if (canFindUsages(element)) { + return new FindUsagesHandler(element){}; + } + return null; + } +} diff --git a/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandler.java b/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandler.java index 47684faf44..8e95a2de99 100644 --- a/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandler.java +++ b/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandler.java @@ -24,7 +24,7 @@ import java.util.Collection; /** * @author peter */ -public class FindUsagesHandler { +public abstract class FindUsagesHandler { private final PsiElement myPsiElement; protected FindUsagesHandler(@NotNull PsiElement psiElement) { diff --git a/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandlerFactory.java b/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandlerFactory.java index 2cb530f2a0..583fd31186 100644 --- a/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandlerFactory.java +++ b/lang-impl/src/com/intellij/find/findUsages/FindUsagesHandlerFactory.java @@ -1,14 +1,17 @@ package com.intellij.find.findUsages; import com.intellij.psi.PsiElement; +import com.intellij.openapi.extensions.ExtensionPointName; import org.jetbrains.annotations.Nullable; /** * @author yole */ -public interface FindUsagesHandlerFactory { - boolean canFindUsages(PsiElement element); +public abstract class FindUsagesHandlerFactory { + public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.findUsagesHandlerFactory"); + + public abstract boolean canFindUsages(PsiElement element); @Nullable - FindUsagesHandler createFindUsagesHandler(PsiElement element, final boolean forHighlightUsages); + public abstract FindUsagesHandler createFindUsagesHandler(PsiElement element, final boolean forHighlightUsages); } diff --git a/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java b/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java index a5ce1af793..1e8919bcc8 100644 --- a/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java +++ b/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java @@ -12,6 +12,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorLocation; import com.intellij.openapi.fileEditor.TextEditor; @@ -92,25 +93,6 @@ public class FindUsagesManager implements JDOMExternalizable { public FindUsagesManager(final Project project, com.intellij.usages.UsageViewManager anotherManager) { myProject = project; myAnotherManager = anotherManager; - - myHandlers.add(new FindUsagesHandlerFactory() { - public boolean canFindUsages(final PsiElement element) { - if (element instanceof PsiFile) { - if (((PsiFile)element).getVirtualFile() == null) return false; - } - else if (!LanguageFindUsages.INSTANCE.forLanguage(element.getLanguage()).canFindUsagesFor(element)) { - return false; - } - return true; - } - - public FindUsagesHandler createFindUsagesHandler(final PsiElement element, final boolean forHighlightUsages) { - if (canFindUsages(element)) { - return new FindUsagesHandler(element); - } - return null; - } - }); } public void registerFindUsagesHandler(FindUsagesHandlerFactory handler) { @@ -123,6 +105,11 @@ public class FindUsagesManager implements JDOMExternalizable { return true; } } + for (FindUsagesHandlerFactory factory : Extensions.getExtensions(FindUsagesHandlerFactory.EP_NAME, myProject)) { + if (factory.canFindUsages(element)) { + return true; + } + } return false; } @@ -213,6 +200,14 @@ public class FindUsagesManager implements JDOMExternalizable { } } } + for (FindUsagesHandlerFactory factory : Extensions.getExtensions(FindUsagesHandlerFactory.EP_NAME, myProject)) { + if (factory.canFindUsages(element)) { + final FindUsagesHandler handler = factory.createFindUsagesHandler(element, forHighlightUsages); + if (handler != null) { + return handler; + } + } + } return null; } @@ -618,4 +613,5 @@ public class FindUsagesManager implements JDOMExternalizable { if (elements == null || elements.length == 0) myFindUsagesHistory.remove(data); } } + } \ No newline at end of file diff --git a/platform-resources/src/META-INF/LangExtensionPoints.xml b/platform-resources/src/META-INF/LangExtensionPoints.xml index dcc9403a8b..f998a20302 100644 --- a/platform-resources/src/META-INF/LangExtensionPoints.xml +++ b/platform-resources/src/META-INF/LangExtensionPoints.xml @@ -249,6 +249,8 @@ + + diff --git a/platform-resources/src/META-INF/LangExtensions.xml b/platform-resources/src/META-INF/LangExtensions.xml index 526f6e1c47..8fce69b504 100644 --- a/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform-resources/src/META-INF/LangExtensions.xml @@ -224,6 +224,8 @@ + + diff --git a/source/com/intellij/find/findUsages/JavaFindUsagesHandler.java b/source/com/intellij/find/findUsages/JavaFindUsagesHandler.java index 0e3cbbbe49..9420c88901 100644 --- a/source/com/intellij/find/findUsages/JavaFindUsagesHandler.java +++ b/source/com/intellij/find/findUsages/JavaFindUsagesHandler.java @@ -5,15 +5,12 @@ package com.intellij.find.findUsages; import com.intellij.CommonBundle; import com.intellij.find.FindBundle; -import com.intellij.find.FindManager; -import com.intellij.find.impl.FindManagerImpl; import com.intellij.ide.util.SuperMethodWarningUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadActionProcessor; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Computable; @@ -683,58 +680,11 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{ return psiElement instanceof PsiPackage; } - - public static void setupForProject(Project project) { - final FindUsagesOptions findClassOptions = FindUsagesHandler.createFindUsagesOptions(project); - final FindUsagesOptions findMethodOptions = FindUsagesHandler.createFindUsagesOptions(project); - findMethodOptions.isCheckDeepInheritance = false; - findMethodOptions.isIncludeSubpackages = false; - findMethodOptions.isSearchForTextOccurences = false; - final FindUsagesOptions findPackageOptions = FindUsagesHandler.createFindUsagesOptions(project); - final FindUsagesOptions findThrowOptions = FindUsagesHandler.createFindUsagesOptions(project); - final FindUsagesOptions findVariableOptions = FindUsagesHandler.createFindUsagesOptions(project); - findVariableOptions.isCheckDeepInheritance = false; - findVariableOptions.isIncludeSubpackages = false; - findVariableOptions.isSearchForTextOccurences = false; - - ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager().registerFindUsagesHandler( - new FindUsagesHandlerFactory() { - public boolean canFindUsages(final PsiElement element) { - return true; - } - - public FindUsagesHandler createFindUsagesHandler(final PsiElement element, final boolean forHighlightUsages) { - if (element instanceof PsiDirectory) { - final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element); - return psiPackage == null - ? null - : new JavaFindUsagesHandler(psiPackage, findClassOptions, findMethodOptions, findPackageOptions, findThrowOptions, - findVariableOptions); - } - - if (element instanceof PsiMethod && !forHighlightUsages) { - final PsiMethod[] methods = SuperMethodWarningUtil.checkSuperMethods((PsiMethod)element, JavaFindUsagesHandler.ACTION_STRING); - if (methods.length > 1) { - return new JavaFindUsagesHandler(element, methods, findClassOptions, findMethodOptions, findPackageOptions, - findThrowOptions, findVariableOptions); - } - if (methods.length == 1) { - return new JavaFindUsagesHandler(methods[0], findClassOptions, findMethodOptions, findPackageOptions, - findThrowOptions, findVariableOptions); - } - return null; - } - - return new JavaFindUsagesHandler(element, findClassOptions, findMethodOptions, findPackageOptions, - findThrowOptions, findVariableOptions); - } - }); - } - public Collection findReferencesToHighlight(final PsiElement target, final SearchScope searchScope) { if (target instanceof PsiMethod) { return MethodReferencesSearch.search((PsiMethod)target, searchScope, true).findAll(); } return super.findReferencesToHighlight(target, searchScope); } + } diff --git a/source/com/intellij/find/findUsages/JavaFindUsagesHandlerFactory.java b/source/com/intellij/find/findUsages/JavaFindUsagesHandlerFactory.java new file mode 100644 index 0000000000..8bcd7ee422 --- /dev/null +++ b/source/com/intellij/find/findUsages/JavaFindUsagesHandlerFactory.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved. + * Use is subject to license terms. + */ +package com.intellij.find.findUsages; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.*; +import com.intellij.ide.util.SuperMethodWarningUtil; + +/** + * @author peter +*/ +public class JavaFindUsagesHandlerFactory extends FindUsagesHandlerFactory { + private final FindUsagesOptions myFindClassOptions; + private final FindUsagesOptions myFindMethodOptions; + private final FindUsagesOptions myFindPackageOptions; + private final FindUsagesOptions myFindThrowOptions; + private final FindUsagesOptions myFindVariableOptions; + + public JavaFindUsagesHandlerFactory(Project project) { + final FindUsagesOptions findClassOptions = FindUsagesHandler.createFindUsagesOptions(project); + final FindUsagesOptions findMethodOptions = FindUsagesHandler.createFindUsagesOptions(project); + findMethodOptions.isCheckDeepInheritance = false; + findMethodOptions.isIncludeSubpackages = false; + findMethodOptions.isSearchForTextOccurences = false; + final FindUsagesOptions findPackageOptions = FindUsagesHandler.createFindUsagesOptions(project); + final FindUsagesOptions findThrowOptions = FindUsagesHandler.createFindUsagesOptions(project); + final FindUsagesOptions findVariableOptions = FindUsagesHandler.createFindUsagesOptions(project); + findVariableOptions.isCheckDeepInheritance = false; + findVariableOptions.isIncludeSubpackages = false; + findVariableOptions.isSearchForTextOccurences = false; + + myFindClassOptions = findClassOptions; + myFindMethodOptions = findMethodOptions; + myFindPackageOptions = findPackageOptions; + myFindThrowOptions = findThrowOptions; + myFindVariableOptions = findVariableOptions; + } + + public boolean canFindUsages(final PsiElement element) { + return true; + } + + public FindUsagesHandler createFindUsagesHandler(final PsiElement element, final boolean forHighlightUsages) { + if (element instanceof PsiDirectory) { + final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element); + return psiPackage == null + ? null + : new JavaFindUsagesHandler(psiPackage, myFindClassOptions, myFindMethodOptions, myFindPackageOptions, myFindThrowOptions, + myFindVariableOptions); + } + + if (element instanceof PsiMethod && !forHighlightUsages) { + final PsiMethod[] methods = SuperMethodWarningUtil.checkSuperMethods((PsiMethod)element, JavaFindUsagesHandler.ACTION_STRING); + if (methods.length > 1) { + return new JavaFindUsagesHandler(element, methods, myFindClassOptions, myFindMethodOptions, myFindPackageOptions, + myFindThrowOptions, myFindVariableOptions); + } + if (methods.length == 1) { + return new JavaFindUsagesHandler(methods[0], myFindClassOptions, myFindMethodOptions, myFindPackageOptions, myFindThrowOptions, + myFindVariableOptions); + } + return null; + } + + return new JavaFindUsagesHandler(element, myFindClassOptions, myFindMethodOptions, myFindPackageOptions, myFindThrowOptions, + myFindVariableOptions); + } +} diff --git a/source/com/intellij/psi/impl/JavaPsiFacadeImpl.java b/source/com/intellij/psi/impl/JavaPsiFacadeImpl.java index 349f95122f..8f3a1e0cc0 100644 --- a/source/com/intellij/psi/impl/JavaPsiFacadeImpl.java +++ b/source/com/intellij/psi/impl/JavaPsiFacadeImpl.java @@ -112,7 +112,6 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx implements Disposable { ); - JavaFindUsagesHandler.setupForProject(project); JavaChangeUtilSupport.setup(); DummyHolderFactory.setFactory(new JavaDummyHolderFactory()); HelperFactory.setFactory(new JavaHelperFactory()); diff --git a/ui-designer/impl/META-INF/plugin.xml b/ui-designer/impl/META-INF/plugin.xml index 5a44380ba5..b839e69f3f 100644 --- a/ui-designer/impl/META-INF/plugin.xml +++ b/ui-designer/impl/META-INF/plugin.xml @@ -22,7 +22,7 @@ - + -- 2.11.4.GIT