From 5d41414abc5146e4b69bfdcc9211cdba60891a3d Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 27 Feb 2014 13:36:21 +0400 Subject: [PATCH 01/95] Switched from ArrayList to array for annotators for performance reasons --- .../python/validation/PyAnnotatingVisitor.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/python/src/com/jetbrains/python/validation/PyAnnotatingVisitor.java b/python/src/com/jetbrains/python/validation/PyAnnotatingVisitor.java index 39ab3639751a..8accd9854acc 100644 --- a/python/src/com/jetbrains/python/validation/PyAnnotatingVisitor.java +++ b/python/src/com/jetbrains/python/validation/PyAnnotatingVisitor.java @@ -31,10 +31,7 @@ import java.util.List; */ public class PyAnnotatingVisitor implements Annotator { private static final Logger LOGGER = Logger.getInstance(PyAnnotatingVisitor.class.getName()); - - private final List myAnnotators = new ArrayList(); - - private final Class[] ANNOTATOR_CLASSES = new Class[] { + private static final Class[] ANNOTATOR_CLASSES = new Class[] { AssignTargetAnnotator.class, ParameterListAnnotator.class, HighlightingAnnotator.class, @@ -44,10 +41,13 @@ public class PyAnnotatingVisitor implements Annotator { GlobalAnnotator.class, ImportAnnotator.class, PyBuiltinAnnotator.class, - UnsupportedFeatures.class + UnsupportedFeatures.class }; + private final PyAnnotator[] myAnnotators; + public PyAnnotatingVisitor() { + final List annotators = new ArrayList(); for (Class cls : ANNOTATOR_CLASSES) { PyAnnotator annotator; try { @@ -61,13 +61,14 @@ public class PyAnnotatingVisitor implements Annotator { LOGGER.error(e); continue; } - myAnnotators.add(annotator); + annotators.add(annotator); } + myAnnotators = annotators.toArray(new PyAnnotator[annotators.size()]); } public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) { final PsiFile file = psiElement.getContainingFile(); - for(PyAnnotator annotator: myAnnotators) { + for (PyAnnotator annotator : myAnnotators) { if (file instanceof PyFileImpl && !((PyFileImpl)file).isAcceptedFor(annotator.getClass())) continue; annotator.annotateElement(psiElement, holder); } From 9194fc697ab7a2c89f67ba521556384445a274f2 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 27 Feb 2014 15:23:39 +0400 Subject: [PATCH 02/95] Renamed PyBuiltinCache.hasInBuiltins to isBuiltin --- .../python/findUsages/PyFindUsagesHandlerFactory.java | 2 +- .../inspections/PyArgumentEqualDefaultInspection.java | 2 +- .../python/inspections/PyComparisonWithNoneInspection.java | 2 +- .../python/inspections/PyInitNewSignatureInspection.java | 2 +- .../inspections/PySetFunctionToLiteralInspection.java | 2 +- .../inspections/PyUnboundLocalVariableInspection.java | 2 +- .../inspections/PyUnresolvedReferencesInspection.java | 4 ++-- .../python/inspections/PyUnusedLocalInspectionVisitor.java | 2 +- python/src/com/jetbrains/python/psi/PyUtil.java | 2 +- .../src/com/jetbrains/python/psi/impl/PyBuiltinCache.java | 7 ++----- .../jetbrains/python/psi/impl/PyCallExpressionHelper.java | 2 +- python/src/com/jetbrains/python/psi/impl/PyClassImpl.java | 2 +- .../src/com/jetbrains/python/psi/impl/PyDecoratorImpl.java | 2 +- .../python/psi/impl/references/PyQualifiedReference.java | 2 +- .../python/psi/resolve/CompletionVariantsProcessor.java | 2 +- .../com/jetbrains/python/psi/types/PyClassTypeImpl.java | 2 +- .../changeSignature/PyChangeSignatureHandler.java | 2 +- .../python/refactoring/classes/PyClassRefactoringUtil.java | 2 +- .../jetbrains/python/validation/PyBuiltinAnnotator.java | 2 +- 19 files changed, 21 insertions(+), 24 deletions(-) diff --git a/python/src/com/jetbrains/python/findUsages/PyFindUsagesHandlerFactory.java b/python/src/com/jetbrains/python/findUsages/PyFindUsagesHandlerFactory.java index 78d9d654ef77..82f2605ec5d8 100644 --- a/python/src/com/jetbrains/python/findUsages/PyFindUsagesHandlerFactory.java +++ b/python/src/com/jetbrains/python/findUsages/PyFindUsagesHandlerFactory.java @@ -99,6 +99,6 @@ public class PyFindUsagesHandlerFactory extends FindUsagesHandlerFactory { return false; } return (PyNames.FAKE_OLD_BASE.equals(containingClass.getName()) || - (PyNames.OBJECT.equals(containingClass.getName()) && PyBuiltinCache.getInstance(fun).hasInBuiltins(containingClass))); + (PyNames.OBJECT.equals(containingClass.getName()) && PyBuiltinCache.getInstance(fun).isBuiltin(containingClass))); } } diff --git a/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java b/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java index 6a06f875b1b2..9b8b0891764d 100644 --- a/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyArgumentEqualDefaultInspection.java @@ -84,7 +84,7 @@ public class PyArgumentEqualDefaultInspection extends PyInspection { private static boolean hasSpecialCasedDefaults(Callable callable, PsiElement anchor) { final String name = callable.getName(); final PyBuiltinCache cache = PyBuiltinCache.getInstance(anchor); - if ("getattr".equals(name) && cache.hasInBuiltins(callable)) { + if ("getattr".equals(name) && cache.isBuiltin(callable)) { return true; } else if ("get".equals(name) || "pop".equals(name)) { diff --git a/python/src/com/jetbrains/python/inspections/PyComparisonWithNoneInspection.java b/python/src/com/jetbrains/python/inspections/PyComparisonWithNoneInspection.java index 3883cd0a6f43..ec31c002a803 100644 --- a/python/src/com/jetbrains/python/inspections/PyComparisonWithNoneInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyComparisonWithNoneInspection.java @@ -64,7 +64,7 @@ public class PyComparisonWithNoneInspection extends PyInspection { PsiReference reference = node.getReference(); assert reference != null; PsiElement result = reference.resolve(); - if (result == null || PyBuiltinCache.getInstance(node).hasInBuiltins(result)) { + if (result == null || PyBuiltinCache.getInstance(node).isBuiltin(result)) { registerProblem(node, "Comparison with None performed with equality operators", new ComparisonWithNoneQuickFix()); } } diff --git a/python/src/com/jetbrains/python/inspections/PyInitNewSignatureInspection.java b/python/src/com/jetbrains/python/inspections/PyInitNewSignatureInspection.java index 6ced1d18eae1..694d7ad17611 100644 --- a/python/src/com/jetbrains/python/inspections/PyInitNewSignatureInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyInitNewSignatureInspection.java @@ -57,7 +57,7 @@ public class PyInitNewSignatureInspection extends PyInspection { if (! cls.isNewStyleClass()) return; // old-style classes don't know about __new__ PyFunction init_or_new = cls.findInitOrNew(false); // only local final PyBuiltinCache builtins = PyBuiltinCache.getInstance(cls); - if (init_or_new == null || builtins.hasInBuiltins(init_or_new.getContainingClass())) return; // nothing is overridden + if (init_or_new == null || builtins.isBuiltin(init_or_new.getContainingClass())) return; // nothing is overridden String the_other_name = PyNames.NEW.equals(init_or_new.getName()) ? PyNames.INIT : PyNames.NEW; PyFunction the_other = cls.findMethodByName(the_other_name, true); if (the_other == null || builtins.getClass("object") == the_other.getContainingClass()) return; diff --git a/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java b/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java index f0bdeb399a1b..186d012a382f 100644 --- a/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java +++ b/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java @@ -99,7 +99,7 @@ public class PySetFunctionToLiteralInspection extends PyInspection { PsiReference reference = callee.getReference(); if (reference != null) { PsiElement resolved = reference.resolve(); - if (resolved != null && PyBuiltinCache.getInstance(callee).hasInBuiltins(resolved)) { + if (resolved != null && PyBuiltinCache.getInstance(callee).isBuiltin(resolved)) { return true; } } diff --git a/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java b/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java index abec5b165fb9..9e0031afec84 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java @@ -132,7 +132,7 @@ public class PyUnboundLocalVariableInspection extends PyInspection { return; } final PsiElement resolved = ref.resolve(); - final boolean isBuiltin = PyBuiltinCache.getInstance(node).hasInBuiltins(resolved); + final boolean isBuiltin = PyBuiltinCache.getInstance(node).isBuiltin(resolved); if (owner instanceof PyClass) { if (isBuiltin || ScopeUtil.getDeclarationScopeOwner(owner, name) != null) { return; diff --git a/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java b/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java index 9e08a47eafc9..2e33a1f175b1 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java @@ -749,7 +749,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection { PsiElement element = reference.getElement(); if (type instanceof PyClassTypeImpl) { PyClass cls = ((PyClassType)type).getPyClass(); - if (!PyBuiltinCache.getInstance(element).hasInBuiltins(cls)) { + if (!PyBuiltinCache.getInstance(element).isBuiltin(cls)) { if (element.getParent() instanceof PyCallExpression) { actions.add(new AddMethodQuickFix(refText, (PyClassType)type, true)); } @@ -886,7 +886,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection { return true; } method = resolveClassMember(cls, PyNames.GETATTRIBUTE, context); - if (method != null && !PyBuiltinCache.getInstance(cls).hasInBuiltins(method)) { + if (method != null && !PyBuiltinCache.getInstance(cls).isBuiltin(method)) { return true; } return false; diff --git a/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java b/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java index f7883535d2e6..3dc42057348f 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java +++ b/python/src/com/jetbrains/python/inspections/PyUnusedLocalInspectionVisitor.java @@ -328,7 +328,7 @@ public class PyUnusedLocalInspectionVisitor extends PyInspectionVisitor { PyCallExpression expr = (PyCallExpression) source; if (expr.isCalleeText("range", "xrange")) { final Callable callee = expr.resolveCalleeFunction(PyResolveContext.noImplicits().withTypeEvalContext(myTypeEvalContext)); - if (callee != null && PyBuiltinCache.getInstance(forStatement).hasInBuiltins(callee)) { + if (callee != null && PyBuiltinCache.getInstance(forStatement).isBuiltin(callee)) { return true; } } diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index 83036eec8626..e174412fcf5b 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -1138,7 +1138,7 @@ public class PyUtil { if (reference == null) return false; PsiElement resolved = reference.resolve(); PyBuiltinCache cache = PyBuiltinCache.getInstance(node); - if (resolved != null && cache.hasInBuiltins(resolved)) { + if (resolved != null && cache.isBuiltin(resolved)) { PyExpression[] args = node.getArguments(); if (args.length > 0) { String firstArg = args[0].getText(); diff --git a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java index b545290c13c6..aefeb6bbba8e 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java +++ b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java @@ -27,10 +27,7 @@ import com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiFileSystemItem; -import com.intellij.psi.PsiManager; +import com.intellij.psi.*; import com.jetbrains.python.PyNames; import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyClass; @@ -337,7 +334,7 @@ public class PyBuiltinCache { * @param target an element to check. * @return true iff target is inside the __builtins__.py */ - public boolean hasInBuiltins(@Nullable PsiElement target) { + public boolean isBuiltin(@Nullable PsiElement target) { if (target == null) return false; if (! target.isValid()) return false; final PsiFile the_file = target.getContainingFile(); diff --git a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java index 781dc28c0d35..c32ec1ba1566 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java +++ b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java @@ -439,7 +439,7 @@ public class PyCallExpressionHelper { } if (cls != null && t == null) { final PyFunction newMethod = cls.findMethodByName(PyNames.NEW, true); - if (newMethod != null && !PyBuiltinCache.getInstance(call).hasInBuiltins(newMethod)) { + if (newMethod != null && !PyBuiltinCache.getInstance(call).isBuiltin(newMethod)) { return PyUnionType.createWeakType(new PyClassTypeImpl(cls, false)); } } diff --git a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java index bea0e10312bb..516cb4704a95 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java @@ -1149,7 +1149,7 @@ public class PyClassImpl extends PyPresentableElementImpl implement } } final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(this); - if (result.isEmpty() && isValid() && !builtinCache.hasInBuiltins(this)) { + if (result.isEmpty() && isValid() && !builtinCache.isBuiltin(this)) { final String implicitSuperName = LanguageLevel.forElement(this).isPy3K() ? PyNames.OBJECT : PyNames.FAKE_OLD_BASE; final PyClass implicitSuper = builtinCache.getClass(implicitSuperName); if (implicitSuper != null) { diff --git a/python/src/com/jetbrains/python/psi/impl/PyDecoratorImpl.java b/python/src/com/jetbrains/python/psi/impl/PyDecoratorImpl.java index 92e75ed21a5a..9e8ef1aa8c69 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyDecoratorImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyDecoratorImpl.java @@ -65,7 +65,7 @@ public class PyDecoratorImpl extends StubBasedPsiElementBase im if (node != null) { PyReferenceExpression ref = (PyReferenceExpression)node.getPsi(); PsiElement target = ref.getReference().resolve(); - return PyBuiltinCache.getInstance(this).hasInBuiltins(target); + return PyBuiltinCache.getInstance(this).isBuiltin(target); } return false; } diff --git a/python/src/com/jetbrains/python/psi/impl/references/PyQualifiedReference.java b/python/src/com/jetbrains/python/psi/impl/references/PyQualifiedReference.java index e66a219062b6..a537dae722c1 100644 --- a/python/src/com/jetbrains/python/psi/impl/references/PyQualifiedReference.java +++ b/python/src/com/jetbrains/python/psi/impl/references/PyQualifiedReference.java @@ -212,7 +212,7 @@ public class PyQualifiedReference extends PyReferenceImpl { PyExpression callee = ((PyCallExpression)qualifier).getCallee(); if (callee instanceof PyReferenceExpression && PyNames.SUPER.equals(callee.getName())) { PsiElement target = ((PyReferenceExpression)callee).getReference().resolve(); - if (target != null && PyBuiltinCache.getInstance(qualifier).hasInBuiltins(target)) return false; // super() of unresolved type + if (target != null && PyBuiltinCache.getInstance(qualifier).isBuiltin(target)) return false; // super() of unresolved type } } } diff --git a/python/src/com/jetbrains/python/psi/resolve/CompletionVariantsProcessor.java b/python/src/com/jetbrains/python/psi/resolve/CompletionVariantsProcessor.java index 3987e4e03032..bfa402449853 100644 --- a/python/src/com/jetbrains/python/psi/resolve/CompletionVariantsProcessor.java +++ b/python/src/com/jetbrains/python/psi/resolve/CompletionVariantsProcessor.java @@ -124,7 +124,7 @@ public class CompletionVariantsProcessor extends VariantsProcessor { // special case hack to avoid the need of patching generator3.py PyClass containingClass = callee.getContainingClass(); if (containingClass != null && PyNames.PROPERTY.equals(containingClass.getName()) && - PyBuiltinCache.getInstance(elementInCall).hasInBuiltins(containingClass)) { + PyBuiltinCache.getInstance(elementInCall).isBuiltin(containingClass)) { return true; } diff --git a/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java b/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java index 715421ace1cb..a63fd46bf3a7 100644 --- a/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java +++ b/python/src/com/jetbrains/python/psi/types/PyClassTypeImpl.java @@ -531,7 +531,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType { @Override public boolean isBuiltin(TypeEvalContext context) { - return PyBuiltinCache.getInstance(myClass).hasInBuiltins(myClass); + return PyBuiltinCache.getInstance(myClass).isBuiltin(myClass); } @Override diff --git a/python/src/com/jetbrains/python/refactoring/changeSignature/PyChangeSignatureHandler.java b/python/src/com/jetbrains/python/refactoring/changeSignature/PyChangeSignatureHandler.java index 719bc833d1bf..6895249a641f 100644 --- a/python/src/com/jetbrains/python/refactoring/changeSignature/PyChangeSignatureHandler.java +++ b/python/src/com/jetbrains/python/refactoring/changeSignature/PyChangeSignatureHandler.java @@ -153,7 +153,7 @@ public class PyChangeSignatureHandler implements ChangeSignatureHandler { final PyClass baseClass = deepestSuperMethod.getContainingClass(); final PyBuiltinCache cache = PyBuiltinCache.getInstance(baseClass); String baseClassName = baseClass == null? "" : baseClass.getName(); - if (cache.hasInBuiltins(baseClass)) + if (cache.isBuiltin(baseClass)) return function; final String message = PyBundle.message( "refactoring.change.signature.find.usages.of.base.class", diff --git a/python/src/com/jetbrains/python/refactoring/classes/PyClassRefactoringUtil.java b/python/src/com/jetbrains/python/refactoring/classes/PyClassRefactoringUtil.java index 79f0382a8e23..3dfc71bc87f7 100644 --- a/python/src/com/jetbrains/python/refactoring/classes/PyClassRefactoringUtil.java +++ b/python/src/com/jetbrains/python/refactoring/classes/PyClassRefactoringUtil.java @@ -298,7 +298,7 @@ public final class PyClassRefactoringUtil { } public static boolean insertImport(PsiElement anchor, PsiNamedElement element, @Nullable String asName, boolean preferFromImport) { - if (PyBuiltinCache.getInstance(element).hasInBuiltins(element)) return false; + if (PyBuiltinCache.getInstance(element).isBuiltin(element)) return false; final PsiFile newFile = element.getContainingFile(); final PsiFile file = anchor.getContainingFile(); if (newFile == file) return false; diff --git a/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java b/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java index 417c3621d095..8c82f3a5c5bd 100644 --- a/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java +++ b/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java @@ -40,7 +40,7 @@ public class PyBuiltinAnnotator extends PyAnnotator { // things like len() ResolveResult[] resolved = node.getReference().multiResolve(false); // constructors, etc may give multiple results... if (resolved.length > 0) { - if (PyBuiltinCache.getInstance(node).hasInBuiltins(resolved[0].getElement())) { // ...but we only care about the default resolution + if (PyBuiltinCache.getInstance(node).isBuiltin(resolved[0].getElement())) { // ...but we only care about the default resolution Annotation ann; PsiElement parent = node.getParent(); if (parent instanceof PyDecorator) { From 64d19effe4464117c3f8a022cc559695fbb388a0 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 27 Feb 2014 15:32:18 +0400 Subject: [PATCH 03/95] Moved isInBuiltins check for expressions to PyBuiltinCache --- .../PySetFunctionToLiteralInspection.java | 18 +----------------- .../python/psi/impl/PyBuiltinCache.java | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java b/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java index 186d012a382f..e846fdba3c19 100644 --- a/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java +++ b/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java @@ -22,9 +22,7 @@ import com.intellij.codeInspection.ProblemsHolder; import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.openapi.util.JDOMExternalizableStringList; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; -import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.PsiReference; import com.jetbrains.python.PyBundle; import com.jetbrains.python.PyNames; import com.jetbrains.python.inspections.quickfix.ReplaceFunctionWithSetLiteralQuickFix; @@ -66,7 +64,7 @@ public class PySetFunctionToLiteralInspection extends PyInspection { public void visitPyCallExpression(final PyCallExpression node) { if (!isAvailable(node)) return; PyExpression callee = node.getCallee(); - if (node.isCalleeText(PyNames.SET) && isInBuiltins(callee)) { + if (node.isCalleeText(PyNames.SET) && callee != null && PyBuiltinCache.isInBuiltins(callee)) { PyExpression[] arguments = node.getArguments(); if (arguments.length == 1) { PyElement[] elements = getSetCallArguments(node); @@ -91,20 +89,6 @@ public class PySetFunctionToLiteralInspection extends PyInspection { } return LanguageLevel.forElement(node).supportsSetLiterals(); } - - private static boolean isInBuiltins(PyExpression callee) { - if (callee instanceof PyQualifiedExpression && (((PyQualifiedExpression)callee).isQualified())) { - return false; - } - PsiReference reference = callee.getReference(); - if (reference != null) { - PsiElement resolved = reference.resolve(); - if (resolved != null && PyBuiltinCache.getInstance(callee).isBuiltin(resolved)) { - return true; - } - } - return false; - } } public static PyElement[] getSetCallArguments(PyCallExpression node) { diff --git a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java index aefeb6bbba8e..32183f5d650d 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java +++ b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java @@ -29,10 +29,7 @@ import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.jetbrains.python.PyNames; -import com.jetbrains.python.psi.LanguageLevel; -import com.jetbrains.python.psi.PyClass; -import com.jetbrains.python.psi.PyFile; -import com.jetbrains.python.psi.PySequenceExpression; +import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.resolve.PythonSdkPathCache; import com.jetbrains.python.psi.types.*; import com.jetbrains.python.sdk.PythonSdkType; @@ -344,4 +341,18 @@ public class PyBuiltinCache { // files are singletons, no need to compare URIs return the_file == myBuiltinsFile || the_file == myExceptionsFile; } + + public static boolean isInBuiltins(@NotNull PyExpression expression) { + if (expression instanceof PyQualifiedExpression && (((PyQualifiedExpression)expression).isQualified())) { + return false; + } + PsiReference reference = expression.getReference(); + if (reference != null) { + PsiElement resolved = reference.resolve(); + if (resolved != null && getInstance(expression).isBuiltin(resolved)) { + return true; + } + } + return false; + } } From f16a6ddbf3da28cb198541fb74416e74ddfd33ff Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 27 Feb 2014 15:38:46 +0400 Subject: [PATCH 04/95] Cleanup --- .../python/validation/PyBuiltinAnnotator.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java b/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java index 8c82f3a5c5bd..5f8acb73e086 100644 --- a/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java +++ b/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java @@ -19,35 +19,37 @@ import com.intellij.lang.ASTNode; import com.intellij.lang.annotation.Annotation; import com.intellij.psi.PsiElement; import com.intellij.psi.ResolveResult; -import com.jetbrains.python.highlighting.PyHighlighter; import com.jetbrains.python.PyNames; import com.jetbrains.python.PyTokenTypes; +import com.jetbrains.python.highlighting.PyHighlighter; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.impl.PyBuiltinCache; +import org.jetbrains.annotations.NotNull; /** * Marks built-in names. - * User: dcheryasov - * Date: Jan 10, 2009 12:17:15 PM + * + * @author dcheryasov */ public class PyBuiltinAnnotator extends PyAnnotator { @Override public void visitPyReferenceExpression(PyReferenceExpression node) { final String name = node.getName(); - if (name == null) return; - boolean highlighted_as_attribute = highlightAsAttribute(node, name); - if (! highlighted_as_attribute && !node.isQualified()) { + if (name == null) return; + if (!highlightAsAttribute(node, name) && !node.isQualified()) { // things like len() - ResolveResult[] resolved = node.getReference().multiResolve(false); // constructors, etc may give multiple results... + final ResolveResult[] resolved = node.getReference().multiResolve(false); // constructors, etc may give multiple results... if (resolved.length > 0) { if (PyBuiltinCache.getInstance(node).isBuiltin(resolved[0].getElement())) { // ...but we only care about the default resolution - Annotation ann; - PsiElement parent = node.getParent(); + final Annotation ann; + final PsiElement parent = node.getParent(); if (parent instanceof PyDecorator) { // don't mark the entire decorator, only mark the "@", else we'll conflict with deco annotator ann = getHolder().createInfoAnnotation(parent.getFirstChild(), null); // first child is there, or we'd not parse as deco } - else ann = getHolder().createInfoAnnotation(node, null); + else { + ann = getHolder().createInfoAnnotation(node, null); + } ann.setTextAttributes(PyHighlighter.PY_BUILTIN_NAME); } } @@ -57,28 +59,27 @@ public class PyBuiltinAnnotator extends PyAnnotator { @Override public void visitPyTargetExpression(PyTargetExpression node) { final String name = node.getName(); - if (name == null) return; - highlightAsAttribute(node, name); + if (name != null) { + highlightAsAttribute(node, name); + } } /** * Try to highlight a node as a class attribute. + * * @param node what to work with - * @return true iff the node was highlighted. + * @return true iff the node was highlighted. */ - private boolean highlightAsAttribute(PyQualifiedExpression node, String name) { - LanguageLevel languageLevel = LanguageLevel.forElement(node); + private boolean highlightAsAttribute(@NotNull PyQualifiedExpression node, @NotNull String name) { + final LanguageLevel languageLevel = LanguageLevel.forElement(node); if (PyNames.UnderscoredAttributes.contains(name) || PyNames.getBuiltinMethods(languageLevel).containsKey(name)) { - // things like __len__ - if ( - node.isQualified() // foo.__len__ - || (PyUtil.getConcealingParent(node) instanceof PyClass) // class Foo: ... __len__ = myLenImpl - ) { + // things like __len__: foo.__len__ or class Foo: ... __len__ = my_len_impl + if (node.isQualified() || PyUtil.getConcealingParent(node) instanceof PyClass) { final ASTNode astNode = node.getNode(); if (astNode != null) { - ASTNode tgt = astNode.findChildByType(PyTokenTypes.IDENTIFIER); // only the id, not all qualifiers subtree + final ASTNode tgt = astNode.findChildByType(PyTokenTypes.IDENTIFIER); // only the id, not all qualifiers subtree if (tgt != null) { - Annotation ann = getHolder().createInfoAnnotation(tgt, null); + final Annotation ann = getHolder().createInfoAnnotation(tgt, null); ann.setTextAttributes(PyHighlighter.PY_PREDEFINED_USAGE); return true; } @@ -87,5 +88,4 @@ public class PyBuiltinAnnotator extends PyAnnotator { } return false; } - } From b649cb8b5f03e8508fc9ed5a77d4aaaa64315078 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 27 Feb 2014 15:43:17 +0400 Subject: [PATCH 05/95] Deprecated PyUtil.getConcealingParent --- python/src/com/jetbrains/python/psi/PyUtil.java | 3 +++ .../com/jetbrains/python/validation/PyBuiltinAnnotator.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index e174412fcf5b..97b380b4f381 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -857,7 +857,10 @@ public class PyUtil { * * @param elt starting point of search. * @return 'class' or 'def' element, or null if not found. + * + * @deprecated Use {@link ScopeUtil#getScopeOwner} instead. */ + @Deprecated @Nullable public static PsiElement getConcealingParent(PsiElement elt) { if (elt == null || elt instanceof PsiFile) { diff --git a/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java b/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java index 5f8acb73e086..ae344355ee7a 100644 --- a/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java +++ b/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java @@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.ResolveResult; import com.jetbrains.python.PyNames; import com.jetbrains.python.PyTokenTypes; +import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; import com.jetbrains.python.highlighting.PyHighlighter; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.impl.PyBuiltinCache; @@ -74,7 +75,7 @@ public class PyBuiltinAnnotator extends PyAnnotator { final LanguageLevel languageLevel = LanguageLevel.forElement(node); if (PyNames.UnderscoredAttributes.contains(name) || PyNames.getBuiltinMethods(languageLevel).containsKey(name)) { // things like __len__: foo.__len__ or class Foo: ... __len__ = my_len_impl - if (node.isQualified() || PyUtil.getConcealingParent(node) instanceof PyClass) { + if (node.isQualified() || ScopeUtil.getScopeOwner(node) instanceof PyClass) { final ASTNode astNode = node.getNode(); if (astNode != null) { final ASTNode tgt = astNode.findChildByType(PyTokenTypes.IDENTIFIER); // only the id, not all qualifiers subtree From abf9500cde7b944e12fb0737afa0560a865ed596 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 27 Feb 2014 15:51:24 +0400 Subject: [PATCH 06/95] Switched to potentially faster PyBuiltinCache.isInBuilins --- .../python/validation/PyBuiltinAnnotator.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java b/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java index ae344355ee7a..102867fba9a6 100644 --- a/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java +++ b/python/src/com/jetbrains/python/validation/PyBuiltinAnnotator.java @@ -18,7 +18,6 @@ package com.jetbrains.python.validation; import com.intellij.lang.ASTNode; import com.intellij.lang.annotation.Annotation; import com.intellij.psi.PsiElement; -import com.intellij.psi.ResolveResult; import com.jetbrains.python.PyNames; import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; @@ -37,23 +36,18 @@ public class PyBuiltinAnnotator extends PyAnnotator { public void visitPyReferenceExpression(PyReferenceExpression node) { final String name = node.getName(); if (name == null) return; - if (!highlightAsAttribute(node, name) && !node.isQualified()) { - // things like len() - final ResolveResult[] resolved = node.getReference().multiResolve(false); // constructors, etc may give multiple results... - if (resolved.length > 0) { - if (PyBuiltinCache.getInstance(node).isBuiltin(resolved[0].getElement())) { // ...but we only care about the default resolution - final Annotation ann; - final PsiElement parent = node.getParent(); - if (parent instanceof PyDecorator) { - // don't mark the entire decorator, only mark the "@", else we'll conflict with deco annotator - ann = getHolder().createInfoAnnotation(parent.getFirstChild(), null); // first child is there, or we'd not parse as deco - } - else { - ann = getHolder().createInfoAnnotation(node, null); - } - ann.setTextAttributes(PyHighlighter.PY_BUILTIN_NAME); - } + final boolean highlightedAsAttribute = highlightAsAttribute(node, name); + if (!highlightedAsAttribute && PyBuiltinCache.isInBuiltins(node)) { + final Annotation ann; + final PsiElement parent = node.getParent(); + if (parent instanceof PyDecorator) { + // don't mark the entire decorator, only mark the "@", else we'll conflict with deco annotator + ann = getHolder().createInfoAnnotation(parent.getFirstChild(), null); // first child is there, or we'd not parse as deco } + else { + ann = getHolder().createInfoAnnotation(node, null); + } + ann.setTextAttributes(PyHighlighter.PY_BUILTIN_NAME); } } From 9df88a0b6171c30f4d19c59532914b012bf72e6d Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 27 Feb 2014 13:12:07 +0100 Subject: [PATCH 07/95] overrides, notnull --- .../com/intellij/xdebugger/XDebugSession.java | 1 + .../xdebugger/impl/DebuggerSupport.java | 7 +++-- .../xdebugger/impl/XDebugSessionImpl.java | 2 +- .../xdebugger/impl/XDebuggerSupport.java | 31 +++++++++++++++++-- .../actions/ShowExecutionPointAction.java | 3 +- .../XDebuggerSuspendedActionHandler.java | 4 +-- .../handlers/XDebuggerActionHandler.java | 11 ++++--- 7 files changed, 45 insertions(+), 14 deletions(-) diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugSession.java b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugSession.java index 534545847f42..be71aac98d1e 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugSession.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugSession.java @@ -83,6 +83,7 @@ public interface XDebugSession extends AbstractDebuggerSession { /** * @deprecated use {@link #setCurrentStackFrame(com.intellij.xdebugger.frame.XExecutionStack, com.intellij.xdebugger.frame.XStackFrame)} instead */ + @SuppressWarnings("UnusedDeclaration") void setCurrentStackFrame(@NotNull XStackFrame frame); /** diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/DebuggerSupport.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/DebuggerSupport.java index 42bee651e742..2fd665496ba6 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/DebuggerSupport.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/DebuggerSupport.java @@ -19,7 +19,10 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.xdebugger.AbstractDebuggerSession; -import com.intellij.xdebugger.impl.actions.*; +import com.intellij.xdebugger.impl.actions.DebuggerActionHandler; +import com.intellij.xdebugger.impl.actions.DebuggerToggleActionHandler; +import com.intellij.xdebugger.impl.actions.EditBreakpointActionHandler; +import com.intellij.xdebugger.impl.actions.MarkObjectActionHandler; import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointPanelProvider; import com.intellij.xdebugger.impl.evaluate.quick.common.QuickEvaluateHandler; import com.intellij.xdebugger.impl.settings.DebuggerSettingsPanelProvider; @@ -116,6 +119,6 @@ public abstract class DebuggerSupport { return support; } } - return null; + throw new IllegalStateException(); } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java index ea407a2cfcd4..d32c26cf8bac 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java @@ -780,7 +780,7 @@ public class XDebugSessionImpl implements XDebugSession { myBreakpointsDisabled = false; new ReadAction() { @Override - protected void run(final Result result) { + protected void run(@NotNull Result result) { processAllBreakpoints(true, false); } }.execute(); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerSupport.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerSupport.java index c56f2c723261..0215c37812cb 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerSupport.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerSupport.java @@ -54,7 +54,7 @@ public class XDebuggerSupport extends DebuggerSupport { private final DebuggerToggleActionHandler myMuteBreakpointsHandler; private final DebuggerActionHandler mySmartStepIntoHandler; private final XMarkObjectActionHandler myMarkObjectActionHandler; - private final EditBreakpointActionHandler myEditBreakpointActoinHandler; + private final EditBreakpointActionHandler myEditBreakpointActionHandler; public XDebuggerSupport() { myBreakpointPanelProvider = new XBreakpointPanelProvider(); @@ -62,26 +62,31 @@ public class XDebuggerSupport extends DebuggerSupport { myToggleTemporaryLineBreakpointActionHandler = new XToggleLineBreakpointActionHandler(true); myAddToWatchesActionHandler = new XAddToWatchesFromEditorActionHandler(); myStepOverHandler = new XDebuggerSuspendedActionHandler() { + @Override protected void perform(@NotNull final XDebugSession session, final DataContext dataContext) { session.stepOver(false); } }; myStepIntoHandler = new XDebuggerSuspendedActionHandler() { + @Override protected void perform(@NotNull final XDebugSession session, final DataContext dataContext) { session.stepInto(); } }; myStepOutHandler = new XDebuggerSuspendedActionHandler() { + @Override protected void perform(@NotNull final XDebugSession session, final DataContext dataContext) { session.stepOut(); } }; myForceStepOverHandler = new XDebuggerSuspendedActionHandler() { + @Override protected void perform(@NotNull final XDebugSession session, final DataContext dataContext) { session.stepOver(true); } }; myForceStepIntoHandler = new XDebuggerSuspendedActionHandler() { + @Override protected void perform(@NotNull final XDebugSession session, final DataContext dataContext) { session.forceStepInto(); } @@ -90,16 +95,19 @@ public class XDebuggerSupport extends DebuggerSupport { myRunToCursorHandler = new XDebuggerRunToCursorActionHandler(false); myForceRunToCursor = new XDebuggerRunToCursorActionHandler(true); myResumeHandler = new XDebuggerActionHandler() { + @Override protected boolean isEnabled(@NotNull final XDebugSession session, final DataContext dataContext) { return session.isPaused(); } + @Override protected void perform(@NotNull final XDebugSession session, final DataContext dataContext) { session.resume(); } }; myPauseHandler = new XDebuggerPauseActionHandler(); myShowExecutionPointHandler = new XDebuggerSuspendedActionHandler() { + @Override protected void perform(@NotNull final XDebugSession session, final DataContext dataContext) { session.showExecutionPoint(); } @@ -109,64 +117,76 @@ public class XDebuggerSupport extends DebuggerSupport { myQuickEvaluateHandler = new XQuickEvaluateHandler(); mySettingsPanelProvider = new XDebuggerSettingsPanelProviderImpl(); myMarkObjectActionHandler = new XMarkObjectActionHandler(); - myEditBreakpointActoinHandler = new XDebuggerEditBreakpointActionHandler(); + myEditBreakpointActionHandler = new XDebuggerEditBreakpointActionHandler(); } + @Override @NotNull public BreakpointPanelProvider getBreakpointPanelProvider() { return myBreakpointPanelProvider; } + @Override @NotNull public DebuggerActionHandler getStepOverHandler() { return myStepOverHandler; } + @Override @NotNull public DebuggerActionHandler getStepIntoHandler() { return myStepIntoHandler; } + @Override @NotNull public DebuggerActionHandler getSmartStepIntoHandler() { return mySmartStepIntoHandler; } + @Override @NotNull public DebuggerActionHandler getStepOutHandler() { return myStepOutHandler; } + @Override @NotNull public DebuggerActionHandler getForceStepOverHandler() { return myForceStepOverHandler; } + @Override @NotNull public DebuggerActionHandler getForceStepIntoHandler() { return myForceStepIntoHandler; } + @Override @NotNull public DebuggerActionHandler getRunToCursorHandler() { return myRunToCursorHandler; } + @Override @NotNull public DebuggerActionHandler getForceRunToCursorHandler() { return myForceRunToCursor; } + @Override @NotNull public DebuggerActionHandler getResumeActionHandler() { return myResumeHandler; } + @Override @NotNull public DebuggerActionHandler getPauseHandler() { return myPauseHandler; } + @Override @NotNull public DebuggerActionHandler getToggleLineBreakpointHandler() { return myToggleLineBreakpointActionHandler; @@ -178,16 +198,19 @@ public class XDebuggerSupport extends DebuggerSupport { return myToggleTemporaryLineBreakpointActionHandler; } + @Override @NotNull public DebuggerActionHandler getShowExecutionPointHandler() { return myShowExecutionPointHandler; } + @Override @NotNull public DebuggerActionHandler getEvaluateHandler() { return myEvaluateHandler; } + @Override @NotNull public QuickEvaluateHandler getQuickEvaluateHandler() { return myQuickEvaluateHandler; @@ -199,6 +222,7 @@ public class XDebuggerSupport extends DebuggerSupport { return myAddToWatchesActionHandler; } + @Override @NotNull public DebuggerToggleActionHandler getMuteBreakpointsHandler() { return myMuteBreakpointsHandler; @@ -218,9 +242,10 @@ public class XDebuggerSupport extends DebuggerSupport { @NotNull @Override public EditBreakpointActionHandler getEditBreakpointAction() { - return myEditBreakpointActoinHandler; + return myEditBreakpointActionHandler; } + @Override @NotNull public DebuggerSettingsPanelProvider getSettingsPanelProvider() { return mySettingsPanelProvider; diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/ShowExecutionPointAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/ShowExecutionPointAction.java index a00e2618c5a5..12def64e36ef 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/ShowExecutionPointAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/ShowExecutionPointAction.java @@ -15,13 +15,14 @@ */ package com.intellij.xdebugger.impl.actions; -import org.jetbrains.annotations.NotNull; import com.intellij.xdebugger.impl.DebuggerSupport; +import org.jetbrains.annotations.NotNull; /** * @author nik */ public class ShowExecutionPointAction extends XDebuggerActionBase { + @Override @NotNull protected DebuggerActionHandler getHandler(@NotNull final DebuggerSupport debuggerSupport) { return debuggerSupport.getShowExecutionPointHandler(); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/XDebuggerSuspendedActionHandler.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/XDebuggerSuspendedActionHandler.java index 70ecabddcdea..0137fac87ac2 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/XDebuggerSuspendedActionHandler.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/XDebuggerSuspendedActionHandler.java @@ -15,16 +15,16 @@ */ package com.intellij.xdebugger.impl.actions; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.impl.actions.handlers.XDebuggerActionHandler; -import com.intellij.openapi.actionSystem.DataContext; import org.jetbrains.annotations.NotNull; /** * @author nik */ public abstract class XDebuggerSuspendedActionHandler extends XDebuggerActionHandler { - + @Override protected boolean isEnabled(final @NotNull XDebugSession session, final DataContext dataContext) { return session.isSuspended(); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerActionHandler.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerActionHandler.java index 3ac02a62dbdb..fa079b3ff707 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerActionHandler.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerActionHandler.java @@ -15,19 +15,19 @@ */ package com.intellij.xdebugger.impl.actions.handlers; -import com.intellij.xdebugger.impl.actions.DebuggerActionHandler; -import com.intellij.xdebugger.XDebuggerManager; -import com.intellij.xdebugger.XDebugSession; -import com.intellij.openapi.project.Project; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.project.Project; +import com.intellij.xdebugger.XDebugSession; +import com.intellij.xdebugger.XDebuggerManager; +import com.intellij.xdebugger.impl.actions.DebuggerActionHandler; import org.jetbrains.annotations.NotNull; /** * @author nik */ public abstract class XDebuggerActionHandler extends DebuggerActionHandler { - + @Override public void perform(@NotNull final Project project, final AnActionEvent event) { XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession(); if (session != null) { @@ -35,6 +35,7 @@ public abstract class XDebuggerActionHandler extends DebuggerActionHandler { } } + @Override public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) { XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession(); return session != null && isEnabled(session, event.getDataContext()); From 5c2b0796da31b6273db9c24b91506ee56e2f542a Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 27 Feb 2014 13:14:28 +0100 Subject: [PATCH 08/95] IDEA-81276 Show the current program execution point does not bring hidden windows to front --- .../intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java index 47485e568a14..db7aef7d61cb 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java @@ -72,7 +72,7 @@ public class ExecutionPointHighlighter { public void navigateTo() { if (myOpenFileDescriptor != null) { - FileEditorManager.getInstance(myProject).openTextEditor(myOpenFileDescriptor, false); + FileEditorManager.getInstance(myProject).openTextEditor(myOpenFileDescriptor, true); } } From 13bfcb52473afe9bae4a4aaff6860731bd49a90c Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 27 Feb 2014 10:55:40 +0100 Subject: [PATCH 09/95] why does GroovyCompilerTest blink on TC? --- .../impl/TranslatingCompilerFilesMonitor.java | 2 +- .../groovy/compiler/GroovyCompilerTest.groovy | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java index a20c6975baa8..1bcff3f8bae6 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java @@ -80,7 +80,7 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.TranslatingCompilerFilesMonitor"); - private static final boolean ourDebugMode = false; + public static boolean ourDebugMode = false; private static final FileAttribute ourSourceFileAttribute = new FileAttribute("_make_source_file_info_", 3); private static final FileAttribute ourOutputFileAttribute = new FileAttribute("_make_output_file_info_", 3); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy index da3963e9b7e1..25f1d2dc20fc 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy @@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.compiler import com.intellij.compiler.CompilerConfiguration import com.intellij.compiler.CompilerConfigurationImpl +import com.intellij.compiler.impl.TranslatingCompilerFilesMonitor import com.intellij.compiler.server.BuildManager import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.PathManager @@ -41,6 +42,12 @@ public abstract class GroovyCompilerTest extends GroovyCompilerTestCase { addGroovyLibrary(myModule); } + @Override + protected void tearDown() throws Exception { + TranslatingCompilerFilesMonitor.ourDebugMode = false + super.tearDown() + } + public void testPlainGroovy() throws Throwable { myFixture.addFileToProject("A.groovy", "println '239'"); assertEmpty(make()); @@ -128,6 +135,8 @@ public abstract class GroovyCompilerTest extends GroovyCompilerTestCase { } public void testTransitiveJavaDependencyThroughGroovy() throws Throwable { + TranslatingCompilerFilesMonitor.ourDebugMode = true + myFixture.addClass("public class IFoo { void foo() {} }").getContainingFile().getVirtualFile(); myFixture.addFileToProject("Foo.groovy", "class Foo {\n" + " static IFoo f\n" + @@ -725,11 +734,11 @@ public class Main { ApplicationManager.application.runWriteAction { msg.virtualFile.delete(this) } def messages = make() - assert messages + assert messages def error = messages.find { it.message.contains('InvalidType') } assert error?.virtualFile assert groovyFile.classes[0] == GroovycStubGenerator.findClassByStub(project, error.virtualFile) - + } public void "test ignore groovy internal non-existent interface helper inner class"() { From 53ae56bee03b784aebab470c4db908d9c06412c6 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 27 Feb 2014 13:10:19 +0100 Subject: [PATCH 10/95] correct server log location in GroovyCompilerTest --- .../plugins/groovy/compiler/GroovyCompilerTest.groovy | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy index 25f1d2dc20fc..9be76d2096db 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy @@ -20,7 +20,6 @@ import com.intellij.compiler.CompilerConfigurationImpl import com.intellij.compiler.impl.TranslatingCompilerFilesMonitor import com.intellij.compiler.server.BuildManager import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.application.PathManager import com.intellij.openapi.compiler.CompilerMessage import com.intellij.openapi.compiler.CompilerMessageCategory import com.intellij.openapi.compiler.options.ExcludeEntryDescription @@ -217,7 +216,7 @@ public abstract class GroovyCompilerTest extends GroovyCompilerTestCase { @Override void runBare() { - new File(PathManager.systemPath, "compile-server/server.log").delete() + new File(TestLoggerFactory.testLogDir, "../log/build-log/build.log").delete() super.runBare() } @@ -240,7 +239,7 @@ public abstract class GroovyCompilerTest extends GroovyCompilerTestCase { def logText = ideaLog.text println(logText.size() < limit ? logText : logText.substring(logText.size() - limit)) } - def makeLog = new File(PathManager.systemPath, "compile-server/server.log") + def makeLog = new File(TestLoggerFactory.testLogDir, "../log/build-log/build.log") if (makeLog.exists()) { println "\n\nServer Log:" println makeLog.text From 16748dca79cd9067a8eaceac6af3873f557cd9be Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 27 Feb 2014 13:24:39 +0100 Subject: [PATCH 11/95] lazy icons for groovy elements --- .../groovy/lang/psi/impl/statements/GrFieldImpl.java | 3 ++- .../psi/impl/statements/typedef/GrTypeDefinitionImpl.java | 8 +++----- .../impl/statements/typedef/members/GrMethodBaseImpl.java | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java index 7e852036dc04..d0fbca04dab7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java @@ -240,7 +240,8 @@ public class GrFieldImpl extends GrVariableBaseImpl implements GrFi } @Nullable - public Icon getIcon(int flags) { + @Override + protected Icon getElementIcon(@IconFlags int flags) { Icon superIcon = JetgroovyIcons.Groovy.Field; if (!isProperty()) return superIcon; LayeredIcon rowIcon = new LayeredIcon(2); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrTypeDefinitionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrTypeDefinitionImpl.java index 0298021c626f..3f68e29875d7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrTypeDefinitionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrTypeDefinitionImpl.java @@ -19,10 +19,7 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef; import com.intellij.lang.ASTNode; import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentationProviders; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.RecursionGuard; -import com.intellij.openapi.util.RecursionManager; +import com.intellij.openapi.util.*; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleSettings; @@ -680,7 +677,8 @@ public abstract class GrTypeDefinitionImpl extends GrStubElementBase i return true; } + @Nullable @Override - public Icon getIcon(int flags) { + protected Icon getElementIcon(@IconFlags int flags) { RowIcon baseIcon = ElementPresentationUtil.createLayeredIcon(JetgroovyIcons.Groovy.Method, this, false); return ElementPresentationUtil.addVisibilityIcon(this, flags, baseIcon); } From 2a39a63aa1cde98c8f5f64617fcb44cee5d43d98 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Thu, 27 Feb 2014 16:28:07 +0400 Subject: [PATCH 12/95] IDEA-121285 Maven: missing classifier in managed dependency --- .../maven/dom/generate/GenerateManagedDependencyAction.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/generate/GenerateManagedDependencyAction.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/generate/GenerateManagedDependencyAction.java index 18250c395ee5..93af00a1e1e2 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/generate/GenerateManagedDependencyAction.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/generate/GenerateManagedDependencyAction.java @@ -78,10 +78,16 @@ public class GenerateManagedDependencyAction extends GenerateDomElementAction { dependency.getGroupId().setStringValue(groupId); dependency.getArtifactId().setStringValue(artifactId); String typeValue = parentDependency.getType().getStringValue(); + String classifier = parentDependency.getClassifier().getStringValue(); if (!StringUtil.isEmptyOrSpaces(typeValue)) { dependency.getType().setStringValue(typeValue); } + + if (!StringUtil.isEmptyOrSpaces(classifier)) { + dependency.getClassifier().setStringValue(classifier); + } + dependency.getVersion().undefine(); } } From 0cfaba5554d543f985f9a2e18ce9ea3e3c0d2ed7 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 27 Feb 2014 13:35:55 +0100 Subject: [PATCH 13/95] New plugin description --- plugins/git4idea/src/META-INF/plugin.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/src/META-INF/plugin.xml b/plugins/git4idea/src/META-INF/plugin.xml index 5bd07d3b8883..8664c8ae51e2 100644 --- a/plugins/git4idea/src/META-INF/plugin.xml +++ b/plugins/git4idea/src/META-INF/plugin.xml @@ -1,7 +1,18 @@ Git Integration Git4Idea - Provides integration with Git version control system + + Git version control system. + The following features are available: +
    +
  • Dedicated page under the Version Control node in the Settings/Preferences dialog.
  • +
  • Ability to browse, check out sources from and import into the available Git repositories, when Git is not enabled.
  • +
  • When Git is enabled, the Git node appears on the VCS menu, and on the context menu of the editor.
  • +
+

Numerous plugins depend on the Git Integration plugin.

+ ]]> +
8.1 VCS Integration JetBrains From 279985e5df48238677c23d0c98c6b773dd7eb505 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 27 Feb 2014 16:42:18 +0400 Subject: [PATCH 14/95] Faster isInBuilitins check that doesn't require resolve for non-builtin names --- .../python/psi/impl/PyBuiltinCache.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java index 32183f5d650d..0f4b0813cf7c 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java +++ b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java @@ -177,7 +177,13 @@ public class PyBuiltinCache { @Nullable public PsiElement getByName(@NonNls String name) { if (myBuiltinsFile != null) { - return myBuiltinsFile.getElementNamed(name); + final PsiElement element = myBuiltinsFile.getElementNamed(name); + if (element != null) { + return element; + } + } + if (myExceptionsFile != null) { + return myExceptionsFile.getElementNamed(name); } return null; } @@ -346,11 +352,15 @@ public class PyBuiltinCache { if (expression instanceof PyQualifiedExpression && (((PyQualifiedExpression)expression).isQualified())) { return false; } + final String name = expression.getName(); PsiReference reference = expression.getReference(); - if (reference != null) { - PsiElement resolved = reference.resolve(); - if (resolved != null && getInstance(expression).isBuiltin(resolved)) { - return true; + if (reference != null && name != null) { + final PyBuiltinCache cache = getInstance(expression); + if (cache.getByName(name) != null) { + final PsiElement resolved = reference.resolve(); + if (resolved != null && cache.isBuiltin(resolved)) { + return true; + } } } return false; From 75feb752ad52e17647bca6f6ba883fa6cc89e753 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 27 Feb 2014 14:26:27 +0100 Subject: [PATCH 15/95] EA-54419 (severity lowered) --- .../src/com/intellij/ui/SystemNotificationsImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/SystemNotificationsImpl.java b/platform/platform-impl/src/com/intellij/ui/SystemNotificationsImpl.java index 597301bb1a2d..a4201ea37022 100644 --- a/platform/platform-impl/src/com/intellij/ui/SystemNotificationsImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/SystemNotificationsImpl.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. @@ -83,7 +83,7 @@ public class SystemNotificationsImpl extends SystemNotifications implements Pers } } catch (Throwable t) { - Logger.getInstance(SystemNotifications.class).error(t); + Logger.getInstance(SystemNotifications.class).warn(t); } return null; From c367db22bfc85a07d1cc7f8ff09b3d18bd72e45a Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 27 Feb 2014 13:35:36 +0400 Subject: [PATCH 16/95] 'Select in -> Project Structure' should select corresponding module when invoked on iml file --- .../impl/ProjectStructureSelectInTarget.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java b/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java index d282c684e3db..70457eb6bdf3 100644 --- a/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java +++ b/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java @@ -18,6 +18,7 @@ package com.intellij.ide.impl; import com.intellij.facet.*; import com.intellij.ide.*; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.DumbAware; @@ -48,7 +49,8 @@ public class ProjectStructureSelectInTarget extends SelectInTargetBase implement final Object o = ((WrappingVirtualFile)file).getWrappedObject(context.getProject()); return o instanceof Facet; } - return fileIndex.isInContent(file) || fileIndex.isInLibraryClasses(file) || fileIndex.isInLibrarySource(file); + return fileIndex.isInContent(file) || fileIndex.isInLibraryClasses(file) || fileIndex.isInLibrarySource(file) + || StdFileTypes.IDEA_MODULE.equals(file.getFileType()) && findModuleByModuleFile(context.getProject(), file) != null; } @Override @@ -64,8 +66,9 @@ public class ProjectStructureSelectInTarget extends SelectInTargetBase implement module = facet == null? null : facet.getModule(); } else { + Module moduleByIml = file.getFileType().equals(StdFileTypes.IDEA_MODULE) ? findModuleByModuleFile(project, file) : null; final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - module = fileIndex.getModuleForFile(file); + module = moduleByIml != null ? moduleByIml : fileIndex.getModuleForFile(file); facet = fileIndex.isInSourceContent(file) ? null : findFacet(project, file); } if (module != null || facet != null) { @@ -94,6 +97,16 @@ public class ProjectStructureSelectInTarget extends SelectInTargetBase implement } } + @Nullable + private static Module findModuleByModuleFile(@NotNull Project project, @NotNull VirtualFile file) { + for (Module module : ModuleManager.getInstance(project).getModules()) { + if (file.equals(module.getModuleFile())) { + return module; + } + } + return null; + } + @Nullable private static Facet findFacet(final @NotNull Project project, final @NotNull VirtualFile file) { for (FacetTypeId id : FacetTypeRegistry.getInstance().getFacetTypeIds()) { From 140bfa46407d0ffc06586de590b110c1b8013e9f Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 27 Feb 2014 18:05:54 +0400 Subject: [PATCH 17/95] test from jps modules extracted to separate modules to get rid of cyclic dependencies involving JPS modules --- .idea/modules.xml | 2 ++ build/scripts/layouts.gant | 4 ++-- community-main.iml | 3 +++ jps/jps-builders/jps-builders.iml | 1 + jps/model-impl/jps-model-impl.iml | 2 -- jps/model-impl/jps-model-tests.iml | 14 ++++++++++++++ .../jps-model-serialization.iml | 3 --- .../jps-serialization-tests.iml | 14 ++++++++++++++ platform/platform-tests/platform-tests.iml | 1 + plugins/ant/jps-plugin/ant-jps-plugin.iml | 1 + plugins/devkit/jps-plugin/devkit-jps-plugin.iml | 1 + .../jps-plugin/google-app-engine-jps-plugin.iml | 1 + plugins/maven/jps-plugin/maven-jps-plugin.iml | 1 + .../jps-plugin/ui-designer-jps-plugin.iml | 1 + 14 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 jps/model-impl/jps-model-tests.iml create mode 100644 jps/model-serialization/jps-serialization-tests.iml diff --git a/.idea/modules.xml b/.idea/modules.xml index d7c5d4aea264..2c0aba589b39 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -98,6 +98,8 @@ + + diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index 8a9c8d069137..ef49e7357182 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -749,8 +749,8 @@ def layoutCommunityJps(String home, String target) { dir("test") { jar("jps-build-test.jar") { moduleTests("jps-builders") - moduleTests("jps-model-impl") - moduleTests("jps-model-serialization") + moduleTests("jps-model-tests") + moduleTests("jps-serialization-tests") } } jar("ant-jps-plugin.jar") { module("ant-jps-plugin") } diff --git a/community-main.iml b/community-main.iml index 6e14389c34ad..474b93df4d31 100644 --- a/community-main.iml +++ b/community-main.iml @@ -93,6 +93,9 @@ + + + diff --git a/jps/jps-builders/jps-builders.iml b/jps/jps-builders/jps-builders.iml index fea80a020e80..9dd56d591d6e 100644 --- a/jps/jps-builders/jps-builders.iml +++ b/jps/jps-builders/jps-builders.iml @@ -36,6 +36,7 @@ + diff --git a/jps/model-impl/jps-model-impl.iml b/jps/model-impl/jps-model-impl.iml index 5e72944c0f30..447c25cc7583 100644 --- a/jps/model-impl/jps-model-impl.iml +++ b/jps/model-impl/jps-model-impl.iml @@ -4,13 +4,11 @@ - - diff --git a/jps/model-impl/jps-model-tests.iml b/jps/model-impl/jps-model-tests.iml new file mode 100644 index 000000000000..f42308922277 --- /dev/null +++ b/jps/model-impl/jps-model-tests.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/jps/model-serialization/jps-model-serialization.iml b/jps/model-serialization/jps-model-serialization.iml index 988e3c506729..6859151b1bd5 100644 --- a/jps/model-serialization/jps-model-serialization.iml +++ b/jps/model-serialization/jps-model-serialization.iml @@ -4,15 +4,12 @@ - - - diff --git a/jps/model-serialization/jps-serialization-tests.iml b/jps/model-serialization/jps-serialization-tests.iml new file mode 100644 index 000000000000..953fef28dd82 --- /dev/null +++ b/jps/model-serialization/jps-serialization-tests.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/platform/platform-tests/platform-tests.iml b/platform/platform-tests/platform-tests.iml index d1018688da69..f6d37e431c5e 100644 --- a/platform/platform-tests/platform-tests.iml +++ b/platform/platform-tests/platform-tests.iml @@ -23,6 +23,7 @@ + diff --git a/plugins/ant/jps-plugin/ant-jps-plugin.iml b/plugins/ant/jps-plugin/ant-jps-plugin.iml index 976f684d067a..12aeb835539a 100644 --- a/plugins/ant/jps-plugin/ant-jps-plugin.iml +++ b/plugins/ant/jps-plugin/ant-jps-plugin.iml @@ -13,6 +13,7 @@ + diff --git a/plugins/devkit/jps-plugin/devkit-jps-plugin.iml b/plugins/devkit/jps-plugin/devkit-jps-plugin.iml index f88b075e0722..a80f7f38f339 100644 --- a/plugins/devkit/jps-plugin/devkit-jps-plugin.iml +++ b/plugins/devkit/jps-plugin/devkit-jps-plugin.iml @@ -12,6 +12,7 @@ + diff --git a/plugins/google-app-engine/jps-plugin/google-app-engine-jps-plugin.iml b/plugins/google-app-engine/jps-plugin/google-app-engine-jps-plugin.iml index e471a6a62370..313b6317ce0a 100644 --- a/plugins/google-app-engine/jps-plugin/google-app-engine-jps-plugin.iml +++ b/plugins/google-app-engine/jps-plugin/google-app-engine-jps-plugin.iml @@ -13,6 +13,7 @@ + diff --git a/plugins/maven/jps-plugin/maven-jps-plugin.iml b/plugins/maven/jps-plugin/maven-jps-plugin.iml index 8098c4c4d4ba..f601ed39bca5 100644 --- a/plugins/maven/jps-plugin/maven-jps-plugin.iml +++ b/plugins/maven/jps-plugin/maven-jps-plugin.iml @@ -22,6 +22,7 @@ + diff --git a/plugins/ui-designer/jps-plugin/ui-designer-jps-plugin.iml b/plugins/ui-designer/jps-plugin/ui-designer-jps-plugin.iml index f46639653871..70277d7b2991 100644 --- a/plugins/ui-designer/jps-plugin/ui-designer-jps-plugin.iml +++ b/plugins/ui-designer/jps-plugin/ui-designer-jps-plugin.iml @@ -16,6 +16,7 @@ + From 13c7ba02ee539b66bb539cb5731f3975432fe1ca Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Thu, 27 Feb 2014 18:22:30 +0400 Subject: [PATCH 18/95] improve stub-psi-mismatch diagnostic: add language --- .../com/intellij/psi/stubs/StubIndexImpl.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java index 0877a65f51bc..3eb77ddc0738 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java @@ -19,6 +19,7 @@ */ package com.intellij.psi.stubs; +import com.intellij.lang.Language; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.*; @@ -26,12 +27,15 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.ManagingFS; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; +import com.intellij.psi.LanguageSubstitutors; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; @@ -465,8 +469,13 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe out.printf("\nfile: %s\npsiElement: %s\nrequiredClass: %s\nactualClass: %s", file, psi, requiredClass, psi.getClass()); - out.printf("\nvirtualFile: size:%s; stamp:%s; modCount:%s", - file.getLength(), file.getModificationStamp(), file.getModificationCount()); + FileType fileType = file.getFileType(); + Language language = fileType instanceof LanguageFileType ? + LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), file, psi.getProject()) : + Language.ANY; + out.printf("\nvirtualFile: size:%s; stamp:%s; modCount:%s; fileType:%s; language:%s", + file.getLength(), file.getModificationStamp(), file.getModificationCount(), + fileType.getName(), language.getID()); Document document = FileDocumentManager.getInstance().getCachedDocument(file); if (document != null) { @@ -478,8 +487,9 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe PsiFile psiFile = psi.getManager().findFile(file); if (psiFile != null) { - out.printf("\npsiFile: size:%s; stamp:%s; class:%s", - psiFile.getTextLength(), psiFile.getViewProvider().getModificationStamp(), psiFile.getClass().getName()); + out.printf("\npsiFile: size:%s; stamp:%s; class:%s; language:%s", + psiFile.getTextLength(), psiFile.getViewProvider().getModificationStamp(), psiFile.getClass().getName(), + psiFile.getLanguage().getID()); } StubTree stub = psiFile instanceof PsiFileWithStubSupport ? ((PsiFileWithStubSupport)psiFile).getStubTree() : null; From a3258e2d4762bc77487d68226167fbc327b20244 Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Thu, 27 Feb 2014 18:47:12 +0400 Subject: [PATCH 19/95] IDEA-121283 Multiple Carets: Alt-J keyboard shortcut should be changed for Mac --- platform/platform-resources/src/idea/Keymap_Mac.xml | 7 +++++++ platform/platform-resources/src/idea/Keymap_MacClassic.xml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/platform/platform-resources/src/idea/Keymap_Mac.xml b/platform/platform-resources/src/idea/Keymap_Mac.xml index 42cf466cd85b..044d5b91c7c7 100644 --- a/platform/platform-resources/src/idea/Keymap_Mac.xml +++ b/platform/platform-resources/src/idea/Keymap_Mac.xml @@ -349,6 +349,13 @@ + + + + + + + diff --git a/platform/platform-resources/src/idea/Keymap_MacClassic.xml b/platform/platform-resources/src/idea/Keymap_MacClassic.xml index 1ce8e72fa7bc..9d2b440f2797 100644 --- a/platform/platform-resources/src/idea/Keymap_MacClassic.xml +++ b/platform/platform-resources/src/idea/Keymap_MacClassic.xml @@ -258,6 +258,13 @@ + + + + + + + From 399fdef08e184f5efbc4b8ba1d39a311277dd8c0 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Thu, 27 Feb 2014 19:03:00 +0400 Subject: [PATCH 20/95] fix multi-caret completion issues, make TypedHandlers supporting block selection work also with multiple carets (IDEA-80056) --- .../completion/normal/MulticaretTyping.java | 4 + .../normal/MulticaretTyping_after.java | 4 + .../completion/JavaAutoPopupTest.groovy | 51 +++++++++++++ .../completion/NormalCompletionTest.groovy | 15 ++++ .../editorActions/TypedHandler.java | 21 +++-- .../lookup/impl/LookupTypedHandler.java | 4 +- .../editor/EditorModificationUtil.java | 76 ++++++++++++++++++- .../editor/actionSystem/TypedAction.java | 13 +--- .../openapi/editor/actions/CutAction.java | 7 +- .../codeInsight/PyMethodNameTypedHandler.java | 5 +- 10 files changed, 163 insertions(+), 37 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/MulticaretTyping.java create mode 100644 java/java-tests/testData/codeInsight/completion/normal/MulticaretTyping_after.java diff --git a/java/java-tests/testData/codeInsight/completion/normal/MulticaretTyping.java b/java/java-tests/testData/codeInsight/completion/normal/MulticaretTyping.java new file mode 100644 index 000000000000..00d3186f4ef2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/MulticaretTyping.java @@ -0,0 +1,4 @@ +class Foo {{ + System.out.p + System.out.p +}} diff --git a/java/java-tests/testData/codeInsight/completion/normal/MulticaretTyping_after.java b/java/java-tests/testData/codeInsight/completion/normal/MulticaretTyping_after.java new file mode 100644 index 000000000000..87debd854955 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/MulticaretTyping_after.java @@ -0,0 +1,4 @@ +class Foo {{ + System.out.append() + System.out.append() +}} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 4e8961dbe192..0b12b544bbfd 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -52,6 +52,7 @@ import com.intellij.psi.PsiFile import com.intellij.psi.PsiJavaFile import com.intellij.psi.statistics.StatisticsManager import com.intellij.psi.statistics.impl.StatisticsManagerImpl +import com.intellij.testFramework.EditorTestUtil import com.intellij.util.containers.ContainerUtil import org.jetbrains.annotations.NotNull @@ -1141,6 +1142,56 @@ class Foo {{ }}''' } + public void testMulticaret() { + doTestMulticaret """ +class Foo {{ + tx; + tx; +}}""", '\n', ''' +class Foo {{ + toString()x; + toString()x; +}}''' + } + + public void testMulticaretTab() { + doTestMulticaret """ +class Foo {{ + tx; + tx; +}}""", '\t', ''' +class Foo {{ + toString(); + toString(); +}}''' + } + + public void testMulticaretBackspace() { + doTestMulticaret """ +class Foo {{ + t; + t; +}}""", '\b\t', ''' +class Foo {{ + toString(); + toString(); +}}''' + } + + private doTestMulticaret(final String textBefore, final String toType, final String textAfter) { + EditorTestUtil.enableMultipleCarets() + try { + myFixture.configureByText "a.java", textBefore + type 'toStr' + assert lookup + type toType + myFixture.checkResult textAfter + } + finally { + EditorTestUtil.disableMultipleCarets() + } + } + private doTestBlockSelection(final String textBefore, final String toType, final String textAfter) { myFixture.configureByText "a.java", textBefore edt { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index f07a9635da0c..31a146b70531 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -1403,6 +1403,21 @@ class Foo {{ } } + public void testMulticaretTyping() { + EditorTestUtil.enableMultipleCarets() + try { + configure() + assert lookup + type('p') + assert lookup + type('\n') + checkResult() + } + finally { + EditorTestUtil.disableMultipleCarets() + } + } + public void "test complete lowercase class name"() { myFixture.addClass("package foo; public class myClass {}") myFixture.configureByText "a.java", """ diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java index 216227d7744c..767256f2fb99 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java @@ -135,10 +135,7 @@ public class TypedHandler extends TypedActionHandlerBase { Project project = CommonDataKeys.PROJECT.getData(dataContext); PsiFile file; - if (project == null - || editor.isColumnMode() - || editor.getCaretModel().getAllCarets().size() > 1 - || (file = PsiUtilBase.getPsiFileInEditor(editor, project)) == null) { + if (project == null || editor.isColumnMode() || (file = PsiUtilBase.getPsiFileInEditor(editor, project)) == null) { if (myOriginalHandler != null){ myOriginalHandler.execute(editor, charTyped, dataContext); } @@ -174,13 +171,13 @@ public class TypedHandler extends TypedActionHandlerBase { } if (!editor.isInsertMode()){ - myOriginalHandler.execute(originalEditor, charTyped, dataContext); + if (myOriginalHandler != null) { + myOriginalHandler.execute(originalEditor, charTyped, dataContext); + } return; } - if (editor.getSelectionModel().hasSelection()){ - EditorModificationUtil.deleteSelectedText(editor); - } + EditorModificationUtil.deleteSelectedTextForAllCarets(editor); FileType fileType = getFileType(file, editor); @@ -194,7 +191,7 @@ public class TypedHandler extends TypedActionHandlerBase { } } - if (!editor.getSelectionModel().hasBlockSelection()) { + if (!editor.getSelectionModel().hasBlockSelection() && editor.getCaretModel().getAllCarets().size() == 1) { if (')' == charTyped || ']' == charTyped || '}' == charTyped) { if (FileTypes.PLAIN_TEXT != fileType) { if (handleRParen(editor, fileType, charTyped)) return; @@ -206,12 +203,14 @@ public class TypedHandler extends TypedActionHandlerBase { } long modificationStampBeforeTyping = editor.getDocument().getModificationStamp(); - myOriginalHandler.execute(originalEditor, charTyped, dataContext); + if (myOriginalHandler != null) { + myOriginalHandler.execute(originalEditor, charTyped, dataContext); + } AutoHardWrapHandler.getInstance().wrapLineIfNecessary(editor, dataContext, modificationStampBeforeTyping); if (('(' == charTyped || '[' == charTyped || '{' == charTyped) && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && - !editor.getSelectionModel().hasBlockSelection() && fileType != FileTypes.PLAIN_TEXT) { + !editor.getSelectionModel().hasBlockSelection() && editor.getCaretModel().getAllCarets().size() == 1 && fileType != FileTypes.PLAIN_TEXT) { handleAfterLParen(editor, fileType, charTyped); } else if ('}' == charTyped) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java index be95eed73160..9d8c67938907 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.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. @@ -80,7 +80,7 @@ public class LookupTypedHandler extends TypedHandlerDelegate { if (!lookup.performGuardedChange(new Runnable() { @Override public void run() { - EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, String.valueOf(charTyped), true); + EditorModificationUtil.typeInStringAtCaretHonorMultipleCarets(editor, String.valueOf(charTyped), true); } })) { return Result.STOP; diff --git a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java index cf674d6abe72..cf36d1831b53 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java @@ -25,6 +25,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.LineTokenizer; import com.intellij.psi.PsiDocumentManager; import com.intellij.util.Producer; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; @@ -51,6 +52,15 @@ public class EditorModificationUtil { editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); } + public static void deleteSelectedTextForAllCarets(@NotNull final Editor editor) { + editor.getCaretModel().runForEachCaret(new CaretAction() { + @Override + public void perform(Caret caret) { + deleteSelectedText(editor); + } + }); + } + public static void deleteBlockSelection(Editor editor) { SelectionModel selectionModel = editor.getSelectionModel(); if (!selectionModel.hasBlockSelection()) return; @@ -81,11 +91,15 @@ public class EditorModificationUtil { editor.getSelectionModel().setBlockSelection(new LogicalPosition(startLine, caretColumn), new LogicalPosition(endLine, caretColumn)); } - public static void insertStringAtCaret(Editor editor, String s) { + public static void insertStringAtCaret(Editor editor, @NotNull String s) { insertStringAtCaret(editor, s, false, true); } - public static int insertStringAtCaret(Editor editor, String s, boolean toProcessOverwriteMode, boolean toMoveCaret) { + public static int insertStringAtCaret(Editor editor, @NotNull String s, boolean toProcessOverwriteMode, boolean toMoveCaret) { + return insertStringAtCaret(editor, s, toProcessOverwriteMode, toMoveCaret, s.length()); + } + + public static int insertStringAtCaret(Editor editor, @NotNull String s, boolean toProcessOverwriteMode, boolean toMoveCaret, int caretShift) { final SelectionModel selectionModel = editor.getSelectionModel(); if (selectionModel.hasSelection()) { editor.getCaretModel().moveToOffset(selectionModel.getSelectionStart(), true); @@ -120,7 +134,7 @@ public class EditorModificationUtil { document.replaceString(oldOffset, Math.min(endOffset, oldOffset + s.length()), s); } - int offset = oldOffset + s.length(); + int offset = oldOffset + filler.length() + caretShift; if (toMoveCaret){ editor.getCaretModel().moveToOffset(offset, true); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); @@ -365,6 +379,62 @@ public class EditorModificationUtil { } } + public static void typeInStringAtCaretHonorMultipleCarets(final Editor editor, @NotNull final String str, final boolean toProcessOverwriteMode) { + typeInStringAtCaretHonorMultipleCarets(editor, str, toProcessOverwriteMode, str.length()); + } + + /** + * Inserts given string at each caret's position. Effective caret shift will be equal to caretShift for each caret. + */ + public static void typeInStringAtCaretHonorMultipleCarets(final Editor editor, @NotNull final String str, final boolean toProcessOverwriteMode, final int caretShift) + throws ReadOnlyFragmentModificationException + { + Document doc = editor.getDocument(); + final SelectionModel selectionModel = editor.getSelectionModel(); + if (selectionModel.hasBlockSelection()) { + RangeMarker guard = selectionModel.getBlockSelectionGuard(); + if (guard != null) { + DocumentEvent evt = new MockDocumentEvent(doc, editor.getCaretModel().getOffset()); + ReadOnlyFragmentModificationException e = new ReadOnlyFragmentModificationException(evt, guard); + EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(doc).handle(e); + } + else { + final LogicalPosition start = selectionModel.getBlockStart(); + final LogicalPosition end = selectionModel.getBlockEnd(); + assert start != null; + assert end != null; + + int column = Math.min(start.column, end.column); + int startLine = Math.min(start.line, end.line); + int endLine = Math.max(start.line, end.line); + deleteBlockSelection(editor); + for (int i = startLine; i <= endLine; i++) { + editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(i, column)); + insertStringAtCaret(editor, str, toProcessOverwriteMode, true, caretShift); + } + selectionModel.setBlockSelection(new LogicalPosition(startLine, column + str.length()), + new LogicalPosition(endLine, column + str.length())); + } + } + else { + editor.getCaretModel().runForEachCaret(new CaretAction() { + @Override + public void perform(Caret caret) { + insertStringAtCaret(editor, str, toProcessOverwriteMode, true, caretShift); + } + }); + } + } + + public static void moveAllCaretsRelatively(@NotNull Editor editor, final int caretShift) { + editor.getCaretModel().runForEachCaret(new CaretAction() { + @Override + public void perform(Caret caret) { + caret.moveToOffset(caret.getOffset() + caretShift); + } + }); + } + /** @deprecated use {@link #pasteTransferable(Editor, Producer)} (to remove in IDEA 14) */ @SuppressWarnings("UnusedDeclaration") public static TextRange pasteFromClipboard(Editor editor) { diff --git a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/TypedAction.java b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/TypedAction.java index 28bc0f0510ed..1e49937e7765 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/TypedAction.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/TypedAction.java @@ -64,18 +64,7 @@ public class TypedAction { try { final String str = String.valueOf(charTyped); CommandProcessor.getInstance().setCurrentCommandName(EditorBundle.message("typing.in.editor.command.name")); - - if (editor.getCaretModel().getAllCarets().size() == 1) { // temporary fix for completion - going forward we shouldn't use this check - EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, str, true); - } - else { - editor.getCaretModel().runForEachCaret(new CaretAction() { - @Override - public void perform(Caret caret) { - EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, str, true); - } - }); - } + EditorModificationUtil.typeInStringAtCaretHonorMultipleCarets(editor, str, true); } catch (ReadOnlyFragmentModificationException e) { EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(doc).handle(e); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/CutAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/CutAction.java index 4fc378e566c6..dd54b1de2087 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/CutAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/CutAction.java @@ -53,12 +53,7 @@ public class CutAction extends EditorAction { }); } editor.getSelectionModel().copySelectionToClipboard(); - editor.getCaretModel().runForEachCaret(new CaretAction() { - @Override - public void perform(Caret caret) { - EditorModificationUtil.deleteSelectedText(editor); - } - }); + EditorModificationUtil.deleteSelectedTextForAllCarets(editor); } } } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java b/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java index f30febe2988d..15b29c1c584a 100644 --- a/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java +++ b/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.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. @@ -82,8 +82,7 @@ public class PyMethodNameTypedHandler extends TypedHandlerDelegate { if (caretOffset == chars.length() || chars.charAt(caretOffset) != ':') { textToType += ':'; } - EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, textToType, true); - editor.getCaretModel().moveToOffset(offset + 1 + pname.length()); // right after param name + EditorModificationUtil.typeInStringAtCaretHonorMultipleCarets(editor, textToType, true, 1 + pname.length()); // right after param name return Result.STOP; } } From a3bbf916e4b8fc6e50e983626025af0b3f30356b Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Thu, 27 Feb 2014 19:25:22 +0400 Subject: [PATCH 21/95] IDEA-105837 Intellij Idea caches maven snapshot dependencies forever --- .../maven/server/MavenServerEmbedder.java | 3 ++- .../embedder/Maven2ServerEmbedderImpl.java | 3 ++- .../server/Maven3ServerEmbedderImpl.java | 9 +++++++- .../idea/maven/project/MavenProjectsTree.java | 4 ++-- .../maven/server/MavenEmbedderWrapper.java | 22 ++++++++++++------- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/plugins/maven/maven-server-api/src/org/jetbrains/idea/maven/server/MavenServerEmbedder.java b/plugins/maven/maven-server-api/src/org/jetbrains/idea/maven/server/MavenServerEmbedder.java index 8fe4348a0ade..0c4be99814c1 100644 --- a/plugins/maven/maven-server-api/src/org/jetbrains/idea/maven/server/MavenServerEmbedder.java +++ b/plugins/maven/maven-server-api/src/org/jetbrains/idea/maven/server/MavenServerEmbedder.java @@ -29,7 +29,8 @@ public interface MavenServerEmbedder extends Remote { void customize(@Nullable MavenWorkspaceMap workspaceMap, boolean failOnUnresolvedDependency, @NotNull MavenServerConsole console, - @NotNull MavenServerProgressIndicator indicator) throws RemoteException; + @NotNull MavenServerProgressIndicator indicator, + boolean alwaysUpdateSnapshots) throws RemoteException; @NotNull MavenServerExecutionResult resolveProject(@NotNull File file, diff --git a/plugins/maven/maven2-server-impl/src/org/jetbrains/idea/maven/server/embedder/Maven2ServerEmbedderImpl.java b/plugins/maven/maven2-server-impl/src/org/jetbrains/idea/maven/server/embedder/Maven2ServerEmbedderImpl.java index 630e664c2366..7ed82b0494dc 100644 --- a/plugins/maven/maven2-server-impl/src/org/jetbrains/idea/maven/server/embedder/Maven2ServerEmbedderImpl.java +++ b/plugins/maven/maven2-server-impl/src/org/jetbrains/idea/maven/server/embedder/Maven2ServerEmbedderImpl.java @@ -586,7 +586,8 @@ public class Maven2ServerEmbedderImpl extends MavenRemoteObject implements Maven public void customize(@Nullable MavenWorkspaceMap workspaceMap, boolean failOnUnresolvedDependency, @NotNull MavenServerConsole console, - @NotNull MavenServerProgressIndicator indicator) { + @NotNull MavenServerProgressIndicator indicator, + boolean alwaysUpdateSnapshots) { try { ((CustomArtifactFactory)getComponent(ArtifactFactory.class)).customize(); ((CustomArtifactFactory)getComponent(ProjectArtifactFactory.class)).customize(); diff --git a/plugins/maven/maven3-server-impl/src/org/jetbrains/idea/maven/server/Maven3ServerEmbedderImpl.java b/plugins/maven/maven3-server-impl/src/org/jetbrains/idea/maven/server/Maven3ServerEmbedderImpl.java index ae454210c909..ded8fa37a958 100644 --- a/plugins/maven/maven3-server-impl/src/org/jetbrains/idea/maven/server/Maven3ServerEmbedderImpl.java +++ b/plugins/maven/maven3-server-impl/src/org/jetbrains/idea/maven/server/Maven3ServerEmbedderImpl.java @@ -111,6 +111,8 @@ public class Maven3ServerEmbedderImpl extends MavenRemoteObject implements Maven private Date myBuildStartTime; + private boolean myAlwaysUpdateSnapshots; + public Maven3ServerEmbedderImpl(MavenServerSettings settings) throws RemoteException { File mavenHome = settings.getMavenHome(); if (mavenHome != null) { @@ -269,7 +271,8 @@ public class Maven3ServerEmbedderImpl extends MavenRemoteObject implements Maven public void customize(@Nullable MavenWorkspaceMap workspaceMap, boolean failOnUnresolvedDependency, @NotNull MavenServerConsole console, - @NotNull MavenServerProgressIndicator indicator) throws RemoteException { + @NotNull MavenServerProgressIndicator indicator, + boolean alwaysUpdateSnapshots) throws RemoteException { try { ((CustomMaven3ArtifactFactory)getComponent(ArtifactFactory.class)).customize(); @@ -281,6 +284,8 @@ public class Maven3ServerEmbedderImpl extends MavenRemoteObject implements Maven myBuildStartTime = new Date(); + myAlwaysUpdateSnapshots = alwaysUpdateSnapshots; + setConsoleAndIndicator(console, new MavenServerProgressIndicatorWrapper(indicator)); } catch (Exception e) { @@ -349,6 +354,8 @@ public class Maven3ServerEmbedderImpl extends MavenRemoteObject implements Maven final MavenExecutionRequest request = createRequest(file, activeProfiles, Collections.emptyList(), Collections.emptyList()); + request.setUpdateSnapshots(myAlwaysUpdateSnapshots); + final AtomicReference ref = new AtomicReference(); executeWithMavenSession(request, new Runnable() { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java index 4089981b1627..0019d59b3d7d 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java @@ -1206,7 +1206,7 @@ public class MavenProjectsTree { @NotNull ResolveContext context, @NotNull MavenProgressIndicator process) throws MavenProcessCanceledException { MavenEmbedderWrapper embedder = embeddersManager.getEmbedder(MavenEmbeddersManager.FOR_DEPENDENCIES_RESOLVE); - embedder.customizeForResolve(getWorkspaceMap(), console, process); + embedder.customizeForResolve(getWorkspaceMap(), console, process, generalSettings.isAlwaysUpdateSnapshots()); try { process.checkCanceled(); @@ -1321,7 +1321,7 @@ public class MavenProjectsTree { @NotNull MavenProgressIndicator process, @NotNull EmbedderTask task) throws MavenProcessCanceledException { MavenEmbedderWrapper embedder = embeddersManager.getEmbedder(embedderKind); - embedder.customizeForResolve(getWorkspaceMap(), console, process); + embedder.customizeForResolve(getWorkspaceMap(), console, process, false); embedder.clearCachesFor(mavenProject.getMavenId()); try { task.run(embedder); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenEmbedderWrapper.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenEmbedderWrapper.java index c5ac93cd6d7b..a0882e7c87fd 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenEmbedderWrapper.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenEmbedderWrapper.java @@ -49,7 +49,7 @@ public abstract class MavenEmbedderWrapper extends RemoteObjectWrapper() { @Override public Object execute() throws RemoteException { @@ -59,8 +59,8 @@ public abstract class MavenEmbedderWrapper extends RemoteObjectWrapper() { @Override public Object execute() throws RemoteException { @@ -73,7 +73,7 @@ public abstract class MavenEmbedderWrapper extends RemoteObjectWrapper() { @Override public Object execute() throws RemoteException { @@ -87,7 +87,8 @@ public abstract class MavenEmbedderWrapper extends RemoteObjectWrapper Date: Thu, 27 Feb 2014 15:55:37 +0100 Subject: [PATCH 22/95] optimization for inspections tree filtering --- .../platform-api/src/com/intellij/util/ui/tree/TreeUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java index 97ecd972b350..66698eeae309 100644 --- a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java +++ b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java @@ -787,7 +787,9 @@ public final class TreeUtil { if (rowCount == oldRowCount) break; oldRowCount = rowCount; for (int i = 0; i < rowCount; i++) { - tree.expandRow(i); + if (!tree.isExpanded(i)) { + tree.expandRow(i); + } } } while (true); From 1f37c792027f1150eb31ad337d74ceeef146b95a Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 27 Feb 2014 16:12:23 +0100 Subject: [PATCH 23/95] fix "Extract parameter as local variable" quickfix for expression lambda's --- .../tree/java/ExpressionPsiElement.java | 5 +- .../ExtractParameterAsLocalVariableFix.java | 22 ++-- .../com/siyeh/ig/IGQuickFixesTestCase.java | 35 +++-- ...xtractParameterAsLocalVariableFixTest.java | 121 ++++++++++++++++++ 4 files changed, 161 insertions(+), 22 deletions(-) create mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFixTest.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ExpressionPsiElement.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ExpressionPsiElement.java index cf40d04ca427..1d8693efc55c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ExpressionPsiElement.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ExpressionPsiElement.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. @@ -38,7 +38,8 @@ public class ExpressionPsiElement extends CompositePsiElement { @Override public void replaceChildInternal(@NotNull ASTNode child, @NotNull TreeElement newElement) { - if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) { + if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType()) && + ElementType.EXPRESSION_BIT_SET.contains(newElement.getElementType())) { boolean needParenth = ReplaceExpressionUtil.isNeedParenthesis(child, newElement); if (needParenth) { newElement = SourceUtil.addParenthToReplacedChild(JavaElementType.PARENTH_EXPRESSION, newElement, getManager()); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFix.java index 9ef4c14e4a84..31a7987f40f1 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFix.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2011 Bas Leijdekkers + * Copyright 2008-2014 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.tree.IElementType; -import com.intellij.util.IncorrectOperationException; import com.intellij.util.Query; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.InspectionGadgetsFix; @@ -46,8 +45,7 @@ public class ExtractParameterAsLocalVariableFix } @Override - public void doFix(Project project, ProblemDescriptor descriptor) - throws IncorrectOperationException { + public void doFix(Project project, ProblemDescriptor descriptor) { final PsiReferenceExpression parameterReference = (PsiReferenceExpression)descriptor.getPsiElement(); final PsiElement target = parameterReference.resolve(); @@ -79,6 +77,10 @@ public class ExtractParameterAsLocalVariableFix body = forBody; } } + else if (declarationScope instanceof PsiLambdaExpression) { + final PsiLambdaExpression lambdaExpression = (PsiLambdaExpression)declarationScope; + body = lambdaExpression.getBody(); + } else { return; } @@ -125,15 +127,16 @@ public class ExtractParameterAsLocalVariableFix replaceVariableName(child, firstReference, variableName, parameterName, buffer); } + if (body instanceof PsiExpression) { // expression lambda + buffer.insert(0, "return "); + buffer.append(';'); + } final String replacementText; if (newDeclarationCreated) { replacementText = "{" + buffer + '}'; } else { - final PsiType type = parameterReference.getType(); - if (type == null) { - return; - } + final PsiType type = parameter.getType(); final String className = type.getCanonicalText(); replacementText = '{' + className + ' ' + variableName + " = " + parameterName + ';' + buffer + '}'; @@ -141,8 +144,7 @@ public class ExtractParameterAsLocalVariableFix final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory(); final PsiCodeBlock block = - elementFactory.createCodeBlockFromText( - replacementText, null); + elementFactory.createCodeBlockFromText(replacementText, declarationScope); body.replace(block); codeStyleManager.reformat(declarationScope); } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java index b56c340f5400..2ce63ec4814e 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/IGQuickFixesTestCase.java @@ -21,6 +21,7 @@ import com.intellij.openapi.application.PluginPathManager; import com.intellij.pom.java.LanguageLevel; import com.intellij.testFramework.builders.JavaModuleFixtureBuilder; import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; +import com.intellij.util.ArrayUtil; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -38,19 +39,33 @@ public abstract class IGQuickFixesTestCase extends JavaCodeInsightFixtureTestCas protected void setUp() throws Exception { super.setUp(); - final BaseInspection inspection = getInspection(); - if (inspection != null) { - myFixture.enableInspections(inspection); + for (String environmentClass : getEnvironmentClasses()) { + myFixture.addClass(environmentClass); } + myFixture.enableInspections(getInspections()); } protected BaseInspection getInspection() { return null; } + protected BaseInspection[] getInspections() { + final BaseInspection inspection = getInspection(); + if (inspection != null) { + return new BaseInspection[] {inspection}; + } + return new BaseInspection[0]; + } + + @NonNls + @Language("JAVA") + protected String[] getEnvironmentClasses() { + return ArrayUtil.EMPTY_STRING_ARRAY; + } + @Override protected void tuneFixture(final JavaModuleFixtureBuilder builder) throws Exception { - builder.setLanguageLevel(LanguageLevel.JDK_1_7); + builder.setLanguageLevel(LanguageLevel.JDK_1_8); } @Override @@ -79,16 +94,16 @@ public abstract class IGQuickFixesTestCase extends JavaCodeInsightFixtureTestCas protected void doExpressionTest( String hint, - @Language(value = "JAVA", prefix = "class X {{System.out.print(", suffix = ");}}") @NotNull @NonNls String before, - @Language(value = "JAVA", prefix = "class X {{System.out.print(", suffix = ");}}") @NotNull @NonNls String after) { - doTest(hint, "class X {{System.out.print(" + before + ");}}", "class X {{System.out.print(" + after + ");}}"); + @Language(value = "JAVA", prefix = "class $X$ {{System.out.print(", suffix = ");}}") @NotNull @NonNls String before, + @Language(value = "JAVA", prefix = "class $X$ {{System.out.print(", suffix = ");}}") @NotNull @NonNls String after) { + doTest(hint, "class $X$ {{System.out.print(" + before + ");}}", "class $X$ {{System.out.print(" + after + ");}}"); } protected void doMemberTest( String hint, - @Language(value = "JAVA", prefix = "class X {", suffix = "}") @NotNull @NonNls String before, - @Language(value = "JAVA", prefix = "class X {", suffix = "}") @NotNull @NonNls String after) { - doTest(hint, "class X {" + before + "}", "class X {" + after + "}"); + @Language(value = "JAVA", prefix = "class $X$ {", suffix = "}") @NotNull @NonNls String before, + @Language(value = "JAVA", prefix = "class $X$ {", suffix = "}") @NotNull @NonNls String after) { + doTest(hint, "class $X$ {" + before + "}", "class $X$ {\n " + after + "\n}"); } protected void doTest(String hint, @Language("JAVA") @NotNull @NonNls String before, @Language("JAVA") @NotNull @NonNls String after) { diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFixTest.java new file mode 100644 index 000000000000..b8b74aecf249 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFixTest.java @@ -0,0 +1,121 @@ +/* + * 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.siyeh.ig.fixes; + +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.BaseInspection; +import com.siyeh.ig.IGQuickFixesTestCase; +import com.siyeh.ig.assignment.AssignmentToCatchBlockParameterInspection; +import com.siyeh.ig.assignment.AssignmentToForLoopParameterInspection; +import com.siyeh.ig.assignment.AssignmentToMethodParameterInspection; + +/** + * @author Bas Leijdekkers + */ +public class ExtractParameterAsLocalVariableFixTest extends IGQuickFixesTestCase { + + + @Override + protected BaseInspection[] getInspections() { + final AssignmentToForLoopParameterInspection inspection2 = new AssignmentToForLoopParameterInspection(); + inspection2.m_checkForeachParameters = true; + return new BaseInspection[] { + new AssignmentToMethodParameterInspection(), + inspection2, + new AssignmentToCatchBlockParameterInspection() + }; + } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] {"class A {}", + "public interface Function {\n" + + " R apply(T t);" + + "}"}; + } + + public void testLambdaWithExpressionBody() { + doTest( + InspectionGadgetsBundle.message("extract.parameter.as.local.variable.quickfix"), + "class X {" + + " Function f = (a) -> a/**/ = null;" + + "}", + "class X {" + + " Function f = (a) -> {\n" + + " A a1 = a;\n" + + " return a1 = null;\n" + + "};}" + ); + } + + public void testSimpleMethod() { + doTest( + InspectionGadgetsBundle.message("extract.parameter.as.local.variable.quickfix"), + "class X {" + + " void m(String s) {" + + " /**/s = \"hello\";" + + " System.out.println(s);" + + " }" + + "}", + "class X {\n" + + " void m(String s) {\n" + + " String s1 = \"hello\";\n" + + " System.out.println(s1);\n" + + " }\n" + + "}" + ); + } + + public void testSimpleForeach() { + doTest( + InspectionGadgetsBundle.message("extract.parameter.as.local.variable.quickfix"), + "class X {" + + " void m() {" + + " for (String s : new String[]{\"one\", \"two\", \"three\"})" + + " s/**/ = \"four\";" + + "}}", + "class X {" + + " void m() {\n" + + " for (String s : new String[]{\"one\", \"two\", \"three\"}){\n" + + " String s1 = \"four\";\n" + + " }\n" + + "}}" + ); + } + + public void testSimleCatchBlock() { + doTest( + InspectionGadgetsBundle.message("extract.parameter.as.local.variable.quickfix"), + "class X {" + + " void m() {" + + " try (java.io.InputStream in = null) {" + + " } catch (java.io.IOException e) {" + + " e/**/ = null;" + + " System.out.println(e);" + + " }" + + " }" + + "}", + "class X {" + + " void m() {" + + " try (java.io.InputStream in = null) {" + + " } catch (java.io.IOException e) {\n" + + " java.io.IOException e1 = null;\n" + + " System.out.println(e1);\n" + + "}\n" + + "}}" + ); + } +} From 2af38aea2e8a87c480120d9b49a89f803602b0e8 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 27 Feb 2014 16:57:09 +0100 Subject: [PATCH 24/95] new "Lambda parameter hides field" inspection --- .../src/META-INF/InspectionGadgets.xml | 4 + .../siyeh/InspectionGadgetsBundle.properties | 3 + ...terHidingMemberVariableInspectionBase.java | 110 ++++++++++++++++++ ...rameterHidingMemberVariableInspection.java | 26 +++++ .../LambdaParameterHidingMemberVariable.html | 11 ++ ...terHidingMemberVariableInspectionTest.java | 48 ++++++++ 6 files changed, 202 insertions(+) create mode 100644 plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionBase.java create mode 100644 plugins/InspectionGadgets/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspection.java create mode 100644 plugins/InspectionGadgets/src/inspectionDescriptions/LambdaParameterHidingMemberVariable.html create mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionTest.java diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml index dddb6e1d3988..eca27bdaf661 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml @@ -2640,6 +2640,10 @@ bundle="com.siyeh.InspectionGadgetsBundle" key="parameter.hides.member.variable.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.visibility.issues" enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.visibility.ParameterHidingMemberVariableInspection"/> + diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties index 7f61b374c9a9..feb3c083ed25 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties @@ -2066,3 +2066,6 @@ implicit.default.charset.usage.constructor.problem.descriptor=new #ref()#ref may be annotated with @FunctionalInterface only.report.public.methods.option=Only report 'public' methods +lambda.parameter.hides.member.variable.display.name=Lambda parameter hides field +lambda.parameter.hides.member.variable.problem.descriptor=Lambda parameter #ref hides field in class ''{0}'' #loc + diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionBase.java new file mode 100644 index 000000000000..5b245eccc0a0 --- /dev/null +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionBase.java @@ -0,0 +1,110 @@ +/* + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers + * + * 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.siyeh.ig.visibility; + +import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; +import com.intellij.psi.*; +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.BaseInspection; +import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.psiutils.ClassUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public class LambdaParameterHidingMemberVariableInspectionBase extends BaseInspection { + + @SuppressWarnings("PublicField") + public boolean m_ignoreInvisibleFields = true; + + @Override + @NotNull + public String getID() { + return "LambdaParameterHidesMemberVariable"; + } + + @Override + @NotNull + public String getDisplayName() { + return InspectionGadgetsBundle.message("lambda.parameter.hides.member.variable.display.name"); + } + + @Override + protected boolean buildQuickFixesOnlyForOnTheFlyErrors() { + return true; + } + + @Override + @NotNull + public String buildErrorString(Object... infos) { + final PsiClass aClass = (PsiClass)infos[0]; + return InspectionGadgetsBundle.message("lambda.parameter.hides.member.variable.problem.descriptor", aClass.getName()); + } + + @Override + public JComponent createOptionsPanel() { + final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this); + optionsPanel.addCheckbox(InspectionGadgetsBundle.message("parameter.hides.member.variable.ignore.superclass.option"), + "m_ignoreInvisibleFields"); + return optionsPanel; + } + + @Override + public BaseInspectionVisitor buildVisitor() { + return new LambdaParameterHidingMemberVariableVisitor(); + } + + private class LambdaParameterHidingMemberVariableVisitor extends BaseInspectionVisitor { + + @Override + public void visitParameter(@NotNull PsiParameter variable) { + super.visitParameter(variable); + final PsiElement declarationScope = variable.getDeclarationScope(); + if (!(declarationScope instanceof PsiLambdaExpression)) { + return; + } + final PsiClass aClass = checkFieldName(variable); + if (aClass == null) { + return; + } + registerVariableError(variable, aClass); + } + + @Nullable + private PsiClass checkFieldName(PsiVariable variable) { + final String variableName = variable.getName(); + if (variableName == null) { + return null; + } + PsiClass aClass = ClassUtils.getContainingClass(variable); + while (aClass != null) { + final PsiField[] fields = aClass.getAllFields(); + for (PsiField field : fields) { + final String fieldName = field.getName(); + if (!variableName.equals(fieldName)) { + continue; + } + if (!m_ignoreInvisibleFields || ClassUtils.isFieldVisible(field, aClass)) { + return aClass; + } + } + aClass = ClassUtils.getContainingClass(aClass); + } + return null; + } + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspection.java new file mode 100644 index 000000000000..4112dfe911da --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspection.java @@ -0,0 +1,26 @@ +/* + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers + * + * 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.siyeh.ig.visibility; + +import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.fixes.RenameFix; + +public class LambdaParameterHidingMemberVariableInspection extends LambdaParameterHidingMemberVariableInspectionBase { + @Override + protected InspectionGadgetsFix buildFix(Object... infos) { + return new RenameFix(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/LambdaParameterHidingMemberVariable.html b/plugins/InspectionGadgets/src/inspectionDescriptions/LambdaParameterHidingMemberVariable.html new file mode 100644 index 000000000000..3817e402e632 --- /dev/null +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/LambdaParameterHidingMemberVariable.html @@ -0,0 +1,11 @@ + + +Reports lambda parameters named identically to visible fields of the surrounding classes +and their superclasses. + +

+Use the checkbox below to ignore fields that are not actually visible from the lambda expression, for example private fields +

+New in 13.1 + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionTest.java new file mode 100644 index 000000000000..e7c3b75f1a6d --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/visibility/LambdaParameterHidingMemberVariableInspectionTest.java @@ -0,0 +1,48 @@ +/* + * 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.siyeh.ig.visibility; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; + +/** + * @author Bas Leijdekkers + */ +public class LambdaParameterHidingMemberVariableInspectionTest extends LightInspectionTestCase { + @Override + protected InspectionProfileEntry getInspection() { + return new LambdaParameterHidingMemberVariableInspection(); + } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] {"package java.util.function;" + + "public interface Function {" + + " R apply(T t);" + + "}"}; + } + + public void testSimple() { + doTest("import java.util.function.Function;" + + "class X {" + + " private String s;" + + "" + + " void m() {" + + " Function f = (/*Lambda parameter 's' hides field in class 'X'*/s/**/) -> null;" + + " }" + + "}"); + } +} From f8d1847829e231c19dc0f2e52acc8188d7e87201 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 27 Feb 2014 16:43:58 +0100 Subject: [PATCH 25/95] New plugin description --- plugins/hg4idea/src/META-INF/plugin.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/hg4idea/src/META-INF/plugin.xml b/plugins/hg4idea/src/META-INF/plugin.xml index ba40408dd98d..f0ce13c23b43 100644 --- a/plugins/hg4idea/src/META-INF/plugin.xml +++ b/plugins/hg4idea/src/META-INF/plugin.xml @@ -1,7 +1,17 @@ hg4idea hg4idea - Provides integration with Mercurial version control system. Supports Mercurial 1.3+. + + Mercurial version control system. + The following features are available: +

    +
  • Dedicated page under the Version Control node in the Settings/Preferences dialog.
  • +
  • Ability to browse, check out sources from and import into the available Mercurial repositories, when Mercurial is not enabled.
  • +
  • When Mercurial is enabled, the Mercurial node appears on the VCS menu, and on the context menu of the editor. +
+ ]]> + VCS Integration 10.0 Victor Iacoban and Willem Verstraeten From 17c097a5e191bdca1a070e2bb423759df5d964c0 Mon Sep 17 00:00:00 2001 From: "andrey.vokin" Date: Thu, 27 Feb 2014 18:51:13 +0400 Subject: [PATCH 26/95] SlimEnterHandler should pass processing --- .../enter/BaseIndentEnterHandler.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/BaseIndentEnterHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/BaseIndentEnterHandler.java index 48c1dfbef792..524a2b2f286a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/BaseIndentEnterHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/BaseIndentEnterHandler.java @@ -83,15 +83,7 @@ public class BaseIndentEnterHandler extends EnterHandlerDelegateAdapter { myWorksWithFormatter = worksWithFormatter; } - @Override - public Result preprocessEnter( - @NotNull final PsiFile file, - @NotNull final Editor editor, - @NotNull final Ref caretOffset, - @NotNull final Ref caretAdvance, - @NotNull final DataContext dataContext, - final EditorActionHandler originalHandler) - { + protected Result shouldSkipWithResult(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return Result.Continue; @@ -119,7 +111,25 @@ public class BaseIndentEnterHandler extends EnterHandlerDelegateAdapter { if (caret <= 0) { return Result.Continue; } + return null; + } + @Override + public Result preprocessEnter( + @NotNull final PsiFile file, + @NotNull final Editor editor, + @NotNull final Ref caretOffset, + @NotNull final Ref caretAdvance, + @NotNull final DataContext dataContext, + final EditorActionHandler originalHandler) + { + Result res = shouldSkipWithResult(file, editor, dataContext); + if (res != null) { + return res; + } + + final Document document = editor.getDocument(); + int caret = editor.getCaretModel().getOffset(); final int lineNumber = document.getLineNumber(caret); final int lineStartOffset = document.getLineStartOffset(lineNumber); @@ -207,7 +217,7 @@ public class BaseIndentEnterHandler extends EnterHandlerDelegateAdapter { } @Nullable - private IElementType getNonWhitespaceElementType(final HighlighterIterator iterator, int currentLineStartOffset, final int prevLineStartOffset) { + protected IElementType getNonWhitespaceElementType(final HighlighterIterator iterator, int currentLineStartOffset, final int prevLineStartOffset) { while (!iterator.atEnd() && iterator.getEnd() >= currentLineStartOffset && iterator.getStart() >= prevLineStartOffset) { final IElementType tokenType = iterator.getTokenType(); if (!myWhitespaceTokens.contains(tokenType)) { From 88189ccf342aeee85f569bb4b940ed23a35315a5 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 27 Feb 2014 17:33:02 +0100 Subject: [PATCH 27/95] New plugin description --- .../src/com/intellij/cvsSupport2/CvsBundle.properties | 1 - plugins/cvs/cvs-plugin/src/META-INF/plugin.xml | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties index 89385066f85a..15ce261fa653 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties @@ -415,7 +415,6 @@ action.Cvs.ToggleOffline.text=_Work Offline action.Cvs.ToggleOffline.description=Toggle offline mode for CVS root containing selected file set.online.notification.text=Set to online mode set.offline.notification.text=Set to offline mode -plugin.CVS.description=Provides integration with CVS version control system adding.cvsignore.files.to.cvs.action.name=Adding .cvsignore Files to CVS browse.repository.operation.name=Browse Repository configure.global.cvs.settings.action.name=Configure Global CVS Settings diff --git a/plugins/cvs/cvs-plugin/src/META-INF/plugin.xml b/plugins/cvs/cvs-plugin/src/META-INF/plugin.xml index 20f34c5513b0..1cefc9748ae4 100644 --- a/plugins/cvs/cvs-plugin/src/META-INF/plugin.xml +++ b/plugins/cvs/cvs-plugin/src/META-INF/plugin.xml @@ -5,6 +5,17 @@ JetBrains com.intellij.cvsSupport2.CvsBundle VCS Integration + + +
  • Dedicated page under the Version Control node in the Settings/Preferences dialog.
  • +
  • When CVS is not enabled, it is still possible to browse, check out sources from and import into the available CVS repositories.
  • +
  • When CVS is enabled, the CVS node appears on the VCS menu, and on the context menu of the editor. + + ]]> + com.intellij.modules.lang com.intellij.modules.vcs From 7a3a6cfbcff54d51e2de2b3a02ba9bee30588009 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 14 Feb 2014 21:14:27 +0400 Subject: [PATCH 28/95] java move to xbreakpoints: - removed java own breakpoints UI - added UI for java filters - added support for all kinds of java breakpoints --- .../JavaEditBreakpointActionHandler.java | 116 --- .../ToggleBreakpointEnabledAction.java | 3 +- .../actions/ToggleFieldBreakpointAction.java | 2 +- .../ToggleLineBreakpointActionHandler.java | 163 ---- .../debugger/engine/DebugProcessImpl.java | 6 +- .../engine/requests/RequestManagerImpl.java | 36 +- .../debugger/impl/DebuggerManagerImpl.java | 6 +- .../debugger/ui/JavaDebuggerSupport.java | 203 +++-- .../debugger/ui/PositionHighlighter.java | 2 +- .../debugger/ui/XBreakpointCategoryGroup.java | 81 -- .../ui/XBreakpointGroupingByCategoryRule.java | 64 -- .../breakpoints/AddFieldBreakpointDialog.java | 2 +- .../AddWildcardBreakpointDialog.java | 2 +- .../breakpoints/AnyExceptionBreakpoint.java | 25 +- .../AnyExceptionBreakpointFactory.java | 65 -- .../debugger/ui/breakpoints/Breakpoint.java | 346 +++++++- .../ui/breakpoints/BreakpointFactory.java | 81 -- .../ui/breakpoints/BreakpointManager.java | 831 ++++++++---------- .../BreakpointPropertiesPanel.java | 84 +- .../BreakpointWithHighlighter.java | 436 ++++----- .../ui/breakpoints/ExceptionBreakpoint.java | 108 ++- .../ExceptionBreakpointFactory.java | 94 -- .../ExceptionBreakpointPropertiesPanel.java | 58 +- .../ui/breakpoints/FieldBreakpoint.java | 92 +- .../breakpoints/FieldBreakpointFactory.java | 127 --- .../FieldBreakpointPropertiesPanel.java | 39 +- .../ui/breakpoints/FilteredRequestor.java | 253 +----- .../ui/breakpoints/FilteredRequestorImpl.java | 221 +++++ .../ui/breakpoints/JavaBreakpointItem.java | 184 ---- ...tiesPanel.java => JavaBreakpointType.java} | 21 +- .../breakpoints/JavaBreakpointTypeBase.java | 56 ++ .../JavaExceptionBreakpointType.java | 139 +++ .../breakpoints/JavaFieldBreakpointType.java | 170 ++++ .../breakpoints/JavaLineBreakpointType.java | 86 ++ .../JavaLineBreakpointTypeBase.java | 140 +++ .../breakpoints/JavaMethodBreakpointType.java | 127 +++ .../JavaWildcardMethodBreakpointType.java | 108 +++ .../ui/breakpoints/LineBreakpoint.java | 38 +- .../ui/breakpoints/LineBreakpointFactory.java | 66 -- .../ui/breakpoints/MethodBreakpoint.java | 69 +- .../breakpoints/MethodBreakpointFactory.java | 84 -- .../MethodBreakpointPropertiesPanel.java | 50 +- .../ui/breakpoints/RunToCursorBreakpoint.java | 13 +- .../ui/breakpoints/StepIntoBreakpoint.java | 4 +- .../breakpoints/WildcardMethodBreakpoint.java | 127 +-- .../breakpoints/JavaBreakpointAdapter.java | 157 ---- .../JavaBreakpointAdapterBase.java | 6 +- ...l.form => JavaBreakpointFiltersPanel.form} | 2 +- ...l.java => JavaBreakpointFiltersPanel.java} | 20 +- .../breakpoints/JavaBreakpointType.java | 76 -- .../JavaBreakpointProperties.java | 18 +- .../JavaExceptionBreakpointProperties.java | 52 ++ .../JavaFieldBreakpointProperties.java | 49 ++ .../JavaMethodBreakpointProperties.java | 54 ++ .../ExecutionWithDebuggerToolsTestCase.java | 14 +- .../src/messages/DebuggerBundle.properties | 10 +- resources/src/META-INF/IdeaPlugin.xml | 15 +- 57 files changed, 2665 insertions(+), 2836 deletions(-) delete mode 100644 java/debugger/impl/src/com/intellij/debugger/actions/JavaEditBreakpointActionHandler.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/actions/ToggleLineBreakpointActionHandler.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointCategoryGroup.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByCategoryRule.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpointFactory.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointFactory.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointFactory.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointFactory.java create mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestorImpl.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointItem.java rename java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/{LineBreakpointPropertiesPanel.java => JavaBreakpointType.java} (62%) create mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointTypeBase.java create mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaExceptionBreakpointType.java create mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java create mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java create mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointTypeBase.java create mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaMethodBreakpointType.java create mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpointFactory.java delete mode 100644 java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointFactory.java delete mode 100644 java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointAdapter.java rename java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/{JavaBreakpointPropertiesPanel.form => JavaBreakpointFiltersPanel.form} (99%) rename java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/{JavaBreakpointPropertiesPanel.java => JavaBreakpointFiltersPanel.java} (94%) delete mode 100644 java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointType.java rename java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/{ => properties}/JavaBreakpointProperties.java (84%) create mode 100644 java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaExceptionBreakpointProperties.java create mode 100644 java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java create mode 100644 java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaMethodBreakpointProperties.java diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/JavaEditBreakpointActionHandler.java b/java/debugger/impl/src/com/intellij/debugger/actions/JavaEditBreakpointActionHandler.java deleted file mode 100644 index 9ed769aee350..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/actions/JavaEditBreakpointActionHandler.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.debugger.actions; - -import com.intellij.debugger.DebuggerManagerEx; -import com.intellij.debugger.ui.breakpoints.BreakpointFactory; -import com.intellij.debugger.ui.breakpoints.BreakpointPropertiesPanel; -import com.intellij.debugger.ui.breakpoints.BreakpointWithHighlighter; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.markup.GutterIconRenderer; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.popup.Balloon; -import com.intellij.openapi.ui.popup.JBPopupListener; -import com.intellij.openapi.ui.popup.LightweightWindowEvent; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.wm.IdeFocusManager; -import com.intellij.util.ui.UIUtil; -import com.intellij.xdebugger.impl.actions.EditBreakpointActionHandler; -import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil; -import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointsDialogFactory; -import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.awt.*; - -public class JavaEditBreakpointActionHandler extends EditBreakpointActionHandler { - @Override - protected void doShowPopup(final Project project, final JComponent component, final Point whereToShow, final Object breakpoint) { - if (!(breakpoint instanceof BreakpointWithHighlighter)) { - return; - } - - final BreakpointWithHighlighter javaBreakpoint = (BreakpointWithHighlighter)breakpoint; - BreakpointFactory breakpointFactory = null; - for (BreakpointFactory factory : BreakpointFactory.EXTENSION_POINT_NAME.getExtensions()) { - if (factory.getBreakpointCategory().equals(javaBreakpoint.getCategory())) { - breakpointFactory = factory; - } - } - assert breakpointFactory != null : "can't find factory for breakpoint " + javaBreakpoint; - - final BreakpointPropertiesPanel propertiesPanel = breakpointFactory.createBreakpointPropertiesPanel(project, true); - assert propertiesPanel != null; - propertiesPanel.initFrom(javaBreakpoint, false); - - final JComponent mainPanel = propertiesPanel.getPanel(); - final JBPopupListener saveOnClose = new JBPopupListener.Adapter() { - @Override - public void onClosed(LightweightWindowEvent event) { - propertiesPanel.saveTo(javaBreakpoint); - propertiesPanel.dispose(); - DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().fireBreakpointChanged(javaBreakpoint); - } - }; - - final Runnable showMoreOptions = new Runnable() { - @Override - public void run() { - UIUtil.invokeLaterIfNeeded(new Runnable() { - @Override - public void run() { - BreakpointsDialogFactory.getInstance(project).showDialog(javaBreakpoint); - } - }); - } - }; - - final Balloon balloon = DebuggerUIUtil.showBreakpointEditor(project, mainPanel, whereToShow, component, showMoreOptions, breakpoint); - balloon.addListener(saveOnClose); - - propertiesPanel.setDelegate(new BreakpointPropertiesPanel.Delegate() { - @Override - public void showActionsPanel() { - propertiesPanel.setActionsPanelVisible(true); - balloon.hide(); - DebuggerUIUtil.showBreakpointEditor(project, mainPanel, whereToShow, component, showMoreOptions, breakpoint).addListener(saveOnClose); - } - }); - - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - IdeFocusManager.findInstance().requestFocus(mainPanel, true); - } - }); - } - - @Override - public boolean isEnabled(@NotNull Project project, AnActionEvent event) { - DataContext dataContext = event.getDataContext(); - Editor editor = CommonDataKeys.EDITOR.getData(dataContext); - if (editor == null) { - return false; - } - final Pair pair = XBreakpointUtil.findSelectedBreakpoint(project, editor); - return pair.first != null && pair.second instanceof BreakpointWithHighlighter; - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleBreakpointEnabledAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleBreakpointEnabledAction.java index fda3e6128a3e..693b7f4917a5 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleBreakpointEnabledAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleBreakpointEnabledAction.java @@ -22,7 +22,6 @@ import com.intellij.debugger.ui.breakpoints.BreakpointManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -41,7 +40,7 @@ public class ToggleBreakpointEnabledAction extends AnAction { Breakpoint breakpoint = findBreakpoint(project); if (breakpoint != null) { final BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager(); - breakpointManager.setBreakpointEnabled(breakpoint, !breakpoint.ENABLED); + breakpointManager.setBreakpointEnabled(breakpoint, !breakpoint.isEnabled()); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleFieldBreakpointAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleFieldBreakpointAction.java index 39a397755a5e..a7e00ee0dd72 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleFieldBreakpointAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleFieldBreakpointAction.java @@ -81,7 +81,7 @@ public class ToggleFieldBreakpointAction extends AnAction { long id = object.uniqueID(); InstanceFilter[] instanceFilters = new InstanceFilter[] { InstanceFilter.create(Long.toString(id))}; fieldBreakpoint.setInstanceFilters(instanceFilters); - fieldBreakpoint.INSTANCE_FILTERS_ENABLED = true; + fieldBreakpoint.setInstanceFiltersEnabled(true); } } } diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleLineBreakpointActionHandler.java b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleLineBreakpointActionHandler.java deleted file mode 100644 index 650e7c37cf70..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleLineBreakpointActionHandler.java +++ /dev/null @@ -1,163 +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.debugger.actions; - -import com.intellij.codeInsight.folding.impl.actions.ExpandRegionAction; -import com.intellij.debugger.DebuggerManagerEx; -import com.intellij.debugger.engine.DebuggerUtils; -import com.intellij.debugger.engine.requests.RequestManagerImpl; -import com.intellij.debugger.ui.breakpoints.Breakpoint; -import com.intellij.debugger.ui.breakpoints.BreakpointManager; -import com.intellij.debugger.ui.breakpoints.LineBreakpoint; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.FoldRegion; -import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.fileEditor.FileEditorManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.xdebugger.impl.actions.DebuggerActionHandler; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class ToggleLineBreakpointActionHandler extends DebuggerActionHandler { - - private final boolean myTemporary; - - public ToggleLineBreakpointActionHandler(boolean temporary) { - - myTemporary = temporary; - } - - public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) { - PlaceInDocument place = getPlace(project, event); - if (place != null) { - final Document document = place.getDocument(); - final int offset = place.getOffset(); - int line = document.getLineNumber(offset); - - VirtualFile file = FileDocumentManager.getInstance().getFile(document); - PsiFile psiFile = PsiManager.getInstance(project).findFile(file); - if (DebuggerUtils.supportsJVMDebugging(file.getFileType()) || DebuggerUtils.supportsJVMDebugging(psiFile)) { - final BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager(); - return breakpointManager.findBreakpoint(document, offset, LineBreakpoint.CATEGORY) != null || - LineBreakpoint.canAddLineBreakpoint(project, document, line); - } - } - - return false; - } - - public void perform(@NotNull final Project project, final AnActionEvent event) { - PlaceInDocument place = getPlace(project, event); - if(place == null) { - return; - } - - Editor editor = event.getData(CommonDataKeys.EDITOR); - ExpandRegionAction.expandRegionAtCaret(project, editor); - - Document document = place.getDocument(); - int line = document.getLineNumber(place.getOffset()); - if (editor != null && editor.getCaretModel().getVisualPosition().line != line) { - editor.getCaretModel().moveToOffset(place.getOffset()); - } - - DebuggerManagerEx debugManager = DebuggerManagerEx.getInstanceEx(project); - if (debugManager == null) { - return; - } - BreakpointManager manager = debugManager.getBreakpointManager(); - final Breakpoint breakpoint = manager.findBreakpoint(document, place.getOffset(), LineBreakpoint.CATEGORY); - if(breakpoint == null) { - LineBreakpoint lineBreakpoint = manager.addLineBreakpoint(document, line); - if(lineBreakpoint != null) { - lineBreakpoint.REMOVE_AFTER_HIT = myTemporary; - RequestManagerImpl.createRequests(lineBreakpoint); - } - } - else { - if (!breakpoint.REMOVE_AFTER_HIT && myTemporary) { - breakpoint.REMOVE_AFTER_HIT = true; - breakpoint.updateUI(); - } - else { - manager.removeBreakpoint(breakpoint); - } - } - } - - private static boolean containsOnlyDeclarations(int line, Document document, PsiFile file) { - int lineStart = document.getLineStartOffset(line); - int lineEnd = document.getLineEndOffset(line); - PsiElement start = file.findElementAt(lineStart); - PsiElement end = file.findElementAt(lineEnd - 1); - if (start == null || end == null) return false; - - PsiElement commonParent = PsiTreeUtil.findCommonParent(start, end); - for (PsiElement element : PsiTreeUtil.findChildrenOfAnyType(commonParent, PsiStatement.class, PsiExpression.class)) { - if (new TextRange(lineStart, lineEnd).contains(element.getTextRange().getStartOffset())) { - return false; - } - } - return true; - } - - @Nullable - private static PlaceInDocument getPlace(@NotNull final Project project, AnActionEvent event) { - Editor editor = event.getData(CommonDataKeys.EDITOR); - if(editor == null) { - editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); - } - if (editor == null) { - return null; - } - - final Document document = editor.getDocument(); - PsiDocumentManager.getInstance(project).commitDocument(document); - PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); - if (file == null) { - return null; - } - - // if several lines are merged into one visual line (using folding), try to find the most appropriate of those lines - int visualLine = editor.getCaretModel().getVisualPosition().getLine(); - int visibleOffset = editor.getCaretModel().getOffset(); - while (editor.offsetToVisualPosition(visibleOffset).line == visualLine) { - int line = document.getLineNumber(visibleOffset); - if (!containsOnlyDeclarations(line, document, file)) { - return new PlaceInDocument(document, visibleOffset); - } - int lineEndOffset = document.getLineEndOffset(line); - FoldRegion region = editor.getFoldingModel().getCollapsedRegionAtOffset(lineEndOffset); - if (region != null) { - int foldEnd = region.getEndOffset(); - if (foldEnd > lineEndOffset) { - visibleOffset = foldEnd; - continue; - } - } - visibleOffset = lineEndOffset + 1; - } - - return new PlaceInDocument(document, editor.getCaretModel().getOffset()); - } -} \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java index a5b1be2ba733..56e8cd383ee6 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java @@ -1409,7 +1409,7 @@ public abstract class DebugProcessImpl implements DebugProcess { hint.setIgnoreFilters(myForcedIgnoreFilters || mySession.shouldIgnoreSteppingFilters()); applyThreadFilter(stepThread); if (myBreakpoint != null) { - myBreakpoint.SUSPEND_POLICY = suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD? DebuggerSettings.SUSPEND_THREAD : DebuggerSettings.SUSPEND_ALL; + myBreakpoint.setSuspendPolicy(suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD? DebuggerSettings.SUSPEND_THREAD : DebuggerSettings.SUSPEND_ALL); myBreakpoint.createRequest(suspendContext.getDebugProcess()); myRunToCursorBreakpoint = myBreakpoint; } @@ -1476,8 +1476,8 @@ public abstract class DebugProcessImpl implements DebugProcess { } applyThreadFilter(getContextThread()); final SuspendContextImpl context = getSuspendContext(); - myRunToCursorBreakpoint.SUSPEND_POLICY = context.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD? DebuggerSettings.SUSPEND_THREAD : DebuggerSettings.SUSPEND_ALL; - myRunToCursorBreakpoint.LOG_ENABLED = false; + myRunToCursorBreakpoint.setSuspendPolicy(context.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD? DebuggerSettings.SUSPEND_THREAD : DebuggerSettings.SUSPEND_ALL); + myRunToCursorBreakpoint.setLogEnabled(false); myRunToCursorBreakpoint.createRequest(context.getDebugProcess()); DebugProcessImpl.this.myRunToCursorBreakpoint = myRunToCursorBreakpoint; super.contextAction(); diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java index 832958759964..c35c971c5a76 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java @@ -30,9 +30,7 @@ import com.intellij.debugger.settings.DebuggerSettings; import com.intellij.debugger.ui.breakpoints.Breakpoint; import com.intellij.debugger.ui.breakpoints.BreakpointManager; import com.intellij.debugger.ui.breakpoints.FilteredRequestor; -import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; @@ -40,15 +38,10 @@ import com.intellij.openapi.util.Key; import com.intellij.psi.PsiClass; import com.intellij.ui.classFilter.ClassFilter; import com.intellij.util.containers.HashMap; -import com.intellij.xdebugger.XDebuggerManager; -import com.intellij.xdebugger.breakpoints.XBreakpointProperties; -import com.intellij.xdebugger.breakpoints.XLineBreakpoint; import com.sun.jdi.*; import com.sun.jdi.event.ClassPrepareEvent; import com.sun.jdi.request.*; import org.jetbrains.annotations.Nullable; -import org.jetbrains.java.debugger.breakpoints.JavaBreakpointAdapter; -import org.jetbrains.java.debugger.breakpoints.JavaBreakpointType; import java.util.Collections; import java.util.HashSet; @@ -158,11 +151,11 @@ public class RequestManagerImpl extends DebugProcessAdapterImpl implements Reque request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); } - if (requestor.COUNT_FILTER_ENABLED && requestor.COUNT_FILTER > 0) { - request.addCountFilter(requestor.COUNT_FILTER); + if (requestor.isCountFilterEnabled() && requestor.getCountFilter() > 0) { + request.addCountFilter(requestor.getCountFilter()); } - if (requestor.CLASS_FILTERS_ENABLED && !(request instanceof BreakpointRequest) /*no built-in class filters support for breakpoint requests*/ ) { + if (requestor.isClassFiltersEnabled() && !(request instanceof BreakpointRequest) /*no built-in class filters support for breakpoint requests*/ ) { ClassFilter[] classFilters = requestor.getClassFilters(); if (DebuggerUtilsEx.getEnabledNumber(classFilters) == 1) { for (final ClassFilter filter : classFilters) { @@ -408,17 +401,18 @@ public class RequestManagerImpl extends DebugProcessAdapterImpl implements Reque breakpoint.createRequest(myDebugProcess); } - AccessToken token = ReadAction.start(); - try { - JavaBreakpointAdapter adapter = new JavaBreakpointAdapter(project); - for (XLineBreakpoint breakpoint : XDebuggerManager.getInstance(project).getBreakpointManager() - .getBreakpoints(JavaBreakpointType.class)) { - adapter.getOrCreate(breakpoint).createRequest(myDebugProcess); - } - } - finally { - token.finish(); - } + //AccessToken token = ReadAction.start(); + //try { + // JavaBreakpointAdapter adapter = new JavaBreakpointAdapter(project); + // for (XLineBreakpoint breakpoint : XDebuggerManager.getInstance(project).getBreakpointManager() + // .getBreakpoints(JavaLineBreakpointType.class)) { + // //new JavaLineBreakpointRequestor(breakpoint).createRequest(myDebugProcess); + // //adapter.getOrCreate(breakpoint).createRequest(myDebugProcess); + // } + //} + //finally { + // token.finish(); + //} } }); } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java index c60a3b220906..1416dd3b05c3 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java @@ -180,17 +180,17 @@ public class DebuggerManagerImpl extends DebuggerManagerEx implements Persistent @Override public Element getState() { Element state = new Element("state"); - myBreakpointManager.writeExternal(state); + //myBreakpointManager.writeExternal(state); return state; } @Override public void loadState(Element state) { - myBreakpointManager.readExternal(state); + //myBreakpointManager.readExternal(state); } public void writeExternal(Element element) throws WriteExternalException { - myBreakpointManager.writeExternal(element); + //myBreakpointManager.writeExternal(element); } public DebuggerSession attachVirtualMachine(Executor executor, diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/JavaDebuggerSupport.java b/java/debugger/impl/src/com/intellij/debugger/ui/JavaDebuggerSupport.java index e021d76b271b..af5202ccd260 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/JavaDebuggerSupport.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/JavaDebuggerSupport.java @@ -19,19 +19,17 @@ import com.intellij.debugger.DebuggerManagerEx; import com.intellij.debugger.actions.*; import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.settings.*; -import com.intellij.debugger.ui.breakpoints.*; +import com.intellij.debugger.ui.breakpoints.Breakpoint; import com.intellij.ide.DataManager; import com.intellij.openapi.Disposable; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.markup.GutterIconRenderer; -import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.Key; -import com.intellij.util.containers.ContainerUtil; import com.intellij.xdebugger.AbstractDebuggerSession; import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule; import com.intellij.xdebugger.impl.DebuggerSupport; @@ -45,9 +43,10 @@ import com.intellij.xdebugger.impl.evaluate.quick.common.QuickEvaluateHandler; import com.intellij.xdebugger.impl.settings.DebuggerSettingsPanelProvider; import org.jetbrains.annotations.NotNull; +import javax.swing.*; +import java.awt.*; import java.util.ArrayList; import java.util.Collection; -import java.util.List; /** * @author nik @@ -63,8 +62,6 @@ public class JavaDebuggerSupport extends DebuggerSupport { private final ForceRunToCursorActionHandler myForceRunToCursorActionHandler = new ForceRunToCursorActionHandler(); private final ResumeActionHandler myResumeActionHandler = new ResumeActionHandler(); private final PauseActionHandler myPauseActionHandler = new PauseActionHandler(); - private final ToggleLineBreakpointActionHandler myToggleLineBreakpointActionHandler = new ToggleLineBreakpointActionHandler(false); - private final ToggleLineBreakpointActionHandler myToggleTemporaryLineBreakpointActionHandler = new ToggleLineBreakpointActionHandler(true); private final ShowExecutionPointActionHandler myShowExecutionPointActionHandler = new ShowExecutionPointActionHandler(); private final EvaluateActionHandler myEvaluateActionHandler = new EvaluateActionHandler(); private final QuickEvaluateActionHandler myQuickEvaluateHandler = new QuickEvaluateActionHandler(); @@ -73,7 +70,6 @@ public class JavaDebuggerSupport extends DebuggerSupport { private final DebuggerActionHandler mySmartStepIntoHandler = new JvmSmartStepIntoActionHandler(); private final DebuggerActionHandler myAddToWatchedActionHandler = new AddToWatchActionHandler(); private final JavaMarkObjectActionHandler myMarkObjectActionHandler = new JavaMarkObjectActionHandler(); - private final JavaEditBreakpointActionHandler myEditBreakpointActionHandler = new JavaEditBreakpointActionHandler(); @NotNull public BreakpointPanelProvider getBreakpointPanelProvider() { @@ -132,13 +128,13 @@ public class JavaDebuggerSupport extends DebuggerSupport { @NotNull public DebuggerActionHandler getToggleLineBreakpointHandler() { - return myToggleLineBreakpointActionHandler; + return DISABLED; } @NotNull @Override public DebuggerActionHandler getToggleTemporaryLineBreakpointHandler() { - return myToggleTemporaryLineBreakpointActionHandler; + return DISABLED; } @NotNull @@ -182,7 +178,7 @@ public class JavaDebuggerSupport extends DebuggerSupport { @NotNull @Override public EditBreakpointActionHandler getEditBreakpointAction() { - return myEditBreakpointActionHandler; + return DISABLED_EDIT; } @NotNull @@ -191,122 +187,124 @@ public class JavaDebuggerSupport extends DebuggerSupport { } private static class JavaBreakpointPanelProvider extends BreakpointPanelProvider { - private final List myListeners = ContainerUtil.createLockFreeCopyOnWriteList(); + //private final List myListeners = ContainerUtil.createLockFreeCopyOnWriteList(); @Override public AnAction[] getAddBreakpointActions(@NotNull Project project) { - List result = new ArrayList(); - BreakpointFactory[] breakpointFactories = BreakpointFactory.getBreakpointFactories(); - for (BreakpointFactory breakpointFactory : breakpointFactories) { - result.add(new AddJavaBreakpointAction(breakpointFactory)); - } - return result.toArray(new AnAction[result.size()]); + //List result = new ArrayList(); + //BreakpointFactory[] breakpointFactories = BreakpointFactory.getBreakpointFactories(); + //for (BreakpointFactory breakpointFactory : breakpointFactories) { + // result.add(new AddJavaBreakpointAction(breakpointFactory)); + //} + //return result.toArray(new AnAction[result.size()]); + return AnAction.EMPTY_ARRAY; } @Override public void createBreakpointsGroupingRules(Collection rules) { - rules.add(new XBreakpointGroupingByCategoryRule()); + //rules.add(new XBreakpointGroupingByCategoryRule()); rules.add(new XBreakpointGroupingByPackageRule()); rules.add(new XBreakpointGroupingByClassRule()); } @Override public void addListener(final BreakpointsListener listener, Project project, Disposable disposable) { - BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager(); - final MyBreakpointManagerListener listener1 = new MyBreakpointManagerListener(listener, breakpointManager); - breakpointManager.addBreakpointManagerListener(listener1); - myListeners.add(listener1); - Disposer.register(disposable, new Disposable() { - @Override - public void dispose() { - removeListener(listener); - } - }); + //BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager(); + //final MyBreakpointManagerListener listener1 = new MyBreakpointManagerListener(listener, breakpointManager); + //breakpointManager.addBreakpointManagerListener(listener1); + //myListeners.add(listener1); + //Disposer.register(disposable, new Disposable() { + // @Override + // public void dispose() { + // removeListener(listener); + // } + //}); } @Override protected void removeListener(BreakpointsListener listener) { - for (MyBreakpointManagerListener managerListener : myListeners) { - if (managerListener.myListener == listener) { - BreakpointManager manager = managerListener.myBreakpointManager; - manager.removeBreakpointManagerListener(managerListener); - myListeners.remove(managerListener); - break; - } - } + //for (MyBreakpointManagerListener managerListener : myListeners) { + // if (managerListener.myListener == listener) { + // BreakpointManager manager = managerListener.myBreakpointManager; + // manager.removeBreakpointManagerListener(managerListener); + // myListeners.remove(managerListener); + // break; + // } + //} } public int getPriority() { - return 1; + return 100; } public Breakpoint findBreakpoint(@NotNull final Project project, @NotNull final Document document, final int offset) { - return DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().findBreakpoint(document, offset, null); + return null; + //return DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().findBreakpoint(document, offset, null); } @Override public GutterIconRenderer getBreakpointGutterIconRenderer(Object breakpoint) { - if (breakpoint instanceof BreakpointWithHighlighter) { - final RangeHighlighter highlighter = ((BreakpointWithHighlighter)breakpoint).getHighlighter(); - if (highlighter != null) { - return (GutterIconRenderer)highlighter.getGutterIconRenderer(); - } - } + //if (breakpoint instanceof BreakpointWithHighlighter) { + // final RangeHighlighter highlighter = ((BreakpointWithHighlighter)breakpoint).getHighlighter(); + // if (highlighter != null) { + // return (GutterIconRenderer)highlighter.getGutterIconRenderer(); + // } + //} return null; } public void onDialogClosed(final Project project) { - DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().updateAllRequests(); + //DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().updateAllRequests(); } @Override public void provideBreakpointItems(Project project, Collection items) { - for (BreakpointFactory breakpointFactory : BreakpointFactory.getBreakpointFactories()) { - Key category = breakpointFactory.getBreakpointCategory(); - Breakpoint[] breakpoints = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().getBreakpoints(category); - for (Breakpoint breakpoint : breakpoints) { - items.add(breakpointFactory.createBreakpointItem(breakpoint)); - } - } + //for (BreakpointFactory breakpointFactory : BreakpointFactory.getBreakpointFactories()) { + // Key category = breakpointFactory.getBreakpointCategory(); + // Breakpoint[] breakpoints = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().getBreakpoints(category); + // for (Breakpoint breakpoint : breakpoints) { + // items.add(breakpointFactory.createBreakpointItem(breakpoint)); + // } + //} } - private static class AddJavaBreakpointAction extends AnAction { - private BreakpointFactory myBreakpointFactory; + //private static class AddJavaBreakpointAction extends AnAction { + // private BreakpointFactory myBreakpointFactory; + // + // public AddJavaBreakpointAction(BreakpointFactory breakpointFactory) { + // myBreakpointFactory = breakpointFactory; + // Presentation p = getTemplatePresentation(); + // p.setIcon(myBreakpointFactory.getIcon()); + // p.setText(breakpointFactory.getDisplayName()); + // } + // + // @Override + // public void update(AnActionEvent e) { + // e.getPresentation().setVisible(myBreakpointFactory.canAddBreakpoints()); + // } + // + // @Override + // public void actionPerformed(AnActionEvent e) { + // myBreakpointFactory.addBreakpoint(getEventProject(e)); + // } + //} - public AddJavaBreakpointAction(BreakpointFactory breakpointFactory) { - myBreakpointFactory = breakpointFactory; - Presentation p = getTemplatePresentation(); - p.setIcon(myBreakpointFactory.getIcon()); - p.setText(breakpointFactory.getDisplayName()); - } - - @Override - public void update(AnActionEvent e) { - e.getPresentation().setVisible(myBreakpointFactory.canAddBreakpoints()); - } - - @Override - public void actionPerformed(AnActionEvent e) { - myBreakpointFactory.addBreakpoint(getEventProject(e)); - } - } - - private static class MyBreakpointManagerListener implements BreakpointManagerListener { - - private final BreakpointsListener myListener; - public BreakpointManager myBreakpointManager; - - - public MyBreakpointManagerListener(BreakpointsListener listener, BreakpointManager breakpointManager) { - myListener = listener; - myBreakpointManager = breakpointManager; - } - - @Override - public void breakpointsChanged() { - myListener.breakpointsChanged(); - } - } + //private static class MyBreakpointManagerListener implements BreakpointManagerListener { + // + // private final BreakpointsListener myListener; + // public BreakpointManager myBreakpointManager; + // + // + // public MyBreakpointManagerListener(BreakpointsListener listener, BreakpointManager breakpointManager) { + // myListener = listener; + // myBreakpointManager = breakpointManager; + // } + // + // @Override + // public void breakpointsChanged() { + // myListener.breakpointsChanged(); + // } + //} } public static class JavaDebuggerSettingsPanelProvider extends DebuggerSettingsPanelProvider { @@ -341,4 +339,27 @@ public class JavaDebuggerSupport extends DebuggerSupport { } return ProjectManager.getInstance().getDefaultProject(); } + + private static final DebuggerActionHandler DISABLED = new DebuggerActionHandler() { + @Override + public void perform(@NotNull Project project, AnActionEvent event) { + } + + @Override + public boolean isEnabled(@NotNull Project project, AnActionEvent event) { + return false; + } + }; + + private static final EditBreakpointActionHandler DISABLED_EDIT = new EditBreakpointActionHandler() { + @Override + protected void doShowPopup(Project project, JComponent component, Point whereToShow, Object breakpoint) { + + } + + @Override + public boolean isEnabled(@NotNull Project project, AnActionEvent event) { + return false; + } + }; } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/PositionHighlighter.java b/java/debugger/impl/src/com/intellij/debugger/ui/PositionHighlighter.java index e5bb8faafb61..dd0b0de43151 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/PositionHighlighter.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/PositionHighlighter.java @@ -437,7 +437,7 @@ public class PositionHighlighter { public void actionPerformed(AnActionEvent e) { if (myEventsOutOfLine.size() == 1) { Breakpoint breakpoint = myEventsOutOfLine.get(0).getFirst(); - breakpoint.ENABLED = !breakpoint.ENABLED; + breakpoint.setEnabled(!breakpoint.isEnabled()); DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().fireBreakpointChanged(breakpoint); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointCategoryGroup.java b/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointCategoryGroup.java deleted file mode 100644 index 032b480c5584..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointCategoryGroup.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.debugger.ui; - -import com.intellij.debugger.ui.breakpoints.Breakpoint; -import com.intellij.debugger.ui.breakpoints.BreakpointFactory; -import com.intellij.openapi.util.Key; -import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroup; -import com.intellij.xdebugger.impl.breakpoints.ui.grouping.XBreakpointTypeGroup; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; - -/** - * Created with IntelliJ IDEA. - * User: zajac - * Date: 23.05.12 - * Time: 16:22 - * To change this template use File | Settings | File Templates. - */ -public class XBreakpointCategoryGroup extends XBreakpointGroup { - private Key myCategory; - private Icon myIcon; - private final String myName; - - public XBreakpointCategoryGroup(BreakpointFactory factory) { - myCategory = factory.getBreakpointCategory(); - myIcon = factory.getIcon(); - final String name = factory.getDisplayName(); - myName = name != null ? name : "UNKNOWN"; - } - - public Key getCategory() { - return myCategory; - } - - @Override - public Icon getIcon(boolean isOpen) { - return myIcon; - } - - @NotNull - @Override - public String getName() { - return myName; - } - - @Override - public int compareTo(XBreakpointGroup o) { - if (o instanceof XBreakpointTypeGroup) { - return -1; - } - if (o instanceof XBreakpointCategoryGroup) { - return getFactoryIndex() - ((XBreakpointCategoryGroup)o).getFactoryIndex(); - } - return super.compareTo(o); - } - - private int getFactoryIndex() { - BreakpointFactory[] breakpointFactories = BreakpointFactory.getBreakpointFactories(); - for (int i = 0; i < breakpointFactories.length; ++i) { - if (breakpointFactories[i].getBreakpointCategory().equals(myCategory)) { - return i; - } - } - return -1; - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByCategoryRule.java b/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByCategoryRule.java deleted file mode 100644 index f9dc88af07ac..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByCategoryRule.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.debugger.ui; - -import com.intellij.debugger.ui.breakpoints.AnyExceptionBreakpoint; -import com.intellij.debugger.ui.breakpoints.Breakpoint; -import com.intellij.debugger.ui.breakpoints.BreakpointFactory; -import com.intellij.debugger.ui.breakpoints.ExceptionBreakpoint; -import com.intellij.openapi.util.Key; -import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule; -import com.intellij.xdebugger.breakpoints.ui.XBreakpointsGroupingPriorities; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; - -class XBreakpointGroupingByCategoryRule extends XBreakpointGroupingRule { - XBreakpointGroupingByCategoryRule() { - super("XBreakpointGroupingByCategoryRule", "Type"); - } - - @Override - public boolean isAlwaysEnabled() { - return true; - } - - @Override - public int getPriority() { - return XBreakpointsGroupingPriorities.BY_TYPE; - } - - @Override - public XBreakpointCategoryGroup getGroup(@NotNull B b, @NotNull Collection groups) { - if (b instanceof Breakpoint) { - final Breakpoint breakpoint = (Breakpoint)b; - Key category = breakpoint.getCategory(); - if (category.equals(AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT)) { - category = ExceptionBreakpoint.CATEGORY; - } - for (XBreakpointCategoryGroup group : groups) { - if (group.getCategory().equals(category)) { - return group; - } - } - final BreakpointFactory factory = BreakpointFactory.getInstance(category); - if (factory != null) { - return new XBreakpointCategoryGroup(factory); - } - } - return null; - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AddFieldBreakpointDialog.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AddFieldBreakpointDialog.java index f325da10fcde..e3cd5229e0ab 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AddFieldBreakpointDialog.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AddFieldBreakpointDialog.java @@ -41,7 +41,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; -abstract class AddFieldBreakpointDialog extends DialogWrapper { +public abstract class AddFieldBreakpointDialog extends DialogWrapper { private final Project myProject; private JPanel myPanel; private TextFieldWithBrowseButton myFieldChooser; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AddWildcardBreakpointDialog.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AddWildcardBreakpointDialog.java index c18acb715935..73c74a4eed0a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AddWildcardBreakpointDialog.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AddWildcardBreakpointDialog.java @@ -30,7 +30,7 @@ public class AddWildcardBreakpointDialog extends DialogWrapper { private JTextField myClassPatternField; private JTextField myMethodNameField; - protected AddWildcardBreakpointDialog(Project project) { + public AddWildcardBreakpointDialog(Project project) { super(project, true); setTitle("Add Method Breakpoint"); init(); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpoint.java index 3d1ff8507d10..25864de5d3af 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpoint.java @@ -27,6 +27,7 @@ import com.intellij.debugger.engine.DebuggerManagerThreadImpl; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.Key; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.sun.jdi.ReferenceType; import org.jdom.Element; import org.jetbrains.annotations.NonNls; @@ -34,9 +35,9 @@ import org.jetbrains.annotations.NonNls; public class AnyExceptionBreakpoint extends ExceptionBreakpoint { public static final @NonNls Key ANY_EXCEPTION_BREAKPOINT = BreakpointCategory.lookup("breakpoint_any"); - protected AnyExceptionBreakpoint(Project project) { - super(project, null, null); - ENABLED = false; + protected AnyExceptionBreakpoint(Project project, XBreakpoint xBreakpoint) { + super(project, null, null, xBreakpoint); + //setEnabled(false); } public Key getCategory() { @@ -49,7 +50,7 @@ public class AnyExceptionBreakpoint extends ExceptionBreakpoint { public void createRequest(DebugProcessImpl debugProcess) { DebuggerManagerThreadImpl.assertIsManagerThread(); - if (!ENABLED || !debugProcess.isAttached() || debugProcess.areBreakpointsMuted() || !debugProcess.getRequestsManager().findRequests(this).isEmpty()) { + if (!isEnabled() || !debugProcess.isAttached() || debugProcess.areBreakpointsMuted() || !debugProcess.getRequestsManager().findRequests(this).isEmpty()) { return; } super.processClassPrepare(debugProcess, null); @@ -59,13 +60,13 @@ public class AnyExceptionBreakpoint extends ExceptionBreakpoint { // should be emty - does not make sense for this breakpoint } - public void readExternal(Element parentNode) throws InvalidDataException { - try { - super.readExternal(parentNode); - } - catch (InvalidDataException e) { - if(!READ_NO_CLASS_NAME.equals(e.getMessage())) throw e; - } - } + //public void readExternal(Element parentNode) throws InvalidDataException { + // try { + // super.readExternal(parentNode); + // } + // catch (InvalidDataException e) { + // if(!READ_NO_CLASS_NAME.equals(e.getMessage())) throw e; + // } + //} } \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpointFactory.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpointFactory.java deleted file mode 100644 index f595c1d81c65..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpointFactory.java +++ /dev/null @@ -1,65 +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.debugger.ui.breakpoints; - -import com.intellij.icons.AllIcons; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; -import org.jdom.Element; - -import javax.swing.*; - -/** - * @author Eugene Zhuravlev - * Date: Apr 26, 2005 - */ -public class AnyExceptionBreakpointFactory extends BreakpointFactory{ - public Breakpoint createBreakpoint(Project project, final Element element) { - return new AnyExceptionBreakpoint(project); - } - - public Icon getIcon() { - return AllIcons.Debugger.Db_exception_breakpoint; - } - - public Icon getDisabledIcon() { - return AllIcons.Debugger.Db_disabled_exception_breakpoint; - } - - @Override - protected String getHelpID() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public String getDisplayName() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public BreakpointPropertiesPanel createBreakpointPropertiesPanel(Project project, boolean compact) { - return new ExceptionBreakpointPropertiesPanel(project, compact); - } - - @Override - public boolean breakpointCanBeRemoved(Breakpoint breakpoint) { - return false; - } - - public Key getBreakpointCategory() { - return AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT; - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index 1b370ca47ded..8ea3fea6923d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -30,45 +30,58 @@ import com.intellij.debugger.engine.requests.RequestManagerImpl; import com.intellij.debugger.jdi.StackFrameProxyImpl; import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; import com.intellij.debugger.requests.ClassPrepareRequestor; +import com.intellij.debugger.settings.DebuggerSettings; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.JDOMExternalizerUtil; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; import com.intellij.ui.AppUIUtil; +import com.intellij.ui.classFilter.ClassFilter; import com.intellij.util.StringBuilderSpinAllocator; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.ReferenceType; -import com.sun.jdi.Value; -import com.sun.jdi.VoidValue; +import com.intellij.xdebugger.breakpoints.SuspendPolicy; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; +import com.sun.jdi.*; import com.sun.jdi.event.LocatableEvent; -import org.jdom.Element; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; import javax.swing.*; import java.util.List; -public abstract class Breakpoint extends FilteredRequestor implements ClassPrepareRequestor { - public boolean ENABLED = true; - public boolean LOG_ENABLED = false; - public boolean LOG_EXPRESSION_ENABLED = false; - public boolean REMOVE_AFTER_HIT = false; - private TextWithImports myLogMessage; // an expression to be evaluated and printed - @NonNls private static final String LOG_MESSAGE_OPTION_NAME = "LOG_MESSAGE"; +public abstract class Breakpoint

    implements FilteredRequestor, ClassPrepareRequestor { + final XBreakpoint

    myXBreakpoint; + protected final Project myProject; + + //private boolean ENABLED = true; + //private boolean LOG_ENABLED = false; + //private boolean LOG_EXPRESSION_ENABLED = false; + //private boolean REMOVE_AFTER_HIT = false; + //private TextWithImports myLogMessage; // an expression to be evaluated and printed + //@NonNls private static final String LOG_MESSAGE_OPTION_NAME = "LOG_MESSAGE"; public static final Breakpoint[] EMPTY_ARRAY = new Breakpoint[0]; protected boolean myCachedVerifiedState = false; + //private TextWithImportsImpl myLogMessage; - protected Breakpoint(@NotNull Project project) { - super(project); - myLogMessage = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, ""); + protected Breakpoint(@NotNull Project project, XBreakpoint

    xBreakpoint) { + //super(project); + myProject = project; + myXBreakpoint = xBreakpoint; + //myLogMessage = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, ""); //noinspection AbstractMethodCallInConstructor - final BreakpointDefaults defaults = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().getBreakpointDefaults(getCategory()); - SUSPEND_POLICY = defaults.getSuspendPolicy(); - CONDITION_ENABLED = defaults.isConditionEnabled(); + //final BreakpointDefaults defaults = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().getBreakpointDefaults(getCategory()); + //SUSPEND_POLICY = defaults.getSuspendPolicy(); + //CONDITION_ENABLED = defaults.isConditionEnabled(); + } + + public Project getProject() { + return myProject; + } + + protected P getProperties() { + return myXBreakpoint.getProperties(); } public abstract PsiClass getPsiClass(); @@ -100,6 +113,16 @@ public abstract class Breakpoint extends FilteredRequestor implements ClassPrepa myCachedVerifiedState = isVerified; } + public boolean isRemoveAfterHit() { + return myXBreakpoint instanceof XLineBreakpoint && ((XLineBreakpoint)myXBreakpoint).isTemporary(); + } + + public void setRemoveAfterHit(boolean value) { + if (myXBreakpoint instanceof XLineBreakpoint) { + ((XLineBreakpoint)myXBreakpoint).setTemporary(value); + } + } + @Nullable public String getShortClassName() { final String className = getClassName(); @@ -210,15 +233,15 @@ public abstract class Breakpoint extends FilteredRequestor implements ClassPrepa private void runAction(final EvaluationContextImpl context, LocatableEvent event) { final DebugProcessImpl debugProcess = context.getDebugProcess(); - if (LOG_ENABLED || LOG_EXPRESSION_ENABLED) { + if (myXBreakpoint.isLogMessage() || myXBreakpoint.getLogExpression() != null) { final StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { - if (LOG_ENABLED) { + if (myXBreakpoint.isLogMessage()) { buf.append(getEventMessage(event)); buf.append("\n"); } final TextWithImports expressionToEvaluate = getLogMessage(); - if (LOG_EXPRESSION_ENABLED && expressionToEvaluate != null && !"".equals(expressionToEvaluate.getText())) { + if (myXBreakpoint.getLogExpression() != null && !expressionToEvaluate.getText().isEmpty()) { if(!debugProcess.isAttached()) { return; } @@ -252,11 +275,112 @@ public abstract class Breakpoint extends FilteredRequestor implements ClassPrepa StringBuilderSpinAllocator.dispose(buf); } } - if (REMOVE_AFTER_HIT) { + if (isRemoveAfterHit()) { handleTemporaryBreakpointHit(debugProcess); } } + /** + * @return true if the ID was added or false otherwise + */ + private boolean hasObjectID(long id) { + for (InstanceFilter instanceFilter : getInstanceFilters()) { + if (instanceFilter.getId() == id) { + return true; + } + } + return false; + } + + public boolean evaluateCondition(final EvaluationContextImpl context, LocatableEvent event) throws EvaluateException { + if(isCountFilterEnabled()) { + final DebugProcessImpl debugProcess = context.getDebugProcess(); + debugProcess.getVirtualMachineProxy().suspend(); + debugProcess.getRequestsManager().deleteRequest(this); + ((Breakpoint)this).createRequest(debugProcess); + debugProcess.getVirtualMachineProxy().resume(); + } + if (isInstanceFiltersEnabled()) { + Value value = context.getThisObject(); + if (value != null) { // non-static + ObjectReference reference = (ObjectReference)value; + if(!hasObjectID(reference.uniqueID())) { + return false; + } + } + } + + if (isClassFiltersEnabled()) { + String typeName = calculateEventClass(context, event); + if (!typeMatchesClassFilters(typeName)) return false; + } + + if (isConditionEnabled() && !getCondition().getText().isEmpty()) { + try { + ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(context.getProject(), new EvaluatingComputable() { + public ExpressionEvaluator compute() throws EvaluateException { + final SourcePosition contextSourcePosition = ContextUtil.getSourcePosition(context); + // IMPORTANT: calculate context psi element basing on the location where the exception + // has been hit, not on the location where it was set. (For line breakpoints these locations are the same, however, + // for method, exception and field breakpoints these locations differ) + PsiElement contextPsiElement = ContextUtil.getContextElement(contextSourcePosition); + if (contextPsiElement == null) { + contextPsiElement = getEvaluationElement(); // as a last resort + } + return EvaluatorBuilderImpl.build(getCondition(), contextPsiElement, contextSourcePosition); + } + }); + final Value value = evaluator.evaluate(context); + if (!(value instanceof BooleanValue)) { + throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.boolean.expected")); + } + if(!((BooleanValue)value).booleanValue()) { + return false; + } + } + catch (EvaluateException ex) { + if(ex.getCause() instanceof VMDisconnectedException) { + return false; + } + throw EvaluateExceptionUtil.createEvaluateException( + DebuggerBundle.message("error.failed.evaluating.breakpoint.condition", getCondition(), ex.getMessage()) + ); + } + return true; + } + + return true; + } + + protected String calculateEventClass(EvaluationContextImpl context, LocatableEvent event) throws EvaluateException { + return event.location().declaringType().name(); + } + + private boolean typeMatchesClassFilters(@Nullable String typeName) { + if (typeName == null) { + return true; + } + boolean matches = false, hasEnabled = false; + for (ClassFilter classFilter : getClassFilters()) { + if (classFilter.isEnabled()) { + hasEnabled = true; + if (classFilter.matches(typeName)) { + matches = true; + break; + } + } + } + if(hasEnabled && !matches) { + return false; + } + for (ClassFilter classFilter : getClassExclusionFilters()) { + if (classFilter.isEnabled() && classFilter.matches(typeName)) { + return false; + } + } + return true; + } + private void handleTemporaryBreakpointHit(final DebugProcessImpl debugProcess) { debugProcess.addDebugProcessListener(new DebugProcessAdapter() { @Override @@ -288,26 +412,172 @@ public abstract class Breakpoint extends FilteredRequestor implements ClassPrepa RequestManagerImpl.deleteRequests(this); } + //@Override + //public void readExternal(Element parentNode) throws InvalidDataException { + //super.readExternal(parentNode); + //String logMessage = JDOMExternalizerUtil.readField(parentNode, LOG_MESSAGE_OPTION_NAME); + //if (logMessage != null) { + // setLogMessage(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, logMessage)); + //} + //} + + //@Override + //public void writeExternal(Element parentNode) throws WriteExternalException { + //super.writeExternal(parentNode); + //JDOMExternalizerUtil.writeField(parentNode, LOG_MESSAGE_OPTION_NAME, getLogMessage().toExternalForm()); + //} + + //public void setLogMessage(TextWithImports logMessage) { + // myLogMessage = logMessage; + //} + + public abstract PsiElement getEvaluationElement(); + + protected TextWithImports getLogMessage() { + return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, myXBreakpoint.getLogExpression()); + } + + protected TextWithImports getCondition() { + return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, myXBreakpoint.getCondition()); + } + + public boolean isEnabled() { + return myXBreakpoint.isEnabled(); + } + + public void setEnabled(boolean enabled) { + myXBreakpoint.setEnabled(enabled); + } + + public boolean isLogEnabled() { + return myXBreakpoint.isLogMessage(); + } + + public void setLogEnabled(boolean logEnabled) { + myXBreakpoint.setLogMessage(logEnabled); + } + + public boolean isLogExpressionEnabled() { + return myXBreakpoint.getLogExpression() != null; + } + + public void setLogExpressionEnabled(boolean LOG_EXPRESSION_ENABLED) { + } + @Override - public void readExternal(Element parentNode) throws InvalidDataException { - super.readExternal(parentNode); - String logMessage = JDOMExternalizerUtil.readField(parentNode, LOG_MESSAGE_OPTION_NAME); - if (logMessage != null) { - setLogMessage(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, logMessage)); + public boolean isCountFilterEnabled() { + return myXBreakpoint.getProperties().COUNT_FILTER_ENABLED; + } + public void setCountFilterEnabled(boolean enabled) { + myXBreakpoint.getProperties().COUNT_FILTER_ENABLED = enabled; + } + + @Override + public int getCountFilter() { + return myXBreakpoint.getProperties().COUNT_FILTER; + } + + public void setCountFilter(int filter) { + myXBreakpoint.getProperties().COUNT_FILTER = filter; + } + + @Override + public boolean isClassFiltersEnabled() { + return myXBreakpoint.getProperties().CLASS_FILTERS_ENABLED; + } + + public void setClassFiltersEnabled(boolean enabled) { + myXBreakpoint.getProperties().CLASS_FILTERS_ENABLED = enabled; + } + + @Override + public ClassFilter[] getClassFilters() { + return myXBreakpoint.getProperties().getClassFilters(); + } + + public void setClassFilters(ClassFilter[] filters) { + myXBreakpoint.getProperties().setClassFilters(filters); + } + + @Override + public ClassFilter[] getClassExclusionFilters() { + return myXBreakpoint.getProperties().getClassExclusionFilters(); + } + + public void setClassExclusionFilters(ClassFilter[] filters) { + myXBreakpoint.getProperties().setClassExclusionFilters(filters); + } + + @Override + public boolean isInstanceFiltersEnabled() { + return myXBreakpoint.getProperties().INSTANCE_FILTERS_ENABLED; + } + + public void setInstanceFiltersEnabled(boolean enabled) { + myXBreakpoint.getProperties().INSTANCE_FILTERS_ENABLED = enabled; + } + + @Override + public InstanceFilter[] getInstanceFilters() { + return myXBreakpoint.getProperties().getInstanceFilters(); + } + + public void setInstanceFilters(InstanceFilter[] filters) { + myXBreakpoint.getProperties().setInstanceFilters(filters); + } + + public static String getSuspendPolicy(XBreakpoint breakpoint) { + switch (breakpoint.getSuspendPolicy()) { + case ALL: + return DebuggerSettings.SUSPEND_ALL; + case THREAD: + return DebuggerSettings.SUSPEND_THREAD; + case NONE: + return DebuggerSettings.SUSPEND_NONE; + + default: + throw new IllegalArgumentException("unknown suspend policy"); } } - @Override - public void writeExternal(Element parentNode) throws WriteExternalException { - super.writeExternal(parentNode); - JDOMExternalizerUtil.writeField(parentNode, LOG_MESSAGE_OPTION_NAME, getLogMessage().toExternalForm()); + public static SuspendPolicy transformSuspendPolicy(String policy) { + if (DebuggerSettings.SUSPEND_ALL.equals(policy)) { + return SuspendPolicy.ALL; + } else if (DebuggerSettings.SUSPEND_THREAD.equals(policy)) { + return SuspendPolicy.THREAD; + } else if (DebuggerSettings.SUSPEND_NONE.equals(policy)) { + return SuspendPolicy.NONE; + } else { + throw new IllegalArgumentException("unknown suspend policy"); + } } - public TextWithImports getLogMessage() { - return myLogMessage; + public boolean isSuspend() { + return myXBreakpoint.getSuspendPolicy() != SuspendPolicy.NONE; + } + + @Override + public String getSuspendPolicy() { + return getSuspendPolicy(myXBreakpoint); + } + + public void setSuspendPolicy(String policy) { + myXBreakpoint.setSuspendPolicy(transformSuspendPolicy(policy)); } public void setLogMessage(TextWithImports logMessage) { - myLogMessage = logMessage; + myXBreakpoint.setLogExpression(logMessage.getText()); + } + + public boolean isConditionEnabled() { + return myXBreakpoint.getCondition() != null && !myXBreakpoint.getCondition().isEmpty(); + } + + public void setCondition(String condition) { + myXBreakpoint.setCondition(condition); + } + + public void addInstanceFilter(long l) { + myXBreakpoint.getProperties().addInstanceFilter(l); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointFactory.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointFactory.java deleted file mode 100644 index 67c32935849e..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointFactory.java +++ /dev/null @@ -1,81 +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.debugger.ui.breakpoints; - -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.extensions.ExtensionPointName; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; -import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointItem; -import org.jdom.Element; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -/** - * Used to deexternalize breakpoints of certain category while reading saved configuration and for creating configuration UI - */ -public abstract class BreakpointFactory { - public static final ExtensionPointName EXTENSION_POINT_NAME = - ExtensionPointName.create("com.intellij.debugger.breakpointFactory"); - - public static BreakpointFactory[] getBreakpointFactories() { - return ApplicationManager.getApplication().getExtensions(EXTENSION_POINT_NAME); - } - - public abstract Breakpoint createBreakpoint(Project project, final Element element); - - public abstract Key getBreakpointCategory(); - - public abstract Icon getIcon(); - - public abstract Icon getDisabledIcon(); - - @Nullable - public static BreakpointFactory getInstance(Key category) { - final BreakpointFactory[] allFactories = getBreakpointFactories(); - for (final BreakpointFactory factory : allFactories) { - if (category.equals(factory.getBreakpointCategory())) { - return factory; - } - } - return null; - } - - protected abstract String getHelpID(); - - public abstract String getDisplayName(); - - @Nullable - public abstract BreakpointPropertiesPanel createBreakpointPropertiesPanel(Project project, boolean compact); - - @Nullable - public Breakpoint addBreakpoint(Project project) { - return null; - } - - public boolean canAddBreakpoints() { - return false; - } - - public boolean breakpointCanBeRemoved(Breakpoint breakpoint) { - return true; - } - - public BreakpointItem createBreakpointItem(final Breakpoint breakpoint) { - return new JavaBreakpointItem(this, breakpoint); - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 1bcbf3e9954b..8e9282747729 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -20,14 +20,10 @@ */ package com.intellij.debugger.ui.breakpoints; -import com.intellij.codeInsight.folding.impl.actions.ExpandRegionAction; -import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.DebuggerInvocationUtil; import com.intellij.debugger.SourcePosition; import com.intellij.debugger.engine.BreakpointStepMethodFilter; import com.intellij.debugger.engine.DebugProcessImpl; -import com.intellij.debugger.engine.evaluation.CodeFragmentKind; -import com.intellij.debugger.engine.evaluation.TextWithImportsImpl; import com.intellij.debugger.engine.requests.RequestManagerImpl; import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.impl.DebuggerContextListener; @@ -35,54 +31,43 @@ import com.intellij.debugger.impl.DebuggerManagerImpl; import com.intellij.debugger.impl.DebuggerSession; import com.intellij.debugger.ui.JavaDebuggerSupport; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.EditorFactory; -import com.intellij.openapi.editor.event.*; import com.intellij.openapi.editor.markup.GutterIconRenderer; -import com.intellij.openapi.editor.markup.MarkupEditorFilterFactory; import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.fileEditor.FileEditorManager; -import com.intellij.openapi.fileEditor.TextEditor; -import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.ui.MessageType; -import com.intellij.openapi.util.*; -import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiField; import com.intellij.psi.PsiFile; import com.intellij.util.Alarm; import com.intellij.util.EventDispatcher; -import com.intellij.util.IJSwingUtilities; -import com.intellij.util.SystemProperties; -import com.intellij.util.containers.MultiMap; import com.intellij.xdebugger.XDebuggerManager; -import com.intellij.xdebugger.XDebuggerUtil; -import com.intellij.xdebugger.breakpoints.XBreakpointType; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.XBreakpointListener; +import com.intellij.xdebugger.breakpoints.XBreakpointManager; import com.intellij.xdebugger.impl.DebuggerSupport; import com.intellij.xdebugger.impl.XDebugSessionImpl; +import com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl; +import com.intellij.xdebugger.impl.breakpoints.XDependentBreakpointManager; import com.sun.jdi.Field; import com.sun.jdi.InternalException; import com.sun.jdi.ObjectReference; import com.sun.jdi.ThreadReference; import com.sun.jdi.request.*; -import gnu.trove.THashMap; import gnu.trove.TIntHashSet; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.java.debugger.breakpoints.JavaBreakpointAdapter; -import org.jetbrains.java.debugger.breakpoints.JavaBreakpointType; import javax.swing.*; -import java.awt.event.MouseEvent; import java.util.*; public class BreakpointManager { @@ -96,11 +81,9 @@ public class BreakpointManager { @NonNls private static final String RULES_GROUP_NAME = "breakpoint_rules"; private final Project myProject; - private AnyExceptionBreakpoint myAnyExceptionBreakpoint; - private final List myBreakpoints = new ArrayList(); // breakpoints storage, access should be synchronized - private final List myBreakpointRules = new ArrayList(); // breakpoint rules + private XBreakpointManager myXBreakpointManager; + private final Map myBreakpoints = new HashMap(); // breakpoints storage, access should be synchronized @Nullable private List myBreakpointsListForIteration = null; // another list for breakpoints iteration, unsynchronized access ok - private final MultiMap myDocumentBreakpoints = MultiMap.createSmartList(); private final Map myUIProperties = new LinkedHashMap(); private final Map, BreakpointDefaults> myBreakpointDefaults = new LinkedHashMap, BreakpointDefaults>(); @@ -155,212 +138,35 @@ public class BreakpointManager { } } }); - - if (!project.isDefault()) { - XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpointListener( - XBreakpointType.EXTENSION_POINT_NAME.findExtension(JavaBreakpointType.class), new JavaBreakpointAdapter(project), project); - } } public void init() { - EditorEventMulticaster eventMulticaster = EditorFactory.getInstance().getEventMulticaster(); - eventMulticaster.addEditorMouseListener(new EditorMouseAdapter() { - @Nullable private EditorMouseEvent myMousePressedEvent; - - @Nullable - private Breakpoint toggleBreakpoint(final boolean mostSuitingBreakpoint, final int line, boolean temporary) { - final Editor editor = FileEditorManager.getInstance(myProject).getSelectedTextEditor(); - if (editor == null) { - return null; + myXBreakpointManager = XDebuggerManager.getInstance(myProject).getBreakpointManager(); + myXBreakpointManager.addBreakpointListener(new XBreakpointListener() { + @Override + public void breakpointAdded(@NotNull XBreakpoint xBreakpoint) { + if (isJavaType(xBreakpoint)) { + onBreakpointAdded(xBreakpoint); } - final Document document = editor.getDocument(); - final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document); - if (!JavaBreakpointType.doCanPutAt(psiFile)) { - return null; + } + + @Override + public void breakpointRemoved(@NotNull XBreakpoint xBreakpoint) { + if (isJavaType(xBreakpoint)) { + onBreakpointRemoved(xBreakpoint); } + } - if (SystemProperties.getBooleanProperty("java.debugger.xBreakpoint", false) && - XBreakpointType.EXTENSION_POINT_NAME.findExtension(JavaBreakpointType.class) - .canPutAt(psiFile.getVirtualFile(), line, myProject)) { - return null; - } - - PsiDocumentManager.getInstance(myProject).commitDocument(document); - - int offset = editor.getCaretModel().getOffset(); - int editorLine = editor.getDocument().getLineNumber(offset); - if (editorLine != line) { - if (line < 0 || line >= document.getLineCount()) { - return null; - } - offset = editor.getDocument().getLineStartOffset(line); - } - - ExpandRegionAction.expandRegionAtOffset(myProject, editor, offset); - - Breakpoint breakpoint = findBreakpoint(document, offset, null); - if (breakpoint == null) { - boolean isInsideCompiledClass = StdFileTypes.CLASS.equals(psiFile.getFileType()); - if (mostSuitingBreakpoint || isInsideCompiledClass) { - breakpoint = addFieldBreakpoint(document, offset); - if (breakpoint == null) { - breakpoint = addMethodBreakpoint(document, line); - } - if (breakpoint == null && !isInsideCompiledClass) { - breakpoint = addLineBreakpoint(document, line); - } - } - else { - breakpoint = addLineBreakpoint(document, line); - - if (breakpoint == null) { - breakpoint = addMethodBreakpoint(document, line); - } - } - + @Override + public void breakpointChanged(@NotNull XBreakpoint xBreakpoint) { + if (isJavaType(xBreakpoint)) { + Breakpoint breakpoint = myBreakpoints.get(xBreakpoint); if (breakpoint != null) { - breakpoint.REMOVE_AFTER_HIT = temporary; - RequestManagerImpl.createRequests(breakpoint); - } - return breakpoint; - } - else { - removeBreakpoint(breakpoint); - return null; - } - } - - private boolean isFromMyProject(Editor editor) { - FileEditor[] allEditors = FileEditorManager.getInstance(myProject).getAllEditors(); - for (FileEditor ed : allEditors) { - if (!(ed instanceof TextEditor)) { - continue; - } - if (((TextEditor)ed).getEditor().equals(editor)) { - return true; - } - } - return false; - } - - //mousePressed + mouseReleased is a hack to keep selection in editor when shift is pressed - @Override - public void mousePressed(@NotNull EditorMouseEvent e) { - if (MarkupEditorFilterFactory.createIsDiffFilter().avaliableIn(e.getEditor())) return; - - if (e.isConsumed()) return; - - if (e.getArea() == EditorMouseEventArea.LINE_MARKERS_AREA && e.getMouseEvent().isShiftDown()) { - myMousePressedEvent = e; - e.consume(); - } - } - - @Override - public void mouseReleased(@NotNull EditorMouseEvent e) { - if (myMousePressedEvent != null) { - mouseClicked(e); - } - myMousePressedEvent = null; - } - - @Override - public void mouseClicked(@NotNull final EditorMouseEvent e) { - if (MarkupEditorFilterFactory.createIsDiffFilter().avaliableIn(e.getEditor())) return; - - if (e.isConsumed()) return; - - if (e.getArea() == EditorMouseEventArea.LINE_MARKERS_AREA) { - PsiDocumentManager.getInstance(myProject).commitAndRunReadAction(new Runnable() { - @Override - public void run() { - final Editor editor = e.getEditor(); - if (!isFromMyProject(editor)) { - return; - } - final int line = editor.xyToLogicalPosition(e.getMouseEvent().getPoint()).line; - final Document document = editor.getDocument(); - if (line < 0 || line >= document.getLineCount()) { - return; - } - MouseEvent event = e.getMouseEvent(); - if (event.isPopupTrigger()) { - return; - } - if (event.getButton() != 1) { - return; - } - if (e.getMouseEvent().isControlDown() || e.getMouseEvent().isMetaDown()) { - return; - } - - VirtualFile file = FileDocumentManager.getInstance().getFile(document); - if (file != null && XDebuggerUtil.getInstance().canPutBreakpointAt(myProject, file, line)) { - return; - } - e.consume(); - - DebuggerInvocationUtil.invokeLater(myProject, new Runnable() { - @Override - public void run() { - final boolean suitingBreakpoint = e.getMouseEvent().isAltDown() && !e.getMouseEvent().isShiftDown(); - final boolean temporary = e.getMouseEvent().isAltDown() && e.getMouseEvent().isShiftDown(); - - final Breakpoint breakpoint = toggleBreakpoint(suitingBreakpoint, line, temporary); - - - if (!e.getMouseEvent().isAltDown() && e.getMouseEvent().isShiftDown() && breakpoint != null) { - breakpoint.LOG_EXPRESSION_ENABLED = true; - String selection = editor.getSelectionModel().getSelectedText(); - String text = selection != null ? selection : DebuggerBundle.message("breakpoint.log.message", - breakpoint.getDisplayName()); - breakpoint.setLogMessage(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, text)); - breakpoint.SUSPEND = false; - editBreakpoint(breakpoint, editor); - - - //DialogWrapper dialog = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager() - // .createConfigurationDialog(breakpoint, BreakpointPropertiesPanel.CONTROL_LOG_MESSAGE); - //dialog.show(); - // - //if (!dialog.isOK()) { - // removeBreakpoint(breakpoint); - //} - } - } - }); - } - }); - } - } - }, myProject); - - eventMulticaster.addDocumentListener(new DocumentAdapter() { - private final Alarm myUpdateAlarm = new Alarm(); - - @Override - public void documentChanged(@NotNull final DocumentEvent e) { - final Document document = e.getDocument(); - //noinspection SynchronizeOnThis - synchronized (BreakpointManager.this) { - Collection breakpoints = myDocumentBreakpoints.get(document); - if (!breakpoints.isEmpty()) { - myUpdateAlarm.cancelAllRequests(); - // must create new array in order to avoid "concurrent modification" errors - final List breakpointsToUpdate = new ArrayList(breakpoints); - myUpdateAlarm.addRequest(new Runnable() { - @Override - public void run() { - if (!myProject.isDisposed()) { - PsiDocumentManager.getInstance(myProject).commitDocument(document); - update(breakpointsToUpdate); - } - } - }, 300, ModalityState.NON_MODAL); + fireBreakpointChanged(breakpoint); } } } - }, myProject); + }); } public void editBreakpoint(final Breakpoint breakpoint, final Editor editor) { @@ -396,7 +202,7 @@ public class BreakpointManager { @Nullable public RunToCursorBreakpoint addRunToCursorBreakpoint(Document document, int lineIndex, final boolean ignoreBreakpoints) { - return RunToCursorBreakpoint.create(myProject, document, lineIndex, ignoreBreakpoints); + return RunToCursorBreakpoint.create(myProject, document, lineIndex, ignoreBreakpoints, null); } @Nullable @@ -411,7 +217,7 @@ public class BreakpointManager { return null; } - LineBreakpoint breakpoint = LineBreakpoint.create(myProject, document, lineIndex); + LineBreakpoint breakpoint = LineBreakpoint.create(myProject, document, lineIndex, null); if (breakpoint == null) { return null; } @@ -423,7 +229,7 @@ public class BreakpointManager { @Nullable public FieldBreakpoint addFieldBreakpoint(Field field, ObjectReference object) { ApplicationManager.getApplication().assertIsDispatchThread(); - final FieldBreakpoint fieldBreakpoint = FieldBreakpoint.create(myProject, field, object); + final FieldBreakpoint fieldBreakpoint = FieldBreakpoint.create(myProject, field, object, null); if (fieldBreakpoint != null) { addBreakpoint(fieldBreakpoint); } @@ -449,7 +255,7 @@ public class BreakpointManager { @Nullable public FieldBreakpoint addFieldBreakpoint(Document document, int lineIndex, String fieldName) { ApplicationManager.getApplication().assertIsDispatchThread(); - FieldBreakpoint fieldBreakpoint = FieldBreakpoint.create(myProject, document, lineIndex, fieldName); + FieldBreakpoint fieldBreakpoint = FieldBreakpoint.create(myProject, document, lineIndex, fieldName, null); if (fieldBreakpoint != null) { addBreakpoint(fieldBreakpoint); } @@ -459,7 +265,7 @@ public class BreakpointManager { @NotNull public ExceptionBreakpoint addExceptionBreakpoint(@NotNull String exceptionClassName, String packageName) { ApplicationManager.getApplication().assertIsDispatchThread(); - ExceptionBreakpoint breakpoint = new ExceptionBreakpoint(myProject, exceptionClassName, packageName); + ExceptionBreakpoint breakpoint = new ExceptionBreakpoint(myProject, exceptionClassName, packageName, null); addBreakpoint(breakpoint); if (LOG.isDebugEnabled()) { LOG.debug("ExceptionBreakpoint Added"); @@ -471,7 +277,7 @@ public class BreakpointManager { public MethodBreakpoint addMethodBreakpoint(Document document, int lineIndex) { ApplicationManager.getApplication().assertIsDispatchThread(); - MethodBreakpoint breakpoint = MethodBreakpoint.create(myProject, document, lineIndex); + MethodBreakpoint breakpoint = MethodBreakpoint.create(myProject, document, lineIndex, null); if (breakpoint == null) { return null; } @@ -485,7 +291,7 @@ public class BreakpointManager { @Nullable public WildcardMethodBreakpoint addMethodBreakpoint(String classPattern, String methodName) { ApplicationManager.getApplication().assertIsDispatchThread(); - WildcardMethodBreakpoint breakpoint = WildcardMethodBreakpoint.create(myProject, classPattern, methodName); + WildcardMethodBreakpoint breakpoint = WildcardMethodBreakpoint.create(myProject, classPattern, methodName, null); if (breakpoint == null) { return null; } @@ -531,14 +337,6 @@ public class BreakpointManager { */ @Nullable public T findBreakpoint(final Document document, final int offset, @Nullable final Key category) { - for (BreakpointWithHighlighter breakpointWithHighlighter : myDocumentBreakpoints.get(document)) { - if (breakpointWithHighlighter.isAt(document, offset) && - (category == null || category.equals(breakpointWithHighlighter.getCategory()))) { - //noinspection unchecked - return (T)breakpointWithHighlighter; - } - } - for (final Breakpoint breakpoint : getBreakpoints()) { if (breakpoint instanceof BreakpointWithHighlighter && ((BreakpointWithHighlighter)breakpoint).isAt(document, offset)) { if (category == null || category.equals(breakpoint.getCategory())) { @@ -550,224 +348,239 @@ public class BreakpointManager { return null; } - public void readExternal(@NotNull final Element parentNode) { - if (myProject.isOpen()) { - doRead(parentNode); - } - else { - myStartupManager.registerPostStartupActivity(new Runnable() { - @Override - public void run() { - doRead(parentNode); - } - }); - } - } - - private void doRead(@NotNull final Element parentNode) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - @SuppressWarnings({"HardCodedStringLiteral"}) - public void run() { - final Map nameToBreakpointMap = new THashMap(); - try { - final List groups = parentNode.getChildren(); - for (final Object group1 : groups) { - final Element group = (Element)group1; - if (group.getName().equals(RULES_GROUP_NAME)) { - continue; - } - final String categoryName = group.getName(); - final Key breakpointCategory = BreakpointCategory.lookup(categoryName); - final String defaultPolicy = group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME); - final boolean conditionEnabled = Boolean.parseBoolean(group.getAttributeValue(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, "true")); - setBreakpointDefaults(breakpointCategory, new BreakpointDefaults(defaultPolicy, conditionEnabled)); - Element anyExceptionBreakpointGroup; - if (!AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.equals(breakpointCategory)) { - // for compatibility with previous format - anyExceptionBreakpointGroup = group.getChild(AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.toString()); - final BreakpointFactory factory = BreakpointFactory.getInstance(breakpointCategory); - if (factory != null) { - for (final Object o : group.getChildren("breakpoint")) { - Element breakpointNode = (Element)o; - Breakpoint breakpoint = factory.createBreakpoint(myProject, breakpointNode); - breakpoint.readExternal(breakpointNode); - addBreakpoint(breakpoint); - nameToBreakpointMap.put(breakpoint.getDisplayName(), breakpoint); - } - } - } - else { - anyExceptionBreakpointGroup = group; - } - - if (anyExceptionBreakpointGroup != null) { - final Element breakpointElement = group.getChild("breakpoint"); - if (breakpointElement != null) { - getAnyExceptionBreakpoint().readExternal(breakpointElement); - } - } - - } - } - catch (InvalidDataException ignored) { - } - - final Element rulesGroup = parentNode.getChild(RULES_GROUP_NAME); - if (rulesGroup != null) { - final List rules = rulesGroup.getChildren("rule"); - for (final Object rule1 : rules) { - final Element rule = (Element)rule1; - final Element master = rule.getChild(MASTER_BREAKPOINT_TAGNAME); - if (master == null) { - continue; - } - final Element slave = rule.getChild(SLAVE_BREAKPOINT_TAGNAME); - if (slave == null) { - continue; - } - final Breakpoint masterBreakpoint = nameToBreakpointMap.get(master.getAttributeValue("name")); - if (masterBreakpoint == null) { - continue; - } - final Breakpoint slaveBreakpoint = nameToBreakpointMap.get(slave.getAttributeValue("name")); - if (slaveBreakpoint == null) { - continue; - } - addBreakpointRule(new EnableBreakpointRule(BreakpointManager.this, masterBreakpoint, slaveBreakpoint, "true".equalsIgnoreCase(rule.getAttributeValue("leaveEnabled")))); - } - } - - DebuggerInvocationUtil.invokeLater(myProject, new Runnable() { - @Override - public void run() { - updateBreakpointsUI(); - } - }); - } - }); - - myUIProperties.clear(); - final Element props = parentNode.getChild("ui_properties"); - if (props != null) { - final List children = props.getChildren("property"); - for (Object child : children) { - Element property = (Element)child; - final String name = property.getAttributeValue("name"); - final String value = property.getAttributeValue("value"); - if (name != null && value != null) { - myUIProperties.put(name, value); - } + private XBreakpoint findXBreakpoint(Breakpoint breakpoint) { + for (Map.Entry entry : myBreakpoints.entrySet()) { + if (entry.getValue().equals(breakpoint)) { + return entry.getKey(); } } + return null; } + //public void readExternal(@NotNull final Element parentNode) { + // if (true) return; + // if (myProject.isOpen()) { + // doRead(parentNode); + // } + // else { + // myStartupManager.registerPostStartupActivity(new Runnable() { + // @Override + // public void run() { + // doRead(parentNode); + // } + // }); + // } + //} + + //private void doRead(@NotNull final Element parentNode) { + // ApplicationManager.getApplication().runReadAction(new Runnable() { + // @Override + // @SuppressWarnings({"HardCodedStringLiteral"}) + // public void run() { + // final Map nameToBreakpointMap = new THashMap(); + // try { + // final List groups = parentNode.getChildren(); + // for (final Object group1 : groups) { + // final Element group = (Element)group1; + // if (group.getName().equals(RULES_GROUP_NAME)) { + // continue; + // } + // final String categoryName = group.getName(); + // final Key breakpointCategory = BreakpointCategory.lookup(categoryName); + // final String defaultPolicy = group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME); + // final boolean conditionEnabled = Boolean.parseBoolean(group.getAttributeValue(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, "true")); + // setBreakpointDefaults(breakpointCategory, new BreakpointDefaults(defaultPolicy, conditionEnabled)); + // Element anyExceptionBreakpointGroup; + // if (!AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.equals(breakpointCategory)) { + // // for compatibility with previous format + // anyExceptionBreakpointGroup = group.getChild(AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.toString()); + // final BreakpointFactory factory = BreakpointFactory.getInstance(breakpointCategory); + // if (factory != null) { + // for (final Object o : group.getChildren("breakpoint")) { + // Element breakpointNode = (Element)o; + // Breakpoint breakpoint = factory.createBreakpoint(myProject, breakpointNode); + // breakpoint.readExternal(breakpointNode); + // addBreakpoint(breakpoint); + // nameToBreakpointMap.put(breakpoint.getDisplayName(), breakpoint); + // } + // } + // } + // else { + // anyExceptionBreakpointGroup = group; + // } + // + // if (anyExceptionBreakpointGroup != null) { + // final Element breakpointElement = group.getChild("breakpoint"); + // if (breakpointElement != null) { + // getAnyExceptionBreakpoint().readExternal(breakpointElement); + // } + // } + // + // } + // } + // catch (InvalidDataException ignored) { + // } + // + // final Element rulesGroup = parentNode.getChild(RULES_GROUP_NAME); + // if (rulesGroup != null) { + // final List rules = rulesGroup.getChildren("rule"); + // for (final Object rule1 : rules) { + // final Element rule = (Element)rule1; + // final Element master = rule.getChild(MASTER_BREAKPOINT_TAGNAME); + // if (master == null) { + // continue; + // } + // final Element slave = rule.getChild(SLAVE_BREAKPOINT_TAGNAME); + // if (slave == null) { + // continue; + // } + // final Breakpoint masterBreakpoint = nameToBreakpointMap.get(master.getAttributeValue("name")); + // if (masterBreakpoint == null) { + // continue; + // } + // final Breakpoint slaveBreakpoint = nameToBreakpointMap.get(slave.getAttributeValue("name")); + // if (slaveBreakpoint == null) { + // continue; + // } + // addBreakpointRule(new EnableBreakpointRule(BreakpointManager.this, masterBreakpoint, slaveBreakpoint, "true".equalsIgnoreCase(rule.getAttributeValue("leaveEnabled")))); + // } + // } + // + // DebuggerInvocationUtil.invokeLater(myProject, new Runnable() { + // @Override + // public void run() { + // updateBreakpointsUI(); + // } + // }); + // } + // }); + // + // myUIProperties.clear(); + // final Element props = parentNode.getChild("ui_properties"); + // if (props != null) { + // final List children = props.getChildren("property"); + // for (Object child : children) { + // Element property = (Element)child; + // final String name = property.getAttributeValue("name"); + // final String value = property.getAttributeValue("value"); + // if (name != null && value != null) { + // myUIProperties.put(name, value); + // } + // } + // } + //} + //used in Fabrique public synchronized void addBreakpoint(Breakpoint breakpoint) { - myBreakpoints.add(breakpoint); + myBreakpoints.put(breakpoint.myXBreakpoint, breakpoint); myBreakpointsListForIteration = null; - if (breakpoint instanceof BreakpointWithHighlighter) { - BreakpointWithHighlighter breakpointWithHighlighter = (BreakpointWithHighlighter)breakpoint; - final Document document = breakpointWithHighlighter.getDocument(); - if (document != null) { - myDocumentBreakpoints.putValue(document, breakpointWithHighlighter); - } - } myDispatcher.getMulticaster().breakpointsChanged(); } - public synchronized void removeBreakpoint(@Nullable final Breakpoint breakpoint) { - ApplicationManager.getApplication().assertIsDispatchThread(); + private synchronized void onBreakpointAdded(XBreakpoint xBreakpoint) { + Breakpoint breakpoint = createJavaBreakpoint(xBreakpoint); + myBreakpoints.put(xBreakpoint, breakpoint); + myBreakpointsListForIteration = null; + RequestManagerImpl.createRequests(breakpoint); + myDispatcher.getMulticaster().breakpointsChanged(); + } + + public void removeBreakpoint(@Nullable final Breakpoint breakpoint) { if (breakpoint == null) { return; } - if (myBreakpoints.remove(breakpoint)) { - updateBreakpointRules(breakpoint); + myXBreakpointManager.removeBreakpoint(breakpoint.myXBreakpoint); + } + + private synchronized void onBreakpointRemoved(@Nullable final XBreakpoint xBreakpoint) { + ApplicationManager.getApplication().assertIsDispatchThread(); + if (xBreakpoint == null) { + return; + } + + Breakpoint breakpoint = myBreakpoints.remove(xBreakpoint); + if (breakpoint != null) { + //updateBreakpointRules(breakpoint); myBreakpointsListForIteration = null; - if (breakpoint instanceof BreakpointWithHighlighter) { - for (Document document : myDocumentBreakpoints.keySet()) { - if (myDocumentBreakpoints.remove(document, (BreakpointWithHighlighter)breakpoint)) { - break; - } - } - } //we delete breakpoints inside release, so gutter will not fire events to deleted breakpoints breakpoint.delete(); + RequestManagerImpl.deleteRequests(breakpoint); myDispatcher.getMulticaster().breakpointsChanged(); } } public void writeExternal(@NotNull final Element parentNode) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - public void run() { - removeInvalidBreakpoints(); - final Map, Element> categoryToElementMap = new THashMap, Element>(); - for (Key category : myBreakpointDefaults.keySet()) { - final Element group = getCategoryGroupElement(categoryToElementMap, category, parentNode); - final BreakpointDefaults defaults = getBreakpointDefaults(category); - group.setAttribute(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME, String.valueOf(defaults.getSuspendPolicy())); - group.setAttribute(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, String.valueOf(defaults.isConditionEnabled())); - } - // don't store invisible breakpoints - for (Breakpoint breakpoint : getBreakpoints()) { - if (breakpoint.isValid() && - (!(breakpoint instanceof BreakpointWithHighlighter) || ((BreakpointWithHighlighter)breakpoint).isVisible())) { - writeBreakpoint(getCategoryGroupElement(categoryToElementMap, breakpoint.getCategory(), parentNode), breakpoint); - } - } - final AnyExceptionBreakpoint anyExceptionBreakpoint = getAnyExceptionBreakpoint(); - final Element group = getCategoryGroupElement(categoryToElementMap, anyExceptionBreakpoint.getCategory(), parentNode); - writeBreakpoint(group, anyExceptionBreakpoint); - - final Element rules = new Element(RULES_GROUP_NAME); - parentNode.addContent(rules); - for (EnableBreakpointRule myBreakpointRule : myBreakpointRules) { - writeRule(myBreakpointRule, rules); - } - } - }); - - final Element uiProperties = new Element("ui_properties"); - parentNode.addContent(uiProperties); - for (final String name : myUIProperties.keySet()) { - Element property = new Element("property"); - uiProperties.addContent(property); - property.setAttribute("name", name); - property.setAttribute("value", myUIProperties.get(name)); - } + // if (true) return; + // ApplicationManager.getApplication().runReadAction(new Runnable() { + // @Override + // public void run() { + // removeInvalidBreakpoints(); + // final Map, Element> categoryToElementMap = new THashMap, Element>(); + // for (Key category : myBreakpointDefaults.keySet()) { + // final Element group = getCategoryGroupElement(categoryToElementMap, category, parentNode); + // final BreakpointDefaults defaults = getBreakpointDefaults(category); + // group.setAttribute(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME, String.valueOf(defaults.getSuspendPolicy())); + // group.setAttribute(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, String.valueOf(defaults.isConditionEnabled())); + // } + // // don't store invisible breakpoints + // for (Breakpoint breakpoint : getBreakpoints()) { + // if (breakpoint.isValid() && + // (!(breakpoint instanceof BreakpointWithHighlighter) || ((BreakpointWithHighlighter)breakpoint).isVisible())) { + // writeBreakpoint(getCategoryGroupElement(categoryToElementMap, breakpoint.getCategory(), parentNode), breakpoint); + // } + // } + // final AnyExceptionBreakpoint anyExceptionBreakpoint = getAnyExceptionBreakpoint(); + // final Element group = getCategoryGroupElement(categoryToElementMap, anyExceptionBreakpoint.getCategory(), parentNode); + // writeBreakpoint(group, anyExceptionBreakpoint); + // + // final Element rules = new Element(RULES_GROUP_NAME); + // parentNode.addContent(rules); + // //for (EnableBreakpointRule myBreakpointRule : myBreakpointRules) { + // // writeRule(myBreakpointRule, rules); + // //} + // } + // }); + // + // final Element uiProperties = new Element("ui_properties"); + // parentNode.addContent(uiProperties); + // for (final String name : myUIProperties.keySet()) { + // Element property = new Element("property"); + // uiProperties.addContent(property); + // property.setAttribute("name", name); + // property.setAttribute("value", myUIProperties.get(name)); + // } } - @SuppressWarnings({"HardCodedStringLiteral"}) - private static void writeRule(@NotNull final EnableBreakpointRule enableBreakpointRule, @NotNull Element element) { - Element rule = new Element("rule"); - if (enableBreakpointRule.isLeaveEnabled()) { - rule.setAttribute("leaveEnabled", Boolean.toString(true)); - } - element.addContent(rule); - writeRuleBreakpoint(rule, MASTER_BREAKPOINT_TAGNAME, enableBreakpointRule.getMasterBreakpoint()); - writeRuleBreakpoint(rule, SLAVE_BREAKPOINT_TAGNAME, enableBreakpointRule.getSlaveBreakpoint()); - } + //@SuppressWarnings({"HardCodedStringLiteral"}) + //private static void writeRule(@NotNull final EnableBreakpointRule enableBreakpointRule, @NotNull Element element) { + // Element rule = new Element("rule"); + // if (enableBreakpointRule.isLeaveEnabled()) { + // rule.setAttribute("leaveEnabled", Boolean.toString(true)); + // } + // element.addContent(rule); + // writeRuleBreakpoint(rule, MASTER_BREAKPOINT_TAGNAME, enableBreakpointRule.getMasterBreakpoint()); + // writeRuleBreakpoint(rule, SLAVE_BREAKPOINT_TAGNAME, enableBreakpointRule.getSlaveBreakpoint()); + //} - @SuppressWarnings({"HardCodedStringLiteral"}) private static void writeRuleBreakpoint(@NotNull final Element element, final String tagName, @NotNull final Breakpoint breakpoint) { - Element master = new Element(tagName); - element.addContent(master); - master.setAttribute("name", breakpoint.getDisplayName()); - } + //@SuppressWarnings({"HardCodedStringLiteral"}) private static void writeRuleBreakpoint(@NotNull final Element element, final String tagName, @NotNull final Breakpoint breakpoint) { + // Element master = new Element(tagName); + // element.addContent(master); + // master.setAttribute("name", breakpoint.getDisplayName()); + //} - @SuppressWarnings({"HardCodedStringLiteral"}) - private static void writeBreakpoint(@NotNull final Element group, @NotNull final Breakpoint breakpoint) { - Element breakpointNode = new Element("breakpoint"); - group.addContent(breakpointNode); - try { - breakpoint.writeExternal(breakpointNode); - } - catch (WriteExternalException e) { - LOG.error(e); - } - } + //@SuppressWarnings({"HardCodedStringLiteral"}) + //private static void writeBreakpoint(@NotNull final Element group, @NotNull final Breakpoint breakpoint) { + // Element breakpointNode = new Element("breakpoint"); + // group.addContent(breakpointNode); + // try { + // breakpoint.writeExternal(breakpointNode); + // } + // catch (WriteExternalException e) { + // LOG.error(e); + // } + //} private static Element getCategoryGroupElement(@NotNull final Map, Element> categoryToElementMap, @NotNull final Key category, @NotNull final Element parentNode) { Element group = categoryToElementMap.get(category); @@ -814,18 +627,31 @@ public class BreakpointManager { @NotNull public synchronized List getBreakpoints() { if (myBreakpointsListForIteration == null) { - myBreakpointsListForIteration = new ArrayList(myBreakpoints.size() + 1); - myBreakpointsListForIteration.addAll(myBreakpoints); - myBreakpointsListForIteration.add(getAnyExceptionBreakpoint()); + myBreakpointsListForIteration = new ArrayList(myBreakpoints.size()); + + for (XBreakpoint xBreakpoint : myXBreakpointManager.getAllBreakpoints()) { + if (isJavaType(xBreakpoint)) { + Breakpoint breakpoint = myBreakpoints.get(xBreakpoint); + if (breakpoint == null) { + breakpoint = createJavaBreakpoint(xBreakpoint); + myBreakpoints.put(xBreakpoint, breakpoint); + } + myBreakpointsListForIteration.add(breakpoint); + } + } } return myBreakpointsListForIteration; } - public AnyExceptionBreakpoint getAnyExceptionBreakpoint() { - if (myAnyExceptionBreakpoint == null) { - myAnyExceptionBreakpoint = new AnyExceptionBreakpoint(myProject); + private boolean isJavaType(XBreakpoint xBreakpoint) { + return xBreakpoint.getType() instanceof JavaBreakpointType; + } + + private Breakpoint createJavaBreakpoint(XBreakpoint xBreakpoint) { + if (xBreakpoint.getType() instanceof JavaBreakpointType) { + return ((JavaBreakpointType)xBreakpoint.getType()).createJavaBreakpoint(myProject, xBreakpoint); } - return myAnyExceptionBreakpoint; + throw new IllegalStateException("Unsupported breakpoint type:" + xBreakpoint.getType()); } //interaction with RequestManagerImpl @@ -963,6 +789,7 @@ public class BreakpointManager { private boolean myAllowMulticasting = true; private final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); public void fireBreakpointChanged(Breakpoint breakpoint) { + breakpoint.reload(); RequestManagerImpl.updateRequests(breakpoint); if (myAllowMulticasting) { // can be invoked from non-AWT thread @@ -988,84 +815,104 @@ public class BreakpointManager { } public void setBreakpointEnabled(@NotNull final Breakpoint breakpoint, final boolean enabled) { - if (breakpoint.ENABLED != enabled) { - breakpoint.ENABLED = enabled; - fireBreakpointChanged(breakpoint); - breakpoint.updateUI(); + if (breakpoint.isEnabled() != enabled) { + breakpoint.setEnabled(enabled); + //fireBreakpointChanged(breakpoint); + //breakpoint.updateUI(); } } public void addBreakpointRule(@NotNull EnableBreakpointRule rule) { - rule.init(); - myBreakpointRules.add(rule); + //rule.init(); + //myBreakpointRules.add(rule); } public boolean removeBreakpointRule(@NotNull EnableBreakpointRule rule) { - final boolean removed = myBreakpointRules.remove(rule); - if (removed) { - rule.dispose(); - } - return removed; + //final boolean removed = myBreakpointRules.remove(rule); + //if (removed) { + // rule.dispose(); + //} + //return removed; + return false; } public boolean removeBreakpointRule(@NotNull Breakpoint slaveBreakpoint) { - for (final EnableBreakpointRule rule : myBreakpointRules) { - if (slaveBreakpoint.equals(rule.getSlaveBreakpoint())) { - removeBreakpointRule(rule); - return true; - } - } + //for (final EnableBreakpointRule rule : myBreakpointRules) { + // if (slaveBreakpoint.equals(rule.getSlaveBreakpoint())) { + // removeBreakpointRule(rule); + // return true; + // } + //} return false; } - private void updateBreakpointRules(@NotNull Breakpoint removedBreakpoint) { - for (Iterator it = myBreakpointRules.iterator(); it.hasNext();) { - final EnableBreakpointRule rule = it.next(); - if (removedBreakpoint.equals(rule.getMasterBreakpoint()) || removedBreakpoint.equals(rule.getSlaveBreakpoint())) { - it.remove(); - } - } - } + //private void updateBreakpointRules(@NotNull Breakpoint removedBreakpoint) { + // for (Iterator it = myBreakpointRules.iterator(); it.hasNext();) { + // final EnableBreakpointRule rule = it.next(); + // if (removedBreakpoint.equals(rule.getMasterBreakpoint()) || removedBreakpoint.equals(rule.getSlaveBreakpoint())) { + // it.remove(); + // } + // } + //} + // copied from XDebugSessionImpl processDependencies public void processBreakpointHit(@NotNull final Breakpoint breakpoint) { - for (final EnableBreakpointRule rule : myBreakpointRules) { - rule.processBreakpointHit(breakpoint); + XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)myXBreakpointManager).getDependentBreakpointManager(); + XBreakpoint xBreakpoint = findXBreakpoint(breakpoint); + if (!dependentBreakpointManager.isMasterOrSlave(xBreakpoint)) { + return; + } + List> breakpoints = dependentBreakpointManager.getSlaveBreakpoints(xBreakpoint); + for (final XBreakpoint slaveBreakpoint : breakpoints) { + DebuggerInvocationUtil.invokeLater(myProject, new Runnable() { + @Override + public void run() { + slaveBreakpoint.setEnabled(true); + } + }); + } + + if (dependentBreakpointManager.getMasterBreakpoint(xBreakpoint) != null && !dependentBreakpointManager.isLeaveEnabled(xBreakpoint)) { + DebuggerInvocationUtil.invokeLater(myProject, new Runnable() { + @Override + public void run() { + breakpoint.setEnabled(false); + } + }); + //myDebuggerManager.getBreakpointManager().getLineBreakpointManager().queueBreakpointUpdate(breakpoint); } } public void setInitialBreakpointsState() { - myAllowMulticasting = false; - for (final EnableBreakpointRule myBreakpointRule : myBreakpointRules) { - myBreakpointRule.init(); - } - myAllowMulticasting = true; - if (!myBreakpointRules.isEmpty()) { - IJSwingUtilities.invoke(new Runnable() { - @Override - public void run() { - myDispatcher.getMulticaster().breakpointsChanged(); - } - }); - } + //myAllowMulticasting = false; + //for (final EnableBreakpointRule myBreakpointRule : myBreakpointRules) { + // myBreakpointRule.init(); + //} + //myAllowMulticasting = true; + //if (!myBreakpointRules.isEmpty()) { + // IJSwingUtilities.invoke(new Runnable() { + // @Override + // public void run() { + // myDispatcher.getMulticaster().breakpointsChanged(); + // } + // }); + //} } @Nullable public Breakpoint findMasterBreakpoint(@NotNull Breakpoint dependentBreakpoint) { - for (final EnableBreakpointRule rule : myBreakpointRules) { - if (dependentBreakpoint.equals(rule.getSlaveBreakpoint())) { - return rule.getMasterBreakpoint(); - } - } - return null; + XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)myXBreakpointManager).getDependentBreakpointManager(); + XBreakpoint xBreakpoint = findXBreakpoint(dependentBreakpoint); + return myBreakpoints.get(dependentBreakpointManager.getMasterBreakpoint(xBreakpoint)); } @Nullable public EnableBreakpointRule findBreakpointRule(@NotNull Breakpoint dependentBreakpoint) { - for (final EnableBreakpointRule rule : myBreakpointRules) { - if (dependentBreakpoint.equals(rule.getSlaveBreakpoint())) { - return rule; - } - } + //for (final EnableBreakpointRule rule : myBreakpointRules) { + // if (dependentBreakpoint.equals(rule.getSlaveBreakpoint())) { + // return rule; + // } + //} return null; } @@ -1076,4 +923,14 @@ public class BreakpointManager { public String setProperty(String name, String value) { return myUIProperties.put(name, value); } + + public static PsiFile getPsiFile(XBreakpoint xBreakpoint, Project project) { + try { + final Document document = FileDocumentManager.getInstance().getDocument(xBreakpoint.getSourcePosition().getFile()); + return PsiDocumentManager.getInstance(project).getPsiFile(document); + } catch (Exception e) { + LOG.error(e); + } + return null; + } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java index d52044bbeb71..38031d4735a6 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java @@ -59,6 +59,9 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +/* + * Not used any more, since move to xBreakpoints + */ public abstract class BreakpointPropertiesPanel { private BreakpointChooser myMasterBreakpointChooser; @@ -465,8 +468,8 @@ public abstract class BreakpointPropertiesPanel { initMasterBreakpointPanel(); - if (breakpoint.COUNT_FILTER > 0) { - myPassCountField.setText(Integer.toString(breakpoint.COUNT_FILTER)); + if (breakpoint.getCountFilter() > 0) { + myPassCountField.setText(Integer.toString(breakpoint.getCountFilter())); moreOptionsVisible = true; } else { @@ -474,23 +477,23 @@ public abstract class BreakpointPropertiesPanel { } PsiElement context = breakpoint.getEvaluationElement(); - myPassCountCheckbox.setSelected(breakpoint.COUNT_FILTER_ENABLED); + myPassCountCheckbox.setSelected(breakpoint.isCountFilterEnabled()); - myConditionCheckbox.setSelected(breakpoint.CONDITION_ENABLED); + myConditionCheckbox.setSelected(breakpoint.isConditionEnabled()); - myConditionCombo.setEnabled(breakpoint.CONDITION_ENABLED); + myConditionCombo.setEnabled(breakpoint.isConditionEnabled()); myConditionCombo.setContext(context); myConditionCombo.setText(breakpoint.getCondition() != null ? breakpoint.getCondition() : emptyText()); - myCbSuspend.setSelected(breakpoint.SUSPEND); + myCbSuspend.setSelected(breakpoint.isSuspend()); myRbSuspendThread.setEnabled(myCbSuspend.isSelected()); myRbSuspendAll.setEnabled(myCbSuspend.isSelected()); - if(!breakpoint.SUSPEND) { + if(!breakpoint.isSuspend()) { actionsPanelVisible = true; } - if(DebuggerSettings.SUSPEND_THREAD.equals(breakpoint.SUSPEND_POLICY)){ + if(DebuggerSettings.SUSPEND_THREAD.equals(breakpoint.getSuspendPolicy())){ myRbSuspendThread.setSelected(true); } else { @@ -511,31 +514,32 @@ public abstract class BreakpointPropertiesPanel { myRbSuspendAll.setEnabled(myCbSuspend.isSelected()); } }); - myLogMessageCheckBox.setSelected(breakpoint.LOG_ENABLED); - myTemporaryCheckBox.setSelected(breakpoint.REMOVE_AFTER_HIT); - myEnabledCheckbox.setSelected(breakpoint.ENABLED); + myLogMessageCheckBox.setSelected(breakpoint.isLogEnabled()); + myTemporaryCheckBox.setSelected(breakpoint.isRemoveAfterHit()); + myEnabledCheckbox.setSelected(breakpoint.isEnabled()); myEnabledCheckbox.setText(breakpoint.getShortName() + " enabled"); DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().addBreakpointManagerListener(new BreakpointManagerListener() { @Override public void breakpointsChanged() { - myEnabledCheckbox.setSelected(myBreakpoint.ENABLED); + myEnabledCheckbox.setSelected(myBreakpoint.isEnabled()); } }); myEnabledCheckbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { - if (myBreakpoint.ENABLED != myEnabledCheckbox.isSelected()) { - myBreakpoint.ENABLED = myEnabledCheckbox.isSelected(); + if (myBreakpoint.isEnabled() != myEnabledCheckbox.isSelected()) { + myBreakpoint.setEnabled(myEnabledCheckbox.isSelected()); getBreakpointManager(myProject).fireBreakpointChanged(myBreakpoint); myBreakpoint.updateUI(); } } }); myTemporaryCheckBox.setVisible(breakpoint instanceof LineBreakpoint); - myLogExpressionCheckBox.setSelected(breakpoint.LOG_EXPRESSION_ENABLED); - if (breakpoint.LOG_ENABLED || breakpoint.LOG_EXPRESSION_ENABLED || (breakpoint instanceof LineBreakpoint && breakpoint.REMOVE_AFTER_HIT)) { + myLogExpressionCheckBox.setSelected(breakpoint.isLogExpressionEnabled()); + if (breakpoint.isLogEnabled() || + breakpoint.isLogExpressionEnabled() || (breakpoint instanceof LineBreakpoint && breakpoint.isRemoveAfterHit())) { actionsPanelVisible = true; } @@ -548,27 +552,27 @@ public abstract class BreakpointPropertiesPanel { myLogExpressionCombo.setText(emptyText()); } - myLogExpressionCombo.setEnabled(breakpoint.LOG_EXPRESSION_ENABLED); - if (breakpoint.LOG_EXPRESSION_ENABLED) { + myLogExpressionCombo.setEnabled(breakpoint.isLogExpressionEnabled()); + if (breakpoint.isLogExpressionEnabled()) { actionsPanelVisible = true; } - myInstanceFiltersCheckBox.setSelected(breakpoint.INSTANCE_FILTERS_ENABLED); - myInstanceFiltersField.setEnabled(breakpoint.INSTANCE_FILTERS_ENABLED); - myInstanceFiltersField.getTextField().setEditable(breakpoint.INSTANCE_FILTERS_ENABLED); + myInstanceFiltersCheckBox.setSelected(breakpoint.isInstanceFiltersEnabled()); + myInstanceFiltersField.setEnabled(breakpoint.isInstanceFiltersEnabled()); + myInstanceFiltersField.getTextField().setEditable(breakpoint.isInstanceFiltersEnabled()); myInstanceFilters = breakpoint.getInstanceFilters(); updateInstanceFilterEditor(true); - if (breakpoint.INSTANCE_FILTERS_ENABLED) { + if (breakpoint.isInstanceFiltersEnabled()) { moreOptionsVisible = true; } - myClassFiltersCheckBox.setSelected(breakpoint.CLASS_FILTERS_ENABLED); - myClassFiltersField.setEnabled(breakpoint.CLASS_FILTERS_ENABLED); - myClassFiltersField.getTextField().setEditable(breakpoint.CLASS_FILTERS_ENABLED); + myClassFiltersCheckBox.setSelected(breakpoint.isClassFiltersEnabled()); + myClassFiltersField.setEnabled(breakpoint.isClassFiltersEnabled()); + myClassFiltersField.getTextField().setEditable(breakpoint.isClassFiltersEnabled()); myClassFilters = breakpoint.getClassFilters(); myClassExclusionFilters = breakpoint.getClassExclusionFilters(); updateClassFilterEditor(true); - if (breakpoint.CLASS_FILTERS_ENABLED) { + if (breakpoint.isClassFiltersEnabled()) { moreOptionsVisible = true; } @@ -635,31 +639,31 @@ public abstract class BreakpointPropertiesPanel { saveMasterBreakpoint(); try { String text = myPassCountField.getText().trim(); - breakpoint.COUNT_FILTER = !text.isEmpty() ? Integer.parseInt(text) : 0; - if (breakpoint.COUNT_FILTER < 0) { - breakpoint.COUNT_FILTER = 0; + breakpoint.setCountFilter(!text.isEmpty() ? Integer.parseInt(text) : 0); + if (breakpoint.getCountFilter() < 0) { + breakpoint.setCountFilter(0); } } catch (Exception ignored) { } - breakpoint.COUNT_FILTER_ENABLED = breakpoint.COUNT_FILTER > 0 && myPassCountCheckbox.isSelected(); - breakpoint.setCondition(myConditionCombo.getText()); - breakpoint.CONDITION_ENABLED = myConditionCheckbox.isSelected(); + breakpoint.setCountFilterEnabled(breakpoint.getCountFilter() > 0 && myPassCountCheckbox.isSelected()); + breakpoint.setCondition(myConditionCombo.getText().getText()); + //breakpoint.setConditionEnabled(myConditionCheckbox.isSelected()); breakpoint.setLogMessage(myLogExpressionCombo.getText()); - breakpoint.LOG_EXPRESSION_ENABLED = !breakpoint.getLogMessage().isEmpty() && myLogExpressionCheckBox.isSelected(); - breakpoint.LOG_ENABLED = myLogMessageCheckBox.isSelected(); - breakpoint.ENABLED = myEnabledCheckbox.isSelected(); - breakpoint.REMOVE_AFTER_HIT = myTemporaryCheckBox.isSelected(); - breakpoint.SUSPEND = myCbSuspend.isSelected(); - breakpoint.SUSPEND_POLICY = getSelectedSuspendPolicy(); + breakpoint.setLogExpressionEnabled(!breakpoint.getLogMessage().isEmpty() && myLogExpressionCheckBox.isSelected()); + breakpoint.setLogEnabled(myLogMessageCheckBox.isSelected()); + breakpoint.setEnabled(myEnabledCheckbox.isSelected()); + breakpoint.setRemoveAfterHit(myTemporaryCheckBox.isSelected()); + //breakpoint.setSuspend(myCbSuspend.isSelected()); + breakpoint.setSuspendPolicy(getSelectedSuspendPolicy()); reloadInstanceFilters(); reloadClassFilters(); updateInstanceFilterEditor(true); updateClassFilterEditor(true); - breakpoint.INSTANCE_FILTERS_ENABLED = myInstanceFiltersField.getText().length() > 0 && myInstanceFiltersCheckBox.isSelected(); - breakpoint.CLASS_FILTERS_ENABLED = myClassFiltersField.getText().length() > 0 && myClassFiltersCheckBox.isSelected(); + breakpoint.setInstanceFiltersEnabled(myInstanceFiltersField.getText().length() > 0 && myInstanceFiltersCheckBox.isSelected()); + breakpoint.setClassFiltersEnabled(myClassFiltersField.getText().length() > 0 && myClassFiltersCheckBox.isSelected()); breakpoint.setClassFilters(myClassFilters); breakpoint.setClassExclusionFilters(myClassExclusionFilters); breakpoint.setInstanceFilters(myInstanceFilters); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java index 16b75279099e..200e377b87f8 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java @@ -25,49 +25,52 @@ import com.intellij.debugger.engine.events.DebuggerCommandImpl; import com.intellij.debugger.engine.requests.RequestManagerImpl; import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.settings.DebuggerSettings; -import com.intellij.debugger.ui.JavaDebuggerSupport; -import com.intellij.openapi.actionSystem.ActionGroup; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.ex.MarkupModelEx; import com.intellij.openapi.editor.impl.DocumentMarkupModel; -import com.intellij.openapi.editor.markup.*; +import com.intellij.openapi.editor.markup.MarkupEditorFilterFactory; +import com.intellij.openapi.editor.markup.RangeHighlighter; +import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import com.intellij.psi.jsp.JspFile; -import com.intellij.ui.AppUIUtil; import com.intellij.ui.classFilter.ClassFilter; import com.intellij.util.StringBuilderSpinAllocator; -import com.intellij.xdebugger.impl.DebuggerSupport; -import com.intellij.xdebugger.impl.actions.EditBreakpointAction; +import com.intellij.xdebugger.XDebuggerManager; +import com.intellij.xdebugger.XDebuggerUtil; +import com.intellij.xdebugger.XSourcePosition; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.XBreakpointManager; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; import com.intellij.xdebugger.ui.DebuggerColors; import com.intellij.xml.util.XmlStringUtil; import com.sun.jdi.ReferenceType; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; import javax.swing.*; -import java.awt.*; -import java.awt.dnd.DragSource; /** * User: lex * Date: Sep 2, 2003 * Time: 3:22:55 PM */ -public abstract class BreakpointWithHighlighter extends Breakpoint { +public abstract class BreakpointWithHighlighter

    extends Breakpoint

    { @Nullable private RangeHighlighter myHighlighter; @@ -150,7 +153,7 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { private Icon calcIcon(@Nullable DebugProcessImpl debugProcess) { final boolean muted = debugProcess != null && isMuted(debugProcess); - if (!ENABLED) { + if (!isEnabled()) { return getDisabledIcon(muted); } @@ -184,13 +187,14 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { return getSetIcon(muted); } - protected BreakpointWithHighlighter(@NotNull Project project) { + protected BreakpointWithHighlighter(@NotNull Project project, XBreakpoint xBreakpoint) { //for persistency - super(project); + super(project, xBreakpoint); + reload(); } - public BreakpointWithHighlighter(@NotNull final Project project, @NotNull final RangeHighlighter highlighter) { - super(project); + public BreakpointWithHighlighter(@NotNull final Project project, @NotNull final RangeHighlighter highlighter, XBreakpoint breakpoint) { + super(project, breakpoint); myHighlighter = highlighter; setEditorFilter(highlighter); reload(); @@ -208,10 +212,10 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { @Override public boolean isValid() { - return isPositionValid(getSourcePosition()); + return isPositionValid(myXBreakpoint.getSourcePosition()); } - private static boolean isPositionValid(@Nullable final SourcePosition sourcePosition) { + private static boolean isPositionValid(@Nullable final XSourcePosition sourcePosition) { return ApplicationManager.getApplication().runReadAction(new Computable() { @Override public Boolean compute() { @@ -238,34 +242,34 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { } buf.append(" 
     "); buf.append(DebuggerBundle.message("breakpoint.property.name.suspend.policy")).append(" : "); - if (DebuggerSettings.SUSPEND_NONE.equals(SUSPEND_POLICY) || !SUSPEND) { + if (DebuggerSettings.SUSPEND_NONE.equals(getSuspendPolicy()) || !isSuspend()) { buf.append(DebuggerBundle.message("breakpoint.properties.panel.option.suspend.none")); } - else if (DebuggerSettings.SUSPEND_ALL.equals(SUSPEND_POLICY)) { + else if (DebuggerSettings.SUSPEND_ALL.equals(getSuspendPolicy())) { buf.append(DebuggerBundle.message("breakpoint.properties.panel.option.suspend.all")); } - else if (DebuggerSettings.SUSPEND_THREAD.equals(SUSPEND_POLICY)) { + else if (DebuggerSettings.SUSPEND_THREAD.equals(getSuspendPolicy())) { buf.append(DebuggerBundle.message("breakpoint.properties.panel.option.suspend.thread")); } buf.append(" 
     "); buf.append(DebuggerBundle.message("breakpoint.property.name.log.message")).append(": "); - buf.append(LOG_ENABLED ? CommonBundle.getYesButtonText() : CommonBundle.getNoButtonText()); - if (LOG_EXPRESSION_ENABLED) { + buf.append(isLogEnabled() ? CommonBundle.getYesButtonText() : CommonBundle.getNoButtonText()); + if (isLogExpressionEnabled()) { buf.append(" 
     "); buf.append(DebuggerBundle.message("breakpoint.property.name.log.expression")).append(": "); buf.append(XmlStringUtil.escapeString(getLogMessage().getText())); } - if (CONDITION_ENABLED && getCondition() != null && getCondition().getText() != null && !getCondition().getText().isEmpty()) { + if (isConditionEnabled() && getCondition() != null && getCondition().getText() != null && !getCondition().getText().isEmpty()) { buf.append(" 
     "); buf.append(DebuggerBundle.message("breakpoint.property.name.condition")).append(": "); buf.append(XmlStringUtil.escapeString(getCondition().getText())); } - if (COUNT_FILTER_ENABLED) { + if (isCountFilterEnabled()) { buf.append(" 
     "); buf.append(DebuggerBundle.message("breakpoint.property.name.pass.count")).append(": "); - buf.append(COUNT_FILTER); + buf.append(getCountFilter()); } - if (CLASS_FILTERS_ENABLED) { + if (isClassFiltersEnabled()) { buf.append(" 
     "); buf.append(DebuggerBundle.message("breakpoint.property.name.class.filters")).append(": "); ClassFilter[] classFilters = getClassFilters(); @@ -273,7 +277,7 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { buf.append(classFilter.getPattern()).append(" "); } } - if (INSTANCE_FILTERS_ENABLED) { + if (isInstanceFiltersEnabled()) { buf.append(" 
     "); buf.append(DebuggerBundle.message("breakpoint.property.name.instance.filters")); InstanceFilter[] instanceFilters = getInstanceFilters(); @@ -292,23 +296,21 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { @Override public final void reload() { ApplicationManager.getApplication().assertReadAccessAllowed(); - RangeHighlighter highlighter = myHighlighter; - if (highlighter != null && highlighter.isValid()) { - PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(highlighter.getDocument()); - if (psiFile != null) { - mySourcePosition = SourcePosition.createFromOffset(psiFile, highlighter.getStartOffset()); - reload(psiFile); - return; - } + final XSourcePosition position = myXBreakpoint.getSourcePosition(); + try { + PsiElement element = XDebuggerUtil.getInstance().findContextElement(position.getFile(), position.getOffset(), myProject, false); + mySourcePosition = SourcePosition.createFromOffset(element.getContainingFile(), position.getOffset()); + } catch (Exception e) { + mySourcePosition = null; } - mySourcePosition = null; + reload(BreakpointManager.getPsiFile(myXBreakpoint, myProject)); } @Override public void createRequest(@NotNull DebugProcessImpl debugProcess) { DebuggerManagerThreadImpl.assertIsManagerThread(); // check is this breakpoint is enabled, vm reference is valid and there're no requests created yet - if (!ENABLED || + if (!isEnabled() || !debugProcess.isAttached() || isMuted(debugProcess) || !debugProcess.getRequestsManager().findRequests(this).isEmpty()) { @@ -329,7 +331,7 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { @Override public void processClassPrepare(final DebugProcess debugProcess, final ReferenceType classType) { - if (!ENABLED || !isValid()) { + if (!isEnabled() || !isValid()) { return; } createRequestForPreparedClass((DebugProcessImpl)debugProcess, classType); @@ -383,20 +385,24 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { private void updateGutter() { if (myVisible) { - RangeHighlighter highlighter = myHighlighter; - if (highlighter != null && highlighter.isValid() && isValid()) { - AppUIUtil.invokeLaterIfProjectAlive(myProject, new Runnable() { - @Override - public void run() { - if (isValid()) { - setupGutterRenderer(myHighlighter); - } - } - }); - } - else { - DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().removeBreakpoint(this); + if (isValid()) { + final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(myProject).getBreakpointManager(); + breakpointManager.updateBreakpointPresentation((XLineBreakpoint)myXBreakpoint, getIcon(), getDescription()); } + //RangeHighlighter highlighter = myHighlighter; + //if (highlighter != null && highlighter.isValid() && isValid()) { + // AppUIUtil.invokeLaterIfProjectAlive(myProject, new Runnable() { + // @Override + // public void run() { + // if (isValid()) { + // setupGutterRenderer(myHighlighter); + // } + // } + // }); + //} + //else { + // DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().removeBreakpoint(this); + //} } } @@ -448,9 +454,9 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { }); } - private void setupGutterRenderer(@NotNull RangeHighlighter highlighter) { - highlighter.setGutterIconRenderer(new MyGutterIconRenderer(getIcon(), getDescription())); - } + //private void setupGutterRenderer(@NotNull RangeHighlighter highlighter) { + // highlighter.setGutterIconRenderer(new MyGutterIconRenderer(getIcon(), getDescription())); + //} @Override public abstract Key getCategory(); @@ -555,164 +561,164 @@ public abstract class BreakpointWithHighlighter extends Breakpoint { return highlighter; } - @Override - public void readExternal(@NotNull Element breakpointNode) throws InvalidDataException { - super.readExternal(breakpointNode); - //noinspection HardCodedStringLiteral - final String url = breakpointNode.getAttributeValue("url"); + //@Override + //public void readExternal(@NotNull Element breakpointNode) throws InvalidDataException { + // super.readExternal(breakpointNode); + // //noinspection HardCodedStringLiteral + // final String url = breakpointNode.getAttributeValue("url"); + // + // //noinspection HardCodedStringLiteral + // final String className = breakpointNode.getAttributeValue("class"); + // if (className != null) { + // myClassName = className; + // } + // + // //noinspection HardCodedStringLiteral + // final String packageName = breakpointNode.getAttributeValue("package"); + // if (packageName != null) { + // myPackageName = packageName; + // } + // + // VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url); + // if (vFile == null) { + // throw new InvalidDataException(DebuggerBundle.message("error.breakpoint.file.not.found", url)); + // } + // final Document doc = FileDocumentManager.getInstance().getDocument(vFile); + // if (doc == null) { + // throw new InvalidDataException(DebuggerBundle.message("error.cannot.load.breakpoint.file", url)); + // } + // + // // line number + // final int line; + // try { + // //noinspection HardCodedStringLiteral + // line = Integer.parseInt(breakpointNode.getAttributeValue("line")); + // } + // catch (Exception e) { + // throw new InvalidDataException("Line number is invalid for breakpoint"); + // } + // if (line < 0) { + // throw new InvalidDataException("Line number is invalid for breakpoint"); + // } + // + // RangeHighlighter highlighter = createHighlighter(myProject, doc, line); + // + // if (highlighter == null) { + // throw new InvalidDataException(""); + // } + // + // myHighlighter = highlighter; + // reload(); + //} + // + //@Override + //@SuppressWarnings({"HardCodedStringLiteral"}) + //public void writeExternal(@NotNull Element parentNode) throws WriteExternalException { + // super.writeExternal(parentNode); + // PsiFile psiFile = getSourcePosition().getFile(); + // final VirtualFile virtualFile = psiFile.getVirtualFile(); + // final String url = virtualFile != null ? virtualFile.getUrl() : ""; + // parentNode.setAttribute("url", url); + // parentNode.setAttribute("line", Integer.toString(getSourcePosition().getLine())); + // if (myClassName != null) { + // parentNode.setAttribute("class", myClassName); + // } + // if (myPackageName != null) { + // parentNode.setAttribute("package", myPackageName); + // } + //} - //noinspection HardCodedStringLiteral - final String className = breakpointNode.getAttributeValue("class"); - if (className != null) { - myClassName = className; - } - - //noinspection HardCodedStringLiteral - final String packageName = breakpointNode.getAttributeValue("package"); - if (packageName != null) { - myPackageName = packageName; - } - - VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url); - if (vFile == null) { - throw new InvalidDataException(DebuggerBundle.message("error.breakpoint.file.not.found", url)); - } - final Document doc = FileDocumentManager.getInstance().getDocument(vFile); - if (doc == null) { - throw new InvalidDataException(DebuggerBundle.message("error.cannot.load.breakpoint.file", url)); - } - - // line number - final int line; - try { - //noinspection HardCodedStringLiteral - line = Integer.parseInt(breakpointNode.getAttributeValue("line")); - } - catch (Exception e) { - throw new InvalidDataException("Line number is invalid for breakpoint"); - } - if (line < 0) { - throw new InvalidDataException("Line number is invalid for breakpoint"); - } - - RangeHighlighter highlighter = createHighlighter(myProject, doc, line); - - if (highlighter == null) { - throw new InvalidDataException(""); - } - - myHighlighter = highlighter; - reload(); - } - - @Override - @SuppressWarnings({"HardCodedStringLiteral"}) - public void writeExternal(@NotNull Element parentNode) throws WriteExternalException { - super.writeExternal(parentNode); - PsiFile psiFile = getSourcePosition().getFile(); - final VirtualFile virtualFile = psiFile.getVirtualFile(); - final String url = virtualFile != null ? virtualFile.getUrl() : ""; - parentNode.setAttribute("url", url); - parentNode.setAttribute("line", Integer.toString(getSourcePosition().getLine())); - if (myClassName != null) { - parentNode.setAttribute("class", myClassName); - } - if (myPackageName != null) { - parentNode.setAttribute("package", myPackageName); - } - } - - private class MyGutterIconRenderer extends GutterIconRenderer { - private final Icon myIcon; - private final String myDescription; - - public MyGutterIconRenderer(@NotNull Icon icon, @NotNull String description) { - myIcon = icon; - myDescription = description; - } - - @Override - @NotNull - public Icon getIcon() { - return myIcon; - } - - @Override - public String getTooltipText() { - return myDescription; - } - - @Override - public Alignment getAlignment() { - return Alignment.RIGHT; - } - - @Override - public AnAction getClickAction() { - return new AnAction() { - @Override - public void actionPerformed(AnActionEvent e) { - DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().removeBreakpoint(BreakpointWithHighlighter.this); - } - }; - } - - @Override - public AnAction getMiddleButtonClickAction() { - return new AnAction() { - @Override - public void actionPerformed(AnActionEvent e) { - ENABLED = !ENABLED; - DebuggerManagerEx.getInstanceEx(getProject()).getBreakpointManager().fireBreakpointChanged(BreakpointWithHighlighter.this); - updateUI(); - } - }; - } - - @Override - public ActionGroup getPopupMenuActions() { - return null; - } - - @Nullable - @Override - public AnAction getRightButtonClickAction() { - return new EditBreakpointAction.ContextAction(this, BreakpointWithHighlighter.this, DebuggerSupport.getDebuggerSupport(JavaDebuggerSupport.class)); - } - - @Override - public GutterDraggableObject getDraggableObject() { - return new GutterDraggableObject() { - @Override - public boolean copy(int line, @NotNull VirtualFile file) { - final PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file); - return psiFile != null && moveTo(SourcePosition.createFromLine(psiFile, line)); - } - - @Override - public Cursor getCursor(int line) { - final SourcePosition newPosition = SourcePosition.createFromLine(getSourcePosition().getFile(), line); - return canMoveTo(newPosition) ? DragSource.DefaultMoveDrop : DragSource.DefaultMoveNoDrop; - } - }; - } - - @Override - public boolean equals(@NotNull Object obj) { - return obj instanceof MyGutterIconRenderer && - Comparing.equal(getTooltipText(), ((MyGutterIconRenderer)obj).getTooltipText()) && - Comparing.equal(getIcon(), ((MyGutterIconRenderer)obj).getIcon()); - } - - @Override - public int hashCode() { - return getIcon().hashCode(); - } - - @Override - public String toString() { - return "LB " + getDisplayName(); - } - } + //private class MyGutterIconRenderer extends GutterIconRenderer { + // private final Icon myIcon; + // private final String myDescription; + // + // public MyGutterIconRenderer(@NotNull Icon icon, @NotNull String description) { + // myIcon = icon; + // myDescription = description; + // } + // + // @Override + // @NotNull + // public Icon getIcon() { + // return myIcon; + // } + // + // @Override + // public String getTooltipText() { + // return myDescription; + // } + // + // @Override + // public Alignment getAlignment() { + // return Alignment.RIGHT; + // } + // + // @Override + // public AnAction getClickAction() { + // return new AnAction() { + // @Override + // public void actionPerformed(AnActionEvent e) { + // DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().removeBreakpoint(BreakpointWithHighlighter.this); + // } + // }; + // } + // + // @Override + // public AnAction getMiddleButtonClickAction() { + // return new AnAction() { + // @Override + // public void actionPerformed(AnActionEvent e) { + // setEnabled(!isEnabled()); + // DebuggerManagerEx.getInstanceEx(getProject()).getBreakpointManager().fireBreakpointChanged(BreakpointWithHighlighter.this); + // updateUI(); + // } + // }; + // } + // + // @Override + // public ActionGroup getPopupMenuActions() { + // return null; + // } + // + // @Nullable + // @Override + // public AnAction getRightButtonClickAction() { + // return new EditBreakpointAction.ContextAction(this, BreakpointWithHighlighter.this, DebuggerSupport.getDebuggerSupport(JavaDebuggerSupport.class)); + // } + // + // @Override + // public GutterDraggableObject getDraggableObject() { + // return new GutterDraggableObject() { + // @Override + // public boolean copy(int line, @NotNull VirtualFile file) { + // final PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file); + // return psiFile != null && moveTo(SourcePosition.createFromLine(psiFile, line)); + // } + // + // @Override + // public Cursor getCursor(int line) { + // final SourcePosition newPosition = SourcePosition.createFromLine(getSourcePosition().getFile(), line); + // return canMoveTo(newPosition) ? DragSource.DefaultMoveDrop : DragSource.DefaultMoveNoDrop; + // } + // }; + // } + // + // @Override + // public boolean equals(@NotNull Object obj) { + // return obj instanceof MyGutterIconRenderer && + // Comparing.equal(getTooltipText(), ((MyGutterIconRenderer)obj).getTooltipText()) && + // Comparing.equal(getIcon(), ((MyGutterIconRenderer)obj).getIcon()); + // } + // + // @Override + // public int hashCode() { + // return getIcon().hashCode(); + // } + // + // @Override + // public String toString() { + // return "LB " + getDisplayName(); + // } + //} } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java index c6a19557f4e8..88a9a6ff329e 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java @@ -33,14 +33,13 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.sun.jdi.AbsentInformationException; import com.sun.jdi.Location; import com.sun.jdi.ObjectReference; @@ -48,38 +47,33 @@ import com.sun.jdi.ReferenceType; import com.sun.jdi.event.ExceptionEvent; import com.sun.jdi.event.LocatableEvent; import com.sun.jdi.request.ExceptionRequest; -import org.jdom.Element; import org.jetbrains.annotations.NonNls; +import org.jetbrains.java.debugger.breakpoints.properties.JavaExceptionBreakpointProperties; import javax.swing.*; -public class ExceptionBreakpoint extends Breakpoint { +public class ExceptionBreakpoint extends Breakpoint { private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.breakpoints.ExceptionBreakpoint"); - public boolean NOTIFY_CAUGHT = true; - public boolean NOTIFY_UNCAUGHT = true; - private String myQualifiedName; - private String myPackageName; - protected final static String READ_NO_CLASS_NAME = DebuggerBundle.message("error.absent.exception.breakpoint.class.name"); public static final @NonNls Key CATEGORY = BreakpointCategory.lookup("exception_breakpoints"); - public ExceptionBreakpoint(Project project) { - super(project); + public ExceptionBreakpoint(Project project, XBreakpoint xBreakpoint) { + super(project, xBreakpoint); } public Key getCategory() { return CATEGORY; } - protected ExceptionBreakpoint(Project project, String qualifiedName, String packageName) { - super(project); - myQualifiedName = qualifiedName; + protected ExceptionBreakpoint(Project project, String qualifiedName, String packageName, XBreakpoint xBreakpoint) { + super(project, xBreakpoint); + setQualifiedName(qualifiedName); if (packageName == null) { - myPackageName = calcPackageName(qualifiedName); + setPackageName(calcPackageName(qualifiedName)); } else { - myPackageName = packageName; + setPackageName(packageName); } } @@ -92,27 +86,27 @@ public class ExceptionBreakpoint extends Breakpoint { } public String getClassName() { - return myQualifiedName; + return getQualifiedName(); } public String getPackageName() { - return myPackageName; + return getProperties().myPackageName; } public PsiClass getPsiClass() { return PsiDocumentManager.getInstance(myProject).commitAndRunReadAction(new Computable() { public PsiClass compute() { - return myQualifiedName != null ? DebuggerUtilsEx.findClass(myQualifiedName, myProject, GlobalSearchScope.allScope(myProject)) : null; + return getQualifiedName() != null ? DebuggerUtilsEx.findClass(getQualifiedName(), myProject, GlobalSearchScope.allScope(myProject)) : null; } }); } public String getDisplayName() { - return DebuggerBundle.message("breakpoint.exception.breakpoint.display.name", myQualifiedName); + return DebuggerBundle.message("breakpoint.exception.breakpoint.display.name", getQualifiedName()); } public Icon getIcon() { - if (!ENABLED) { + if (!isEnabled()) { final Breakpoint master = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().findMasterBreakpoint(this); return master == null? AllIcons.Debugger.Db_disabled_exception_breakpoint : AllIcons.Debugger.Db_dep_exception_breakpoint; } @@ -124,20 +118,20 @@ public class ExceptionBreakpoint extends Breakpoint { public void createRequest(final DebugProcessImpl debugProcess) { DebuggerManagerThreadImpl.assertIsManagerThread(); - if (!ENABLED || !debugProcess.isAttached() || debugProcess.areBreakpointsMuted() || !debugProcess.getRequestsManager().findRequests(this).isEmpty()) { + if (!isEnabled() || !debugProcess.isAttached() || debugProcess.areBreakpointsMuted() || !debugProcess.getRequestsManager().findRequests(this).isEmpty()) { return; } SourcePosition classPosition = PsiDocumentManager.getInstance(myProject).commitAndRunReadAction(new Computable() { public SourcePosition compute() { - PsiClass psiClass = DebuggerUtilsEx.findClass(myQualifiedName, myProject, debugProcess.getSearchScope()); + PsiClass psiClass = DebuggerUtilsEx.findClass(getQualifiedName(), myProject, debugProcess.getSearchScope()); return psiClass != null ? SourcePosition.createFromElement(psiClass) : null; } }); if(classPosition == null) { - createOrWaitPrepare(debugProcess, myQualifiedName); + createOrWaitPrepare(debugProcess, getQualifiedName()); } else { createOrWaitPrepare(debugProcess, classPosition); @@ -146,11 +140,12 @@ public class ExceptionBreakpoint extends Breakpoint { public void processClassPrepare(DebugProcess process, ReferenceType refType) { DebugProcessImpl debugProcess = (DebugProcessImpl)process; - if (!ENABLED) { + if (!isEnabled()) { return; } // trying to create a request - ExceptionRequest request = debugProcess.getRequestsManager().createExceptionRequest(this, refType, NOTIFY_CAUGHT, NOTIFY_UNCAUGHT); + ExceptionRequest request = debugProcess.getRequestsManager().createExceptionRequest(this, refType, isNOTIFY_CAUGHT(), + isNOTIFY_UNCAUGHT()); debugProcess.getRequestsManager().enableRequest(request); if (LOG.isDebugEnabled()) { if (refType != null) { @@ -170,7 +165,7 @@ public class ExceptionBreakpoint extends Breakpoint { } public String getEventMessage(LocatableEvent event) { - String exceptionName = (myQualifiedName != null)? myQualifiedName : "java.lang.Throwable"; + String exceptionName = (getQualifiedName() != null)? getQualifiedName() : "java.lang.Throwable"; String threadName = null; if (event instanceof ExceptionEvent) { ExceptionEvent exceptionEvent = (ExceptionEvent)event; @@ -216,15 +211,15 @@ public class ExceptionBreakpoint extends Breakpoint { return true; } - @SuppressWarnings({"HardCodedStringLiteral"}) public void writeExternal(Element parentNode) throws WriteExternalException { - super.writeExternal(parentNode); - if(myQualifiedName != null) { - parentNode.setAttribute("class_name", myQualifiedName); - } - if(myPackageName != null) { - parentNode.setAttribute("package_name", myPackageName); - } - } + //@SuppressWarnings({"HardCodedStringLiteral"}) public void writeExternal(Element parentNode) throws WriteExternalException { + // super.writeExternal(parentNode); + // if(getQualifiedName() != null) { + // parentNode.setAttribute("class_name", getQualifiedName()); + // } + // if(getPackageName() != null) { + // parentNode.setAttribute("package_name", getPackageName()); + // } + //} public PsiElement getEvaluationElement() { if (getClassName() == null) { @@ -233,18 +228,37 @@ public class ExceptionBreakpoint extends Breakpoint { return JavaPsiFacade.getInstance(myProject).findClass(getClassName(), GlobalSearchScope.allScope(myProject)); } - public void readExternal(Element parentNode) throws InvalidDataException { - super.readExternal(parentNode); - //noinspection HardCodedStringLiteral - String className = parentNode.getAttributeValue("class_name"); - myQualifiedName = className; - if(className == null) { - throw new InvalidDataException(READ_NO_CLASS_NAME); - } + //public void readExternal(Element parentNode) throws InvalidDataException { + // super.readExternal(parentNode); + // //noinspection HardCodedStringLiteral + // String className = parentNode.getAttributeValue("class_name"); + // setQualifiedName(className); + // if(className == null) { + // throw new InvalidDataException(READ_NO_CLASS_NAME); + // } + // + // //noinspection HardCodedStringLiteral + // String packageName = parentNode.getAttributeValue("package_name"); + // setPackageName(packageName != null? packageName : calcPackageName(packageName)); + //} - //noinspection HardCodedStringLiteral - String packageName = parentNode.getAttributeValue("package_name"); - myPackageName = packageName != null? packageName : calcPackageName(packageName); + public boolean isNOTIFY_CAUGHT() { + return getProperties().NOTIFY_CAUGHT; } + public boolean isNOTIFY_UNCAUGHT() { + return getProperties().NOTIFY_UNCAUGHT; + } + + public String getQualifiedName() { + return getProperties().myQualifiedName; + } + + public void setQualifiedName(String qualifiedName) { + getProperties().myQualifiedName = qualifiedName; + } + + public void setPackageName(String packageName) { + getProperties().myPackageName = packageName; + } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointFactory.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointFactory.java deleted file mode 100644 index 40b75c4ffc71..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointFactory.java +++ /dev/null @@ -1,94 +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.debugger.ui.breakpoints; - -import com.intellij.debugger.DebuggerBundle; -import com.intellij.debugger.DebuggerManagerEx; -import com.intellij.debugger.HelpID; -import com.intellij.debugger.engine.JVMNameUtil; -import com.intellij.icons.AllIcons; -import com.intellij.ide.util.TreeClassChooser; -import com.intellij.ide.util.TreeClassChooserFactory; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; -import com.intellij.psi.JavaPsiFacade; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiClassOwner; -import com.intellij.psi.search.GlobalSearchScope; -import org.jdom.Element; - -import javax.swing.*; - -/** - * @author Eugene Zhuravlev - * Date: Apr 26, 2005 - */ -public class ExceptionBreakpointFactory extends BreakpointFactory { - public Breakpoint createBreakpoint(Project project, final Element element) { - return new ExceptionBreakpoint(project); - } - - public Icon getIcon() { - return AllIcons.Debugger.Db_exception_breakpoint; - } - - public Icon getDisabledIcon() { - return AllIcons.Debugger.Db_disabled_exception_breakpoint; - } - - @Override - protected String getHelpID() { - return HelpID.EXCEPTION_BREAKPOINTS; - } - - @Override - public String getDisplayName() { - return DebuggerBundle.message("exception.breakpoints.tab.title"); - } - - @Override - public BreakpointPropertiesPanel createBreakpointPropertiesPanel(Project project, boolean compact) { - return new ExceptionBreakpointPropertiesPanel(project, compact); - } - - public Key getBreakpointCategory() { - return ExceptionBreakpoint.CATEGORY; - } - - @Override - public boolean canAddBreakpoints() { - return true; - } - - @Override - public Breakpoint addBreakpoint(Project project) { - ExceptionBreakpoint breakpoint = null; - final PsiClass throwableClass = - JavaPsiFacade.getInstance(project).findClass("java.lang.Throwable", GlobalSearchScope.allScope(project)); - TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project) - .createInheritanceClassChooser(DebuggerBundle.message("add.exception.breakpoint.classchooser.title"), - GlobalSearchScope.allScope(project), throwableClass, true, true, null); - chooser.showDialog(); - PsiClass selectedClass = chooser.getSelected(); - String qName = selectedClass == null ? null : JVMNameUtil.getNonAnonymousClassName(selectedClass); - - if (qName != null && qName.length() > 0) { - breakpoint = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager() - .addExceptionBreakpoint(qName, ((PsiClassOwner)selectedClass.getContainingFile()).getPackageName()); - } - return breakpoint; - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointPropertiesPanel.java index 6d02499f227c..4af7275d1258 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpointPropertiesPanel.java @@ -21,31 +21,34 @@ package com.intellij.debugger.ui.breakpoints; import com.intellij.debugger.DebuggerBundle; -import com.intellij.ide.util.ClassFilter; -import com.intellij.openapi.project.Project; import com.intellij.ui.IdeBorderFactory; import com.intellij.util.ui.DialogUtil; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.java.debugger.breakpoints.properties.JavaExceptionBreakpointProperties; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -public class ExceptionBreakpointPropertiesPanel extends BreakpointPropertiesPanel { +public class ExceptionBreakpointPropertiesPanel extends XBreakpointCustomPropertiesPanel> { private JCheckBox myNotifyCaughtCheckBox; private JCheckBox myNotifyUncaughtCheckBox; - private ExceptionBreakpoint myExceptionBreakpoint; + //private ExceptionBreakpoint myExceptionBreakpoint; - public ExceptionBreakpointPropertiesPanel(Project project, boolean compact) { - super(project, ExceptionBreakpoint.CATEGORY, compact); - } + //public ExceptionBreakpointPropertiesPanel(Project project, boolean compact) { + // super(project, ExceptionBreakpoint.CATEGORY, compact); + //} - protected ClassFilter createClassConditionFilter() { - return null; - } - - protected JComponent createSpecialBox() { + //protected ClassFilter createClassConditionFilter() { + // return null; + //} + @NotNull + @Override + public JComponent getComponent() { myNotifyCaughtCheckBox = new JCheckBox(DebuggerBundle.message("label.exception.breakpoint.properties.panel.caught.exception")); myNotifyUncaughtCheckBox = new JCheckBox(DebuggerBundle.message("label.exception.breakpoint.properties.panel.uncaught.exception")); DialogUtil.registerMnemonic(myNotifyCaughtCheckBox); @@ -91,25 +94,20 @@ public class ExceptionBreakpointPropertiesPanel extends BreakpointPropertiesPane return _panel; } - protected void updateCheckboxes() { - super.updateCheckboxes(); - myPassCountCheckbox.setEnabled(!(myExceptionBreakpoint instanceof AnyExceptionBreakpoint)); + //protected void updateCheckboxes() { + // super.updateCheckboxes(); + // myPassCountCheckbox.setEnabled(!(myExceptionBreakpoint instanceof AnyExceptionBreakpoint)); + //} + + @Override + public void loadFrom(@NotNull XBreakpoint breakpoint) { + myNotifyCaughtCheckBox.setSelected(breakpoint.getProperties().NOTIFY_CAUGHT); + myNotifyUncaughtCheckBox.setSelected(breakpoint.getProperties().NOTIFY_UNCAUGHT); } - public void initFrom(Breakpoint breakpoint, boolean moreOptionsVisible) { - ExceptionBreakpoint exceptionBreakpoint = (ExceptionBreakpoint)breakpoint; - myExceptionBreakpoint = exceptionBreakpoint; - super.initFrom(breakpoint, moreOptionsVisible); - - myNotifyCaughtCheckBox.setSelected(exceptionBreakpoint.NOTIFY_CAUGHT); - myNotifyUncaughtCheckBox.setSelected(exceptionBreakpoint.NOTIFY_UNCAUGHT); - } - - public void saveTo(Breakpoint breakpoint) { - ExceptionBreakpoint exceptionBreakpoint = (ExceptionBreakpoint)breakpoint; - exceptionBreakpoint.NOTIFY_CAUGHT = myNotifyCaughtCheckBox.isSelected(); - exceptionBreakpoint.NOTIFY_UNCAUGHT = myNotifyUncaughtCheckBox.isSelected(); - - super.saveTo(breakpoint); + @Override + public void saveTo(@NotNull XBreakpoint breakpoint) { + breakpoint.getProperties().NOTIFY_CAUGHT = myNotifyCaughtCheckBox.isSelected(); + breakpoint.getProperties().NOTIFY_UNCAUGHT = myNotifyUncaughtCheckBox.isSelected(); } } \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpoint.java index 365ae242b36d..ada59099a2db 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpoint.java @@ -36,9 +36,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.psi.*; @@ -46,35 +44,33 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.Processor; import com.intellij.util.text.CharArrayUtil; import com.intellij.xdebugger.XDebuggerUtil; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.sun.jdi.*; import com.sun.jdi.event.AccessWatchpointEvent; import com.sun.jdi.event.LocatableEvent; import com.sun.jdi.event.ModificationWatchpointEvent; import com.sun.jdi.request.AccessWatchpointRequest; import com.sun.jdi.request.ModificationWatchpointRequest; -import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.java.debugger.breakpoints.properties.JavaFieldBreakpointProperties; import javax.swing.*; import java.util.List; -public class FieldBreakpoint extends BreakpointWithHighlighter { +public class FieldBreakpoint extends BreakpointWithHighlighter { private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.breakpoints.FieldBreakpoint"); - public boolean WATCH_MODIFICATION = true; - public boolean WATCH_ACCESS = false; private boolean myIsStatic; - private String myFieldName; @NonNls public static final Key CATEGORY = BreakpointCategory.lookup("field_breakpoints"); - protected FieldBreakpoint(Project project) { - super(project); + protected FieldBreakpoint(Project project, XBreakpoint breakpoint) { + super(project, breakpoint); } - private FieldBreakpoint(Project project, RangeHighlighter highlighter, @NotNull String fieldName) { - super(project, highlighter); - myFieldName = fieldName; + private FieldBreakpoint(Project project, RangeHighlighter highlighter, @NotNull String fieldName, XBreakpoint breakpoint) { + super(project, highlighter, breakpoint); + setFieldName(fieldName); } public boolean isStatic() { @@ -82,10 +78,9 @@ public class FieldBreakpoint extends BreakpointWithHighlighter { } public String getFieldName() { - return myFieldName; + return getProperties().myFieldName; } - @Override protected Icon getDisabledIcon(boolean isMuted) { final Breakpoint master = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().findMasterBreakpoint(this); @@ -128,7 +123,7 @@ public class FieldBreakpoint extends BreakpointWithHighlighter { @Override public PsiField compute() { final PsiClass psiClass = getPsiClassAt(sourcePosition); - return psiClass != null ? psiClass.findFieldByName(myFieldName, true) : null; + return psiClass != null ? psiClass.findFieldByName(getFieldName(), true) : null; } }); if (field != null) { @@ -142,11 +137,11 @@ public class FieldBreakpoint extends BreakpointWithHighlighter { super.reload(psiFile); PsiField field = PositionUtil.getPsiElementAt(getProject(), PsiField.class, getSourcePosition()); if(field != null) { - myFieldName = field.getName(); + setFieldName(field.getName()); myIsStatic = field.hasModifierProperty(PsiModifier.STATIC); } if (myIsStatic) { - INSTANCE_FILTERS_ENABLED = false; + setInstanceFiltersEnabled(false); } } @@ -181,20 +176,21 @@ public class FieldBreakpoint extends BreakpointWithHighlighter { ReferenceType refType) { VirtualMachineProxy vm = debugProcess.getVirtualMachineProxy(); try { - Field field = refType.fieldByName(myFieldName); + Field field = refType.fieldByName(getFieldName()); if (field == null) { - debugProcess.getRequestsManager().setInvalid(this, DebuggerBundle.message("error.invalid.breakpoint.missing.field.in.class", myFieldName, refType.name())); + debugProcess.getRequestsManager().setInvalid(this, DebuggerBundle.message("error.invalid.breakpoint.missing.field.in.class", + getFieldName(), refType.name())); return; } RequestManagerImpl manager = debugProcess.getRequestsManager(); - if (WATCH_MODIFICATION && vm.canWatchFieldModification()) { + if (isWATCH_MODIFICATION() && vm.canWatchFieldModification()) { ModificationWatchpointRequest request = manager.createModificationWatchpointRequest(this, field); debugProcess.getRequestsManager().enableRequest(request); if (LOG.isDebugEnabled()) { LOG.debug("Modification request added"); } } - if (WATCH_ACCESS && vm.canWatchFieldAccess()) { + if (isWATCH_ACCESS() && vm.canWatchFieldAccess()) { AccessWatchpointRequest request = manager.createAccessWatchpointRequest(this, field); debugProcess.getRequestsManager().enableRequest(request); if (LOG.isDebugEnabled()) { @@ -284,11 +280,11 @@ public class FieldBreakpoint extends BreakpointWithHighlighter { return DebuggerBundle.message("status.breakpoint.invalid"); } final String className = getClassName(); - return className != null && !className.isEmpty() ? className + "." + myFieldName : myFieldName; + return className != null && !className.isEmpty() ? className + "." + getFieldName() : getFieldName(); } - public static FieldBreakpoint create(@NotNull Project project, @NotNull Document document, int lineIndex, String fieldName) { - FieldBreakpoint breakpoint = new FieldBreakpoint(project, createHighlighter(project, document, lineIndex), fieldName); + public static FieldBreakpoint create(@NotNull Project project, @NotNull Document document, int lineIndex, String fieldName, XBreakpoint xBreakpoint) { + FieldBreakpoint breakpoint = new FieldBreakpoint(project, createHighlighter(project, document, lineIndex), fieldName, xBreakpoint); return (FieldBreakpoint)breakpoint.init(); } @@ -308,7 +304,7 @@ public class FieldBreakpoint extends BreakpointWithHighlighter { return field == getPsiField(); } - protected static FieldBreakpoint create(@NotNull Project project, @NotNull Field field, ObjectReference object) { + protected static FieldBreakpoint create(@NotNull Project project, @NotNull Field field, ObjectReference object, XBreakpoint xBreakpoint) { String fieldName = field.name(); int line = 0; Document document = null; @@ -335,7 +331,7 @@ public class FieldBreakpoint extends BreakpointWithHighlighter { if(document == null) return null; - FieldBreakpoint fieldBreakpoint = new FieldBreakpoint(project, createHighlighter(project, document, line), fieldName); + FieldBreakpoint fieldBreakpoint = new FieldBreakpoint(project, createHighlighter(project, document, line), fieldName, xBreakpoint); if (!fieldBreakpoint.isStatic()) { fieldBreakpoint.addInstanceFilter(object.uniqueID()); } @@ -369,25 +365,37 @@ public class FieldBreakpoint extends BreakpointWithHighlighter { return field; } - @Override - public void readExternal(@NotNull Element breakpointNode) throws InvalidDataException { - super.readExternal(breakpointNode); - //noinspection HardCodedStringLiteral - myFieldName = breakpointNode.getAttributeValue("field_name"); - if(myFieldName == null) { - throw new InvalidDataException("No field name for field breakpoint"); - } - } - - @Override - @SuppressWarnings({"HardCodedStringLiteral"}) - public void writeExternal(@NotNull Element parentNode) throws WriteExternalException { - super.writeExternal(parentNode); - parentNode.setAttribute("field_name", getFieldName()); - } + //@Override + //public void readExternal(@NotNull Element breakpointNode) throws InvalidDataException { + // super.readExternal(breakpointNode); + // //noinspection HardCodedStringLiteral + // setFieldName(breakpointNode.getAttributeValue("field_name")); + // if(getFieldName() == null) { + // throw new InvalidDataException("No field name for field breakpoint"); + // } + //} + // + //@Override + //@SuppressWarnings({"HardCodedStringLiteral"}) + //public void writeExternal(@NotNull Element parentNode) throws WriteExternalException { + // super.writeExternal(parentNode); + // parentNode.setAttribute("field_name", getFieldName()); + //} @Override public PsiElement getEvaluationElement() { return getPsiClass(); } + + public boolean isWATCH_MODIFICATION() { + return getProperties().WATCH_MODIFICATION; + } + + public boolean isWATCH_ACCESS() { + return getProperties().WATCH_ACCESS; + } + + public void setFieldName(String fieldName) { + getProperties().myFieldName = fieldName; + } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointFactory.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointFactory.java deleted file mode 100644 index 1bdef0c862e7..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointFactory.java +++ /dev/null @@ -1,127 +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.debugger.ui.breakpoints; - -import com.intellij.CommonBundle; -import com.intellij.debugger.DebuggerBundle; -import com.intellij.debugger.DebuggerManagerEx; -import com.intellij.debugger.HelpID; -import com.intellij.icons.AllIcons; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.Ref; -import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; -import org.jdom.Element; - -import javax.swing.*; - -/** - * @author Eugene Zhuravlev - * Date: Apr 26, 2005 - */ -public class FieldBreakpointFactory extends BreakpointFactory{ - public Breakpoint createBreakpoint(Project project, final Element element) { - return new FieldBreakpoint(project); - } - - public Icon getIcon() { - return AllIcons.Debugger.Db_field_breakpoint; - } - - public Icon getDisabledIcon() { - return AllIcons.Debugger.Db_disabled_field_breakpoint; - } - - @Override - protected String getHelpID() { - return HelpID.FIELD_WATCHPOINTS; - } - - @Override - public String getDisplayName() { - return DebuggerBundle.message("field.watchpoints.tab.title"); - } - - @Override - public BreakpointPropertiesPanel createBreakpointPropertiesPanel(Project project, boolean compact) { - return new FieldBreakpointPropertiesPanel(project, compact); - } - - public Key getBreakpointCategory() { - return FieldBreakpoint.CATEGORY; - } - - @Override - public Breakpoint addBreakpoint(final Project project) { - final Ref result = Ref.create(null); - AddFieldBreakpointDialog dialog = new AddFieldBreakpointDialog(project) { - protected boolean validateData() { - String className = getClassName(); - if (className.length() == 0) { - Messages.showMessageDialog(project, DebuggerBundle.message("error.field.breakpoint.class.name.not.specified"), - DebuggerBundle.message("add.field.breakpoint.dialog.title"), Messages.getErrorIcon()); - return false; - } - String fieldName = getFieldName(); - if (fieldName.length() == 0) { - Messages.showMessageDialog(project, DebuggerBundle.message("error.field.breakpoint.field.name.not.specified"), - DebuggerBundle.message("add.field.breakpoint.dialog.title"), Messages.getErrorIcon()); - return false; - } - PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project)); - if (psiClass != null) { - PsiFile psiFile = psiClass.getContainingFile(); - Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); - if(document != null) { - PsiField field = psiClass.findFieldByName(fieldName, true); - if(field != null) { - int line = document.getLineNumber(field.getTextOffset()); - FieldBreakpoint fieldBreakpoint = DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().addFieldBreakpoint(document, line, fieldName); - if (fieldBreakpoint != null) { - result.set(fieldBreakpoint); - return true; - } - } - else { - Messages.showMessageDialog(project, - DebuggerBundle.message("error.field.breakpoint.field.not.found", className, fieldName, fieldName), - CommonBundle.getErrorTitle(), - Messages.getErrorIcon() - ); - } - } - } else { - Messages.showMessageDialog(project, - DebuggerBundle.message("error.field.breakpoint.class.sources.not.found", className, fieldName, className), - CommonBundle.getErrorTitle(), - Messages.getErrorIcon() - ); - } - return false; - } - }; - dialog.show(); - return result.get(); - } - - @Override - public boolean canAddBreakpoints() { - return true; - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointPropertiesPanel.java index bec12645dd80..4d0bec2e165b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpointPropertiesPanel.java @@ -21,24 +21,30 @@ package com.intellij.debugger.ui.breakpoints; import com.intellij.debugger.DebuggerBundle; -import com.intellij.openapi.project.Project; import com.intellij.ui.IdeBorderFactory; import com.intellij.util.ui.DialogUtil; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.java.debugger.breakpoints.properties.JavaFieldBreakpointProperties; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -public class FieldBreakpointPropertiesPanel extends BreakpointPropertiesPanel { +public class FieldBreakpointPropertiesPanel extends XBreakpointCustomPropertiesPanel> { private JCheckBox myWatchAccessCheckBox; private JCheckBox myWatchModificationCheckBox; - public FieldBreakpointPropertiesPanel(final Project project, boolean compact) { - super(project, FieldBreakpoint.CATEGORY, compact); - } + //public FieldBreakpointPropertiesPanel(final Project project, boolean compact) { + // super(project, FieldBreakpoint.CATEGORY, compact); + //} - protected JComponent createSpecialBox() { + + @NotNull + @Override + public JComponent getComponent() { JPanel _panel; JPanel _panel0; myWatchAccessCheckBox = new JCheckBox(DebuggerBundle.message("label.filed.breakpoint.properties.panel.field.access")); @@ -86,20 +92,15 @@ public class FieldBreakpointPropertiesPanel extends BreakpointPropertiesPanel { return _panel; } - public void initFrom(Breakpoint breakpoint, boolean moreOptionsVisible) { - super.initFrom(breakpoint, moreOptionsVisible); - FieldBreakpoint fieldBreakpoint = (FieldBreakpoint)breakpoint; - - myWatchAccessCheckBox.setSelected(fieldBreakpoint.WATCH_ACCESS); - myWatchModificationCheckBox.setSelected(fieldBreakpoint.WATCH_MODIFICATION); + @Override + public void loadFrom(@NotNull XLineBreakpoint breakpoint) { + myWatchAccessCheckBox.setSelected(breakpoint.getProperties().WATCH_ACCESS); + myWatchModificationCheckBox.setSelected(breakpoint.getProperties().WATCH_MODIFICATION); } - public void saveTo(Breakpoint breakpoint) { - FieldBreakpoint fieldBreakpoint = (FieldBreakpoint)breakpoint; - - fieldBreakpoint.WATCH_ACCESS = myWatchAccessCheckBox.isSelected(); - fieldBreakpoint.WATCH_MODIFICATION = myWatchModificationCheckBox.isSelected(); - - super.saveTo(breakpoint); + @Override + public void saveTo(@NotNull XLineBreakpoint breakpoint) { + breakpoint.getProperties().WATCH_ACCESS = myWatchAccessCheckBox.isSelected(); + breakpoint.getProperties().WATCH_MODIFICATION = myWatchModificationCheckBox.isSelected(); } } \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestor.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestor.java index 8aa57bd351d8..6a628f189bc5 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestor.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestor.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. @@ -13,250 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * class FilteredRequestor - * @author Jeka - */ package com.intellij.debugger.ui.breakpoints; -import com.intellij.debugger.*; -import com.intellij.debugger.engine.ContextUtil; -import com.intellij.debugger.engine.DebugProcessImpl; -import com.intellij.debugger.engine.evaluation.*; -import com.intellij.debugger.engine.evaluation.expression.EvaluatorBuilderImpl; -import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator; +import com.intellij.debugger.InstanceFilter; import com.intellij.debugger.engine.requests.LocatableEventRequestor; -import com.intellij.debugger.impl.DebuggerUtilsEx; -import com.intellij.debugger.settings.DebuggerSettings; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.*; -import com.intellij.psi.PsiElement; import com.intellij.ui.classFilter.ClassFilter; -import com.sun.jdi.BooleanValue; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.VMDisconnectedException; -import com.sun.jdi.Value; -import com.sun.jdi.event.LocatableEvent; -import org.jdom.Element; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.List; +/** + * @author egor + */ +public interface FilteredRequestor extends LocatableEventRequestor { + String getSuspendPolicy(); -public abstract class FilteredRequestor implements LocatableEventRequestor, JDOMExternalizable { + boolean isInstanceFiltersEnabled(); + InstanceFilter[] getInstanceFilters(); - public String SUSPEND_POLICY = DebuggerSettings.SUSPEND_ALL; - public boolean SUSPEND = true; + boolean isCountFilterEnabled(); + int getCountFilter(); - public boolean COUNT_FILTER_ENABLED = false; - public int COUNT_FILTER = 0; - - public boolean CONDITION_ENABLED = false; - private TextWithImports myCondition; - - public boolean CLASS_FILTERS_ENABLED = false; - private ClassFilter[] myClassFilters = ClassFilter.EMPTY_ARRAY; - private ClassFilter[] myClassExclusionFilters = ClassFilter.EMPTY_ARRAY; - - public boolean INSTANCE_FILTERS_ENABLED = false; - private InstanceFilter[] myInstanceFilters = InstanceFilter.EMPTY_ARRAY; - - @NonNls private static final String FILTER_OPTION_NAME = "filter"; - @NonNls private static final String EXCLUSION_FILTER_OPTION_NAME = "exclusion_filter"; - @NonNls private static final String INSTANCE_ID_OPTION_NAME = "instance_id"; - @NonNls private static final String CONDITION_OPTION_NAME = "CONDITION"; - protected final Project myProject; - - public FilteredRequestor(@NotNull Project project) { - myProject = project; - myCondition = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, ""); - } - - public InstanceFilter[] getInstanceFilters() { - return myInstanceFilters; - } - - public void setInstanceFilters(InstanceFilter[] instanceFilters) { - myInstanceFilters = instanceFilters != null? instanceFilters : InstanceFilter.EMPTY_ARRAY; - } - - public String getSuspendPolicy() { - return SUSPEND? SUSPEND_POLICY : DebuggerSettings.SUSPEND_NONE; - } - - /** - * @return true if the ID was added or false otherwise - */ - private boolean hasObjectID(long id) { - for (InstanceFilter instanceFilter : myInstanceFilters) { - if (instanceFilter.getId() == id) { - return true; - } - } - return false; - } - - protected void addInstanceFilter(long l) { - final InstanceFilter[] filters = new InstanceFilter[myInstanceFilters.length + 1]; - System.arraycopy(myInstanceFilters, 0, filters, 0, myInstanceFilters.length); - filters[myInstanceFilters.length] = InstanceFilter.create(String.valueOf(l)); - myInstanceFilters = filters; - } - - public final ClassFilter[] getClassFilters() { - return myClassFilters; - } - - public final void setClassFilters(ClassFilter[] classFilters) { - myClassFilters = classFilters != null? classFilters : ClassFilter.EMPTY_ARRAY; - } - - public ClassFilter[] getClassExclusionFilters() { - return myClassExclusionFilters; - } - - public void setClassExclusionFilters(ClassFilter[] classExclusionFilters) { - myClassExclusionFilters = classExclusionFilters != null? classExclusionFilters : ClassFilter.EMPTY_ARRAY; - } - - public void readExternal(Element parentNode) throws InvalidDataException { - DefaultJDOMExternalizer.readExternal(this, parentNode); - if (DebuggerSettings.SUSPEND_NONE.equals(SUSPEND_POLICY)) { // compatibility with older format - SUSPEND = false; - SUSPEND_POLICY = DebuggerSettings.SUSPEND_ALL; - } - String condition = JDOMExternalizerUtil.readField(parentNode, CONDITION_OPTION_NAME); - if (condition != null) { - setCondition(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, condition)); - } - - myClassFilters = DebuggerUtilsEx.readFilters(parentNode.getChildren(FILTER_OPTION_NAME)); - myClassExclusionFilters = DebuggerUtilsEx.readFilters(parentNode.getChildren(EXCLUSION_FILTER_OPTION_NAME)); - - final ClassFilter [] instanceFilters = DebuggerUtilsEx.readFilters(parentNode.getChildren(INSTANCE_ID_OPTION_NAME)); - final List iFilters = new ArrayList(instanceFilters.length); - - for (ClassFilter instanceFilter : instanceFilters) { - try { - iFilters.add(InstanceFilter.create(instanceFilter)); - } - catch (Exception e) { - } - } - myInstanceFilters = iFilters.isEmpty() ? InstanceFilter.EMPTY_ARRAY : iFilters.toArray(new InstanceFilter[iFilters.size()]); - } - - public void writeExternal(Element parentNode) throws WriteExternalException { - DefaultJDOMExternalizer.writeExternal(this, parentNode); - JDOMExternalizerUtil.writeField(parentNode, CONDITION_OPTION_NAME, getCondition().toExternalForm()); - DebuggerUtilsEx.writeFilters(parentNode, FILTER_OPTION_NAME, myClassFilters); - DebuggerUtilsEx.writeFilters(parentNode, EXCLUSION_FILTER_OPTION_NAME, myClassExclusionFilters); - DebuggerUtilsEx.writeFilters(parentNode, INSTANCE_ID_OPTION_NAME, InstanceFilter.createClassFilters(myInstanceFilters)); - } - - public boolean evaluateCondition(final EvaluationContextImpl context, LocatableEvent event) throws EvaluateException { - if(COUNT_FILTER_ENABLED) { - final DebugProcessImpl debugProcess = context.getDebugProcess(); - debugProcess.getVirtualMachineProxy().suspend(); - debugProcess.getRequestsManager().deleteRequest(this); - ((Breakpoint)this).createRequest(debugProcess); - debugProcess.getVirtualMachineProxy().resume(); - } - if (INSTANCE_FILTERS_ENABLED) { - Value value = context.getThisObject(); - if (value != null) { // non-static - ObjectReference reference = (ObjectReference)value; - if(!hasObjectID(reference.uniqueID())) { - return false; - } - } - } - - if (CLASS_FILTERS_ENABLED) { - String typeName = calculateEventClass(context, event); - if (!typeMatchesClassFilters(typeName)) return false; - } - - if (CONDITION_ENABLED && getCondition() != null && !"".equals(getCondition().getText())) { - try { - ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(context.getProject(), new EvaluatingComputable() { - public ExpressionEvaluator compute() throws EvaluateException { - final SourcePosition contextSourcePosition = ContextUtil.getSourcePosition(context); - // IMPORTANT: calculate context psi element basing on the location where the exception - // has been hit, not on the location where it was set. (For line breakpoints these locations are the same, however, - // for method, exception and field breakpoints these locations differ) - PsiElement contextPsiElement = ContextUtil.getContextElement(contextSourcePosition); - if (contextPsiElement == null) { - contextPsiElement = getEvaluationElement(); // as a last resort - } - return EvaluatorBuilderImpl.build(getCondition(), contextPsiElement, contextSourcePosition); - } - }); - final Value value = evaluator.evaluate(context); - if (!(value instanceof BooleanValue)) { - throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.boolean.expected")); - } - if(!((BooleanValue)value).booleanValue()) { - return false; - } - } - catch (EvaluateException ex) { - if(ex.getCause() instanceof VMDisconnectedException) { - return false; - } - throw EvaluateExceptionUtil.createEvaluateException( - DebuggerBundle.message("error.failed.evaluating.breakpoint.condition", getCondition(), ex.getMessage()) - ); - } - return true; - } - - return true; - } - - protected String calculateEventClass(EvaluationContextImpl context, LocatableEvent event) throws EvaluateException { - return event.location().declaringType().name(); - } - - private boolean typeMatchesClassFilters(@Nullable String typeName) { - if (typeName == null) { - return true; - } - boolean matches = false, hasEnabled = false; - for (ClassFilter classFilter : getClassFilters()) { - if (classFilter.isEnabled()) { - hasEnabled = true; - if (classFilter.matches(typeName)) { - matches = true; - break; - } - } - } - if(hasEnabled && !matches) { - return false; - } - for (ClassFilter classFilter : getClassExclusionFilters()) { - if (classFilter.isEnabled() && classFilter.matches(typeName)) { - return false; - } - } - return true; - } - - public abstract PsiElement getEvaluationElement(); - - public TextWithImports getCondition() { - return myCondition; - } - - public void setCondition(TextWithImports condition) { - myCondition = condition; - } - - public Project getProject() { - return myProject; - } + boolean isClassFiltersEnabled(); + ClassFilter[] getClassFilters(); + ClassFilter[] getClassExclusionFilters(); } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestorImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestorImpl.java new file mode 100644 index 000000000000..2364d9c71ccd --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestorImpl.java @@ -0,0 +1,221 @@ +/* + * 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. + */ + +/** + * class FilteredRequestorImpl + * @author Jeka + */ +package com.intellij.debugger.ui.breakpoints; + +import com.intellij.debugger.*; +import com.intellij.debugger.engine.ContextUtil; +import com.intellij.debugger.engine.DebugProcessImpl; +import com.intellij.debugger.engine.evaluation.*; +import com.intellij.debugger.engine.evaluation.expression.EvaluatorBuilderImpl; +import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator; +import com.intellij.debugger.engine.requests.LocatableEventRequestor; +import com.intellij.debugger.impl.DebuggerUtilsEx; +import com.intellij.debugger.settings.DebuggerSettings; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.*; +import com.intellij.psi.PsiElement; +import com.intellij.ui.classFilter.ClassFilter; +import com.sun.jdi.BooleanValue; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.VMDisconnectedException; +import com.sun.jdi.Value; +import com.sun.jdi.event.LocatableEvent; +import org.jdom.Element; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +/* + * Not used any more, since move to xBreakpoints + */ +public abstract class FilteredRequestorImpl implements JDOMExternalizable, FilteredRequestor { + + public String SUSPEND_POLICY = DebuggerSettings.SUSPEND_ALL; + public boolean SUSPEND = true; + + public boolean COUNT_FILTER_ENABLED = false; + public int COUNT_FILTER = 0; + + public boolean CONDITION_ENABLED = false; + private TextWithImports myCondition; + + public boolean CLASS_FILTERS_ENABLED = false; + private ClassFilter[] myClassFilters = ClassFilter.EMPTY_ARRAY; + private ClassFilter[] myClassExclusionFilters = ClassFilter.EMPTY_ARRAY; + + public boolean INSTANCE_FILTERS_ENABLED = false; + private InstanceFilter[] myInstanceFilters = InstanceFilter.EMPTY_ARRAY; + + @NonNls private static final String FILTER_OPTION_NAME = "filter"; + @NonNls private static final String EXCLUSION_FILTER_OPTION_NAME = "exclusion_filter"; + @NonNls private static final String INSTANCE_ID_OPTION_NAME = "instance_id"; + @NonNls private static final String CONDITION_OPTION_NAME = "CONDITION"; + protected final Project myProject; + + public FilteredRequestorImpl(@NotNull Project project) { + myProject = project; + myCondition = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, ""); + } + + public InstanceFilter[] getInstanceFilters() { + return myInstanceFilters; + } + + public void setInstanceFilters(InstanceFilter[] instanceFilters) { + myInstanceFilters = instanceFilters != null? instanceFilters : InstanceFilter.EMPTY_ARRAY; + } + + public String getSuspendPolicy() { + return SUSPEND? SUSPEND_POLICY : DebuggerSettings.SUSPEND_NONE; + } + + /** + * @return true if the ID was added or false otherwise + */ + private boolean hasObjectID(long id) { + for (InstanceFilter instanceFilter : myInstanceFilters) { + if (instanceFilter.getId() == id) { + return true; + } + } + return false; + } + + protected void addInstanceFilter(long l) { + final InstanceFilter[] filters = new InstanceFilter[myInstanceFilters.length + 1]; + System.arraycopy(myInstanceFilters, 0, filters, 0, myInstanceFilters.length); + filters[myInstanceFilters.length] = InstanceFilter.create(String.valueOf(l)); + myInstanceFilters = filters; + } + + public final ClassFilter[] getClassFilters() { + return myClassFilters; + } + + public final void setClassFilters(ClassFilter[] classFilters) { + myClassFilters = classFilters != null? classFilters : ClassFilter.EMPTY_ARRAY; + } + + public ClassFilter[] getClassExclusionFilters() { + return myClassExclusionFilters; + } + + public void setClassExclusionFilters(ClassFilter[] classExclusionFilters) { + myClassExclusionFilters = classExclusionFilters != null? classExclusionFilters : ClassFilter.EMPTY_ARRAY; + } + + public void readExternal(Element parentNode) throws InvalidDataException { + DefaultJDOMExternalizer.readExternal(this, parentNode); + if (DebuggerSettings.SUSPEND_NONE.equals(SUSPEND_POLICY)) { // compatibility with older format + SUSPEND = false; + SUSPEND_POLICY = DebuggerSettings.SUSPEND_ALL; + } + String condition = JDOMExternalizerUtil.readField(parentNode, CONDITION_OPTION_NAME); + if (condition != null) { + setCondition(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, condition)); + } + + myClassFilters = DebuggerUtilsEx.readFilters(parentNode.getChildren(FILTER_OPTION_NAME)); + myClassExclusionFilters = DebuggerUtilsEx.readFilters(parentNode.getChildren(EXCLUSION_FILTER_OPTION_NAME)); + + final ClassFilter [] instanceFilters = DebuggerUtilsEx.readFilters(parentNode.getChildren(INSTANCE_ID_OPTION_NAME)); + final List iFilters = new ArrayList(instanceFilters.length); + + for (ClassFilter instanceFilter : instanceFilters) { + try { + iFilters.add(InstanceFilter.create(instanceFilter)); + } + catch (Exception e) { + } + } + myInstanceFilters = iFilters.isEmpty() ? InstanceFilter.EMPTY_ARRAY : iFilters.toArray(new InstanceFilter[iFilters.size()]); + } + + public void writeExternal(Element parentNode) throws WriteExternalException { + DefaultJDOMExternalizer.writeExternal(this, parentNode); + JDOMExternalizerUtil.writeField(parentNode, CONDITION_OPTION_NAME, getCondition().toExternalForm()); + DebuggerUtilsEx.writeFilters(parentNode, FILTER_OPTION_NAME, myClassFilters); + DebuggerUtilsEx.writeFilters(parentNode, EXCLUSION_FILTER_OPTION_NAME, myClassExclusionFilters); + DebuggerUtilsEx.writeFilters(parentNode, INSTANCE_ID_OPTION_NAME, InstanceFilter.createClassFilters(myInstanceFilters)); + } + + protected String calculateEventClass(EvaluationContextImpl context, LocatableEvent event) throws EvaluateException { + return event.location().declaringType().name(); + } + + private boolean typeMatchesClassFilters(@Nullable String typeName) { + if (typeName == null) { + return true; + } + boolean matches = false, hasEnabled = false; + for (ClassFilter classFilter : getClassFilters()) { + if (classFilter.isEnabled()) { + hasEnabled = true; + if (classFilter.matches(typeName)) { + matches = true; + break; + } + } + } + if(hasEnabled && !matches) { + return false; + } + for (ClassFilter classFilter : getClassExclusionFilters()) { + if (classFilter.isEnabled() && classFilter.matches(typeName)) { + return false; + } + } + return true; + } + + public abstract PsiElement getEvaluationElement(); + + public TextWithImports getCondition() { + return myCondition; + } + + public void setCondition(TextWithImports condition) { + myCondition = condition; + } + + public Project getProject() { + return myProject; + } + + public boolean isCountFilterEnabled() { + return COUNT_FILTER_ENABLED; + } + + public int getCountFilter() { + return COUNT_FILTER; + } + + public boolean isClassFiltersEnabled() { + return CLASS_FILTERS_ENABLED; + } + + public boolean isInstanceFiltersEnabled() { + return INSTANCE_FILTERS_ENABLED; + } +} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointItem.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointItem.java deleted file mode 100644 index ec3577cbae0a..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointItem.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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.debugger.ui.breakpoints; - -import com.intellij.debugger.DebuggerManagerEx; -import com.intellij.debugger.SourcePosition; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.SimpleColoredComponent; -import com.intellij.ui.SimpleTextAttributes; -import com.intellij.ui.popup.util.DetailView; -import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointItem; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -class JavaBreakpointItem extends BreakpointItem { - private final Breakpoint myBreakpoint; - private BreakpointFactory myBreakpointFactory; - private BreakpointPropertiesPanel myBreakpointPropertiesPanel; - - public JavaBreakpointItem(@Nullable BreakpointFactory breakpointFactory, Breakpoint breakpoint) { - myBreakpointFactory = breakpointFactory; - myBreakpoint = breakpoint; - } - - @Override - public void setupGenericRenderer(SimpleColoredComponent renderer, boolean plainView) { - if (plainView) { - renderer.setIcon(myBreakpoint.getIcon()); - } - renderer.append(plainView ? StringUtil.shortenTextWithEllipsis(myBreakpoint.getShortName(), 60, 0) : myBreakpoint.getDisplayName(), - isEnabled() ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.GRAY_ATTRIBUTES); - } - - @Override - public Icon getIcon() { - return myBreakpoint.getIcon(); - } - - @Override - public String getDisplayText() { - return myBreakpoint.getDisplayName(); - } - - @Override - public String speedSearchText() { - return myBreakpoint.getDisplayName(); - } - - @Override - public String footerText() { - return myBreakpoint.getDisplayName(); - } - - @Override - protected void doUpdateDetailView(DetailView panel, boolean editorOnly) { - //saveState(); - if (myBreakpointPropertiesPanel != null) { - myBreakpointPropertiesPanel.dispose(); - myBreakpointPropertiesPanel = null; - } - - if (!editorOnly) { - myBreakpointPropertiesPanel = myBreakpointFactory != null ? myBreakpointFactory - .createBreakpointPropertiesPanel(myBreakpoint.getProject(), false) : null; - - if (myBreakpointPropertiesPanel != null) { - myBreakpointPropertiesPanel.initFrom(myBreakpoint, true); - - final JPanel mainPanel = myBreakpointPropertiesPanel.getPanel(); - panel.setPropertiesPanel(mainPanel); - } - else { - panel.setPropertiesPanel(null); - } - } - - if (myBreakpoint instanceof BreakpointWithHighlighter) { - SourcePosition sourcePosition = ((BreakpointWithHighlighter)myBreakpoint).getSourcePosition(); - VirtualFile virtualFile = sourcePosition.getFile().getVirtualFile(); - showInEditor(panel, virtualFile, sourcePosition.getLine()); - } else { - panel.clearEditor(); - } - if (myBreakpointPropertiesPanel != null) { - myBreakpointPropertiesPanel.setDetailView(panel); - } - } - - @Override - public void navigate(boolean requestFocus) { - if (myBreakpoint instanceof BreakpointWithHighlighter) { - ((BreakpointWithHighlighter)myBreakpoint).getSourcePosition().navigate(requestFocus); - } - } - - @Override - public boolean canNavigate() { - return myBreakpoint instanceof BreakpointWithHighlighter && ((BreakpointWithHighlighter)myBreakpoint).getSourcePosition().canNavigate(); - } - - @Override - public boolean canNavigateToSource() { - return myBreakpoint instanceof BreakpointWithHighlighter && - ((BreakpointWithHighlighter)myBreakpoint).getSourcePosition().canNavigateToSource(); - } - - @Override - public boolean allowedToRemove() { - return myBreakpointFactory != null && myBreakpointFactory.breakpointCanBeRemoved(myBreakpoint); - } - - @Override - public void removed(Project project) { - dispose(); - DebuggerManagerEx.getInstanceEx(project).getBreakpointManager().removeBreakpoint(myBreakpoint); - } - - @Override - public void saveState() { - if (myBreakpointPropertiesPanel != null) { - myBreakpointPropertiesPanel.saveTo(myBreakpoint); - } - } - - @Override - public Object getBreakpoint() { - return myBreakpoint; - } - - @Override - public boolean isEnabled() { - return myBreakpoint.ENABLED; - } - - @Override - public void setEnabled(boolean state) { - myBreakpoint.ENABLED = state; - myBreakpoint.updateUI(); - DebuggerManagerEx.getInstanceEx(myBreakpoint.getProject()).getBreakpointManager().fireBreakpointChanged(myBreakpoint); - } - - @Override - public boolean isDefaultBreakpoint() { - return myBreakpoint.getCategory().equals(ExceptionBreakpoint.CATEGORY); - } - - @Override - protected void dispose() { - if (myBreakpointPropertiesPanel != null) { - myBreakpointPropertiesPanel.dispose(); - myBreakpointPropertiesPanel = null; - } - } - - @Override - public int compareTo(@NotNull BreakpointItem breakpointItem) { - final Object breakpoint = breakpointItem.getBreakpoint(); - if (breakpoint instanceof Breakpoint) { - return -getIndexOf(myBreakpoint) + getIndexOf((Breakpoint)breakpoint); - } - return getDisplayText().compareTo(breakpointItem.getDisplayText()); - } - - private int getIndexOf(Breakpoint breakpoint) { - return DebuggerManagerEx.getInstanceEx(myBreakpoint.getProject()).getBreakpointManager().getBreakpoints().indexOf(breakpoint); - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointType.java similarity index 62% rename from java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpointPropertiesPanel.java rename to java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointType.java index 802657b44fd9..2776032a2f4f 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointType.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. @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * Class LineBreakpointPropertiesPanel - * @author Jeka - */ package com.intellij.debugger.ui.breakpoints; import com.intellij.openapi.project.Project; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; -public class LineBreakpointPropertiesPanel extends BreakpointPropertiesPanel { - public LineBreakpointPropertiesPanel(Project project, boolean compact) { - super(project, LineBreakpoint.CATEGORY, compact); - } -} \ No newline at end of file +/** + * Base class for all Java breakpoint types + * @author egor + */ +public interface JavaBreakpointType

    { + Breakpoint createJavaBreakpoint(Project project, XBreakpoint

    breakpoint); +} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointTypeBase.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointTypeBase.java new file mode 100644 index 000000000000..69a5dbb32455 --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointTypeBase.java @@ -0,0 +1,56 @@ +/* + * 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.intellij.debugger.ui.breakpoints; + +import com.intellij.openapi.project.Project; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.XBreakpointType; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.JavaDebuggerEditorsProvider; +import org.jetbrains.java.debugger.breakpoints.JavaBreakpointFiltersPanel; +import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; + +/** + * Base class for non-line java breakpoint + * @author egor + */ +public abstract class JavaBreakpointTypeBase extends XBreakpointType, T> { + protected JavaBreakpointTypeBase(@NonNls @NotNull String id, @Nls @NotNull String title) { + super(id, title, true); + } + + @Override + public final boolean isAddBreakpointButtonVisible() { + return true; + } + + @Nullable + @Override + public final XBreakpointCustomPropertiesPanel> createCustomRightPropertiesPanel(@NotNull Project project) { + return new JavaBreakpointFiltersPanel>(project); + } + + @Nullable + @Override + public final XDebuggerEditorsProvider getEditorsProvider(@NotNull XBreakpoint breakpoint, @NotNull Project project) { + return new JavaDebuggerEditorsProvider(); + } +} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaExceptionBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaExceptionBreakpointType.java new file mode 100644 index 000000000000..89f6e432b3d3 --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaExceptionBreakpointType.java @@ -0,0 +1,139 @@ +/* + * 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.debugger.ui.breakpoints; + +import com.intellij.debugger.DebuggerBundle; +import com.intellij.debugger.HelpID; +import com.intellij.debugger.engine.JVMNameUtil; +import com.intellij.icons.AllIcons; +import com.intellij.ide.util.TreeClassChooser; +import com.intellij.ide.util.TreeClassChooserFactory; +import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.project.Project; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiClassOwner; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.xdebugger.XDebuggerManager; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaExceptionBreakpointProperties; + +import javax.swing.*; + +/** + * @author Eugene Zhuravlev + * Date: Apr 26, 2005 + */ +public class JavaExceptionBreakpointType extends JavaBreakpointTypeBase + implements JavaBreakpointType { + public JavaExceptionBreakpointType() { + super("javaException", DebuggerBundle.message("exception.breakpoints.tab.title")); + } + + @NotNull + @Override + public Icon getEnabledIcon() { + return AllIcons.Debugger.Db_exception_breakpoint; + } + + @NotNull + @Override + public Icon getDisabledIcon() { + return AllIcons.Debugger.Db_disabled_exception_breakpoint; + } + + //@Override + protected String getHelpID() { + return HelpID.EXCEPTION_BREAKPOINTS; + } + + //@Override + public String getDisplayName() { + return DebuggerBundle.message("exception.breakpoints.tab.title"); + } + + @Override + public String getDisplayText(XBreakpoint breakpoint) { + String name = breakpoint.getProperties().myQualifiedName; + if (name != null) { + return DebuggerBundle.message("breakpoint.exception.breakpoint.display.name", name); + } + else { + return DebuggerBundle.message("breakpoint.any.exception.display.name"); + } + } + + @Nullable + @Override + public JavaExceptionBreakpointProperties createProperties() { + return new JavaExceptionBreakpointProperties(); + } + + @Nullable + @Override + public XBreakpointCustomPropertiesPanel> createCustomPropertiesPanel() { + return new ExceptionBreakpointPropertiesPanel(); + } + + @Nullable + @Override + public XBreakpoint createDefaultBreakpoint(@NotNull XBreakpointCreator creator) { + return creator.createBreakpoint(new JavaExceptionBreakpointProperties()); + } + + //public Key getBreakpointCategory() { + // return ExceptionBreakpoint.CATEGORY; + //} + + @Nullable + @Override + public XBreakpoint addBreakpoint(Project project, JComponent parentComponent) { + final PsiClass throwableClass = + JavaPsiFacade.getInstance(project).findClass("java.lang.Throwable", GlobalSearchScope.allScope(project)); + TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project) + .createInheritanceClassChooser(DebuggerBundle.message("add.exception.breakpoint.classchooser.title"), + GlobalSearchScope.allScope(project), throwableClass, true, true, null); + chooser.showDialog(); + PsiClass selectedClass = chooser.getSelected(); + String qName = selectedClass == null ? null : JVMNameUtil.getNonAnonymousClassName(selectedClass); + + if (qName != null && qName.length() > 0) { + AccessToken token = WriteAction.start(); + try { + return XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpoint( + this, new JavaExceptionBreakpointProperties(qName, ((PsiClassOwner)selectedClass.getContainingFile()).getPackageName())); + } + finally { + token.finish(); + } + } + return null; + } + + @Override + public Breakpoint createJavaBreakpoint(Project project, XBreakpoint breakpoint) { + if (breakpoint.getProperties().myQualifiedName != null) { + return new ExceptionBreakpoint(project, breakpoint); + } + else { + return new AnyExceptionBreakpoint(project, breakpoint); + } + } +} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java new file mode 100644 index 000000000000..43860054bd8a --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java @@ -0,0 +1,170 @@ +/* + * 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.debugger.ui.breakpoints; + +import com.intellij.CommonBundle; +import com.intellij.debugger.DebuggerBundle; +import com.intellij.debugger.HelpID; +import com.intellij.icons.AllIcons; +import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.*; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.xdebugger.XDebuggerManager; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaFieldBreakpointProperties; + +import javax.swing.*; + +/** + * @author Eugene Zhuravlev + * Date: Apr 26, 2005 + */ +public class JavaFieldBreakpointType extends JavaLineBreakpointTypeBase implements JavaBreakpointType { + public JavaFieldBreakpointType() { + super("javaField", DebuggerBundle.message("field.watchpoints.tab.title")); + } + + @NotNull + @Override + public Icon getEnabledIcon() { + return AllIcons.Debugger.Db_field_breakpoint; + } + + @NotNull + @Override + public Icon getDisabledIcon() { + return AllIcons.Debugger.Db_disabled_field_breakpoint; + } + + //@Override + protected String getHelpID() { + return HelpID.FIELD_WATCHPOINTS; + } + + //@Override + public String getDisplayName() { + return DebuggerBundle.message("field.watchpoints.tab.title"); + } + + @Override + public String getShortText(XLineBreakpoint breakpoint) { + return getDisplayText(breakpoint); + } + + @Override + public String getDisplayText(XLineBreakpoint breakpoint) { + //if(!isValid()) { + // return DebuggerBundle.message("status.breakpoint.invalid"); + //} + JavaFieldBreakpointProperties properties = breakpoint.getProperties(); + final String className = "Class";//properties.getClassName(); + return className != null && !className.isEmpty() ? className + "." + properties.myFieldName : properties.myFieldName; + } + + @Nullable + @Override + public XBreakpointCustomPropertiesPanel> createCustomPropertiesPanel() { + return new FieldBreakpointPropertiesPanel(); + } + + @Nullable + @Override + public JavaFieldBreakpointProperties createProperties() { + return new JavaFieldBreakpointProperties(); + } + + @Nullable + @Override + public JavaFieldBreakpointProperties createBreakpointProperties(@NotNull VirtualFile file, int line) { + return new JavaFieldBreakpointProperties(); + } + + @Nullable + @Override + public XLineBreakpoint addBreakpoint(final Project project, JComponent parentComponent) { + final Ref result = Ref.create(null); + AddFieldBreakpointDialog dialog = new AddFieldBreakpointDialog(project) { + protected boolean validateData() { + String className = getClassName(); + if (className.length() == 0) { + Messages.showMessageDialog(project, DebuggerBundle.message("error.field.breakpoint.class.name.not.specified"), + DebuggerBundle.message("add.field.breakpoint.dialog.title"), Messages.getErrorIcon()); + return false; + } + String fieldName = getFieldName(); + if (fieldName.length() == 0) { + Messages.showMessageDialog(project, DebuggerBundle.message("error.field.breakpoint.field.name.not.specified"), + DebuggerBundle.message("add.field.breakpoint.dialog.title"), Messages.getErrorIcon()); + return false; + } + PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project)); + if (psiClass != null) { + PsiFile psiFile = psiClass.getContainingFile(); + Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); + if(document != null) { + PsiField field = psiClass.findFieldByName(fieldName, true); + if(field != null) { + int line = document.getLineNumber(field.getTextOffset()); + AccessToken token = WriteAction.start(); + try { + XLineBreakpoint fieldBreakpoint = XDebuggerManager.getInstance(project).getBreakpointManager() + .addLineBreakpoint(JavaFieldBreakpointType.this, psiFile.getVirtualFile().getUrl(), line, new JavaFieldBreakpointProperties(fieldName)); + if (fieldBreakpoint != null) { + result.set(fieldBreakpoint); + return true; + } + } + finally { + token.finish(); + } + } + else { + Messages.showMessageDialog(project, + DebuggerBundle.message("error.field.breakpoint.field.not.found", className, fieldName, fieldName), + CommonBundle.getErrorTitle(), + Messages.getErrorIcon() + ); + } + } + } else { + Messages.showMessageDialog(project, + DebuggerBundle.message("error.field.breakpoint.class.sources.not.found", className, fieldName, className), + CommonBundle.getErrorTitle(), + Messages.getErrorIcon() + ); + } + return false; + } + }; + dialog.show(); + return result.get(); + } + + @Override + public Breakpoint createJavaBreakpoint(Project project, XBreakpoint breakpoint) { + return new FieldBreakpoint(project, breakpoint); + } +} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java new file mode 100644 index 000000000000..455d90dd38b6 --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java @@ -0,0 +1,86 @@ +/* + * 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.intellij.debugger.ui.breakpoints; + +import com.intellij.debugger.DebuggerBundle; +import com.intellij.debugger.HelpID; +import com.intellij.icons.AllIcons; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.xdebugger.XDebuggerUtil; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; + +import javax.swing.*; +import java.util.List; + +/** + * Base class for java line-connected exceptions (line, method, field) + * @author egor + */ +public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase implements JavaBreakpointType { + public JavaLineBreakpointType() { + super("javaLine", DebuggerBundle.message("line.breakpoints.tab.title")); + } + + @NotNull + @Override + public Icon getEnabledIcon() { + return AllIcons.Debugger.Db_set_breakpoint; + } + + @NotNull + @Override + public Icon getDisabledIcon() { + return AllIcons.Debugger.Db_disabled_breakpoint; + } + + //@Override + protected String getHelpID() { + return HelpID.LINE_BREAKPOINTS; + } + + //@Override + public String getDisplayName() { + return DebuggerBundle.message("line.breakpoints.tab.title"); + } + + @Override + public List, ?>> getGroupingRules() { + return XDebuggerUtil.getInstance().getGroupingByFileRuleAsList(); + } + + @Nullable + @Override + public JavaBreakpointProperties createProperties() { + return new JavaBreakpointProperties(); + } + + @Nullable + @Override + public JavaBreakpointProperties createBreakpointProperties(@NotNull VirtualFile file, int line) { + return new JavaBreakpointProperties(); + } + + @Override + public Breakpoint createJavaBreakpoint(Project project, XBreakpoint breakpoint) { + return new LineBreakpoint(project, breakpoint); + } +} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointTypeBase.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointTypeBase.java new file mode 100644 index 000000000000..b9d68e3b56a8 --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointTypeBase.java @@ -0,0 +1,140 @@ +/* + * 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.debugger.ui.breakpoints; + +import com.intellij.debugger.engine.DebuggerUtils; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.StdFileTypes; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.Processor; +import com.intellij.xdebugger.XDebuggerUtil; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; +import com.intellij.xdebugger.breakpoints.XLineBreakpointType; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.JavaDebuggerEditorsProvider; +import org.jetbrains.java.debugger.breakpoints.JavaBreakpointFiltersPanel; +import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; + +/** + * Base class for java line-connected exceptions (line, method, field) + * @author egor + */ +public abstract class JavaLineBreakpointTypeBase

    extends XLineBreakpointType

    { + public JavaLineBreakpointTypeBase(@NonNls @NotNull String id, @Nls @NotNull String title) { + super(id, title); + } + + @Override + public boolean isAddBreakpointButtonVisible() { + return true; + } + + @Override + public final boolean isSuspendThreadSupported() { + return true; + } + + @Nullable + @Override + public final XBreakpointCustomPropertiesPanel> createCustomRightPropertiesPanel(@NotNull Project project) { + return new JavaBreakpointFiltersPanel>(project); + } + + @Nullable + @Override + public final XDebuggerEditorsProvider getEditorsProvider(@NotNull XLineBreakpoint

    breakpoint, @NotNull Project project) { + return new JavaDebuggerEditorsProvider(); + } + + @Override + public final boolean canPutAt(@NotNull VirtualFile file, final int line, @NotNull Project project) { + PsiFile psiFile = PsiManager.getInstance(project).findFile(file); + // JSPX supports jvm debugging, but not in XHTML files + if (psiFile == null || psiFile.getVirtualFile().getFileType() == StdFileTypes.XHTML) { + return false; + } + + FileType fileType = psiFile.getFileType(); + if (!StdFileTypes.CLASS.equals(fileType) && + !DebuggerUtils.supportsJVMDebugging(fileType) && + !DebuggerUtils.supportsJVMDebugging(psiFile)) { + return false; + } + + final Document document = FileDocumentManager.getInstance().getDocument(file); + final Ref> result = Ref.create(); + XDebuggerUtil.getInstance().iterateLine(project, document, line, new Processor() { + @Override + public boolean process(PsiElement element) { + // avoid comments + if ((element instanceof PsiWhiteSpace) || (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null)) { + return true; + } + // first check fields + PsiField field = PsiTreeUtil.getParentOfType(element, PsiField.class, false); + if(field != null) { + result.set(JavaFieldBreakpointType.class); + return false; + } + // then methods + PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false); + if(method != null && document.getLineNumber(method.getTextOffset()) == line) { + result.set(JavaMethodBreakpointType.class); + return false; + } + // then regular statements + PsiElement child = element; + while(element != null) { + + final int offset = element.getTextOffset(); + if (offset >= 0) { + if (document.getLineNumber(offset) != line) { + break; + } + } + child = element; + element = element.getParent(); + } + + if(child instanceof PsiMethod && child.getTextRange().getEndOffset() >= document.getLineEndOffset(line)) { + PsiCodeBlock body = ((PsiMethod)child).getBody(); + if(body != null) { + PsiStatement[] statements = body.getStatements(); + if (statements.length > 0 && document.getLineNumber(statements[0].getTextOffset()) == line) { + result.set(JavaLineBreakpointType.class); + } + } + } + else { + result.set(JavaLineBreakpointType.class); + } + return true; + } + }); + return result.get() == getClass(); + } +} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaMethodBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaMethodBreakpointType.java new file mode 100644 index 000000000000..d35983f03d2a --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaMethodBreakpointType.java @@ -0,0 +1,127 @@ +/* + * 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.debugger.ui.breakpoints; + +import com.intellij.debugger.DebuggerBundle; +import com.intellij.debugger.HelpID; +import com.intellij.icons.AllIcons; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.StringBuilderSpinAllocator; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaMethodBreakpointProperties; + +import javax.swing.*; + +/** + * @author Eugene Zhuravlev + * Date: Apr 26, 2005 + */ +public class JavaMethodBreakpointType extends JavaLineBreakpointTypeBase implements JavaBreakpointType { + public JavaMethodBreakpointType() { + super("javaMethod", DebuggerBundle.message("method.breakpoints.tab.title")); + } + + @NotNull + @Override + public Icon getEnabledIcon() { + return AllIcons.Debugger.Db_method_breakpoint; + } + + @NotNull + @Override + public Icon getDisabledIcon() { + return AllIcons.Debugger.Db_disabled_method_breakpoint; + } + + //@Override + protected String getHelpID() { + return HelpID.METHOD_BREAKPOINTS; + } + + @Override + public boolean isAddBreakpointButtonVisible() { + return false; + } + + //@Override + public String getDisplayName() { + return DebuggerBundle.message("method.breakpoints.tab.title"); + } + + @Override + public String getShortText(XLineBreakpoint breakpoint) { + return getDisplayText(breakpoint); + } + + @Override + public String getDisplayText(XLineBreakpoint breakpoint) { + return getText(breakpoint); + } + + static String getText(XBreakpoint breakpoint) { + final StringBuilder buffer = StringBuilderSpinAllocator.alloc(); + try { + //if(isValid()) { + final String className = breakpoint.getProperties().myClassPattern; + final boolean classNameExists = className != null && className.length() > 0; + if (classNameExists) { + buffer.append(className); + } + if(breakpoint.getProperties().myMethodName != null) { + if (classNameExists) { + buffer.append("."); + } + buffer.append(breakpoint.getProperties().myMethodName); + } + //} + //else { + // buffer.append(DebuggerBundle.message("status.breakpoint.invalid")); + //} + return buffer.toString(); + } + finally { + StringBuilderSpinAllocator.dispose(buffer); + } + } + + @Nullable + @Override + public XBreakpointCustomPropertiesPanel createCustomPropertiesPanel() { + return new MethodBreakpointPropertiesPanel(); + } + + @Nullable + @Override + public JavaMethodBreakpointProperties createProperties() { + return new JavaMethodBreakpointProperties(); + } + + @Nullable + @Override + public JavaMethodBreakpointProperties createBreakpointProperties(@NotNull VirtualFile file, int line) { + return new JavaMethodBreakpointProperties(); + } + + @Override + public Breakpoint createJavaBreakpoint(Project project, XBreakpoint breakpoint) { + return new MethodBreakpoint(project, breakpoint); + } +} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java new file mode 100644 index 000000000000..3d19e35fea0b --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java @@ -0,0 +1,108 @@ +/* + * 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.intellij.debugger.ui.breakpoints; + +import com.intellij.debugger.DebuggerBundle; +import com.intellij.debugger.HelpID; +import com.intellij.icons.AllIcons; +import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.project.Project; +import com.intellij.xdebugger.XDebuggerManager; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaMethodBreakpointProperties; + +import javax.swing.*; + +/** + * @author Egor + */ +public class JavaWildcardMethodBreakpointType extends JavaBreakpointTypeBase implements JavaBreakpointType { + public JavaWildcardMethodBreakpointType() { + super("javaWildcardMethod", DebuggerBundle.message("method.breakpoints.tab.title")); + } + + @NotNull + @Override + public Icon getEnabledIcon() { + return AllIcons.Debugger.Db_method_breakpoint; + } + + @NotNull + @Override + public Icon getDisabledIcon() { + return AllIcons.Debugger.Db_disabled_method_breakpoint; + } + + //@Override + protected String getHelpID() { + return HelpID.METHOD_BREAKPOINTS; + } + + //@Override + public String getDisplayName() { + return DebuggerBundle.message("method.breakpoints.tab.title"); + } + + @Override + public String getDisplayText(XBreakpoint breakpoint) { + return JavaMethodBreakpointType.getText(breakpoint); + } + + @Nullable + @Override + public XBreakpointCustomPropertiesPanel> createCustomPropertiesPanel() { + return new MethodBreakpointPropertiesPanel(); + } + + //@Override + //public Key getBreakpointCategory() { + // return MethodBreakpoint.CATEGORY; + //} + + @Nullable + @Override + public JavaMethodBreakpointProperties createProperties() { + return new JavaMethodBreakpointProperties(); + } + + @Nullable + @Override + public XBreakpoint addBreakpoint(Project project, JComponent parentComponent) { + AddWildcardBreakpointDialog dialog = new AddWildcardBreakpointDialog(project); + dialog.show(); + if (!dialog.isOK()) { + return null; + } + AccessToken token = WriteAction.start(); + try { + return XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpoint(this, new JavaMethodBreakpointProperties( + dialog.getClassPattern(), + dialog.getMethodName())); + } + finally { + token.finish(); + } + } + + @Override + public Breakpoint createJavaBreakpoint(Project project, XBreakpoint breakpoint) { + return new WildcardMethodBreakpoint(project, breakpoint); + } +} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java index 307b9629b99f..e9e78df92bdc 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java @@ -54,6 +54,7 @@ import com.intellij.util.Processor; import com.intellij.util.StringBuilderSpinAllocator; import com.intellij.util.containers.ContainerUtil; import com.intellij.xdebugger.XDebuggerUtil; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.sun.jdi.*; import com.sun.jdi.event.LocatableEvent; import com.sun.jdi.request.BreakpointRequest; @@ -74,12 +75,12 @@ public class LineBreakpoint extends BreakpointWithHighlighter { private String myOwnerMethodName; public static final @NonNls Key CATEGORY = BreakpointCategory.lookup("line_breakpoints"); - protected LineBreakpoint(Project project) { - super(project); + protected LineBreakpoint(Project project, XBreakpoint xBreakpoint) { + super(project, xBreakpoint); } - public LineBreakpoint(Project project, RangeHighlighter highlighter) { - super(project, highlighter); + public LineBreakpoint(Project project, RangeHighlighter highlighter, XBreakpoint xBreakpoint) { + super(project, highlighter, xBreakpoint); } @Override @@ -95,7 +96,7 @@ public class LineBreakpoint extends BreakpointWithHighlighter { @Override protected Icon getSetIcon(boolean isMuted) { - if (REMOVE_AFTER_HIT) { + if (isRemoveAfterHit()) { return isMuted ? AllIcons.Debugger.Db_muted_temporary_breakpoint : AllIcons.Debugger.Db_temporary_breakpoint; } return isMuted? AllIcons.Debugger.Db_muted_breakpoint : AllIcons.Debugger.Db_set_breakpoint; @@ -108,7 +109,7 @@ public class LineBreakpoint extends BreakpointWithHighlighter { @Override protected Icon getVerifiedIcon(boolean isMuted) { - if (REMOVE_AFTER_HIT) { + if (isRemoveAfterHit()) { return isMuted ? AllIcons.Debugger.Db_muted_temporary_breakpoint : AllIcons.Debugger.Db_temporary_breakpoint; } return isMuted? AllIcons.Debugger.Db_muted_verified_breakpoint : AllIcons.Debugger.Db_verified_breakpoint; @@ -349,9 +350,8 @@ public class LineBreakpoint extends BreakpointWithHighlighter { } private String getDisplayInfoInternal(boolean showPackageInfo, int totalTextLength) { - final RangeHighlighter highlighter = getHighlighter(); - if(highlighter != null && highlighter.isValid() && isValid()) { - final int lineNumber = (highlighter.getDocument().getLineNumber(highlighter.getStartOffset()) + 1); + if(isValid()) { + final int lineNumber = getSourcePosition().getLine() + 1; String className = getClassName(); final boolean hasClassInfo = className != null && className.length() > 0; final String methodName = getMethodName(); @@ -471,24 +471,24 @@ public class LineBreakpoint extends BreakpointWithHighlighter { return ContextUtil.getContextElement(getSourcePosition()); } - public static LineBreakpoint create(@NotNull Project project, @NotNull Document document, int lineIndex) { + public static LineBreakpoint create(@NotNull Project project, @NotNull Document document, int lineIndex, XBreakpoint xBreakpoint) { final RangeHighlighter highlighter = createHighlighter(project, document, lineIndex); if (highlighter == null) { return null; } - LineBreakpoint breakpoint = new LineBreakpoint(project, highlighter); + LineBreakpoint breakpoint = new LineBreakpoint(project, highlighter, xBreakpoint); return (LineBreakpoint)breakpoint.init(); } - @Override - public boolean canMoveTo(SourcePosition position) { - if (!super.canMoveTo(position)) { - return false; - } - final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(position.getFile()); - return canAddLineBreakpoint(myProject, document, position.getLine()); - } + //@Override + //public boolean canMoveTo(SourcePosition position) { + // if (!super.canMoveTo(position)) { + // return false; + // } + // final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(position.getFile()); + // return canAddLineBreakpoint(myProject, document, position.getLine()); + //} public static boolean canAddLineBreakpoint(Project project, final Document document, final int lineIndex) { if (lineIndex < 0 || lineIndex >= document.getLineCount()) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpointFactory.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpointFactory.java deleted file mode 100644 index 0042074dc798..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpointFactory.java +++ /dev/null @@ -1,66 +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.debugger.ui.breakpoints; - -import com.intellij.debugger.DebuggerBundle; -import com.intellij.debugger.HelpID; -import com.intellij.icons.AllIcons; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; -import org.jdom.Element; - -import javax.swing.*; - -/** - * @author Eugene Zhuravlev - * Date: Apr 26, 2005 - */ -public class LineBreakpointFactory extends BreakpointFactory { - @Override - public Breakpoint createBreakpoint(Project project, final Element element) { - return new LineBreakpoint(project); - } - - @Override - public Icon getIcon() { - return AllIcons.Debugger.Db_set_breakpoint; - } - - @Override - public Icon getDisabledIcon() { - return AllIcons.Debugger.Db_disabled_breakpoint; - } - - @Override - protected String getHelpID() { - return HelpID.LINE_BREAKPOINTS; - } - - @Override - public String getDisplayName() { - return DebuggerBundle.message("line.breakpoints.tab.title"); - } - - @Override - public BreakpointPropertiesPanel createBreakpointPropertiesPanel(Project project, boolean compact) { - return new LineBreakpointPropertiesPanel(project, compact); - } - - @Override - public Key getBreakpointCategory() { - return LineBreakpoint.CATEGORY; - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java index 90a839d425d4..3d7f1ff019a0 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java @@ -35,13 +35,20 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.markup.RangeHighlighter; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.Processor; import com.intellij.util.StringBuilderSpinAllocator; import com.intellij.util.text.CharArrayUtil; +import com.intellij.xdebugger.XDebuggerUtil; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.sun.jdi.AbsentInformationException; import com.sun.jdi.Location; import com.sun.jdi.Method; @@ -55,28 +62,25 @@ import com.sun.jdi.request.MethodExitRequest; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaMethodBreakpointProperties; import javax.swing.*; import java.util.Iterator; import java.util.Set; -public class MethodBreakpoint extends BreakpointWithHighlighter { +public class MethodBreakpoint extends BreakpointWithHighlighter { private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.breakpoints.MethodBreakpoint"); - public boolean WATCH_ENTRY = true; - public boolean WATCH_EXIT = true; - - @Nullable private String myMethodName; @Nullable private JVMName mySignature; private boolean myIsStatic; public static final @NonNls Key CATEGORY = BreakpointCategory.lookup("method_breakpoints"); - protected MethodBreakpoint(@NotNull Project project) { - super(project); + protected MethodBreakpoint(@NotNull Project project, XBreakpoint breakpoint) { + super(project, breakpoint); } private MethodBreakpoint(@NotNull Project project, @NotNull RangeHighlighter highlighter) { - super(project, highlighter); + super(project, highlighter, null); } public boolean isStatic() { @@ -104,21 +108,21 @@ public class MethodBreakpoint extends BreakpointWithHighlighter { } public boolean isValid() { - return super.isValid() && myMethodName != null; + return super.isValid() && getMethodName() != null; } protected void reload(@NotNull PsiFile psiFile) { - myMethodName = null; + setMethodName(null); mySignature = null; MethodDescriptor descriptor = getMethodDescriptor(myProject, psiFile, getSourcePosition()); if (descriptor != null) { - myMethodName = descriptor.methodName; + setMethodName(descriptor.methodName); mySignature = descriptor.methodSignature; myIsStatic = descriptor.isStatic; } if (myIsStatic) { - INSTANCE_FILTERS_ENABLED = false; + setInstanceFiltersEnabled(false); } } @@ -130,7 +134,7 @@ public class MethodBreakpoint extends BreakpointWithHighlighter { String signature = method.signature(); String name = method.name(); - if (myMethodName.equals(name) && mySignature.getName(debugProcess).equals(signature)) { + if (getMethodName().equals(name) && mySignature.getName(debugProcess).equals(signature)) { hasMethod = true; break; } @@ -144,7 +148,7 @@ public class MethodBreakpoint extends BreakpointWithHighlighter { } RequestManagerImpl requestManager = debugProcess.getRequestsManager(); - if (WATCH_ENTRY) { + if (isWATCH_ENTRY()) { MethodEntryRequest entryRequest = (MethodEntryRequest)findRequest(debugProcess, MethodEntryRequest.class); if (entryRequest == null) { entryRequest = requestManager.createMethodEntryRequest(this); @@ -157,7 +161,7 @@ public class MethodBreakpoint extends BreakpointWithHighlighter { entryRequest.addClassFilter(classType); debugProcess.getRequestsManager().enableRequest(entryRequest); } - if (WATCH_EXIT) { + if (isWATCH_EXIT()) { MethodExitRequest exitRequest = (MethodExitRequest)findRequest(debugProcess, MethodExitRequest.class); if (exitRequest == null) { exitRequest = requestManager.createMethodExitRequest(this); @@ -256,11 +260,11 @@ public class MethodBreakpoint extends BreakpointWithHighlighter { if (classNameExists) { buffer.append(className); } - if(myMethodName != null) { + if(getMethodName() != null) { if (classNameExists) { buffer.append("."); } - buffer.append(myMethodName); + buffer.append(getMethodName()); } } else { @@ -281,15 +285,15 @@ public class MethodBreakpoint extends BreakpointWithHighlighter { } public boolean matchesEvent(@NotNull final LocatableEvent event, final DebugProcessImpl process) throws EvaluateException { - if (myMethodName == null || mySignature == null) { + if (getMethodName() == null || mySignature == null) { return false; } final Method method = event.location().method(); - return method != null && method.name().equals(myMethodName) && method.signature().equals(mySignature.getName(process)); + return method != null && method.name().equals(getMethodName()) && method.signature().equals(mySignature.getName(process)); } @Nullable - public static MethodBreakpoint create(@NotNull Project project, @NotNull Document document, int lineIndex) { + public static MethodBreakpoint create(@NotNull Project project, @NotNull Document document, int lineIndex, XBreakpoint xBreakpoint) { final MethodBreakpoint breakpoint = new MethodBreakpoint(project, createHighlighter(project, document, lineIndex)); return (MethodBreakpoint)breakpoint.init(); } @@ -376,6 +380,31 @@ public class MethodBreakpoint extends BreakpointWithHighlighter { return false; } + public boolean isWATCH_ENTRY() { + return getProperties().WATCH_ENTRY; + } + + public void setWATCH_ENTRY(boolean WATCH_ENTRY) { + getProperties().WATCH_ENTRY = WATCH_ENTRY; + } + + public boolean isWATCH_EXIT() { + return getProperties().WATCH_EXIT; + } + + public void setWATCH_EXIT(boolean WATCH_EXIT) { + getProperties().WATCH_EXIT = WATCH_EXIT; + } + + @Nullable + public String getMethodName() { + return getProperties().myMethodName; + } + + public void setMethodName(@Nullable String methodName) { + getProperties().myMethodName = methodName; + } + private static final class MethodDescriptor { String methodName; JVMName methodSignature; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointFactory.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointFactory.java deleted file mode 100644 index a08e2a123ae6..000000000000 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointFactory.java +++ /dev/null @@ -1,84 +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.debugger.ui.breakpoints; - -import com.intellij.debugger.DebuggerBundle; -import com.intellij.debugger.DebuggerManagerEx; -import com.intellij.debugger.HelpID; -import com.intellij.icons.AllIcons; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; -import org.jdom.Element; - -import javax.swing.*; - -/** - * @author Eugene Zhuravlev - * Date: Apr 26, 2005 - */ -public class MethodBreakpointFactory extends BreakpointFactory{ - @Override - public Breakpoint createBreakpoint(Project project, final Element element) { - return element.getAttributeValue(WildcardMethodBreakpoint.JDOM_LABEL) != null? new WildcardMethodBreakpoint(project) : new MethodBreakpoint(project); - } - - @Override - public Icon getIcon() { - return AllIcons.Debugger.Db_method_breakpoint; - } - - @Override - public Icon getDisabledIcon() { - return AllIcons.Debugger.Db_disabled_method_breakpoint; - } - - @Override - protected String getHelpID() { - return HelpID.METHOD_BREAKPOINTS; - } - - @Override - public String getDisplayName() { - return DebuggerBundle.message("method.breakpoints.tab.title"); - } - - @Override - public BreakpointPropertiesPanel createBreakpointPropertiesPanel(Project project, boolean compact) { - return new MethodBreakpointPropertiesPanel(project, compact); - } - - @Override - public Key getBreakpointCategory() { - return MethodBreakpoint.CATEGORY; - } - - @Override - public boolean canAddBreakpoints() { - return true; - } - - @Override - public WildcardMethodBreakpoint addBreakpoint(Project project) { - AddWildcardBreakpointDialog dialog = new AddWildcardBreakpointDialog(project); - dialog.show(); - WildcardMethodBreakpoint methodBreakpoint; - methodBreakpoint = !dialog.isOK() - ? null - : DebuggerManagerEx.getInstanceEx(project).getBreakpointManager() - .addMethodBreakpoint(dialog.getClassPattern(), dialog.getMethodName()); - return methodBreakpoint; - } -} diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointPropertiesPanel.java index c50b6995d038..bf7419264105 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpointPropertiesPanel.java @@ -21,24 +21,30 @@ package com.intellij.debugger.ui.breakpoints; import com.intellij.debugger.DebuggerBundle; -import com.intellij.openapi.project.Project; import com.intellij.ui.IdeBorderFactory; import com.intellij.util.ui.DialogUtil; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.java.debugger.breakpoints.properties.JavaMethodBreakpointProperties; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -public class MethodBreakpointPropertiesPanel extends BreakpointPropertiesPanel { +public class MethodBreakpointPropertiesPanel extends XBreakpointCustomPropertiesPanel> { private JCheckBox myWatchEntryCheckBox; private JCheckBox myWatchExitCheckBox; - public MethodBreakpointPropertiesPanel(final Project project, boolean compact) { - super(project, MethodBreakpoint.CATEGORY, compact); - } + //public MethodBreakpointPropertiesPanel(final Project project, boolean compact) { + // super(project, MethodBreakpoint.CATEGORY, compact); + //} - protected JComponent createSpecialBox() { + + @NotNull + @Override + public JComponent getComponent() { JPanel _panel, _panel0; myWatchEntryCheckBox = new JCheckBox(DebuggerBundle.message("label.method.breakpoint.properties.panel.method.entry")); @@ -86,31 +92,15 @@ public class MethodBreakpointPropertiesPanel extends BreakpointPropertiesPanel { return _panel; } - public void initFrom(Breakpoint breakpoint, boolean moreOptionsVisible) { - super.initFrom(breakpoint, moreOptionsVisible); - if (breakpoint instanceof MethodBreakpoint) { - MethodBreakpoint methodBreakpoint = (MethodBreakpoint)breakpoint; - myWatchEntryCheckBox.setSelected(methodBreakpoint.WATCH_ENTRY); - myWatchExitCheckBox.setSelected(methodBreakpoint.WATCH_EXIT); - } - else if (breakpoint instanceof WildcardMethodBreakpoint){ - final WildcardMethodBreakpoint methodBreakpoint = ((WildcardMethodBreakpoint)breakpoint); - myWatchEntryCheckBox.setSelected(methodBreakpoint.WATCH_ENTRY); - myWatchExitCheckBox.setSelected(methodBreakpoint.WATCH_EXIT); - } + @Override + public void loadFrom(@NotNull XBreakpoint breakpoint) { + myWatchEntryCheckBox.setSelected(breakpoint.getProperties().WATCH_ENTRY); + myWatchExitCheckBox.setSelected(breakpoint.getProperties().WATCH_EXIT); } - public void saveTo(Breakpoint breakpoint) { - if (breakpoint instanceof MethodBreakpoint) { - MethodBreakpoint methodBreakpoint = (MethodBreakpoint)breakpoint; - methodBreakpoint.WATCH_ENTRY = myWatchEntryCheckBox.isSelected(); - methodBreakpoint.WATCH_EXIT = myWatchExitCheckBox.isSelected(); - } - else if (breakpoint instanceof WildcardMethodBreakpoint){ - final WildcardMethodBreakpoint methodBreakpoint = ((WildcardMethodBreakpoint)breakpoint); - methodBreakpoint.WATCH_ENTRY = myWatchEntryCheckBox.isSelected(); - methodBreakpoint.WATCH_EXIT = myWatchExitCheckBox.isSelected(); - } - super.saveTo(breakpoint); + @Override + public void saveTo(@NotNull XBreakpoint breakpoint) { + breakpoint.getProperties().WATCH_ENTRY = myWatchEntryCheckBox.isSelected(); + breakpoint.getProperties().WATCH_EXIT = myWatchExitCheckBox.isSelected(); } } \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/RunToCursorBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/RunToCursorBreakpoint.java index 82f617a14f6b..a103ddcc2709 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/RunToCursorBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/RunToCursorBreakpoint.java @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,15 +35,15 @@ public class RunToCursorBreakpoint extends LineBreakpoint { @Nullable private final SourcePosition myCustomPosition; - protected RunToCursorBreakpoint(@NotNull Project project, @NotNull RangeHighlighter highlighter, boolean restoreBreakpoints) { - super(project, highlighter); + protected RunToCursorBreakpoint(@NotNull Project project, @NotNull RangeHighlighter highlighter, boolean restoreBreakpoints, XBreakpoint xBreakpoint) { + super(project, highlighter, xBreakpoint); setVisible(false); myRestoreBreakpoints = restoreBreakpoints; myCustomPosition = null; } - protected RunToCursorBreakpoint(@NotNull Project project, @NotNull SourcePosition pos, boolean restoreBreakpoints) { - super(project); + protected RunToCursorBreakpoint(@NotNull Project project, @NotNull SourcePosition pos, boolean restoreBreakpoints, XBreakpoint xBreakpoint) { + super(project, xBreakpoint); myCustomPosition = pos; setVisible(false); myRestoreBreakpoints = restoreBreakpoints; @@ -68,7 +69,7 @@ public class RunToCursorBreakpoint extends LineBreakpoint { } @Nullable - protected static RunToCursorBreakpoint create(@NotNull Project project, @NotNull Document document, int lineIndex, boolean restoreBreakpoints) { + protected static RunToCursorBreakpoint create(@NotNull Project project, @NotNull Document document, int lineIndex, boolean restoreBreakpoints, XBreakpoint xBreakpoint) { VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document); if (virtualFile == null) { return null; @@ -79,7 +80,7 @@ public class RunToCursorBreakpoint extends LineBreakpoint { return null; } - final RunToCursorBreakpoint breakpoint = new RunToCursorBreakpoint(project, highlighter, restoreBreakpoints); + final RunToCursorBreakpoint breakpoint = new RunToCursorBreakpoint(project, highlighter, restoreBreakpoints, xBreakpoint); final RangeHighlighter h = breakpoint.getHighlighter(); if (h != null) { h.dispose(); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java index 6e39e5ac1d29..fd575177d273 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/StepIntoBreakpoint.java @@ -41,7 +41,7 @@ public class StepIntoBreakpoint extends RunToCursorBreakpoint { private final BreakpointStepMethodFilter myFilter; StepIntoBreakpoint(@NotNull Project project, @NotNull SourcePosition pos, @NotNull BreakpointStepMethodFilter filter) { - super(project, pos, false); + super(project, pos, false, null); myFilter = filter; } @@ -153,7 +153,7 @@ public class StepIntoBreakpoint extends RunToCursorBreakpoint { if (pos != null) { final StepIntoBreakpoint breakpoint = new StepIntoBreakpoint(project, pos, filter); breakpoint.init(); - breakpoint.LOG_ENABLED = false; + breakpoint.setLogEnabled(false); return breakpoint; } return null; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/WildcardMethodBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/WildcardMethodBreakpoint.java index f6c0dc3c3ab2..3e3553520193 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/WildcardMethodBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/WildcardMethodBreakpoint.java @@ -32,6 +32,7 @@ import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.util.StringBuilderSpinAllocator; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.sun.jdi.AbsentInformationException; import com.sun.jdi.Location; import com.sun.jdi.Method; @@ -45,37 +46,33 @@ import com.sun.jdi.request.MethodExitRequest; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaMethodBreakpointProperties; import javax.swing.*; import java.util.Iterator; import java.util.Set; -public class WildcardMethodBreakpoint extends Breakpoint { +public class WildcardMethodBreakpoint extends Breakpoint { private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.breakpoints.ExceptionBreakpoint"); - public boolean WATCH_ENTRY = true; - public boolean WATCH_EXIT = true; - private String myClassPattern; - private String myMethodName; - public static final String JDOM_LABEL = "wildcard_breakpoint"; - public WildcardMethodBreakpoint(Project project) { - super(project); + public WildcardMethodBreakpoint(Project project, XBreakpoint breakpoint) { + super(project, breakpoint); } public Key getCategory() { return MethodBreakpoint.CATEGORY; } - protected WildcardMethodBreakpoint(Project project, @NotNull String classPattern, @NotNull String methodName) { - super(project); - myClassPattern = classPattern; - myMethodName = methodName; + protected WildcardMethodBreakpoint(Project project, @NotNull String classPattern, @NotNull String methodName, XBreakpoint breakpoint) { + super(project, breakpoint); + setClassPattern(classPattern); + setMethodName(methodName); } public String getClassName() { - return myClassPattern; + return getClassPattern(); } public @Nullable String getShortClassName() { @@ -83,7 +80,7 @@ public class WildcardMethodBreakpoint extends Breakpoint { } public String getMethodName() { - return myMethodName; + return getProperties().myMethodName; } public PsiClass getPsiClass() { @@ -96,9 +93,9 @@ public class WildcardMethodBreakpoint extends Breakpoint { } final StringBuilder buffer = StringBuilderSpinAllocator.alloc(); try { - buffer.append(myClassPattern); + buffer.append(getClassPattern()); buffer.append("."); - buffer.append(myMethodName); + buffer.append(getMethodName()); buffer.append("()"); return buffer.toString(); } @@ -108,7 +105,7 @@ public class WildcardMethodBreakpoint extends Breakpoint { } public Icon getIcon() { - if (!ENABLED) { + if (!isEnabled()) { final Breakpoint master = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().findMasterBreakpoint(this); return master == null? AllIcons.Debugger.Db_disabled_method_breakpoint : AllIcons.Debugger.Db_dep_method_breakpoint; } @@ -124,12 +121,12 @@ public class WildcardMethodBreakpoint extends Breakpoint { public void createRequest(DebugProcessImpl debugProcess) { DebuggerManagerThreadImpl.assertIsManagerThread(); - if (!ENABLED || !debugProcess.isAttached() || debugProcess.areBreakpointsMuted() || !debugProcess.getRequestsManager().findRequests(this).isEmpty()) { + if (!isEnabled() || !debugProcess.isAttached() || debugProcess.areBreakpointsMuted() || !debugProcess.getRequestsManager().findRequests(this).isEmpty()) { return; } try { RequestManagerImpl requestManager = debugProcess.getRequestsManager(); - if (WATCH_ENTRY) { + if (isWATCH_ENTRY()) { MethodEntryRequest entryRequest = (MethodEntryRequest)findRequest(debugProcess, MethodEntryRequest.class); if (entryRequest == null) { entryRequest = requestManager.createMethodEntryRequest(this); @@ -137,10 +134,10 @@ public class WildcardMethodBreakpoint extends Breakpoint { else { entryRequest.disable(); } - entryRequest.addClassFilter(myClassPattern); + entryRequest.addClassFilter(getClassPattern()); debugProcess.getRequestsManager().enableRequest(entryRequest); } - if (WATCH_EXIT) { + if (isWATCH_EXIT()) { MethodExitRequest exitRequest = (MethodExitRequest)findRequest(debugProcess, MethodExitRequest.class); if (exitRequest == null) { exitRequest = requestManager.createMethodExitRequest(this); @@ -148,7 +145,7 @@ public class WildcardMethodBreakpoint extends Breakpoint { else { exitRequest.disable(); } - exitRequest.addClassFilter(myClassPattern); + exitRequest.addClassFilter(getClassPattern()); debugProcess.getRequestsManager().enableRequest(exitRequest); } } @@ -212,46 +209,74 @@ public class WildcardMethodBreakpoint extends Breakpoint { } public boolean isValid() { - return myClassPattern != null && myMethodName != null; + return getClassPattern() != null && getMethodName() != null; } - @SuppressWarnings({"HardCodedStringLiteral"}) public void writeExternal(Element parentNode) throws WriteExternalException { - super.writeExternal(parentNode); - parentNode.setAttribute(JDOM_LABEL, "true"); - if (myClassPattern != null) { - parentNode.setAttribute("class_name", myClassPattern); - } - if (myMethodName != null) { - parentNode.setAttribute("method_name", myMethodName); - } - } + //@SuppressWarnings({"HardCodedStringLiteral"}) public void writeExternal(Element parentNode) throws WriteExternalException { + // super.writeExternal(parentNode); + // parentNode.setAttribute(JDOM_LABEL, "true"); + // if (getClassPattern() != null) { + // parentNode.setAttribute("class_name", getClassPattern()); + // } + // if (getMethodName() != null) { + // parentNode.setAttribute("method_name", getMethodName()); + // } + //} public PsiElement getEvaluationElement() { return null; } - public void readExternal(Element parentNode) throws InvalidDataException { - super.readExternal(parentNode); - - //noinspection HardCodedStringLiteral - String className = parentNode.getAttributeValue("class_name"); - myClassPattern = className; - - //noinspection HardCodedStringLiteral - String methodName = parentNode.getAttributeValue("method_name"); - myMethodName = methodName; - - if(className == null || methodName == null) { - throw new InvalidDataException(); - } - } + //public void readExternal(Element parentNode) throws InvalidDataException { + // super.readExternal(parentNode); + // + // //noinspection HardCodedStringLiteral + // String className = parentNode.getAttributeValue("class_name"); + // setClassPattern(className); + // + // //noinspection HardCodedStringLiteral + // String methodName = parentNode.getAttributeValue("method_name"); + // setMethodName(methodName); + // + // if(className == null || methodName == null) { + // throw new InvalidDataException(); + // } + //} public boolean matchesEvent(final LocatableEvent event){ final Method method = event.location().method(); - return method != null && myMethodName.equals(method.name()); + return method != null && getMethodName().equals(method.name()); } - public static WildcardMethodBreakpoint create(Project project, final String classPattern, final String methodName) { - return new WildcardMethodBreakpoint(project, classPattern, methodName); + public static WildcardMethodBreakpoint create(Project project, final String classPattern, final String methodName, XBreakpoint xBreakpoint) { + return new WildcardMethodBreakpoint(project, classPattern, methodName, xBreakpoint); + } + + public boolean isWATCH_ENTRY() { + return getProperties().WATCH_ENTRY; + } + + public void setWATCH_ENTRY(boolean WATCH_ENTRY) { + getProperties().WATCH_ENTRY = WATCH_ENTRY; + } + + public boolean isWATCH_EXIT() { + return getProperties().WATCH_EXIT; + } + + public void setWATCH_EXIT(boolean WATCH_EXIT) { + getProperties().WATCH_EXIT = WATCH_EXIT; + } + + public String getClassPattern() { + return getProperties().myClassPattern; + } + + public void setClassPattern(String classPattern) { + getProperties().myClassPattern = classPattern; + } + + public void setMethodName(String methodName) { + getProperties().myMethodName = methodName; } } diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointAdapter.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointAdapter.java deleted file mode 100644 index a6705848a44d..000000000000 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointAdapter.java +++ /dev/null @@ -1,157 +0,0 @@ -package org.jetbrains.java.debugger.breakpoints; - -import com.intellij.debugger.engine.evaluation.CodeFragmentKind; -import com.intellij.debugger.engine.evaluation.TextWithImportsImpl; -import com.intellij.debugger.engine.requests.RequestManagerImpl; -import com.intellij.debugger.settings.DebuggerSettings; -import com.intellij.debugger.ui.breakpoints.LineBreakpoint; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.markup.RangeHighlighter; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.xdebugger.breakpoints.XBreakpointProperties; -import com.intellij.xdebugger.breakpoints.XLineBreakpoint; -import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; - -public class JavaBreakpointAdapter extends JavaBreakpointAdapterBase { - private static final Key OLD_JAVA_BREAKPOINT_KEY = Key.create("oldJavaBreakpoint"); - - public JavaBreakpointAdapter(Project project) { - super(project); - } - - @Override - protected void configureCreatedBreakpoint(LineBreakpoint oldBreakpoint, XLineBreakpoint breakpoint) { - oldBreakpoint.SUSPEND_POLICY = transformSuspendPolicy(breakpoint); - applyCondition(oldBreakpoint, breakpoint); - applyFilters(oldBreakpoint, breakpoint); - } - - private boolean applyFilters(LineBreakpoint oldBreakpoint, XLineBreakpoint breakpoint) { - boolean changed = false; - JavaBreakpointProperties properties = (JavaBreakpointProperties)breakpoint.getProperties(); - - changed |= oldBreakpoint.COUNT_FILTER_ENABLED != properties.COUNT_FILTER_ENABLED; - oldBreakpoint.COUNT_FILTER_ENABLED = properties.COUNT_FILTER_ENABLED; - - changed |= oldBreakpoint.COUNT_FILTER != properties.COUNT_FILTER; - oldBreakpoint.COUNT_FILTER = properties.COUNT_FILTER; - - changed |= oldBreakpoint.CLASS_FILTERS_ENABLED != properties.CLASS_FILTERS_ENABLED; - oldBreakpoint.CLASS_FILTERS_ENABLED = properties.CLASS_FILTERS_ENABLED; - - changed |= !Arrays.equals(oldBreakpoint.getClassFilters(), properties.getClassFilters()); - oldBreakpoint.setClassFilters(properties.getClassFilters()); - - changed |= !Arrays.equals(oldBreakpoint.getClassExclusionFilters(), properties.getClassExclusionFilters()); - oldBreakpoint.setClassExclusionFilters(properties.getClassExclusionFilters()); - - changed |= oldBreakpoint.INSTANCE_FILTERS_ENABLED != properties.INSTANCE_FILTERS_ENABLED; - oldBreakpoint.INSTANCE_FILTERS_ENABLED = properties.INSTANCE_FILTERS_ENABLED; - - changed |= !Arrays.equals(oldBreakpoint.getInstanceFilters(), properties.getInstanceFilters()); - oldBreakpoint.setInstanceFilters(properties.getInstanceFilters()); - - return changed; - } - - private static void applyCondition(LineBreakpoint oldBreakpoint, XLineBreakpoint breakpoint) { - if (breakpoint.getCondition() != null) { - oldBreakpoint.CONDITION_ENABLED = true; - oldBreakpoint.setCondition(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, breakpoint.getCondition())); - } - else { - oldBreakpoint.CONDITION_ENABLED = false; - if (!StringUtil.isEmptyOrSpaces(oldBreakpoint.getCondition().getText())) { - oldBreakpoint.setCondition(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, "")); - } - } - } - - @Override - protected void updateBreakpoint(LineBreakpoint jBreakpoint, XLineBreakpoint breakpoint) { - boolean changed = false; - if (jBreakpoint.ENABLED != breakpoint.isEnabled()) { - jBreakpoint.ENABLED = breakpoint.isEnabled(); - changed = true; - } - - String suspendPolicy = transformSuspendPolicy(breakpoint); - if (jBreakpoint.SUSPEND_POLICY != suspendPolicy) { - jBreakpoint.SUSPEND_POLICY = suspendPolicy; - changed = true; - } - - if (StringUtil.compare(breakpoint.getCondition(), jBreakpoint.getCondition().getText(), false) != 0) { - applyCondition(jBreakpoint, breakpoint); - changed = true; - } - - if (applyFilters(jBreakpoint, breakpoint)) { - changed = true; - } - - if (jBreakpoint.getSourcePosition().getLine() != breakpoint.getLine()) { - jBreakpoint.reload(); - changed = true; - } - - if (changed) { - RequestManagerImpl.updateRequests(jBreakpoint); - jBreakpoint.updateUI(); - } - } - - @Override - protected LineBreakpoint findBreakpoint(XLineBreakpoint breakpoint) { - return OLD_JAVA_BREAKPOINT_KEY.get(breakpoint); - } - - public LineBreakpoint getOrCreate(XLineBreakpoint breakpoint) { - LineBreakpoint oldBreakpoint = findBreakpoint(breakpoint); - if (oldBreakpoint == null) { - oldBreakpoint = createBreakpoint(breakpoint); - OLD_JAVA_BREAKPOINT_KEY.set(breakpoint, oldBreakpoint); - } - return oldBreakpoint; - } - - @Override - public void breakpointRemoved(@NotNull XLineBreakpoint breakpoint) { - LineBreakpoint jBreakpoint = findBreakpoint(breakpoint); - if (jBreakpoint != null) { - jBreakpoint.delete(); - } - } - - @Override - protected LineBreakpoint doCreateInstance(Project project, Document document, XLineBreakpoint breakpoint) { - LineBreakpoint lineBreakpoint = new LineBreakpoint(project, ((XLineBreakpointImpl)breakpoint).getHighlighter()) { - @Override - protected void setEditorFilter(RangeHighlighter highlighter) { - } - }; - - lineBreakpoint.setVisible(false); - lineBreakpoint.init(); - return lineBreakpoint; - } - - private static String transformSuspendPolicy(XLineBreakpoint breakpoint) { - switch (breakpoint.getSuspendPolicy()) { - case ALL: - return DebuggerSettings.SUSPEND_ALL; - case THREAD: - return DebuggerSettings.SUSPEND_THREAD; - case NONE: - return DebuggerSettings.SUSPEND_NONE; - - default: - throw new IllegalArgumentException("unknown suspend policy"); - } - } -} diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointAdapterBase.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointAdapterBase.java index 6b249356d340..2f92c7c12428 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointAdapterBase.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointAdapterBase.java @@ -56,11 +56,11 @@ public abstract class JavaBreakpointAdapterBase extends XBreakpointAdapter breakpoint) { - return LineBreakpoint.create(project, document, breakpoint.getLine()); + protected LineBreakpoint doCreateInstance(Project project, Document document, XLineBreakpoint xBreakpoint) { + return LineBreakpoint.create(project, document, xBreakpoint.getLine(), xBreakpoint); } } diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointPropertiesPanel.form b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.form similarity index 99% rename from java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointPropertiesPanel.form rename to java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.form index db560b3feaeb..39507678f8ff 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointPropertiesPanel.form +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.form @@ -1,5 +1,5 @@ -

    + diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointPropertiesPanel.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.java similarity index 94% rename from java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointPropertiesPanel.java rename to java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.java index e575973ea0ba..2afcf0fd339f 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointFiltersPanel.java @@ -26,11 +26,11 @@ import com.intellij.ui.FieldPanel; import com.intellij.ui.MultiLineTooltipUI; import com.intellij.ui.classFilter.ClassFilter; import com.intellij.xdebugger.XSourcePosition; -import com.intellij.xdebugger.breakpoints.XBreakpointProperties; -import com.intellij.xdebugger.breakpoints.XLineBreakpoint; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; import javax.swing.*; import java.awt.*; @@ -44,7 +44,7 @@ import java.util.List; /** * @author egor */ -public class JavaBreakpointPropertiesPanel extends XBreakpointCustomPropertiesPanel> { +public class JavaBreakpointFiltersPanel> extends XBreakpointCustomPropertiesPanel { private JPanel myConditionsPanel; private JPanel myInstanceFiltersPanel; private JCheckBox myInstanceFiltersCheckBox; @@ -66,7 +66,7 @@ public class JavaBreakpointPropertiesPanel extends XBreakpointCustomPropertiesPa private PsiClass myBreakpointPsiClass; - public JavaBreakpointPropertiesPanel(Project project) { + public JavaBreakpointFiltersPanel(Project project) { myProject = project; myInstanceFiltersField = new FieldPanel(new MyTextField(), "", null, new ActionListener() { @@ -135,8 +135,8 @@ public class JavaBreakpointPropertiesPanel extends XBreakpointCustomPropertiesPa } @Override - public boolean isVisibleOnPopup(@NotNull XLineBreakpoint breakpoint) { - JavaBreakpointProperties properties = (JavaBreakpointProperties)breakpoint.getProperties(); + public boolean isVisibleOnPopup(@NotNull B breakpoint) { + JavaBreakpointProperties properties = breakpoint.getProperties(); if (properties != null) { return properties.COUNT_FILTER_ENABLED || properties.CLASS_FILTERS_ENABLED || properties.INSTANCE_FILTERS_ENABLED; } @@ -144,8 +144,8 @@ public class JavaBreakpointPropertiesPanel extends XBreakpointCustomPropertiesPa } @Override - public void saveTo(@NotNull XLineBreakpoint breakpoint) { - JavaBreakpointProperties properties = (JavaBreakpointProperties)breakpoint.getProperties(); + public void saveTo(@NotNull B breakpoint) { + JavaBreakpointProperties properties = breakpoint.getProperties(); if (properties == null) { return; } @@ -179,8 +179,8 @@ public class JavaBreakpointPropertiesPanel extends XBreakpointCustomPropertiesPa } @Override - public void loadFrom(@NotNull XLineBreakpoint breakpoint) { - JavaBreakpointProperties properties = (JavaBreakpointProperties)breakpoint.getProperties(); + public void loadFrom(@NotNull B breakpoint) { + JavaBreakpointProperties properties = breakpoint.getProperties(); if (properties != null) { if (properties.COUNT_FILTER > 0) { myPassCountField.setText(Integer.toString(properties.COUNT_FILTER)); diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointType.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointType.java deleted file mode 100644 index 5e55a49658f8..000000000000 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointType.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.jetbrains.java.debugger.breakpoints; - -import com.intellij.debugger.DebuggerBundle; -import com.intellij.debugger.engine.DebuggerUtils; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.StdFileTypes; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; -import com.intellij.util.SystemProperties; -import com.intellij.xdebugger.XDebuggerUtil; -import com.intellij.xdebugger.breakpoints.XBreakpointProperties; -import com.intellij.xdebugger.breakpoints.XLineBreakpoint; -import com.intellij.xdebugger.breakpoints.XLineBreakpointTypeBase; -import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; -import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.java.debugger.JavaDebuggerEditorsProvider; - -import java.util.List; - -public class JavaBreakpointType extends XLineBreakpointTypeBase { - public JavaBreakpointType() { - super("java", DebuggerBundle.message("java.breakpoint.title"), new JavaDebuggerEditorsProvider()); - } - - @Override - public boolean canPutAt(@NotNull final VirtualFile file, final int line, @NotNull Project project) { - return SystemProperties.getBooleanProperty("java.debugger.xBreakpoint", false) && - doCanPutAt(PsiManager.getInstance(project).findFile(file)); - } - - @Override - public boolean isSuspendThreadSupported() { - return true; - } - - @Override - public List, ?>> getGroupingRules() { - return XDebuggerUtil.getInstance().getGroupingByFileRuleAsList(); - } - - @Contract("null -> false") - public static boolean doCanPutAt(@Nullable PsiFile psiFile) { - // JSPX supports jvm debugging, but not in XHTML files - if (psiFile == null || psiFile.getVirtualFile().getFileType() == StdFileTypes.XHTML) { - return false; - } - - FileType fileType = psiFile.getFileType(); - return StdFileTypes.CLASS.equals(fileType) || DebuggerUtils.supportsJVMDebugging(fileType) || DebuggerUtils.supportsJVMDebugging(psiFile); - } - - @Nullable - @Override - public XBreakpointProperties createProperties() { - return new JavaBreakpointProperties(); - } - - @Nullable - @Override - public XBreakpointProperties createBreakpointProperties(@NotNull VirtualFile file, int line) { - return new JavaBreakpointProperties(); - } - - @Nullable - @Override - public XBreakpointCustomPropertiesPanel> createCustomRightPropertiesPanel(@NotNull Project project) { - return new JavaBreakpointPropertiesPanel(project); - } - - -} \ No newline at end of file diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaBreakpointProperties.java similarity index 84% rename from java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointProperties.java rename to java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaBreakpointProperties.java index e2f3202a0d46..47e35bb86c15 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/JavaBreakpointProperties.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaBreakpointProperties.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.java.debugger.breakpoints; +package org.jetbrains.java.debugger.breakpoints.properties; import com.intellij.debugger.InstanceFilter; import com.intellij.ui.classFilter.ClassFilter; @@ -23,7 +23,7 @@ import org.jetbrains.annotations.Nullable; /** * @author egor */ -public class JavaBreakpointProperties extends XBreakpointProperties { +public class JavaBreakpointProperties extends XBreakpointProperties { public boolean COUNT_FILTER_ENABLED = false; public int COUNT_FILTER = 0; @@ -42,7 +42,7 @@ public class JavaBreakpointProperties extends XBreakpointProperties { + public boolean NOTIFY_CAUGHT = true; + public boolean NOTIFY_UNCAUGHT = true; + public String myQualifiedName; + public String myPackageName; + + public JavaExceptionBreakpointProperties(String qualifiedName, String packageName) { + myQualifiedName = qualifiedName; + myPackageName = packageName; + } + + public JavaExceptionBreakpointProperties() { + } + + @Nullable + @Override + public JavaExceptionBreakpointProperties getState() { + return this; + } + + @Override + public void loadState(JavaExceptionBreakpointProperties state) { + super.loadState(state); + + NOTIFY_CAUGHT = state.NOTIFY_CAUGHT; + NOTIFY_UNCAUGHT = state.NOTIFY_UNCAUGHT; + myQualifiedName = state.myQualifiedName; + myPackageName = state.myPackageName; + } +} diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java new file mode 100644 index 000000000000..4d91a2a44a6e --- /dev/null +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java @@ -0,0 +1,49 @@ +/* + * 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 org.jetbrains.java.debugger.breakpoints.properties; + +import org.jetbrains.annotations.Nullable; + +/** + * @author egor + */ +public class JavaFieldBreakpointProperties extends JavaBreakpointProperties { + public boolean WATCH_MODIFICATION = true; + public boolean WATCH_ACCESS = false; + public String myFieldName; + + public JavaFieldBreakpointProperties(String fieldName) { + myFieldName = fieldName; + } + + public JavaFieldBreakpointProperties() { + } + + @Nullable + @Override + public JavaFieldBreakpointProperties getState() { + return this; + } + + @Override + public void loadState(JavaFieldBreakpointProperties state) { + super.loadState(state); + + WATCH_MODIFICATION = state.WATCH_MODIFICATION; + WATCH_ACCESS = state.WATCH_ACCESS; + myFieldName = state.myFieldName; + } +} diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaMethodBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaMethodBreakpointProperties.java new file mode 100644 index 000000000000..a4750dbdd845 --- /dev/null +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaMethodBreakpointProperties.java @@ -0,0 +1,54 @@ +/* + * 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 org.jetbrains.java.debugger.breakpoints.properties; + +import org.jetbrains.annotations.Nullable; + +/** + * @author egor + */ +public class JavaMethodBreakpointProperties extends JavaBreakpointProperties { + public String myClassPattern; + public String myMethodName; + + public boolean WATCH_ENTRY = true; + public boolean WATCH_EXIT = true; + + public JavaMethodBreakpointProperties(String classPattern, String methodName) { + myClassPattern = classPattern; + myMethodName = methodName; + } + + public JavaMethodBreakpointProperties() { + } + + @Nullable + @Override + public JavaMethodBreakpointProperties getState() { + return this; + } + + @Override + public void loadState(JavaMethodBreakpointProperties state) { + super.loadState(state); + + myClassPattern = state.myClassPattern; + myMethodName = state.myMethodName; + + WATCH_ENTRY = state.WATCH_ENTRY; + WATCH_EXIT = state.WATCH_EXIT; + } +} diff --git a/java/testFramework/src/com/intellij/debugger/ExecutionWithDebuggerToolsTestCase.java b/java/testFramework/src/com/intellij/debugger/ExecutionWithDebuggerToolsTestCase.java index 26e0eb52d34a..e136812fd657 100644 --- a/java/testFramework/src/com/intellij/debugger/ExecutionWithDebuggerToolsTestCase.java +++ b/java/testFramework/src/com/intellij/debugger/ExecutionWithDebuggerToolsTestCase.java @@ -311,26 +311,26 @@ public abstract class ExecutionWithDebuggerToolsTestCase extends ExecutionTestCa String suspendPolicy = readValue(comment, "suspendPolicy"); if (suspendPolicy != null) { - breakpoint.SUSPEND = !DebuggerSettings.SUSPEND_NONE.equals(suspendPolicy); - breakpoint.SUSPEND_POLICY = suspendPolicy; + //breakpoint.setSuspend(!DebuggerSettings.SUSPEND_NONE.equals(suspendPolicy)); + breakpoint.setSuspendPolicy(suspendPolicy); println("SUSPEND_POLICY = " + suspendPolicy, ProcessOutputTypes.SYSTEM); } String condition = readValue(comment, "Condition"); if (condition != null) { - breakpoint.CONDITION_ENABLED = true; - breakpoint.setCondition(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, condition)); + //breakpoint.CONDITION_ENABLED = true; + breakpoint.setCondition(/*new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, */condition/*)*/); println("Condition = " + condition, ProcessOutputTypes.SYSTEM); } String passCount = readValue(comment, "Pass count"); if (passCount != null) { - breakpoint.COUNT_FILTER_ENABLED = true; - breakpoint.COUNT_FILTER = Integer.parseInt(passCount); + breakpoint.setCountFilterEnabled(true); + breakpoint.setCountFilter(Integer.parseInt(passCount)); println("Pass count = " + passCount, ProcessOutputTypes.SYSTEM); } String classFilters = readValue(comment, "Class filters"); if (classFilters != null) { - breakpoint.CLASS_FILTERS_ENABLED = true; + breakpoint.setClassFiltersEnabled(true); StringTokenizer tokenizer = new StringTokenizer(classFilters, " ,"); ArrayList lst = new ArrayList(); diff --git a/resources-en/src/messages/DebuggerBundle.properties b/resources-en/src/messages/DebuggerBundle.properties index 57e0ec144aec..1a08b7c57386 100644 --- a/resources-en/src/messages/DebuggerBundle.properties +++ b/resources-en/src/messages/DebuggerBundle.properties @@ -320,10 +320,10 @@ class.filters.dialog.exclusion.filters.group=Class Exclusion Filters instance.filters.dialog.title=Instance Filters instance.filters.dialog.instance.filters.group=Instance Filters breakpoint.exception.breakpoint.display.name=''{0}'' -exception.breakpoints.tab.title=Exception Breakpoints -field.watchpoints.tab.title=Field Watchpoints -line.breakpoints.tab.title=Line Breakpoints -method.breakpoints.tab.title=Method Breakpoints +exception.breakpoints.tab.title=Java Exception Breakpoints +field.watchpoints.tab.title=Java Field Watchpoints +line.breakpoints.tab.title=Java Line Breakpoints +method.breakpoints.tab.title=Java Method Breakpoints title.error.evaluating.breakpoint.condition=Breakpoint Condition Error title.error.evaluating.breakpoint.action=Breakpoint Action Error error.evaluating.breakpoint.condition.or.action=Problem processing VM event:\nBreakpoint: ''{0}''\nError: {1}\nWould you like to stop at the breakpoint? @@ -446,5 +446,3 @@ error.corrupt.debug.info=Debug info might be corrupt: {0} action.kill.process.text=Kill Process action.kill.process.description=Forcibly terminate debugged application evaluation.error.unknown.method.return.type=Cannot resolve method return type: {0} - -java.breakpoint.title=Java Line Breakpoints diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index d04e05907fa8..dbd4105722bb 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -86,9 +86,6 @@ - - @@ -1378,11 +1375,11 @@ - - - - - + + + + + - - From d49241278b6f4cc3116ee35c80806a42c3c2c2c5 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 17 Feb 2014 17:07:13 +0400 Subject: [PATCH 29/95] java move to xbreakpoints 2: - cleanup - fixed tests - support run to cursor and smart step into - support add field/method breakpoint actions --- .../debugger/engine/DebugProcessImpl.java | 1 - .../debugger/ui/breakpoints/Breakpoint.java | 22 +- .../ui/breakpoints/BreakpointManager.java | 95 ++++-- .../BreakpointPropertiesPanel.java | 310 +++++++++--------- .../BreakpointWithHighlighter.java | 10 +- .../ui/breakpoints/ExceptionBreakpoint.java | 14 +- .../ui/breakpoints/FieldBreakpoint.java | 88 +++-- .../breakpoints/JavaLineBreakpointType.java | 5 +- .../ui/breakpoints/LineBreakpoint.java | 13 +- .../ui/breakpoints/MethodBreakpoint.java | 26 +- .../ui/breakpoints/RunToCursorBreakpoint.java | 84 +++-- .../ui/breakpoints/StepIntoBreakpoint.java | 2 +- .../breakpoints/WildcardMethodBreakpoint.java | 21 +- .../JavaBreakpointAdapterBase.java | 2 +- .../JavaLineBreakpointProperties.java | 22 ++ 15 files changed, 387 insertions(+), 328 deletions(-) create mode 100644 java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaLineBreakpointProperties.java diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java index 56e8cd383ee6..da86bac6e6a2 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java @@ -1477,7 +1477,6 @@ public abstract class DebugProcessImpl implements DebugProcess { applyThreadFilter(getContextThread()); final SuspendContextImpl context = getSuspendContext(); myRunToCursorBreakpoint.setSuspendPolicy(context.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD? DebuggerSettings.SUSPEND_THREAD : DebuggerSettings.SUSPEND_ALL); - myRunToCursorBreakpoint.setLogEnabled(false); myRunToCursorBreakpoint.createRequest(context.getDebugProcess()); DebugProcessImpl.this.myRunToCursorBreakpoint = myRunToCursorBreakpoint; super.contextAction(); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index 8ea3fea6923d..8692fdcbfe5b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -233,7 +233,7 @@ public abstract class Breakpoint

    implements private void runAction(final EvaluationContextImpl context, LocatableEvent event) { final DebugProcessImpl debugProcess = context.getDebugProcess(); - if (myXBreakpoint.isLogMessage() || myXBreakpoint.getLogExpression() != null) { + if (isLogEnabled() || isLogExpressionEnabled()) { final StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { if (myXBreakpoint.isLogMessage()) { @@ -449,7 +449,7 @@ public abstract class Breakpoint

    implements myXBreakpoint.setEnabled(enabled); } - public boolean isLogEnabled() { + protected boolean isLogEnabled() { return myXBreakpoint.isLogMessage(); } @@ -457,11 +457,11 @@ public abstract class Breakpoint

    implements myXBreakpoint.setLogMessage(logEnabled); } - public boolean isLogExpressionEnabled() { + protected boolean isLogExpressionEnabled() { return myXBreakpoint.getLogExpression() != null; } - public void setLogExpressionEnabled(boolean LOG_EXPRESSION_ENABLED) { + protected void setLogExpressionEnabled(boolean LOG_EXPRESSION_ENABLED) { } @Override @@ -504,7 +504,7 @@ public abstract class Breakpoint

    implements return myXBreakpoint.getProperties().getClassExclusionFilters(); } - public void setClassExclusionFilters(ClassFilter[] filters) { + protected void setClassExclusionFilters(ClassFilter[] filters) { myXBreakpoint.getProperties().setClassExclusionFilters(filters); } @@ -526,7 +526,7 @@ public abstract class Breakpoint

    implements myXBreakpoint.getProperties().setInstanceFilters(filters); } - public static String getSuspendPolicy(XBreakpoint breakpoint) { + private static String getSuspendPolicy(XBreakpoint breakpoint) { switch (breakpoint.getSuspendPolicy()) { case ALL: return DebuggerSettings.SUSPEND_ALL; @@ -540,7 +540,7 @@ public abstract class Breakpoint

    implements } } - public static SuspendPolicy transformSuspendPolicy(String policy) { + private static SuspendPolicy transformSuspendPolicy(String policy) { if (DebuggerSettings.SUSPEND_ALL.equals(policy)) { return SuspendPolicy.ALL; } else if (DebuggerSettings.SUSPEND_THREAD.equals(policy)) { @@ -552,7 +552,7 @@ public abstract class Breakpoint

    implements } } - public boolean isSuspend() { + protected boolean isSuspend() { return myXBreakpoint.getSuspendPolicy() != SuspendPolicy.NONE; } @@ -565,11 +565,11 @@ public abstract class Breakpoint

    implements myXBreakpoint.setSuspendPolicy(transformSuspendPolicy(policy)); } - public void setLogMessage(TextWithImports logMessage) { + protected void setLogMessage(TextWithImports logMessage) { myXBreakpoint.setLogExpression(logMessage.getText()); } - public boolean isConditionEnabled() { + protected boolean isConditionEnabled() { return myXBreakpoint.getCondition() != null && !myXBreakpoint.getCondition().isEmpty(); } @@ -577,7 +577,7 @@ public abstract class Breakpoint

    implements myXBreakpoint.setCondition(condition); } - public void addInstanceFilter(long l) { + protected void addInstanceFilter(long l) { myXBreakpoint.getProperties().addInstanceFilter(l); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 8e9282747729..929c3133afde 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -30,7 +30,9 @@ import com.intellij.debugger.impl.DebuggerContextListener; import com.intellij.debugger.impl.DebuggerManagerImpl; import com.intellij.debugger.impl.DebuggerSession; import com.intellij.debugger.ui.JavaDebuggerSupport; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -43,22 +45,20 @@ import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiField; import com.intellij.psi.PsiFile; import com.intellij.util.Alarm; import com.intellij.util.EventDispatcher; import com.intellij.xdebugger.XDebuggerManager; -import com.intellij.xdebugger.breakpoints.XBreakpoint; -import com.intellij.xdebugger.breakpoints.XBreakpointListener; -import com.intellij.xdebugger.breakpoints.XBreakpointManager; +import com.intellij.xdebugger.XDebuggerUtil; +import com.intellij.xdebugger.breakpoints.*; import com.intellij.xdebugger.impl.DebuggerSupport; import com.intellij.xdebugger.impl.XDebugSessionImpl; import com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl; import com.intellij.xdebugger.impl.breakpoints.XDependentBreakpointManager; -import com.sun.jdi.Field; import com.sun.jdi.InternalException; -import com.sun.jdi.ObjectReference; import com.sun.jdi.ThreadReference; import com.sun.jdi.request.*; import gnu.trove.TIntHashSet; @@ -66,6 +66,7 @@ import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.java.debugger.breakpoints.properties.JavaExceptionBreakpointProperties; import javax.swing.*; import java.util.*; @@ -81,7 +82,6 @@ public class BreakpointManager { @NonNls private static final String RULES_GROUP_NAME = "breakpoint_rules"; private final Project myProject; - private XBreakpointManager myXBreakpointManager; private final Map myBreakpoints = new HashMap(); // breakpoints storage, access should be synchronized @Nullable private List myBreakpointsListForIteration = null; // another list for breakpoints iteration, unsynchronized access ok private final Map myUIProperties = new LinkedHashMap(); @@ -141,8 +141,8 @@ public class BreakpointManager { } public void init() { - myXBreakpointManager = XDebuggerManager.getInstance(myProject).getBreakpointManager(); - myXBreakpointManager.addBreakpointListener(new XBreakpointListener() { + XBreakpointManager manager = XDebuggerManager.getInstance(myProject).getBreakpointManager(); + manager.addBreakpointListener(new XBreakpointListener() { @Override public void breakpointAdded(@NotNull XBreakpoint xBreakpoint) { if (isJavaType(xBreakpoint)) { @@ -169,6 +169,10 @@ public class BreakpointManager { }); } + private XBreakpointManager getXBreakpointManager() { + return XDebuggerManager.getInstance(myProject).getBreakpointManager(); + } + public void editBreakpoint(final Breakpoint breakpoint, final Editor editor) { DebuggerInvocationUtil.swingInvokeLater(myProject, new Runnable() { @Override @@ -202,7 +206,7 @@ public class BreakpointManager { @Nullable public RunToCursorBreakpoint addRunToCursorBreakpoint(Document document, int lineIndex, final boolean ignoreBreakpoints) { - return RunToCursorBreakpoint.create(myProject, document, lineIndex, ignoreBreakpoints, null); + return RunToCursorBreakpoint.create(myProject, document, lineIndex, ignoreBreakpoints); } @Nullable @@ -216,8 +220,8 @@ public class BreakpointManager { if (!LineBreakpoint.canAddLineBreakpoint(myProject, document, lineIndex)) { return null; } - - LineBreakpoint breakpoint = LineBreakpoint.create(myProject, document, lineIndex, null); + XLineBreakpoint xLineBreakpoint = addXLineBreakpoint(JavaLineBreakpointType.class, document, lineIndex); + LineBreakpoint breakpoint = LineBreakpoint.create(myProject, xLineBreakpoint); if (breakpoint == null) { return null; } @@ -226,15 +230,15 @@ public class BreakpointManager { return breakpoint; } - @Nullable - public FieldBreakpoint addFieldBreakpoint(Field field, ObjectReference object) { - ApplicationManager.getApplication().assertIsDispatchThread(); - final FieldBreakpoint fieldBreakpoint = FieldBreakpoint.create(myProject, field, object, null); - if (fieldBreakpoint != null) { - addBreakpoint(fieldBreakpoint); - } - return fieldBreakpoint; - } + //@Nullable + //public FieldBreakpoint addFieldBreakpoint(Field field, ObjectReference object) { + // ApplicationManager.getApplication().assertIsDispatchThread(); + // final FieldBreakpoint fieldBreakpoint = FieldBreakpoint.create(myProject, field, object, null); + // if (fieldBreakpoint != null) { + // addBreakpoint(fieldBreakpoint); + // } + // return fieldBreakpoint; + //} @Nullable public FieldBreakpoint addFieldBreakpoint(@NotNull Document document, int offset) { @@ -255,7 +259,8 @@ public class BreakpointManager { @Nullable public FieldBreakpoint addFieldBreakpoint(Document document, int lineIndex, String fieldName) { ApplicationManager.getApplication().assertIsDispatchThread(); - FieldBreakpoint fieldBreakpoint = FieldBreakpoint.create(myProject, document, lineIndex, fieldName, null); + XLineBreakpoint xBreakpoint = addXLineBreakpoint(JavaFieldBreakpointType.class, document, lineIndex); + FieldBreakpoint fieldBreakpoint = FieldBreakpoint.create(myProject, fieldName, xBreakpoint); if (fieldBreakpoint != null) { addBreakpoint(fieldBreakpoint); } @@ -265,19 +270,28 @@ public class BreakpointManager { @NotNull public ExceptionBreakpoint addExceptionBreakpoint(@NotNull String exceptionClassName, String packageName) { ApplicationManager.getApplication().assertIsDispatchThread(); - ExceptionBreakpoint breakpoint = new ExceptionBreakpoint(myProject, exceptionClassName, packageName, null); - addBreakpoint(breakpoint); - if (LOG.isDebugEnabled()) { - LOG.debug("ExceptionBreakpoint Added"); + JavaExceptionBreakpointType type = (JavaExceptionBreakpointType)XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class); + AccessToken token = WriteAction.start(); + try { + XBreakpoint xBreakpoint = XDebuggerManager.getInstance(myProject).getBreakpointManager() + .addBreakpoint(type, new JavaExceptionBreakpointProperties(exceptionClassName, packageName)); + ExceptionBreakpoint breakpoint = new ExceptionBreakpoint(myProject, exceptionClassName, packageName, xBreakpoint); + addBreakpoint(breakpoint); + if (LOG.isDebugEnabled()) { + LOG.debug("ExceptionBreakpoint Added"); + } + return breakpoint; + } finally { + token.finish(); } - return breakpoint; } @Nullable public MethodBreakpoint addMethodBreakpoint(Document document, int lineIndex) { ApplicationManager.getApplication().assertIsDispatchThread(); - MethodBreakpoint breakpoint = MethodBreakpoint.create(myProject, document, lineIndex, null); + XLineBreakpoint xBreakpoint = addXLineBreakpoint(JavaMethodBreakpointType.class, document, lineIndex); + MethodBreakpoint breakpoint = MethodBreakpoint.create(myProject, xBreakpoint); if (breakpoint == null) { return null; } @@ -288,6 +302,19 @@ public class BreakpointManager { return breakpoint; } + private > XLineBreakpoint addXLineBreakpoint(Class> typeCls, Document document, int lineIndex) { + XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); + VirtualFile file = FileDocumentManager.getInstance().getFile(document); + AccessToken token = WriteAction.start(); + try { + return XDebuggerManager.getInstance(myProject).getBreakpointManager() + .addLineBreakpoint((XLineBreakpointType)type, file.getUrl(), lineIndex, + ((XLineBreakpointType)type).createBreakpointProperties(file, lineIndex)); + } finally { + token.finish(); + } + } + @Nullable public WildcardMethodBreakpoint addMethodBreakpoint(String classPattern, String methodName) { ApplicationManager.getApplication().assertIsDispatchThread(); @@ -489,8 +516,12 @@ public class BreakpointManager { if (breakpoint == null) { return; } - - myXBreakpointManager.removeBreakpoint(breakpoint.myXBreakpoint); + AccessToken token = WriteAction.start(); + try { + getXBreakpointManager().removeBreakpoint(breakpoint.myXBreakpoint); + } finally { + token.finish(); + } } private synchronized void onBreakpointRemoved(@Nullable final XBreakpoint xBreakpoint) { @@ -629,7 +660,7 @@ public class BreakpointManager { if (myBreakpointsListForIteration == null) { myBreakpointsListForIteration = new ArrayList(myBreakpoints.size()); - for (XBreakpoint xBreakpoint : myXBreakpointManager.getAllBreakpoints()) { + for (XBreakpoint xBreakpoint : getXBreakpointManager().getAllBreakpoints()) { if (isJavaType(xBreakpoint)) { Breakpoint breakpoint = myBreakpoints.get(xBreakpoint); if (breakpoint == null) { @@ -857,7 +888,7 @@ public class BreakpointManager { // copied from XDebugSessionImpl processDependencies public void processBreakpointHit(@NotNull final Breakpoint breakpoint) { - XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)myXBreakpointManager).getDependentBreakpointManager(); + XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)getXBreakpointManager()).getDependentBreakpointManager(); XBreakpoint xBreakpoint = findXBreakpoint(breakpoint); if (!dependentBreakpointManager.isMasterOrSlave(xBreakpoint)) { return; @@ -901,7 +932,7 @@ public class BreakpointManager { @Nullable public Breakpoint findMasterBreakpoint(@NotNull Breakpoint dependentBreakpoint) { - XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)myXBreakpointManager).getDependentBreakpointManager(); + XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)getXBreakpointManager()).getDependentBreakpointManager(); XBreakpoint xBreakpoint = findXBreakpoint(dependentBreakpoint); return myBreakpoints.get(dependentBreakpointManager.getMasterBreakpoint(xBreakpoint)); } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java index 38031d4735a6..ad9d5c93a47a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java @@ -462,126 +462,126 @@ public abstract class BreakpointPropertiesPanel { * Init UI components with the values from Breakpoint */ public void initFrom(Breakpoint breakpoint, boolean moreOptionsVisible1) { - myBreakpoint = breakpoint; - boolean moreOptionsVisible = moreOptionsVisible1; - boolean actionsPanelVisible = moreOptionsVisible1; - - initMasterBreakpointPanel(); - - if (breakpoint.getCountFilter() > 0) { - myPassCountField.setText(Integer.toString(breakpoint.getCountFilter())); - moreOptionsVisible = true; - } - else { - myPassCountField.setText(""); - } - - PsiElement context = breakpoint.getEvaluationElement(); - myPassCountCheckbox.setSelected(breakpoint.isCountFilterEnabled()); - - myConditionCheckbox.setSelected(breakpoint.isConditionEnabled()); - - myConditionCombo.setEnabled(breakpoint.isConditionEnabled()); - - myConditionCombo.setContext(context); - myConditionCombo.setText(breakpoint.getCondition() != null ? breakpoint.getCondition() : emptyText()); - - myCbSuspend.setSelected(breakpoint.isSuspend()); - myRbSuspendThread.setEnabled(myCbSuspend.isSelected()); - myRbSuspendAll.setEnabled(myCbSuspend.isSelected()); - - if(!breakpoint.isSuspend()) { - actionsPanelVisible = true; - } - if(DebuggerSettings.SUSPEND_THREAD.equals(breakpoint.getSuspendPolicy())){ - myRbSuspendThread.setSelected(true); - } - else { - myRbSuspendAll.setSelected(true); - } - - myCbSuspend.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - if (!myActionsPanel.isVisible()) { - if (!myCbSuspend.isSelected()) { - if (myDelegate != null) { - myDelegate.showActionsPanel(); - } - } - } - myRbSuspendThread.setEnabled(myCbSuspend.isSelected()); - myRbSuspendAll.setEnabled(myCbSuspend.isSelected()); - } - }); - myLogMessageCheckBox.setSelected(breakpoint.isLogEnabled()); - myTemporaryCheckBox.setSelected(breakpoint.isRemoveAfterHit()); - myEnabledCheckbox.setSelected(breakpoint.isEnabled()); - myEnabledCheckbox.setText(breakpoint.getShortName() + " enabled"); - - DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().addBreakpointManagerListener(new BreakpointManagerListener() { - @Override - public void breakpointsChanged() { - myEnabledCheckbox.setSelected(myBreakpoint.isEnabled()); - } - }); - - myEnabledCheckbox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - if (myBreakpoint.isEnabled() != myEnabledCheckbox.isSelected()) { - myBreakpoint.setEnabled(myEnabledCheckbox.isSelected()); - getBreakpointManager(myProject).fireBreakpointChanged(myBreakpoint); - myBreakpoint.updateUI(); - } - } - }); - myTemporaryCheckBox.setVisible(breakpoint instanceof LineBreakpoint); - myLogExpressionCheckBox.setSelected(breakpoint.isLogExpressionEnabled()); - if (breakpoint.isLogEnabled() || - breakpoint.isLogExpressionEnabled() || (breakpoint instanceof LineBreakpoint && breakpoint.isRemoveAfterHit())) { - actionsPanelVisible = true; - } - - myLogExpressionCombo.setContext(context); - - if (breakpoint.getLogMessage() != null) { - myLogExpressionCombo.setText(breakpoint.getLogMessage()); - } - else { - myLogExpressionCombo.setText(emptyText()); - } - - myLogExpressionCombo.setEnabled(breakpoint.isLogExpressionEnabled()); - if (breakpoint.isLogExpressionEnabled()) { - actionsPanelVisible = true; - } - - myInstanceFiltersCheckBox.setSelected(breakpoint.isInstanceFiltersEnabled()); - myInstanceFiltersField.setEnabled(breakpoint.isInstanceFiltersEnabled()); - myInstanceFiltersField.getTextField().setEditable(breakpoint.isInstanceFiltersEnabled()); - myInstanceFilters = breakpoint.getInstanceFilters(); - updateInstanceFilterEditor(true); - if (breakpoint.isInstanceFiltersEnabled()) { - moreOptionsVisible = true; - } - - myClassFiltersCheckBox.setSelected(breakpoint.isClassFiltersEnabled()); - myClassFiltersField.setEnabled(breakpoint.isClassFiltersEnabled()); - myClassFiltersField.getTextField().setEditable(breakpoint.isClassFiltersEnabled()); - myClassFilters = breakpoint.getClassFilters(); - myClassExclusionFilters = breakpoint.getClassExclusionFilters(); - updateClassFilterEditor(true); - if (breakpoint.isClassFiltersEnabled()) { - moreOptionsVisible = true; - } - - myBreakpointPsiClass = breakpoint.getPsiClass(); - - updateCheckboxes(); - - setActionsPanelVisible(actionsPanelVisible && !moreOptionsVisible1); - setMoreOptionsVisible(moreOptionsVisible); + //myBreakpoint = breakpoint; + //boolean moreOptionsVisible = moreOptionsVisible1; + //boolean actionsPanelVisible = moreOptionsVisible1; + // + //initMasterBreakpointPanel(); + // + //if (breakpoint.getCountFilter() > 0) { + // myPassCountField.setText(Integer.toString(breakpoint.getCountFilter())); + // moreOptionsVisible = true; + //} + //else { + // myPassCountField.setText(""); + //} + // + //PsiElement context = breakpoint.getEvaluationElement(); + //myPassCountCheckbox.setSelected(breakpoint.isCountFilterEnabled()); + // + //myConditionCheckbox.setSelected(breakpoint.isConditionEnabled()); + // + //myConditionCombo.setEnabled(breakpoint.isConditionEnabled()); + // + //myConditionCombo.setContext(context); + //myConditionCombo.setText(breakpoint.getCondition() != null ? breakpoint.getCondition() : emptyText()); + // + //myCbSuspend.setSelected(breakpoint.isSuspend()); + //myRbSuspendThread.setEnabled(myCbSuspend.isSelected()); + //myRbSuspendAll.setEnabled(myCbSuspend.isSelected()); + // + //if(!breakpoint.isSuspend()) { + // actionsPanelVisible = true; + //} + //if(DebuggerSettings.SUSPEND_THREAD.equals(breakpoint.getSuspendPolicy())){ + // myRbSuspendThread.setSelected(true); + //} + //else { + // myRbSuspendAll.setSelected(true); + //} + // + //myCbSuspend.addActionListener(new ActionListener() { + // @Override + // public void actionPerformed(ActionEvent event) { + // if (!myActionsPanel.isVisible()) { + // if (!myCbSuspend.isSelected()) { + // if (myDelegate != null) { + // myDelegate.showActionsPanel(); + // } + // } + // } + // myRbSuspendThread.setEnabled(myCbSuspend.isSelected()); + // myRbSuspendAll.setEnabled(myCbSuspend.isSelected()); + // } + //}); + //myLogMessageCheckBox.setSelected(breakpoint.isLogEnabled()); + //myTemporaryCheckBox.setSelected(breakpoint.isRemoveAfterHit()); + //myEnabledCheckbox.setSelected(breakpoint.isEnabled()); + //myEnabledCheckbox.setText(breakpoint.getShortName() + " enabled"); + // + //DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager().addBreakpointManagerListener(new BreakpointManagerListener() { + // @Override + // public void breakpointsChanged() { + // myEnabledCheckbox.setSelected(myBreakpoint.isEnabled()); + // } + //}); + // + //myEnabledCheckbox.addActionListener(new ActionListener() { + // @Override + // public void actionPerformed(ActionEvent event) { + // if (myBreakpoint.isEnabled() != myEnabledCheckbox.isSelected()) { + // myBreakpoint.setEnabled(myEnabledCheckbox.isSelected()); + // getBreakpointManager(myProject).fireBreakpointChanged(myBreakpoint); + // myBreakpoint.updateUI(); + // } + // } + //}); + //myTemporaryCheckBox.setVisible(breakpoint instanceof LineBreakpoint); + //myLogExpressionCheckBox.setSelected(breakpoint.isLogExpressionEnabled()); + //if (breakpoint.isLogEnabled() || + // breakpoint.isLogExpressionEnabled() || (breakpoint instanceof LineBreakpoint && breakpoint.isRemoveAfterHit())) { + // actionsPanelVisible = true; + //} + // + //myLogExpressionCombo.setContext(context); + // + //if (breakpoint.getLogMessage() != null) { + // myLogExpressionCombo.setText(breakpoint.getLogMessage()); + //} + //else { + // myLogExpressionCombo.setText(emptyText()); + //} + // + //myLogExpressionCombo.setEnabled(breakpoint.isLogExpressionEnabled()); + //if (breakpoint.isLogExpressionEnabled()) { + // actionsPanelVisible = true; + //} + // + //myInstanceFiltersCheckBox.setSelected(breakpoint.isInstanceFiltersEnabled()); + //myInstanceFiltersField.setEnabled(breakpoint.isInstanceFiltersEnabled()); + //myInstanceFiltersField.getTextField().setEditable(breakpoint.isInstanceFiltersEnabled()); + //myInstanceFilters = breakpoint.getInstanceFilters(); + //updateInstanceFilterEditor(true); + //if (breakpoint.isInstanceFiltersEnabled()) { + // moreOptionsVisible = true; + //} + // + //myClassFiltersCheckBox.setSelected(breakpoint.isClassFiltersEnabled()); + //myClassFiltersField.setEnabled(breakpoint.isClassFiltersEnabled()); + //myClassFiltersField.getTextField().setEditable(breakpoint.isClassFiltersEnabled()); + //myClassFilters = breakpoint.getClassFilters(); + //myClassExclusionFilters = breakpoint.getClassExclusionFilters(); + //updateClassFilterEditor(true); + //if (breakpoint.isClassFiltersEnabled()) { + // moreOptionsVisible = true; + //} + // + //myBreakpointPsiClass = breakpoint.getPsiClass(); + // + //updateCheckboxes(); + // + //setActionsPanelVisible(actionsPanelVisible && !moreOptionsVisible1); + //setMoreOptionsVisible(moreOptionsVisible); } private void initMasterBreakpointPanel() { @@ -636,41 +636,41 @@ public abstract class BreakpointPropertiesPanel { */ public void saveTo(Breakpoint breakpoint) { - saveMasterBreakpoint(); - try { - String text = myPassCountField.getText().trim(); - breakpoint.setCountFilter(!text.isEmpty() ? Integer.parseInt(text) : 0); - if (breakpoint.getCountFilter() < 0) { - breakpoint.setCountFilter(0); - } - } - catch (Exception ignored) { - } - - breakpoint.setCountFilterEnabled(breakpoint.getCountFilter() > 0 && myPassCountCheckbox.isSelected()); - breakpoint.setCondition(myConditionCombo.getText().getText()); - //breakpoint.setConditionEnabled(myConditionCheckbox.isSelected()); - breakpoint.setLogMessage(myLogExpressionCombo.getText()); - breakpoint.setLogExpressionEnabled(!breakpoint.getLogMessage().isEmpty() && myLogExpressionCheckBox.isSelected()); - breakpoint.setLogEnabled(myLogMessageCheckBox.isSelected()); - breakpoint.setEnabled(myEnabledCheckbox.isSelected()); - breakpoint.setRemoveAfterHit(myTemporaryCheckBox.isSelected()); - //breakpoint.setSuspend(myCbSuspend.isSelected()); - breakpoint.setSuspendPolicy(getSelectedSuspendPolicy()); - reloadInstanceFilters(); - reloadClassFilters(); - updateInstanceFilterEditor(true); - updateClassFilterEditor(true); - - breakpoint.setInstanceFiltersEnabled(myInstanceFiltersField.getText().length() > 0 && myInstanceFiltersCheckBox.isSelected()); - breakpoint.setClassFiltersEnabled(myClassFiltersField.getText().length() > 0 && myClassFiltersCheckBox.isSelected()); - breakpoint.setClassFilters(myClassFilters); - breakpoint.setClassExclusionFilters(myClassExclusionFilters); - breakpoint.setInstanceFilters(myInstanceFilters); - - myConditionCombo.addRecent(myConditionCombo.getText()); - myLogExpressionCombo.addRecent(myLogExpressionCombo.getText()); - breakpoint.updateUI(); + //saveMasterBreakpoint(); + //try { + // String text = myPassCountField.getText().trim(); + // breakpoint.setCountFilter(!text.isEmpty() ? Integer.parseInt(text) : 0); + // if (breakpoint.getCountFilter() < 0) { + // breakpoint.setCountFilter(0); + // } + //} + //catch (Exception ignored) { + //} + // + //breakpoint.setCountFilterEnabled(breakpoint.getCountFilter() > 0 && myPassCountCheckbox.isSelected()); + //breakpoint.setCondition(myConditionCombo.getText().getText()); + ////breakpoint.setConditionEnabled(myConditionCheckbox.isSelected()); + //breakpoint.setLogMessage(myLogExpressionCombo.getText()); + //breakpoint.setLogExpressionEnabled(!breakpoint.getLogMessage().isEmpty() && myLogExpressionCheckBox.isSelected()); + //breakpoint.setLogEnabled(myLogMessageCheckBox.isSelected()); + //breakpoint.setEnabled(myEnabledCheckbox.isSelected()); + //breakpoint.setRemoveAfterHit(myTemporaryCheckBox.isSelected()); + ////breakpoint.setSuspend(myCbSuspend.isSelected()); + //breakpoint.setSuspendPolicy(getSelectedSuspendPolicy()); + //reloadInstanceFilters(); + //reloadClassFilters(); + //updateInstanceFilterEditor(true); + //updateClassFilterEditor(true); + // + //breakpoint.setInstanceFiltersEnabled(myInstanceFiltersField.getText().length() > 0 && myInstanceFiltersCheckBox.isSelected()); + //breakpoint.setClassFiltersEnabled(myClassFiltersField.getText().length() > 0 && myClassFiltersCheckBox.isSelected()); + //breakpoint.setClassFilters(myClassFilters); + //breakpoint.setClassExclusionFilters(myClassExclusionFilters); + //breakpoint.setInstanceFilters(myInstanceFilters); + // + //myConditionCombo.addRecent(myConditionCombo.getText()); + //myLogExpressionCombo.addRecent(myLogExpressionCombo.getText()); + //breakpoint.updateUI(); } private static String concatWithEx(List s, String concator, int N, String NthConcator) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java index 200e377b87f8..0c3178742a58 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java @@ -34,14 +34,9 @@ import com.intellij.openapi.editor.impl.DocumentMarkupModel; import com.intellij.openapi.editor.markup.MarkupEditorFilterFactory; import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; -import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.WriteExternalException; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; @@ -58,7 +53,6 @@ import com.intellij.xdebugger.breakpoints.XLineBreakpoint; import com.intellij.xdebugger.ui.DebuggerColors; import com.intellij.xml.util.XmlStringUtil; import com.sun.jdi.ReferenceType; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; @@ -215,7 +209,7 @@ public abstract class BreakpointWithHighlighter

    () { @Override public Boolean compute() { @@ -294,7 +288,7 @@ public abstract class BreakpointWithHighlighter

    { private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.breakpoints.FieldBreakpoint"); @@ -68,8 +64,8 @@ public class FieldBreakpoint extends BreakpointWithHighlighter xBreakpoint) { - return LineBreakpoint.create(project, document, xBreakpoint.getLine(), xBreakpoint); + return LineBreakpoint.create(project, xBreakpoint); } } diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaLineBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaLineBreakpointProperties.java new file mode 100644 index 000000000000..9a892346ac04 --- /dev/null +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaLineBreakpointProperties.java @@ -0,0 +1,22 @@ +/* + * 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 org.jetbrains.java.debugger.breakpoints.properties; + +/** + * @author egor + */ +public class JavaLineBreakpointProperties extends JavaBreakpointProperties { +} From b903d1071a3fe389e68a84c86704c9797ce9d90c Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 19 Feb 2014 18:52:23 +0400 Subject: [PATCH 30/95] java move to xbreakpoints 3: - breakpoint properties serialization fixes - import old java breakpoint - leave a copy for backward compatibility --- .../com/intellij/debugger/InstanceFilter.java | 2 + .../debugger/impl/DebuggerManagerImpl.java | 6 +- .../debugger/ui/breakpoints/Breakpoint.java | 42 +- .../ui/breakpoints/BreakpointManager.java | 393 +++++++++++------- .../ui/breakpoints/ExceptionBreakpoint.java | 38 +- .../ui/breakpoints/FieldBreakpoint.java | 29 +- .../ui/breakpoints/FilteredRequestorImpl.java | 48 ++- .../ui/breakpoints/MethodBreakpoint.java | 24 +- .../JavaExceptionBreakpointProperties.java | 5 + .../JavaFieldBreakpointProperties.java | 3 + .../JavaMethodBreakpointProperties.java | 4 + .../intellij/ui/classFilter/ClassFilter.java | 4 + 12 files changed, 391 insertions(+), 207 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/InstanceFilter.java b/java/debugger/impl/src/com/intellij/debugger/InstanceFilter.java index 9ce095c038dc..757da4c35a5e 100644 --- a/java/debugger/impl/src/com/intellij/debugger/InstanceFilter.java +++ b/java/debugger/impl/src/com/intellij/debugger/InstanceFilter.java @@ -20,6 +20,7 @@ import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizable; import com.intellij.openapi.util.WriteExternalException; import com.intellij.ui.classFilter.ClassFilter; +import com.intellij.util.xmlb.annotations.Transient; import org.jdom.Element; /** @@ -41,6 +42,7 @@ public class InstanceFilter implements JDOMExternalizable{ this.ENABLED = ENABLED; } + @Transient public long getId() { return ID; } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java index 1416dd3b05c3..c60a3b220906 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java @@ -180,17 +180,17 @@ public class DebuggerManagerImpl extends DebuggerManagerEx implements Persistent @Override public Element getState() { Element state = new Element("state"); - //myBreakpointManager.writeExternal(state); + myBreakpointManager.writeExternal(state); return state; } @Override public void loadState(Element state) { - //myBreakpointManager.readExternal(state); + myBreakpointManager.readExternal(state); } public void writeExternal(Element element) throws WriteExternalException { - //myBreakpointManager.writeExternal(element); + myBreakpointManager.writeExternal(element); } public DebuggerSession attachVirtualMachine(Executor executor, diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index 8692fdcbfe5b..0f6d98220fda 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -33,6 +33,8 @@ import com.intellij.debugger.requests.ClassPrepareRequestor; import com.intellij.debugger.settings.DebuggerSettings; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.JDOMExternalizerUtil; import com.intellij.openapi.util.Key; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; @@ -44,6 +46,8 @@ import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.XLineBreakpoint; import com.sun.jdi.*; import com.sun.jdi.event.LocatableEvent; +import org.jdom.Element; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; @@ -60,7 +64,7 @@ public abstract class Breakpoint

    implements //private boolean LOG_EXPRESSION_ENABLED = false; //private boolean REMOVE_AFTER_HIT = false; //private TextWithImports myLogMessage; // an expression to be evaluated and printed - //@NonNls private static final String LOG_MESSAGE_OPTION_NAME = "LOG_MESSAGE"; + @NonNls private static final String LOG_MESSAGE_OPTION_NAME = "LOG_MESSAGE"; public static final Breakpoint[] EMPTY_ARRAY = new Breakpoint[0]; protected boolean myCachedVerifiedState = false; //private TextWithImportsImpl myLogMessage; @@ -412,14 +416,31 @@ public abstract class Breakpoint

    implements RequestManagerImpl.deleteRequests(this); } - //@Override - //public void readExternal(Element parentNode) throws InvalidDataException { - //super.readExternal(parentNode); - //String logMessage = JDOMExternalizerUtil.readField(parentNode, LOG_MESSAGE_OPTION_NAME); - //if (logMessage != null) { - // setLogMessage(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, logMessage)); - //} - //} + public void readExternal(Element parentNode) throws InvalidDataException { + FilteredRequestorImpl requestor = new FilteredRequestorImpl(myProject); + requestor.readTo(parentNode, this); + try { + setEnabled(Boolean.valueOf(JDOMExternalizerUtil.readField(parentNode, "ENABLED"))); + } catch (Exception e) { + } + try { + setLogEnabled(Boolean.valueOf(JDOMExternalizerUtil.readField(parentNode, "LOG_ENABLED"))); + } catch (Exception e) { + } + try { + if (Boolean.valueOf(JDOMExternalizerUtil.readField(parentNode, "LOG_EXPRESSION_ENABLED"))) { + String logMessage = JDOMExternalizerUtil.readField(parentNode, LOG_MESSAGE_OPTION_NAME); + if (logMessage != null) { + setLogMessage(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, logMessage)); + } + } + } catch (Exception e) { + } + try { + setRemoveAfterHit(Boolean.valueOf(JDOMExternalizerUtil.readField(parentNode, "REMOVE_AFTER_HIT"))); + } catch (Exception e) { + } + } //@Override //public void writeExternal(Element parentNode) throws WriteExternalException { @@ -461,9 +482,6 @@ public abstract class Breakpoint

    implements return myXBreakpoint.getLogExpression() != null; } - protected void setLogExpressionEnabled(boolean LOG_EXPRESSION_ENABLED) { - } - @Override public boolean isCountFilterEnabled() { return myXBreakpoint.getProperties().COUNT_FILTER_ENABLED; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 929c3133afde..fc3dc2016eca 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -20,6 +20,7 @@ */ package com.intellij.debugger.ui.breakpoints; +import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.DebuggerInvocationUtil; import com.intellij.debugger.SourcePosition; import com.intellij.debugger.engine.BreakpointStepMethodFilter; @@ -43,9 +44,11 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiField; import com.intellij.psi.PsiFile; @@ -61,6 +64,7 @@ import com.intellij.xdebugger.impl.breakpoints.XDependentBreakpointManager; import com.sun.jdi.InternalException; import com.sun.jdi.ThreadReference; import com.sun.jdi.request.*; +import gnu.trove.THashMap; import gnu.trove.TIntHashSet; import org.jdom.Element; import org.jetbrains.annotations.NonNls; @@ -80,6 +84,7 @@ public class BreakpointManager { @NonNls private static final String DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME = "default_condition_enabled"; @NonNls private static final String RULES_GROUP_NAME = "breakpoint_rules"; + private static final String CONVERTED_PARAM = "converted"; private final Project myProject; private final Map myBreakpoints = new HashMap(); // breakpoints storage, access should be synchronized @@ -384,118 +389,189 @@ public class BreakpointManager { return null; } - //public void readExternal(@NotNull final Element parentNode) { - // if (true) return; - // if (myProject.isOpen()) { - // doRead(parentNode); - // } - // else { - // myStartupManager.registerPostStartupActivity(new Runnable() { - // @Override - // public void run() { - // doRead(parentNode); - // } - // }); - // } - //} + private List myOriginalBreakpointsNodes = new ArrayList(); - //private void doRead(@NotNull final Element parentNode) { - // ApplicationManager.getApplication().runReadAction(new Runnable() { - // @Override - // @SuppressWarnings({"HardCodedStringLiteral"}) - // public void run() { - // final Map nameToBreakpointMap = new THashMap(); - // try { - // final List groups = parentNode.getChildren(); - // for (final Object group1 : groups) { - // final Element group = (Element)group1; - // if (group.getName().equals(RULES_GROUP_NAME)) { - // continue; - // } - // final String categoryName = group.getName(); - // final Key breakpointCategory = BreakpointCategory.lookup(categoryName); - // final String defaultPolicy = group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME); - // final boolean conditionEnabled = Boolean.parseBoolean(group.getAttributeValue(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, "true")); - // setBreakpointDefaults(breakpointCategory, new BreakpointDefaults(defaultPolicy, conditionEnabled)); - // Element anyExceptionBreakpointGroup; - // if (!AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.equals(breakpointCategory)) { - // // for compatibility with previous format - // anyExceptionBreakpointGroup = group.getChild(AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.toString()); - // final BreakpointFactory factory = BreakpointFactory.getInstance(breakpointCategory); - // if (factory != null) { - // for (final Object o : group.getChildren("breakpoint")) { - // Element breakpointNode = (Element)o; - // Breakpoint breakpoint = factory.createBreakpoint(myProject, breakpointNode); - // breakpoint.readExternal(breakpointNode); - // addBreakpoint(breakpoint); - // nameToBreakpointMap.put(breakpoint.getDisplayName(), breakpoint); - // } - // } - // } - // else { - // anyExceptionBreakpointGroup = group; - // } - // - // if (anyExceptionBreakpointGroup != null) { - // final Element breakpointElement = group.getChild("breakpoint"); - // if (breakpointElement != null) { - // getAnyExceptionBreakpoint().readExternal(breakpointElement); - // } - // } - // - // } - // } - // catch (InvalidDataException ignored) { - // } - // - // final Element rulesGroup = parentNode.getChild(RULES_GROUP_NAME); - // if (rulesGroup != null) { - // final List rules = rulesGroup.getChildren("rule"); - // for (final Object rule1 : rules) { - // final Element rule = (Element)rule1; - // final Element master = rule.getChild(MASTER_BREAKPOINT_TAGNAME); - // if (master == null) { - // continue; - // } - // final Element slave = rule.getChild(SLAVE_BREAKPOINT_TAGNAME); - // if (slave == null) { - // continue; - // } - // final Breakpoint masterBreakpoint = nameToBreakpointMap.get(master.getAttributeValue("name")); - // if (masterBreakpoint == null) { - // continue; - // } - // final Breakpoint slaveBreakpoint = nameToBreakpointMap.get(slave.getAttributeValue("name")); - // if (slaveBreakpoint == null) { - // continue; - // } - // addBreakpointRule(new EnableBreakpointRule(BreakpointManager.this, masterBreakpoint, slaveBreakpoint, "true".equalsIgnoreCase(rule.getAttributeValue("leaveEnabled")))); - // } - // } - // - // DebuggerInvocationUtil.invokeLater(myProject, new Runnable() { - // @Override - // public void run() { - // updateBreakpointsUI(); - // } - // }); - // } - // }); - // - // myUIProperties.clear(); - // final Element props = parentNode.getChild("ui_properties"); - // if (props != null) { - // final List children = props.getChildren("property"); - // for (Object child : children) { - // Element property = (Element)child; - // final String name = property.getAttributeValue("name"); - // final String value = property.getAttributeValue("value"); - // if (name != null && value != null) { - // myUIProperties.put(name, value); - // } - // } - // } - //} + public void readExternal(@NotNull final Element parentNode) { + // save old breakpoints + for (Element element : parentNode.getChildren()) { + myOriginalBreakpointsNodes.add(element.clone()); + } + if (myProject.isOpen()) { + doRead(parentNode); + } + else { + myStartupManager.registerPostStartupActivity(new Runnable() { + @Override + public void run() { + doRead(parentNode); + } + }); + } + } + + private void doRead(@NotNull final Element parentNode) { + ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override + @SuppressWarnings({"HardCodedStringLiteral"}) + public void run() { + final Map nameToBreakpointMap = new THashMap(); + try { + final List groups = parentNode.getChildren(); + for (final Object group1 : groups) { + final Element group = (Element)group1; + if (group.getName().equals(RULES_GROUP_NAME)) { + continue; + } + final String categoryName = group.getName(); + final Key breakpointCategory = BreakpointCategory.lookup(categoryName); + final String defaultPolicy = group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME); + final boolean conditionEnabled = Boolean.parseBoolean(group.getAttributeValue(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, "true")); + setBreakpointDefaults(breakpointCategory, new BreakpointDefaults(defaultPolicy, conditionEnabled)); + Element anyExceptionBreakpointGroup; + if (!AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.equals(breakpointCategory)) { + // for compatibility with previous format + anyExceptionBreakpointGroup = group.getChild(AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.toString()); + //final BreakpointFactory factory = BreakpointFactory.getInstance(breakpointCategory); + //if (factory != null) { + for (Element breakpointNode : group.getChildren("breakpoint")) { + // skip already converted + if (breakpointNode.getAttribute(CONVERTED_PARAM) != null) { + continue; + } + //Breakpoint breakpoint = factory.createBreakpoint(myProject, breakpointNode); + Breakpoint breakpoint = createBreakpoint(categoryName, breakpointNode); + breakpoint.readExternal(breakpointNode); + addBreakpoint(breakpoint); + nameToBreakpointMap.put(breakpoint.getDisplayName(), breakpoint); + } + //} + } + else { + anyExceptionBreakpointGroup = group; + } + + //if (anyExceptionBreakpointGroup != null) { + // final Element breakpointElement = group.getChild("breakpoint"); + // if (breakpointElement != null) { + // getAnyExceptionBreakpoint().readExternal(breakpointElement); + // } + //} + + } + } + catch (InvalidDataException ignored) { + } + + final Element rulesGroup = parentNode.getChild(RULES_GROUP_NAME); + if (rulesGroup != null) { + final List rules = rulesGroup.getChildren("rule"); + for (Element rule : rules) { + // skip already converted + if (rule.getAttribute(CONVERTED_PARAM) != null) { + continue; + } + final Element master = rule.getChild(MASTER_BREAKPOINT_TAGNAME); + if (master == null) { + continue; + } + final Element slave = rule.getChild(SLAVE_BREAKPOINT_TAGNAME); + if (slave == null) { + continue; + } + final Breakpoint masterBreakpoint = nameToBreakpointMap.get(master.getAttributeValue("name")); + if (masterBreakpoint == null) { + continue; + } + final Breakpoint slaveBreakpoint = nameToBreakpointMap.get(slave.getAttributeValue("name")); + if (slaveBreakpoint == null) { + continue; + } + + boolean leaveEnabled = "true".equalsIgnoreCase(rule.getAttributeValue("leaveEnabled")); + XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)getXBreakpointManager()).getDependentBreakpointManager(); + dependentBreakpointManager.setMasterBreakpoint(slaveBreakpoint.myXBreakpoint, masterBreakpoint.myXBreakpoint, leaveEnabled); + //addBreakpointRule(new EnableBreakpointRule(BreakpointManager.this, masterBreakpoint, slaveBreakpoint, leaveEnabled)); + } + } + + DebuggerInvocationUtil.invokeLater(myProject, new Runnable() { + @Override + public void run() { + updateBreakpointsUI(); + } + }); + } + }); + + myUIProperties.clear(); + final Element props = parentNode.getChild("ui_properties"); + if (props != null) { + final List children = props.getChildren("property"); + for (Object child : children) { + Element property = (Element)child; + final String name = property.getAttributeValue("name"); + final String value = property.getAttributeValue("value"); + if (name != null && value != null) { + myUIProperties.put(name, value); + } + } + } + } + + private Breakpoint createBreakpoint(String category, Element breakpointNode) throws InvalidDataException { + if (category.equals(LineBreakpoint.CATEGORY.toString())) { + XLineBreakpoint xBreakpoint = createXLineBreakpoint(JavaLineBreakpointType.class, breakpointNode); + return LineBreakpoint.create(myProject, xBreakpoint); + } + else if (category.equals(MethodBreakpoint.CATEGORY.toString())) { + XLineBreakpoint xBreakpoint = createXLineBreakpoint(JavaMethodBreakpointType.class, breakpointNode); + return MethodBreakpoint.create(myProject, xBreakpoint); + } + else if (category.equals(FieldBreakpoint.CATEGORY.toString())) { + XLineBreakpoint xBreakpoint = createXLineBreakpoint(JavaFieldBreakpointType.class, breakpointNode); + return FieldBreakpoint.create(myProject, "", xBreakpoint); + } + else if (category.equals(ExceptionBreakpoint.CATEGORY.toString())) { + XBreakpoint xBreakpoint = createXBreakpoint(JavaExceptionBreakpointType.class, breakpointNode); + return new ExceptionBreakpoint(myProject, xBreakpoint); + } + throw new IllegalStateException("Unknown breakpoint category " + category); + } + + private > XBreakpoint createXBreakpoint(Class> typeCls, + Element breakpointNode) throws InvalidDataException { + XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); + AccessToken token = WriteAction.start(); + try { + return XDebuggerManager.getInstance(myProject).getBreakpointManager() + .addBreakpoint((XBreakpointType)type, type.createProperties()); + } finally { + token.finish(); + } + } + + private > XLineBreakpoint createXLineBreakpoint(Class> typeCls, + Element breakpointNode) throws InvalidDataException { + final String url = breakpointNode.getAttributeValue("url"); + VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url); + if (vFile == null) { + throw new InvalidDataException(DebuggerBundle.message("error.breakpoint.file.not.found", url)); + } + final Document doc = FileDocumentManager.getInstance().getDocument(vFile); + if (doc == null) { + throw new InvalidDataException(DebuggerBundle.message("error.cannot.load.breakpoint.file", url)); + } + + final int line; + try { + //noinspection HardCodedStringLiteral + line = Integer.parseInt(breakpointNode.getAttributeValue("line")); + } + catch (Exception e) { + throw new InvalidDataException("Line number is invalid for breakpoint"); + } + return addXLineBreakpoint(typeCls, doc, line); + } //used in Fabrique public synchronized void addBreakpoint(Breakpoint breakpoint) { @@ -543,45 +619,62 @@ public class BreakpointManager { } public void writeExternal(@NotNull final Element parentNode) { - // if (true) return; - // ApplicationManager.getApplication().runReadAction(new Runnable() { - // @Override - // public void run() { - // removeInvalidBreakpoints(); - // final Map, Element> categoryToElementMap = new THashMap, Element>(); - // for (Key category : myBreakpointDefaults.keySet()) { - // final Element group = getCategoryGroupElement(categoryToElementMap, category, parentNode); - // final BreakpointDefaults defaults = getBreakpointDefaults(category); - // group.setAttribute(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME, String.valueOf(defaults.getSuspendPolicy())); - // group.setAttribute(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, String.valueOf(defaults.isConditionEnabled())); - // } - // // don't store invisible breakpoints - // for (Breakpoint breakpoint : getBreakpoints()) { - // if (breakpoint.isValid() && - // (!(breakpoint instanceof BreakpointWithHighlighter) || ((BreakpointWithHighlighter)breakpoint).isVisible())) { - // writeBreakpoint(getCategoryGroupElement(categoryToElementMap, breakpoint.getCategory(), parentNode), breakpoint); - // } - // } - // final AnyExceptionBreakpoint anyExceptionBreakpoint = getAnyExceptionBreakpoint(); - // final Element group = getCategoryGroupElement(categoryToElementMap, anyExceptionBreakpoint.getCategory(), parentNode); - // writeBreakpoint(group, anyExceptionBreakpoint); - // - // final Element rules = new Element(RULES_GROUP_NAME); - // parentNode.addContent(rules); - // //for (EnableBreakpointRule myBreakpointRule : myBreakpointRules) { - // // writeRule(myBreakpointRule, rules); - // //} - // } - // }); - // - // final Element uiProperties = new Element("ui_properties"); - // parentNode.addContent(uiProperties); - // for (final String name : myUIProperties.keySet()) { - // Element property = new Element("property"); - // uiProperties.addContent(property); - // property.setAttribute("name", name); - // property.setAttribute("value", myUIProperties.get(name)); - // } + // restore old breakpoints + for (Element group : myOriginalBreakpointsNodes) { + for (Element breakpoint : group.getChildren("breakpoint")) { + if (breakpoint.getAttribute(CONVERTED_PARAM) == null) { + breakpoint.setAttribute(CONVERTED_PARAM, "true"); + } + } + if (RULES_GROUP_NAME.equals(group.getName())) { + List rules = group.getChildren("rule"); + for (Element rule : rules) { + if (rule.getAttribute(CONVERTED_PARAM) == null) { + rule.setAttribute(CONVERTED_PARAM, "true"); + } + } + } + } + + parentNode.addContent(myOriginalBreakpointsNodes); + //ApplicationManager.getApplication().runReadAction(new Runnable() { + // @Override + // public void run() { + // removeInvalidBreakpoints(); + // final Map, Element> categoryToElementMap = new THashMap, Element>(); + // for (Key category : myBreakpointDefaults.keySet()) { + // final Element group = getCategoryGroupElement(categoryToElementMap, category, parentNode); + // final BreakpointDefaults defaults = getBreakpointDefaults(category); + // group.setAttribute(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME, String.valueOf(defaults.getSuspendPolicy())); + // group.setAttribute(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, String.valueOf(defaults.isConditionEnabled())); + // } + // // don't store invisible breakpoints + // for (Breakpoint breakpoint : getBreakpoints()) { + // if (breakpoint.isValid() && + // (!(breakpoint instanceof BreakpointWithHighlighter) || ((BreakpointWithHighlighter)breakpoint).isVisible())) { + // writeBreakpoint(getCategoryGroupElement(categoryToElementMap, breakpoint.getCategory(), parentNode), breakpoint); + // } + // } + // final AnyExceptionBreakpoint anyExceptionBreakpoint = getAnyExceptionBreakpoint(); + // final Element group = getCategoryGroupElement(categoryToElementMap, anyExceptionBreakpoint.getCategory(), parentNode); + // writeBreakpoint(group, anyExceptionBreakpoint); + // + // final Element rules = new Element(RULES_GROUP_NAME); + // parentNode.addContent(rules); + // //for (EnableBreakpointRule myBreakpointRule : myBreakpointRules) { + // // writeRule(myBreakpointRule, rules); + // //} + // } + //}); + // + //final Element uiProperties = new Element("ui_properties"); + //parentNode.addContent(uiProperties); + //for (final String name : myUIProperties.keySet()) { + // Element property = new Element("property"); + // uiProperties.addContent(property); + // property.setAttribute("name", name); + // property.setAttribute("value", myUIProperties.get(name)); + //} } //@SuppressWarnings({"HardCodedStringLiteral"}) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java index b85bf6dfce77..538183e9451d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java @@ -33,6 +33,8 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.JDOMExternalizerUtil; import com.intellij.openapi.util.Key; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; @@ -47,6 +49,7 @@ import com.sun.jdi.ReferenceType; import com.sun.jdi.event.ExceptionEvent; import com.sun.jdi.event.LocatableEvent; import com.sun.jdi.request.ExceptionRequest; +import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.java.debugger.breakpoints.properties.JavaExceptionBreakpointProperties; @@ -228,19 +231,28 @@ public class ExceptionBreakpoint extends Breakpoint { public boolean NOTIFY_CAUGHT = true; public boolean NOTIFY_UNCAUGHT = true; + + @Attribute("class_name") public String myQualifiedName; + + @Attribute("package_name") public String myPackageName; public JavaExceptionBreakpointProperties(String qualifiedName, String packageName) { diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java index 4d91a2a44a6e..42106b3c0eac 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java @@ -15,6 +15,7 @@ */ package org.jetbrains.java.debugger.breakpoints.properties; +import com.intellij.util.xmlb.annotations.Attribute; import org.jetbrains.annotations.Nullable; /** @@ -23,6 +24,8 @@ import org.jetbrains.annotations.Nullable; public class JavaFieldBreakpointProperties extends JavaBreakpointProperties { public boolean WATCH_MODIFICATION = true; public boolean WATCH_ACCESS = false; + + @Attribute("field_name") public String myFieldName; public JavaFieldBreakpointProperties(String fieldName) { diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaMethodBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaMethodBreakpointProperties.java index a4750dbdd845..9392b565645b 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaMethodBreakpointProperties.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaMethodBreakpointProperties.java @@ -15,13 +15,17 @@ */ package org.jetbrains.java.debugger.breakpoints.properties; +import com.intellij.util.xmlb.annotations.Attribute; import org.jetbrains.annotations.Nullable; /** * @author egor */ public class JavaMethodBreakpointProperties extends JavaBreakpointProperties { + @Attribute("class") public String myClassPattern; + + @Attribute("method") public String myMethodName; public boolean WATCH_ENTRY = true; diff --git a/java/openapi/src/com/intellij/ui/classFilter/ClassFilter.java b/java/openapi/src/com/intellij/ui/classFilter/ClassFilter.java index 2749c340c695..a0b4b7d0a40e 100644 --- a/java/openapi/src/com/intellij/ui/classFilter/ClassFilter.java +++ b/java/openapi/src/com/intellij/ui/classFilter/ClassFilter.java @@ -21,6 +21,7 @@ import com.intellij.openapi.util.DefaultJDOMExternalizer; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizable; import com.intellij.openapi.util.WriteExternalException; +import com.intellij.util.xmlb.annotations.Transient; import org.jdom.Element; import java.util.regex.Matcher; @@ -42,9 +43,12 @@ public class ClassFilter implements JDOMExternalizable, Cloneable{ ENABLED = true; } + @Transient public String getPattern() { return PATTERN; } + + @Transient public boolean isEnabled() { return ENABLED; } From 525d80d70fe993179e3775ac73b9363874748a42 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 19 Feb 2014 19:10:27 +0400 Subject: [PATCH 31/95] java move to xbreakpoints 4: - fixed old breakpoints class deserialization --- .../BreakpointWithHighlighter.java | 100 +++++++++--------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java index 0c3178742a58..a1c2df838e65 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java @@ -36,6 +36,7 @@ import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.Key; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiDocumentManager; @@ -53,6 +54,7 @@ import com.intellij.xdebugger.breakpoints.XLineBreakpoint; import com.intellij.xdebugger.ui.DebuggerColors; import com.intellij.xml.util.XmlStringUtil; import com.sun.jdi.ReferenceType; +import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties; @@ -555,55 +557,55 @@ public abstract class BreakpointWithHighlighter

    Date: Wed, 19 Feb 2014 20:26:42 +0400 Subject: [PATCH 32/95] java move to xbreakpoints: - fixed breakpoint groupping --- .../ui/XBreakpointGroupingByClassRule.java | 15 +++++++++++---- .../ui/XBreakpointGroupingByPackageRule.java | 17 ++++++++++------- .../ui/breakpoints/BreakpointManager.java | 6 ++++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByClassRule.java b/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByClassRule.java index f06a17ef0727..cebaf68612a0 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByClassRule.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByClassRule.java @@ -15,8 +15,11 @@ */ package com.intellij.debugger.ui; +import com.intellij.debugger.DebuggerManagerEx; import com.intellij.debugger.ui.breakpoints.Breakpoint; +import com.intellij.debugger.ui.breakpoints.BreakpointManager; import com.intellij.icons.AllIcons; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule; import com.intellij.xdebugger.breakpoints.ui.XBreakpointsGroupingPriorities; import org.jetbrains.annotations.NotNull; @@ -42,10 +45,14 @@ class XBreakpointGroupingByClassRule extends XBreakpointGroupingRule groups) { - if (b instanceof Breakpoint) { - final Breakpoint breakpoint = (Breakpoint)b; - String className = breakpoint.getShortClassName(); - String packageName = breakpoint.getPackageName(); + if (b instanceof XBreakpoint) { + BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(JavaDebuggerSupport.getCurrentProject()).getBreakpointManager(); + Breakpoint javaBreakpoint = breakpointManager.findBreakpoint((XBreakpoint)b); + if (javaBreakpoint == null) { + return null; + } + String className = javaBreakpoint.getShortClassName(); + String packageName = javaBreakpoint.getPackageName(); if (className == null) { return null; } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByPackageRule.java b/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByPackageRule.java index 5763a3648f64..98ef5a3409ec 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByPackageRule.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/XBreakpointGroupingByPackageRule.java @@ -15,10 +15,12 @@ */ package com.intellij.debugger.ui; -import com.intellij.debugger.ui.breakpoints.BreakpointWithHighlighter; -import com.intellij.debugger.ui.breakpoints.ExceptionBreakpoint; +import com.intellij.debugger.DebuggerManagerEx; +import com.intellij.debugger.ui.breakpoints.Breakpoint; +import com.intellij.debugger.ui.breakpoints.BreakpointManager; import com.intellij.icons.AllIcons; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule; import com.intellij.xdebugger.breakpoints.ui.XBreakpointsGroupingPriorities; import org.jetbrains.annotations.NotNull; @@ -41,11 +43,12 @@ public class XBreakpointGroupingByPackageRule extends XBreakpointGroupingRule @Override public XBreakpointPackageGroup getGroup(@NotNull B breakpoint, @NotNull Collection groups) { String packageName = null; - if (breakpoint instanceof BreakpointWithHighlighter) { - packageName = ((BreakpointWithHighlighter)breakpoint).getPackageName(); - } - else if (breakpoint instanceof ExceptionBreakpoint) { - packageName = ((ExceptionBreakpoint)breakpoint).getPackageName(); + if (breakpoint instanceof XBreakpoint) { + BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(JavaDebuggerSupport.getCurrentProject()).getBreakpointManager(); + Breakpoint javaBreakpoint = breakpointManager.findBreakpoint((XBreakpoint)breakpoint); + if (javaBreakpoint != null) { + packageName = javaBreakpoint.getPackageName(); + } } if (packageName == null) { return null; diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index fc3dc2016eca..0746168336b7 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -389,6 +389,10 @@ public class BreakpointManager { return null; } + public Breakpoint findBreakpoint(XBreakpoint xBreakpoint) { + return myBreakpoints.get(xBreakpoint); + } + private List myOriginalBreakpointsNodes = new ArrayList(); public void readExternal(@NotNull final Element parentNode) { @@ -584,6 +588,7 @@ public class BreakpointManager { Breakpoint breakpoint = createJavaBreakpoint(xBreakpoint); myBreakpoints.put(xBreakpoint, breakpoint); myBreakpointsListForIteration = null; + breakpoint.updateUI(); RequestManagerImpl.createRequests(breakpoint); myDispatcher.getMulticaster().breakpointsChanged(); } @@ -621,6 +626,7 @@ public class BreakpointManager { public void writeExternal(@NotNull final Element parentNode) { // restore old breakpoints for (Element group : myOriginalBreakpointsNodes) { + group.detach(); for (Element breakpoint : group.getChildren("breakpoint")) { if (breakpoint.getAttribute(CONVERTED_PARAM) == null) { breakpoint.setAttribute(CONVERTED_PARAM, "true"); From 59b01e4d958205ee847415585796d8f0ab69f4b2 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 19 Feb 2014 20:46:40 +0400 Subject: [PATCH 33/95] java move to xbreakpoints: - fixed old any exception breakpoint load --- .../ui/breakpoints/AnyExceptionBreakpoint.java | 16 ++++++++-------- .../ui/breakpoints/BreakpointManager.java | 18 +++++++++++------- .../ui/breakpoints/ExceptionBreakpoint.java | 13 +++++++------ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpoint.java index 25864de5d3af..8787290c2f09 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/AnyExceptionBreakpoint.java @@ -60,13 +60,13 @@ public class AnyExceptionBreakpoint extends ExceptionBreakpoint { // should be emty - does not make sense for this breakpoint } - //public void readExternal(Element parentNode) throws InvalidDataException { - // try { - // super.readExternal(parentNode); - // } - // catch (InvalidDataException e) { - // if(!READ_NO_CLASS_NAME.equals(e.getMessage())) throw e; - // } - //} + public void readExternal(Element parentNode) throws InvalidDataException { + try { + super.readExternal(parentNode); + } + catch (InvalidDataException e) { + if(!READ_NO_CLASS_NAME.equals(e.getMessage())) throw e; + } + } } \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 0746168336b7..a010bfd9701c 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -454,13 +454,17 @@ public class BreakpointManager { anyExceptionBreakpointGroup = group; } - //if (anyExceptionBreakpointGroup != null) { - // final Element breakpointElement = group.getChild("breakpoint"); - // if (breakpointElement != null) { - // getAnyExceptionBreakpoint().readExternal(breakpointElement); - // } - //} - + if (anyExceptionBreakpointGroup != null) { + final Element breakpointElement = group.getChild("breakpoint"); + if (breakpointElement != null) { + XBreakpointManager manager = XDebuggerManager.getInstance(myProject).getBreakpointManager(); + JavaExceptionBreakpointType type = (JavaExceptionBreakpointType)XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class); + XBreakpoint xBreakpoint = manager.getDefaultBreakpoint(type); + Breakpoint breakpoint = createJavaBreakpoint(xBreakpoint); + breakpoint.readExternal(breakpointElement); + addBreakpoint(breakpoint); + } + } } } catch (InvalidDataException ignored) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java index 538183e9451d..8a0b5159d5f7 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java @@ -233,12 +233,6 @@ public class ExceptionBreakpoint extends Breakpoint Date: Wed, 19 Feb 2014 21:20:58 +0400 Subject: [PATCH 34/95] java move to xbreakpoints: - cleanup after review --- .../ui/breakpoints/BreakpointManager.java | 80 +++++++++---------- .../JavaExceptionBreakpointType.java | 27 +++---- .../breakpoints/JavaFieldBreakpointType.java | 28 +++---- .../breakpoints/JavaLineBreakpointType.java | 2 +- .../breakpoints/JavaMethodBreakpointType.java | 2 +- .../JavaWildcardMethodBreakpointType.java | 27 +++---- 6 files changed, 77 insertions(+), 89 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index a010bfd9701c..e69fbd1ac460 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -31,9 +31,7 @@ import com.intellij.debugger.impl.DebuggerContextListener; import com.intellij.debugger.impl.DebuggerManagerImpl; import com.intellij.debugger.impl.DebuggerSession; import com.intellij.debugger.ui.JavaDebuggerSupport; -import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -43,10 +41,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.ui.MessageType; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.*; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.psi.PsiDocumentManager; @@ -273,22 +268,22 @@ public class BreakpointManager { } @NotNull - public ExceptionBreakpoint addExceptionBreakpoint(@NotNull String exceptionClassName, String packageName) { + public ExceptionBreakpoint addExceptionBreakpoint(@NotNull final String exceptionClassName, final String packageName) { ApplicationManager.getApplication().assertIsDispatchThread(); - JavaExceptionBreakpointType type = (JavaExceptionBreakpointType)XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class); - AccessToken token = WriteAction.start(); - try { - XBreakpoint xBreakpoint = XDebuggerManager.getInstance(myProject).getBreakpointManager() - .addBreakpoint(type, new JavaExceptionBreakpointProperties(exceptionClassName, packageName)); - ExceptionBreakpoint breakpoint = new ExceptionBreakpoint(myProject, exceptionClassName, packageName, xBreakpoint); - addBreakpoint(breakpoint); - if (LOG.isDebugEnabled()) { - LOG.debug("ExceptionBreakpoint Added"); + final JavaExceptionBreakpointType type = (JavaExceptionBreakpointType)XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class); + return ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public ExceptionBreakpoint compute() { + XBreakpoint xBreakpoint = XDebuggerManager.getInstance(myProject).getBreakpointManager() + .addBreakpoint(type, new JavaExceptionBreakpointProperties(exceptionClassName, packageName)); + ExceptionBreakpoint breakpoint = new ExceptionBreakpoint(myProject, exceptionClassName, packageName, xBreakpoint); + addBreakpoint(breakpoint); + if (LOG.isDebugEnabled()) { + LOG.debug("ExceptionBreakpoint Added"); + } + return breakpoint; } - return breakpoint; - } finally { - token.finish(); - } + }); } @Nullable @@ -307,17 +302,17 @@ public class BreakpointManager { return breakpoint; } - private > XLineBreakpoint addXLineBreakpoint(Class> typeCls, Document document, int lineIndex) { - XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); - VirtualFile file = FileDocumentManager.getInstance().getFile(document); - AccessToken token = WriteAction.start(); - try { - return XDebuggerManager.getInstance(myProject).getBreakpointManager() - .addLineBreakpoint((XLineBreakpointType)type, file.getUrl(), lineIndex, - ((XLineBreakpointType)type).createBreakpointProperties(file, lineIndex)); - } finally { - token.finish(); - } + private > XLineBreakpoint addXLineBreakpoint(Class> typeCls, Document document, final int lineIndex) { + final XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); + final VirtualFile file = FileDocumentManager.getInstance().getFile(document); + return ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public XLineBreakpoint compute() { + return XDebuggerManager.getInstance(myProject).getBreakpointManager() + .addLineBreakpoint((XLineBreakpointType)type, file.getUrl(), lineIndex, + ((XLineBreakpointType)type).createBreakpointProperties(file, lineIndex)); + } + }); } @Nullable @@ -548,14 +543,13 @@ public class BreakpointManager { private > XBreakpoint createXBreakpoint(Class> typeCls, Element breakpointNode) throws InvalidDataException { - XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); - AccessToken token = WriteAction.start(); - try { + final XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); + return ApplicationManager.getApplication().runWriteAction(new Computable() { + @Override + public XBreakpoint compute() { return XDebuggerManager.getInstance(myProject).getBreakpointManager() .addBreakpoint((XBreakpointType)type, type.createProperties()); - } finally { - token.finish(); - } + }}); } private > XLineBreakpoint createXLineBreakpoint(Class> typeCls, @@ -601,12 +595,12 @@ public class BreakpointManager { if (breakpoint == null) { return; } - AccessToken token = WriteAction.start(); - try { - getXBreakpointManager().removeBreakpoint(breakpoint.myXBreakpoint); - } finally { - token.finish(); - } + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + getXBreakpointManager().removeBreakpoint(breakpoint.myXBreakpoint); + } + }); } private synchronized void onBreakpointRemoved(@Nullable final XBreakpoint xBreakpoint) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaExceptionBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaExceptionBreakpointType.java index 89f6e432b3d3..f19157b5bf7d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaExceptionBreakpointType.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaExceptionBreakpointType.java @@ -21,9 +21,9 @@ import com.intellij.debugger.engine.JVMNameUtil; import com.intellij.icons.AllIcons; import com.intellij.ide.util.TreeClassChooser; import com.intellij.ide.util.TreeClassChooserFactory; -import com.intellij.openapi.application.AccessToken; -import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiClassOwner; @@ -44,7 +44,7 @@ import javax.swing.*; public class JavaExceptionBreakpointType extends JavaBreakpointTypeBase implements JavaBreakpointType { public JavaExceptionBreakpointType() { - super("javaException", DebuggerBundle.message("exception.breakpoints.tab.title")); + super("java-exception", DebuggerBundle.message("exception.breakpoints.tab.title")); } @NotNull @@ -104,25 +104,24 @@ public class JavaExceptionBreakpointType extends JavaBreakpointTypeBase addBreakpoint(Project project, JComponent parentComponent) { + public XBreakpoint addBreakpoint(final Project project, JComponent parentComponent) { final PsiClass throwableClass = JavaPsiFacade.getInstance(project).findClass("java.lang.Throwable", GlobalSearchScope.allScope(project)); TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project) .createInheritanceClassChooser(DebuggerBundle.message("add.exception.breakpoint.classchooser.title"), GlobalSearchScope.allScope(project), throwableClass, true, true, null); chooser.showDialog(); - PsiClass selectedClass = chooser.getSelected(); - String qName = selectedClass == null ? null : JVMNameUtil.getNonAnonymousClassName(selectedClass); + final PsiClass selectedClass = chooser.getSelected(); + final String qName = selectedClass == null ? null : JVMNameUtil.getNonAnonymousClassName(selectedClass); if (qName != null && qName.length() > 0) { - AccessToken token = WriteAction.start(); - try { - return XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpoint( - this, new JavaExceptionBreakpointProperties(qName, ((PsiClassOwner)selectedClass.getContainingFile()).getPackageName())); - } - finally { - token.finish(); - } + return ApplicationManager.getApplication().runWriteAction(new Computable>() { + @Override + public XBreakpoint compute() { + return XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpoint( + JavaExceptionBreakpointType.this, new JavaExceptionBreakpointProperties(qName, ((PsiClassOwner)selectedClass.getContainingFile()).getPackageName())); + } + }); } return null; } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java index 43860054bd8a..c539afe1263b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java @@ -19,8 +19,7 @@ import com.intellij.CommonBundle; import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.HelpID; import com.intellij.icons.AllIcons; -import com.intellij.openapi.application.AccessToken; -import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -44,7 +43,7 @@ import javax.swing.*; */ public class JavaFieldBreakpointType extends JavaLineBreakpointTypeBase implements JavaBreakpointType { public JavaFieldBreakpointType() { - super("javaField", DebuggerBundle.message("field.watchpoints.tab.title")); + super("java-field", DebuggerBundle.message("field.watchpoints.tab.title")); } @NotNull @@ -114,7 +113,7 @@ public class JavaFieldBreakpointType extends JavaLineBreakpointTypeBase fieldBreakpoint = XDebuggerManager.getInstance(project).getBreakpointManager() - .addLineBreakpoint(JavaFieldBreakpointType.this, psiFile.getVirtualFile().getUrl(), line, new JavaFieldBreakpointProperties(fieldName)); - if (fieldBreakpoint != null) { + final int line = document.getLineNumber(field.getTextOffset()); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + XLineBreakpoint fieldBreakpoint = XDebuggerManager.getInstance(project).getBreakpointManager() + .addLineBreakpoint(JavaFieldBreakpointType.this, psiFile.getVirtualFile().getUrl(), line, new JavaFieldBreakpointProperties(fieldName)); result.set(fieldBreakpoint); - return true; } - } - finally { - token.finish(); - } + }); + return true; } else { Messages.showMessageDialog(project, diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java index 91b270e4c4fb..4f67e68d9003 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointType.java @@ -38,7 +38,7 @@ import java.util.List; */ public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase implements JavaBreakpointType { public JavaLineBreakpointType() { - super("javaLine", DebuggerBundle.message("line.breakpoints.tab.title")); + super("java-line", DebuggerBundle.message("line.breakpoints.tab.title")); } @NotNull diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaMethodBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaMethodBreakpointType.java index d35983f03d2a..3e4afd7ac5cb 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaMethodBreakpointType.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaMethodBreakpointType.java @@ -36,7 +36,7 @@ import javax.swing.*; */ public class JavaMethodBreakpointType extends JavaLineBreakpointTypeBase implements JavaBreakpointType { public JavaMethodBreakpointType() { - super("javaMethod", DebuggerBundle.message("method.breakpoints.tab.title")); + super("java-method", DebuggerBundle.message("method.breakpoints.tab.title")); } @NotNull diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java index 3d19e35fea0b..dd28ee241f1a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java @@ -18,9 +18,9 @@ package com.intellij.debugger.ui.breakpoints; import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.HelpID; import com.intellij.icons.AllIcons; -import com.intellij.openapi.application.AccessToken; -import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; import com.intellij.xdebugger.XDebuggerManager; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; @@ -35,7 +35,7 @@ import javax.swing.*; */ public class JavaWildcardMethodBreakpointType extends JavaBreakpointTypeBase implements JavaBreakpointType { public JavaWildcardMethodBreakpointType() { - super("javaWildcardMethod", DebuggerBundle.message("method.breakpoints.tab.title")); + super("java-wildcard-method", DebuggerBundle.message("method.breakpoints.tab.title")); } @NotNull @@ -84,21 +84,20 @@ public class JavaWildcardMethodBreakpointType extends JavaBreakpointTypeBase addBreakpoint(Project project, JComponent parentComponent) { - AddWildcardBreakpointDialog dialog = new AddWildcardBreakpointDialog(project); + public XBreakpoint addBreakpoint(final Project project, JComponent parentComponent) { + final AddWildcardBreakpointDialog dialog = new AddWildcardBreakpointDialog(project); dialog.show(); if (!dialog.isOK()) { return null; } - AccessToken token = WriteAction.start(); - try { - return XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpoint(this, new JavaMethodBreakpointProperties( - dialog.getClassPattern(), - dialog.getMethodName())); - } - finally { - token.finish(); - } + return ApplicationManager.getApplication().runWriteAction(new Computable>() { + @Override + public XBreakpoint compute() { + return XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpoint(JavaWildcardMethodBreakpointType.this, new JavaMethodBreakpointProperties( + dialog.getClassPattern(), + dialog.getMethodName())); + } + }); } @Override From 3391b3bce4ddb2af3de8abd3e6daef0a572ac238 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Thu, 20 Feb 2014 17:45:49 +0400 Subject: [PATCH 35/95] fixed field and method breakpoints display name --- .../intellij/debugger/ui/breakpoints/FieldBreakpoint.java | 4 ++++ .../debugger/ui/breakpoints/JavaFieldBreakpointType.java | 7 ++++--- .../intellij/debugger/ui/breakpoints/MethodBreakpoint.java | 4 ++++ .../properties/JavaFieldBreakpointProperties.java | 7 ++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpoint.java index 4ee9983b7721..aa3a29511a2f 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FieldBreakpoint.java @@ -137,6 +137,10 @@ public class FieldBreakpoint extends BreakpointWithHighlighter result = Ref.create(null); AddFieldBreakpointDialog dialog = new AddFieldBreakpointDialog(project) { protected boolean validateData() { - String className = getClassName(); + final String className = getClassName(); if (className.length() == 0) { Messages.showMessageDialog(project, DebuggerBundle.message("error.field.breakpoint.class.name.not.specified"), DebuggerBundle.message("add.field.breakpoint.dialog.title"), Messages.getErrorIcon()); @@ -131,7 +132,7 @@ public class JavaFieldBreakpointType extends JavaLineBreakpointTypeBase fieldBreakpoint = XDebuggerManager.getInstance(project).getBreakpointManager() - .addLineBreakpoint(JavaFieldBreakpointType.this, psiFile.getVirtualFile().getUrl(), line, new JavaFieldBreakpointProperties(fieldName)); + .addLineBreakpoint(JavaFieldBreakpointType.this, psiFile.getVirtualFile().getUrl(), line, new JavaFieldBreakpointProperties(fieldName, className)); result.set(fieldBreakpoint); } }); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java index 2089d4952420..be10d56113f8 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java @@ -118,6 +118,10 @@ public class MethodBreakpoint extends BreakpointWithHighlighter Date: Thu, 20 Feb 2014 18:46:29 +0400 Subject: [PATCH 36/95] more clear breakpoint serialization format --- .../src/com/intellij/debugger/InstanceFilter.java | 8 +++++++- .../properties/JavaBreakpointProperties.java | 13 +++++++++++++ .../properties/JavaFieldBreakpointProperties.java | 4 ++-- .../com/intellij/ui/classFilter/ClassFilter.java | 5 +++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/InstanceFilter.java b/java/debugger/impl/src/com/intellij/debugger/InstanceFilter.java index 757da4c35a5e..09be13076ca1 100644 --- a/java/debugger/impl/src/com/intellij/debugger/InstanceFilter.java +++ b/java/debugger/impl/src/com/intellij/debugger/InstanceFilter.java @@ -20,6 +20,8 @@ import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizable; import com.intellij.openapi.util.WriteExternalException; import com.intellij.ui.classFilter.ClassFilter; +import com.intellij.util.xmlb.annotations.Attribute; +import com.intellij.util.xmlb.annotations.Tag; import com.intellij.util.xmlb.annotations.Transient; import org.jdom.Element; @@ -28,10 +30,13 @@ import org.jdom.Element; * Date: Aug 29, 2003 * Time: 2:49:27 PM */ +@Tag("instance-filter") public class InstanceFilter implements JDOMExternalizable{ public static final InstanceFilter[] EMPTY_ARRAY = new InstanceFilter[0]; - + + @Attribute("id") public long ID = 0; + @Attribute("enabled") public boolean ENABLED = true; public InstanceFilter() { @@ -47,6 +52,7 @@ public class InstanceFilter implements JDOMExternalizable{ return ID; } + @Transient public boolean isEnabled() { return ENABLED; } diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaBreakpointProperties.java index 47e35bb86c15..daab63a93265 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaBreakpointProperties.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaBreakpointProperties.java @@ -17,6 +17,9 @@ package org.jetbrains.java.debugger.breakpoints.properties; import com.intellij.debugger.InstanceFilter; import com.intellij.ui.classFilter.ClassFilter; +import com.intellij.util.xmlb.annotations.AbstractCollection; +import com.intellij.util.xmlb.annotations.OptionTag; +import com.intellij.util.xmlb.annotations.Tag; import com.intellij.xdebugger.breakpoints.XBreakpointProperties; import org.jetbrains.annotations.Nullable; @@ -24,16 +27,22 @@ import org.jetbrains.annotations.Nullable; * @author egor */ public class JavaBreakpointProperties extends XBreakpointProperties { + @OptionTag("count-filter-enabled") public boolean COUNT_FILTER_ENABLED = false; + @OptionTag("count-filter") public int COUNT_FILTER = 0; + @OptionTag("class-filters-enabled") public boolean CLASS_FILTERS_ENABLED = false; private ClassFilter[] myClassFilters; private ClassFilter[] myClassExclusionFilters; + @OptionTag("instance-filters-enabled") public boolean INSTANCE_FILTERS_ENABLED = false; private InstanceFilter[] myInstanceFilters; + @Tag("instance-filters") + @AbstractCollection(surroundWithTag = false) public InstanceFilter[] getInstanceFilters() { return myInstanceFilters != null ? myInstanceFilters : InstanceFilter.EMPTY_ARRAY; } @@ -49,6 +58,8 @@ public class JavaBreakpointProperties extend myInstanceFilters = filters; } + @Tag("class-filters") + @AbstractCollection(surroundWithTag = false) public final ClassFilter[] getClassFilters() { return myClassFilters != null ? myClassFilters : ClassFilter.EMPTY_ARRAY; } @@ -57,6 +68,8 @@ public class JavaBreakpointProperties extend myClassFilters = classFilters; } + @Tag("class-exclusion-filters") + @AbstractCollection(surroundWithTag = false) public ClassFilter[] getClassExclusionFilters() { return myClassExclusionFilters != null ? myClassExclusionFilters : ClassFilter.EMPTY_ARRAY; } diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java index 83f60613fbf0..13b760e81428 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaFieldBreakpointProperties.java @@ -25,10 +25,10 @@ public class JavaFieldBreakpointProperties extends JavaBreakpointProperties Date: Mon, 24 Feb 2014 12:43:59 +0400 Subject: [PATCH 37/95] IDEA-121126 Debugger: mute breakpoints: Throwable at ApplicationImpl.assertReadAccessAllowed() --- .../debugger/ui/breakpoints/BreakpointManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index e69fbd1ac460..9ff5dee71e91 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -757,7 +757,12 @@ public class BreakpointManager { if (myBreakpointsListForIteration == null) { myBreakpointsListForIteration = new ArrayList(myBreakpoints.size()); - for (XBreakpoint xBreakpoint : getXBreakpointManager().getAllBreakpoints()) { + XBreakpoint[] xBreakpoints = ApplicationManager.getApplication().runReadAction(new Computable[]>() { + public XBreakpoint[] compute() { + return getXBreakpointManager().getAllBreakpoints(); + } + }); + for (XBreakpoint xBreakpoint : xBreakpoints) { if (isJavaType(xBreakpoint)) { Breakpoint breakpoint = myBreakpoints.get(xBreakpoint); if (breakpoint == null) { From c7b3ad387da9c13fb0976744f9e353f8b5a33c05 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 24 Feb 2014 17:05:57 +0400 Subject: [PATCH 38/95] renamed attributes for exception breakpoint --- .../properties/JavaExceptionBreakpointProperties.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaExceptionBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaExceptionBreakpointProperties.java index 7a4847a70d62..e3b893e926ee 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaExceptionBreakpointProperties.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaExceptionBreakpointProperties.java @@ -25,10 +25,10 @@ public class JavaExceptionBreakpointProperties extends JavaBreakpointProperties< public boolean NOTIFY_CAUGHT = true; public boolean NOTIFY_UNCAUGHT = true; - @Attribute("class_name") + @Attribute("class") public String myQualifiedName; - @Attribute("package_name") + @Attribute("package") public String myPackageName; public JavaExceptionBreakpointProperties(String qualifiedName, String packageName) { From d3a084dd9b1400d784e26da6001322904a48cc00 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 25 Feb 2014 13:07:58 +0400 Subject: [PATCH 39/95] java-xbreakpoints: language selection support in condition and log expression --- .../evaluation/TextWithImportsImpl.java | 5 +- .../debugger/ui/breakpoints/Breakpoint.java | 18 ++-- .../debugger/JavaDebuggerEditorsProvider.java | 82 ++++++++++++++++++- .../ui/DefaultConditionComboBoxPanel.java | 61 ++++++++++++++ .../ui/DefaultLogExpressionComboBoxPanel.java | 59 +++++++++++++ .../ui/XBreakpointActionsPanel.java | 36 ++++---- .../ui/XDebuggerComboBoxProvider.java | 37 +++++++++ .../ui/XLightBreakpointPropertiesPanel.java | 46 ++++------- 8 files changed, 293 insertions(+), 51 deletions(-) create mode 100644 platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/DefaultConditionComboBoxPanel.java create mode 100644 platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/DefaultLogExpressionComboBoxPanel.java create mode 100644 platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XDebuggerComboBoxProvider.java diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java index 4eda8984e285..4cd13553b097 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java @@ -69,7 +69,10 @@ public final class TextWithImportsImpl implements TextWithImports{ } private static Trinity parseExternalForm(String s) { - String[] split = s.split(String.valueOf(DebuggerEditorImpl.SEPARATOR)); + // when serialized into a tag special symbols are now kept as is + // so our separator \r may be converted to \n or \r\n + s = StringUtil.convertLineSeparators(s); + String[] split = s.split(String.valueOf('\n')); return Trinity.create(split[0], split.length > 1 ? split[1] : "", split.length > 2 ? FileTypeManager.getInstance().getStdFileType(split[2]) : null); } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index 0f6d98220fda..94b2f09b6cba 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -244,12 +244,12 @@ public abstract class Breakpoint

    implements buf.append(getEventMessage(event)); buf.append("\n"); } - final TextWithImports expressionToEvaluate = getLogMessage(); - if (myXBreakpoint.getLogExpression() != null && !expressionToEvaluate.getText().isEmpty()) { + if (isLogExpressionEnabled()) { if(!debugProcess.isAttached()) { return; } - + + final TextWithImports expressionToEvaluate = getLogMessage(); try { ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(getProject(), new EvaluatingComputable() { @Override @@ -479,7 +479,11 @@ public abstract class Breakpoint

    implements } protected boolean isLogExpressionEnabled() { - return myXBreakpoint.getLogExpression() != null; + String expression = myXBreakpoint.getLogExpression(); + if (expression == null || expression.isEmpty()) { + return false; + } + return !getLogMessage().isEmpty(); } @Override @@ -588,7 +592,11 @@ public abstract class Breakpoint

    implements } protected boolean isConditionEnabled() { - return myXBreakpoint.getCondition() != null && !myXBreakpoint.getCondition().isEmpty(); + String condition = myXBreakpoint.getCondition(); + if (condition == null || condition.isEmpty()) { + return false; + } + return !getCondition().isEmpty(); } public void setCondition(String condition) { diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java b/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java index 21cdb36a3a4e..36d7170ebe70 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java @@ -1,16 +1,28 @@ package org.jetbrains.java.debugger; +import com.intellij.debugger.engine.evaluation.CodeFragmentKind; +import com.intellij.debugger.engine.evaluation.TextWithImports; +import com.intellij.debugger.engine.evaluation.TextWithImportsImpl; +import com.intellij.debugger.ui.DebuggerExpressionComboBox; import com.intellij.ide.highlighter.JavaFileType; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.JavaCodeFragmentFactory; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.xdebugger.XSourcePosition; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; import com.intellij.xdebugger.evaluation.XDebuggerEditorsProviderBase; +import com.intellij.xdebugger.impl.breakpoints.ui.XDebuggerComboBoxProvider; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class JavaDebuggerEditorsProvider extends XDebuggerEditorsProviderBase { +import javax.swing.*; + +public class JavaDebuggerEditorsProvider extends XDebuggerEditorsProviderBase implements XDebuggerComboBoxProvider { @NotNull @Override public FileType getFileType() { @@ -21,4 +33,72 @@ public class JavaDebuggerEditorsProvider extends XDebuggerEditorsProviderBase { protected PsiFile createExpressionCodeFragment(@NotNull Project project, @NotNull String text, @Nullable PsiElement context, boolean isPhysical) { return JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment(text, context, null, isPhysical); } + + @Override + public XBreakpointCustomPropertiesPanel> createConditionComboBoxPanel(Project project, + XDebuggerEditorsProvider debuggerEditorsProvider, + String historyId, + XSourcePosition sourcePosition) { + return new ExpressionComboBoxPanel(project, historyId, sourcePosition) { + @Override + public void saveTo(@NotNull XBreakpoint breakpoint) { + TextWithImports text = myComboBox.getText(); + final String condition = StringUtil.nullize(text.toExternalForm(), true); + breakpoint.setCondition(condition); + if (condition != null) { + myComboBox.addRecent(text); + } + } + + @Override + public void loadFrom(@NotNull XBreakpoint breakpoint) { + myComboBox.setText(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, StringUtil.notNullize(breakpoint.getCondition()))); + } + }; + } + + @Override + public XBreakpointCustomPropertiesPanel> createLogExpressionComboBoxPanel(Project project, + XDebuggerEditorsProvider debuggerEditorsProvider, + String historyId, + XSourcePosition sourcePosition) { + return new ExpressionComboBoxPanel(project, historyId, sourcePosition) { + @Override + public void saveTo(@NotNull XBreakpoint breakpoint) { + TextWithImports text = myComboBox.isEnabled() ? myComboBox.getText() : null; + breakpoint.setLogExpression(text != null ? text.toExternalForm() : null); + if (text != null) { + myComboBox.addRecent(text); + } + } + + @Override + public void loadFrom(@NotNull XBreakpoint breakpoint) { + myComboBox.setText(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, StringUtil.notNullize(breakpoint.getLogExpression()))); + } + }; + } + + private abstract class ExpressionComboBoxPanel extends XBreakpointCustomPropertiesPanel> { + protected final DebuggerExpressionComboBox myComboBox; + + private ExpressionComboBoxPanel(Project project, + String historyId, + XSourcePosition sourcePosition) { + myComboBox = new DebuggerExpressionComboBox(project, historyId); + if (sourcePosition != null) { + PsiElement element = getContextElement(sourcePosition.getFile(), sourcePosition.getOffset(), project); + myComboBox.setContext(element); + } + else { + myComboBox.setContext(null); + } + } + + @NotNull + @Override + public JComponent getComponent() { + return myComboBox; + } + } } \ No newline at end of file diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/DefaultConditionComboBoxPanel.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/DefaultConditionComboBoxPanel.java new file mode 100644 index 000000000000..9cee406625a7 --- /dev/null +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/DefaultConditionComboBoxPanel.java @@ -0,0 +1,61 @@ +/* + * 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.intellij.xdebugger.impl.breakpoints.ui; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.xdebugger.XSourcePosition; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; +import com.intellij.xdebugger.impl.ui.XDebuggerExpressionComboBox; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author egor + */ +public class DefaultConditionComboBoxPanel> extends XBreakpointCustomPropertiesPanel { + private XDebuggerExpressionComboBox myConditionComboBox; + + public DefaultConditionComboBoxPanel(Project project, + XDebuggerEditorsProvider debuggerEditorsProvider, + String historyId, + XSourcePosition sourcePosition) { + myConditionComboBox = new XDebuggerExpressionComboBox(project, debuggerEditorsProvider, historyId, sourcePosition); + } + + @NotNull + @Override + public JComponent getComponent() { + return myConditionComboBox.getComponent(); + } + + @Override + public void saveTo(@NotNull B breakpoint) { + final String condition = StringUtil.nullize(myConditionComboBox.getText(), true); + breakpoint.setCondition(condition); + if (condition != null) { + myConditionComboBox.saveTextInHistory(); + } + } + + @Override + public void loadFrom(@NotNull B breakpoint) { + myConditionComboBox.setText(StringUtil.notNullize(breakpoint.getCondition())); + } +} diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/DefaultLogExpressionComboBoxPanel.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/DefaultLogExpressionComboBoxPanel.java new file mode 100644 index 000000000000..a4ff954c7375 --- /dev/null +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/DefaultLogExpressionComboBoxPanel.java @@ -0,0 +1,59 @@ +/* + * 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.intellij.xdebugger.impl.breakpoints.ui; + +import com.intellij.openapi.project.Project; +import com.intellij.xdebugger.XSourcePosition; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; +import com.intellij.xdebugger.impl.ui.XDebuggerExpressionComboBox; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author egor + */ +public class DefaultLogExpressionComboBoxPanel> extends XBreakpointCustomPropertiesPanel { + private XDebuggerExpressionComboBox myLogExpressionComboBox; + + public DefaultLogExpressionComboBoxPanel(Project project, + XDebuggerEditorsProvider debuggerEditorsProvider, + String historyId, + XSourcePosition sourcePosition) { + myLogExpressionComboBox = new XDebuggerExpressionComboBox(project, debuggerEditorsProvider, historyId, sourcePosition); + } + + @NotNull + @Override + public JComponent getComponent() { + return myLogExpressionComboBox.getComponent(); + } + + @Override + public void saveTo(@NotNull B breakpoint) { + String logExpression = myLogExpressionComboBox.getComponent().isEnabled() ? myLogExpressionComboBox.getText() : null; + breakpoint.setLogExpression(logExpression); + myLogExpressionComboBox.saveTextInHistory(); + } + + @Override + public void loadFrom(@NotNull B breakpoint) { + String logExpression = breakpoint.getLogExpression(); + myLogExpressionComboBox.setText(logExpression != null ? logExpression : ""); + } +} diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointActionsPanel.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointActionsPanel.java index 26049ac69e51..89541841fc94 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointActionsPanel.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointActionsPanel.java @@ -19,9 +19,9 @@ import com.intellij.openapi.project.Project; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.XBreakpointManager; import com.intellij.xdebugger.breakpoints.XLineBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; -import com.intellij.xdebugger.impl.ui.XDebuggerExpressionComboBox; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,7 +44,7 @@ public class XBreakpointActionsPanel> extends XBreakpoi private JPanel myContentPane; private JPanel myMainPanel; private JCheckBox myTemporaryCheckBox; - private XDebuggerExpressionComboBox myLogExpressionComboBox; + XBreakpointCustomPropertiesPanel logExpressionPanel; public void init(Project project, XBreakpointManager breakpointManager, @NotNull B breakpoint, @Nullable XDebuggerEditorsProvider debuggerEditorsProvider) { init(project, breakpointManager, breakpoint); @@ -55,10 +55,18 @@ public class XBreakpointActionsPanel> extends XBreakpoi } }; - myLogExpressionComboBox = new XDebuggerExpressionComboBox(project, debuggerEditorsProvider, "breakpointLogExpression", myBreakpoint.getSourcePosition()); - JComponent logExpressionComponent = myLogExpressionComboBox.getComponent(); + if (debuggerEditorsProvider instanceof XDebuggerComboBoxProvider) { + logExpressionPanel = ((XDebuggerComboBoxProvider)debuggerEditorsProvider).createLogExpressionComboBoxPanel( + project, debuggerEditorsProvider, "breakpointCondition", myBreakpoint.getSourcePosition()); + } + else { + logExpressionPanel = + new DefaultLogExpressionComboBoxPanel(project, debuggerEditorsProvider, "breakpointCondition", myBreakpoint.getSourcePosition()); + } + + JComponent logExpressionComponent = logExpressionPanel.getComponent(); myLogExpressionPanel.add(logExpressionComponent, BorderLayout.CENTER); - myLogExpressionComboBox.setEnabled(false); + logExpressionComponent.setEnabled(false); myTemporaryCheckBox.setVisible(breakpoint instanceof XLineBreakpoint); myLogExpressionCheckBox.addActionListener(listener); DebuggerUIUtil.focusEditorOnCheck(myLogExpressionCheckBox, logExpressionComponent); @@ -81,8 +89,8 @@ public class XBreakpointActionsPanel> extends XBreakpoi } private void onCheckboxChanged() { - if (myLogExpressionComboBox != null) { - myLogExpressionComboBox.setEnabled(myLogExpressionCheckBox.isSelected()); + if (logExpressionPanel != null) { + logExpressionPanel.getComponent().setEnabled(myLogExpressionCheckBox.isSelected()); } } @@ -94,10 +102,9 @@ public class XBreakpointActionsPanel> extends XBreakpoi myTemporaryCheckBox.setSelected(((XLineBreakpoint)myBreakpoint).isTemporary()); } - if (myLogExpressionComboBox != null) { - String logExpression = myBreakpoint.getLogExpression(); - myLogExpressionCheckBox.setSelected(logExpression != null); - myLogExpressionComboBox.setText(logExpression != null ? logExpression : ""); + if (logExpressionPanel != null) { + myLogExpressionCheckBox.setSelected(myBreakpoint.getLogExpression() != null); + logExpressionPanel.loadFrom(myBreakpoint); } onCheckboxChanged(); } @@ -110,11 +117,8 @@ public class XBreakpointActionsPanel> extends XBreakpoi ((XLineBreakpoint)myBreakpoint).setTemporary(myTemporaryCheckBox.isSelected()); } - if (myLogExpressionComboBox != null) { - String logExpression = myLogExpressionCheckBox.isSelected() ? myLogExpressionComboBox.getText() : null; - myBreakpoint.setLogExpression(logExpression); - myLogExpressionComboBox.saveTextInHistory(); + if (logExpressionPanel != null) { + logExpressionPanel.saveTo(myBreakpoint); } - } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XDebuggerComboBoxProvider.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XDebuggerComboBoxProvider.java new file mode 100644 index 000000000000..fd5391146657 --- /dev/null +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XDebuggerComboBoxProvider.java @@ -0,0 +1,37 @@ +/* + * 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.intellij.xdebugger.impl.breakpoints.ui; + +import com.intellij.openapi.project.Project; +import com.intellij.xdebugger.XSourcePosition; +import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; +import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; + +/** + * @author egor + */ +public interface XDebuggerComboBoxProvider> { + XBreakpointCustomPropertiesPanel createConditionComboBoxPanel(Project project, + XDebuggerEditorsProvider debuggerEditorsProvider, + String historyId, + XSourcePosition sourcePosition); + + XBreakpointCustomPropertiesPanel createLogExpressionComboBoxPanel(Project project, + XDebuggerEditorsProvider debuggerEditorsProvider, + String historyId, + XSourcePosition sourcePosition); +} diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XLightBreakpointPropertiesPanel.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XLightBreakpointPropertiesPanel.java index bc6d5e4395ae..fc1095fac1d3 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XLightBreakpointPropertiesPanel.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XLightBreakpointPropertiesPanel.java @@ -16,7 +16,6 @@ package com.intellij.xdebugger.impl.breakpoints.ui; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.ui.popup.util.DetailView; import com.intellij.xdebugger.breakpoints.XBreakpoint; @@ -26,7 +25,6 @@ import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel; import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider; import com.intellij.xdebugger.impl.breakpoints.XBreakpointBase; import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil; -import com.intellij.xdebugger.impl.ui.XDebuggerExpressionComboBox; import javax.swing.*; import java.awt.*; @@ -83,8 +81,6 @@ public class XLightBreakpointPropertiesPanel> implement private List> mySubPanels = new ArrayList>(); - private XDebuggerExpressionComboBox myConditionComboBox; - private B myBreakpoint; public void setDetailView(DetailView detailView) { @@ -106,10 +102,25 @@ public class XLightBreakpointPropertiesPanel> implement myActionsPanel.init(project, breakpointManager, breakpoint, debuggerEditorsProvider); mySubPanels.add(myActionsPanel); + myCustomPanels = new ArrayList>(); if (debuggerEditorsProvider != null) { - myConditionComboBox = new XDebuggerExpressionComboBox(project, debuggerEditorsProvider, "breakpointCondition", myBreakpoint.getSourcePosition()); - JComponent conditionComponent = myConditionComboBox.getComponent(); - myConditionExpressionPanel.add(conditionComponent, BorderLayout.CENTER); + final XBreakpointCustomPropertiesPanel conditionPanel; + if (debuggerEditorsProvider instanceof XDebuggerComboBoxProvider) { + conditionPanel = ((XDebuggerComboBoxProvider)debuggerEditorsProvider).createConditionComboBoxPanel( + project, debuggerEditorsProvider, "breakpointCondition", myBreakpoint.getSourcePosition()); + } + else { + conditionPanel = + new DefaultConditionComboBoxPanel(project, debuggerEditorsProvider, "breakpointCondition", myBreakpoint.getSourcePosition()); + } + myConditionExpressionPanel.add(conditionPanel.getComponent(), BorderLayout.CENTER); + myCustomPanels.add(conditionPanel); + myMainPanel.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent event) { + IdeFocusManager.findInstance().requestFocus(conditionPanel.getComponent(), false); + } + }); } else { myConditionPanel.setVisible(false); } @@ -121,7 +132,6 @@ public class XLightBreakpointPropertiesPanel> implement } } - myCustomPanels = new ArrayList>(); XBreakpointCustomPropertiesPanel customPropertiesPanel = breakpointType.createCustomPropertiesPanel(); if (customPropertiesPanel != null) { myCustomPropertiesPanelWrapper.add(customPropertiesPanel.getComponent(), BorderLayout.CENTER); @@ -140,14 +150,6 @@ public class XLightBreakpointPropertiesPanel> implement myCustomPanels.add(customRightConditionPanel); } - myMainPanel.addFocusListener(new FocusAdapter() { - @Override - public void focusGained(FocusEvent event) { - if (myConditionComboBox != null) { - IdeFocusManager.findInstance().requestFocus(myConditionComboBox.getComponent(), false); - } - } - }); myEnabledCheckbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @@ -161,14 +163,6 @@ public class XLightBreakpointPropertiesPanel> implement panel.saveProperties(); } - if (myConditionComboBox != null) { - final String condition = StringUtil.nullize(myConditionComboBox.getText(), true); - myBreakpoint.setCondition(condition); - if (condition != null) { - myConditionComboBox.saveTextInHistory(); - } - } - for (XBreakpointCustomPropertiesPanel customPanel : myCustomPanels) { customPanel.saveTo(myBreakpoint); } @@ -183,10 +177,6 @@ public class XLightBreakpointPropertiesPanel> implement panel.loadProperties(); } - if (myConditionComboBox != null) { - myConditionComboBox.setText(StringUtil.notNullize(myBreakpoint.getCondition())); - } - for (XBreakpointCustomPropertiesPanel customPanel : myCustomPanels) { customPanel.loadFrom(myBreakpoint); } From 299183575d092625cef66bf166cd80c3f5953246 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 25 Feb 2014 16:34:26 +0400 Subject: [PATCH 40/95] java-xbreakpoints: support suspend policy defaults --- .../debugger/ui/breakpoints/Breakpoint.java | 2 +- .../ui/breakpoints/BreakpointManager.java | 62 +++++++++++-------- .../BreakpointPropertiesPanel.java | 10 +-- .../impl/breakpoints/BreakpointState.java | 15 +++++ .../breakpoints/ui/XSuspendPolicyPanel.java | 23 +++---- 5 files changed, 65 insertions(+), 47 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index 94b2f09b6cba..470890d7aa09 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -562,7 +562,7 @@ public abstract class Breakpoint

    implements } } - private static SuspendPolicy transformSuspendPolicy(String policy) { + static SuspendPolicy transformSuspendPolicy(String policy) { if (DebuggerSettings.SUSPEND_ALL.equals(policy)) { return SuspendPolicy.ALL; } else if (DebuggerSettings.SUSPEND_THREAD.equals(policy)) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 9ff5dee71e91..d832501571ce 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -54,6 +54,7 @@ import com.intellij.xdebugger.XDebuggerUtil; import com.intellij.xdebugger.breakpoints.*; import com.intellij.xdebugger.impl.DebuggerSupport; import com.intellij.xdebugger.impl.XDebugSessionImpl; +import com.intellij.xdebugger.impl.breakpoints.BreakpointState; import com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl; import com.intellij.xdebugger.impl.breakpoints.XDependentBreakpointManager; import com.sun.jdi.InternalException; @@ -85,7 +86,7 @@ public class BreakpointManager { private final Map myBreakpoints = new HashMap(); // breakpoints storage, access should be synchronized @Nullable private List myBreakpointsListForIteration = null; // another list for breakpoints iteration, unsynchronized access ok private final Map myUIProperties = new LinkedHashMap(); - private final Map, BreakpointDefaults> myBreakpointDefaults = new LinkedHashMap, BreakpointDefaults>(); + //private final Map, BreakpointDefaults> myBreakpointDefaults = new LinkedHashMap, BreakpointDefaults>(); private final EventDispatcher myDispatcher = EventDispatcher.create(BreakpointManagerListener.class); @@ -190,17 +191,34 @@ public class BreakpointManager { }); } - @NotNull - public BreakpointDefaults getBreakpointDefaults(Key category) { - BreakpointDefaults defaults = myBreakpointDefaults.get(category); - if (defaults == null) { - defaults = new BreakpointDefaults(); - } - return defaults; - } + //@NotNull + //public BreakpointDefaults getBreakpointDefaults(Key category) { + // BreakpointDefaults defaults = myBreakpointDefaults.get(category); + // if (defaults == null) { + // defaults = new BreakpointDefaults(); + // } + // return defaults; + //} public void setBreakpointDefaults(Key category, BreakpointDefaults defaults) { - myBreakpointDefaults.put(category, defaults); + Class typeCls = null; + if (LineBreakpoint.CATEGORY.toString().equals(category.toString())) { + typeCls = JavaLineBreakpointType.class; + } + else if (MethodBreakpoint.CATEGORY.toString().equals(category.toString())) { + typeCls = JavaMethodBreakpointType.class; + } + else if (FieldBreakpoint.CATEGORY.toString().equals(category.toString())) { + typeCls = JavaFieldBreakpointType.class; + } + else if (ExceptionBreakpoint.CATEGORY.toString().equals(category.toString())) { + typeCls = JavaExceptionBreakpointType.class; + } + if (typeCls != null) { + XBreakpointType, ?> type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); + BreakpointState.setDefaultSuspendPolicy(type.getId(), Breakpoint.transformSuspendPolicy(defaults.getSuspendPolicy())); + } + //myBreakpointDefaults.put(category, defaults); } @@ -421,6 +439,10 @@ public class BreakpointManager { if (group.getName().equals(RULES_GROUP_NAME)) { continue; } + // skip already converted + if (group.getAttribute(CONVERTED_PARAM) != null) { + continue; + } final String categoryName = group.getName(); final Key breakpointCategory = BreakpointCategory.lookup(categoryName); final String defaultPolicy = group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME); @@ -433,10 +455,6 @@ public class BreakpointManager { //final BreakpointFactory factory = BreakpointFactory.getInstance(breakpointCategory); //if (factory != null) { for (Element breakpointNode : group.getChildren("breakpoint")) { - // skip already converted - if (breakpointNode.getAttribute(CONVERTED_PARAM) != null) { - continue; - } //Breakpoint breakpoint = factory.createBreakpoint(myProject, breakpointNode); Breakpoint breakpoint = createBreakpoint(categoryName, breakpointNode); breakpoint.readExternal(breakpointNode); @@ -624,20 +642,10 @@ public class BreakpointManager { public void writeExternal(@NotNull final Element parentNode) { // restore old breakpoints for (Element group : myOriginalBreakpointsNodes) { + if (group.getAttribute(CONVERTED_PARAM) == null) { + group.setAttribute(CONVERTED_PARAM, "true"); + } group.detach(); - for (Element breakpoint : group.getChildren("breakpoint")) { - if (breakpoint.getAttribute(CONVERTED_PARAM) == null) { - breakpoint.setAttribute(CONVERTED_PARAM, "true"); - } - } - if (RULES_GROUP_NAME.equals(group.getName())) { - List rules = group.getChildren("rule"); - for (Element rule : rules) { - if (rule.getAttribute(CONVERTED_PARAM) == null) { - rule.setAttribute(CONVERTED_PARAM, "true"); - } - } - } } parentNode.addContent(myOriginalBreakpointsNodes); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java index ad9d5c93a47a..afeeb13aeb10 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointPropertiesPanel.java @@ -211,8 +211,8 @@ public abstract class BreakpointPropertiesPanel { final ItemListener suspendPolicyChangeListener = new ItemListener() { @Override public void itemStateChanged(final ItemEvent e) { - final BreakpointDefaults defaults = getBreakpointManager(myProject).getBreakpointDefaults(breakpointCategory); - myMakeDefaultButton.setEnabled(!defaults.getSuspendPolicy().equals(getSelectedSuspendPolicy()) || defaults.isConditionEnabled() != myConditionCheckbox.isSelected()); + //final BreakpointDefaults defaults = getBreakpointManager(myProject).getBreakpointDefaults(breakpointCategory); + //myMakeDefaultButton.setEnabled(!defaults.getSuspendPolicy().equals(getSelectedSuspendPolicy()) || defaults.isConditionEnabled() != myConditionCheckbox.isSelected()); } }; @@ -429,13 +429,13 @@ public abstract class BreakpointPropertiesPanel { } private void updateSuspendPolicyRbFont() { - final String defPolicy = getBreakpointManager(myProject).getBreakpointDefaults(myBreakpointCategory).getSuspendPolicy(); + //final String defPolicy = getBreakpointManager(myProject).getBreakpointDefaults(myBreakpointCategory).getSuspendPolicy(); final Font font = myRbSuspendAll.getFont().deriveFont(Font.PLAIN); final Font boldFont = font.deriveFont(Font.BOLD); - myRbSuspendAll.setFont(DebuggerSettings.SUSPEND_ALL.equals(defPolicy)? boldFont : font); - myRbSuspendThread.setFont(DebuggerSettings.SUSPEND_THREAD.equals(defPolicy)? boldFont : font); + //myRbSuspendAll.setFont(DebuggerSettings.SUSPEND_ALL.equals(defPolicy)? boldFont : font); + //myRbSuspendThread.setFont(DebuggerSettings.SUSPEND_THREAD.equals(defPolicy)? boldFont : font); } protected ClassFilter createClassConditionFilter() { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointState.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointState.java index 530fb995aae9..39bdb0971a95 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointState.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointState.java @@ -15,6 +15,7 @@ */ package com.intellij.xdebugger.impl.breakpoints; +import com.intellij.ide.util.PropertiesComponent; import com.intellij.util.xmlb.annotations.Attribute; import com.intellij.util.xmlb.annotations.Property; import com.intellij.util.xmlb.annotations.Tag; @@ -48,6 +49,7 @@ public class BreakpointState, P extends XBreakpointProp myEnabled = enabled; myTypeId = typeId; myTimeStamp = timeStamp; + mySuspendPolicy = getDefaultSuspendPolicy(myTypeId); // apply default } @Attribute("enabled") @@ -142,4 +144,17 @@ public class BreakpointState, P extends XBreakpointProp public void setTimeStamp(long timeStamp) { myTimeStamp = timeStamp; } + + public static SuspendPolicy getDefaultSuspendPolicy(String typeId) { + String defaultPolicy = PropertiesComponent.getInstance().getValue(getDefaultSuspendPolicyKey(typeId)); + return defaultPolicy != null ? SuspendPolicy.valueOf(defaultPolicy) : SuspendPolicy.ALL; + } + + public static void setDefaultSuspendPolicy(String typeId, SuspendPolicy suspendPolicy) { + PropertiesComponent.getInstance().setValue(getDefaultSuspendPolicyKey(typeId), suspendPolicy.name()); + } + + private static String getDefaultSuspendPolicyKey(String typeId) { + return "debugger.suspend.policy-" + typeId; + } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XSuspendPolicyPanel.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XSuspendPolicyPanel.java index c46914fa06b8..1325687fc8f5 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XSuspendPolicyPanel.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XSuspendPolicyPanel.java @@ -15,11 +15,11 @@ */ package com.intellij.xdebugger.impl.breakpoints.ui; -import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.project.Project; import com.intellij.xdebugger.breakpoints.SuspendPolicy; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.XBreakpointManager; +import com.intellij.xdebugger.impl.breakpoints.BreakpointState; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -72,7 +72,7 @@ public class XSuspendPolicyPanel> extends XBreakpointPr mySuspendPolicyGroup.add(mySuspendAll); mySuspendPolicyGroup.add(mySuspendThread); - updateSuspendPolicyFont(createSettingsKey()); + updateSuspendPolicyFont(); ItemListener suspendPolicyChangeListener = new ItemListener() { @Override @@ -89,9 +89,8 @@ public class XSuspendPolicyPanel> extends XBreakpointPr @Override public void actionPerformed(ActionEvent e) { SuspendPolicy suspendPolicy = getSelectedSuspendPolicy(); - String settingsKey = createSettingsKey(); - PropertiesComponent.getInstance().setValue(settingsKey, suspendPolicy.name()); - updateSuspendPolicyFont(settingsKey); + BreakpointState.setDefaultSuspendPolicy(myBreakpointType.getId(), suspendPolicy); + updateSuspendPolicyFont(); if (SuspendPolicy.THREAD == suspendPolicy) { mySuspendThread.requestFocus(); } @@ -104,20 +103,16 @@ public class XSuspendPolicyPanel> extends XBreakpointPr } private void updateMakeDefaultEnableState() { - myMakeDefaultButton.setEnabled(!getSelectedSuspendPolicy().name().equalsIgnoreCase(PropertiesComponent.getInstance().getValue(createSettingsKey(), SuspendPolicy.ALL.name()))); + myMakeDefaultButton.setEnabled(!getSelectedSuspendPolicy().equals(BreakpointState.getDefaultSuspendPolicy(myBreakpointType.getId()))); } - private String createSettingsKey() { - return "debugger.suspend.policy-" + myBreakpointType.getId(); - } - - private void updateSuspendPolicyFont(String settingsKey) { - String defaultPolicy = PropertiesComponent.getInstance().getValue(settingsKey, SuspendPolicy.ALL.name()); + private void updateSuspendPolicyFont() { + SuspendPolicy defaultPolicy = BreakpointState.getDefaultSuspendPolicy(myBreakpointType.getId()); Font font = mySuspendAll.getFont().deriveFont(Font.PLAIN); Font boldFont = font.deriveFont(Font.BOLD); - mySuspendAll.setFont(SuspendPolicy.ALL.name().equalsIgnoreCase(defaultPolicy) ? boldFont : font); - mySuspendThread.setFont(SuspendPolicy.THREAD.name().equalsIgnoreCase(defaultPolicy) ? boldFont : font); + mySuspendAll.setFont(SuspendPolicy.ALL.equals(defaultPolicy) ? boldFont : font); + mySuspendThread.setFont(SuspendPolicy.THREAD.equals(defaultPolicy) ? boldFont : font); } private void changeEnableState(boolean selected) { From 8541a5c75ab3c11c13e06b2a8838544c3d50cbe7 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 26 Feb 2014 12:05:25 +0400 Subject: [PATCH 41/95] removed useless string conversion --- .../debugger/engine/evaluation/TextWithImportsImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java index 4cd13553b097..f52100aec91b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java @@ -72,7 +72,7 @@ public final class TextWithImportsImpl implements TextWithImports{ // when serialized into a tag special symbols are now kept as is // so our separator \r may be converted to \n or \r\n s = StringUtil.convertLineSeparators(s); - String[] split = s.split(String.valueOf('\n')); + String[] split = s.split("\n"); return Trinity.create(split[0], split.length > 1 ? split[1] : "", split.length > 2 ? FileTypeManager.getInstance().getStdFileType(split[2]) : null); } From 1e9b8fbf5b812c666399af1990f046de60dee0c4 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 26 Feb 2014 17:19:39 +0400 Subject: [PATCH 42/95] java-xbreakpoints: rewrote breakpoints defaults --- .../ui/breakpoints/BreakpointManager.java | 2 +- .../impl/breakpoints/BreakpointState.java | 15 +---- .../breakpoints/XBreakpointManagerImpl.java | 57 +++++++++++++++++-- .../breakpoints/ui/XSuspendPolicyPanel.java | 8 +-- 4 files changed, 60 insertions(+), 22 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index d832501571ce..02217236f4ed 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -216,7 +216,7 @@ public class BreakpointManager { } if (typeCls != null) { XBreakpointType, ?> type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); - BreakpointState.setDefaultSuspendPolicy(type.getId(), Breakpoint.transformSuspendPolicy(defaults.getSuspendPolicy())); + ((XBreakpointManagerImpl)getXBreakpointManager()).getBreakpointDefaults(type).setSuspendPolicy(Breakpoint.transformSuspendPolicy(defaults.getSuspendPolicy())); } //myBreakpointDefaults.put(category, defaults); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointState.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointState.java index 39bdb0971a95..0c7257f226f5 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointState.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/BreakpointState.java @@ -15,7 +15,6 @@ */ package com.intellij.xdebugger.impl.breakpoints; -import com.intellij.ide.util.PropertiesComponent; import com.intellij.util.xmlb.annotations.Attribute; import com.intellij.util.xmlb.annotations.Property; import com.intellij.util.xmlb.annotations.Tag; @@ -49,7 +48,6 @@ public class BreakpointState, P extends XBreakpointProp myEnabled = enabled; myTypeId = typeId; myTimeStamp = timeStamp; - mySuspendPolicy = getDefaultSuspendPolicy(myTypeId); // apply default } @Attribute("enabled") @@ -145,16 +143,7 @@ public class BreakpointState, P extends XBreakpointProp myTimeStamp = timeStamp; } - public static SuspendPolicy getDefaultSuspendPolicy(String typeId) { - String defaultPolicy = PropertiesComponent.getInstance().getValue(getDefaultSuspendPolicyKey(typeId)); - return defaultPolicy != null ? SuspendPolicy.valueOf(defaultPolicy) : SuspendPolicy.ALL; - } - - public static void setDefaultSuspendPolicy(String typeId, SuspendPolicy suspendPolicy) { - PropertiesComponent.getInstance().setValue(getDefaultSuspendPolicyKey(typeId), suspendPolicy.name()); - } - - private static String getDefaultSuspendPolicyKey(String typeId) { - return "debugger.suspend.policy-" + typeId; + void applyDefaults(BreakpointState state) { + state.mySuspendPolicy = mySuspendPolicy; } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java index eb183f9145e9..09b8cb44e1b4 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java @@ -50,6 +50,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta public static final SkipDefaultValuesSerializationFilters SERIALIZATION_FILTER = new SkipDefaultValuesSerializationFilters(); private final MultiValuesMap> myBreakpoints = new MultiValuesMap>(true); private final Map> myDefaultBreakpoints = new LinkedHashMap>(); + private final Map> myBreakpointsDefaults = new LinkedHashMap>(); private final Set> myAllBreakpoints = new HashSet>(); private final Map> myDispatchers = new HashMap>(); private XBreakpointsDialogState myBreakpointsDialogSettings; @@ -127,6 +128,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta BreakpointState state = new BreakpointState,T,XBreakpointType,T>>(enabled, type.getId(), defaultBreakpoint ? 0 : myTime++); + getBreakpointDefaults(type).applyDefaults(state); return new XBreakpointBase,T, BreakpointState>(type, this, properties, state); } @@ -213,8 +215,11 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta @Nullable final T properties, boolean temporary) { ApplicationManager.getApplication().assertWriteAccessAllowed(); + LineBreakpointState state = new LineBreakpointState(true, type.getId(), fileUrl, line, temporary, + myTime++); + getBreakpointDefaults(type).applyDefaults(state); XLineBreakpointImpl breakpoint = new XLineBreakpointImpl(type, this, properties, - new LineBreakpointState(true, type.getId(), fileUrl, line, temporary, myTime++)); + state); addBreakpoint(breakpoint, false, true); return breakpoint; } @@ -353,6 +358,12 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta state.getBreakpoints().add(breakpoint.getState()); } + for (Map.Entry> entry : myBreakpointsDefaults.entrySet()) { + if (statesAreDifferent(entry.getValue(), createBreakpointDefaults(entry.getKey()))) { + state.getBreakpointsDefaults().add(entry.getValue()); + } + } + state.setBreakpointsDialogProperties(myBreakpointsDialogSettings); state.setTime(myTime); return state; @@ -366,9 +377,13 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta } BreakpointState defaultState = ((XBreakpointBase)defaultBreakpoint).getState(); - Element defaultElement = XmlSerializer.serialize(defaultState, SERIALIZATION_FILTER); - Element currentElement = XmlSerializer.serialize(state, SERIALIZATION_FILTER); - return !JDOMUtil.areElementsEqual(defaultElement, currentElement); + return statesAreDifferent(state, defaultState); + } + + private static boolean statesAreDifferent(BreakpointState state1, BreakpointState state2) { + Element elem1 = XmlSerializer.serialize(state1, SERIALIZATION_FILTER); + Element elem2 = XmlSerializer.serialize(state2, SERIALIZATION_FILTER); + return !JDOMUtil.areElementsEqual(elem1, elem2); } @Override @@ -377,6 +392,8 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta myAllBreakpoints.clear(); myDefaultBreakpoints.clear(); + myBreakpointsDefaults.clear(); + for (BreakpointState breakpointState : state.getDefaultBreakpoints()) { loadBreakpoint(breakpointState, true); } @@ -392,6 +409,12 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta for (BreakpointState breakpointState : state.getBreakpoints()) { loadBreakpoint(breakpointState, false); } + + for (BreakpointState defaults : state.getBreakpointsDefaults()) { + XBreakpointType type = XBreakpointUtil.findType(defaults.getTypeId()); + myBreakpointsDefaults.put(type, defaults); + } + myDependentBreakpointManager.loadState(); myLineBreakpointManager.updateBreakpointsUI(); myTime = state.getTime(); @@ -439,11 +462,26 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta return breakpointState.createBreakpoint(type, this); } + public BreakpointState getBreakpointDefaults(XBreakpointType type) { + BreakpointState defaultState = myBreakpointsDefaults.get(type); + if (defaultState == null) { + defaultState = createBreakpointDefaults(type); + myBreakpointsDefaults.put(type, defaultState); + } + return defaultState; + } + + private static BreakpointState createBreakpointDefaults(XBreakpointType type) { + BreakpointState state = new BreakpointState(); + state.setTypeId(type.getId()); + return state; + } @Tag("breakpoint-manager") public static class BreakpointManagerState { private List myDefaultBreakpoints = new ArrayList(); private List myBreakpoints = new ArrayList(); + private List myBreakpointsDefaults = new ArrayList(); private XBreakpointsDialogState myBreakpointsDialogProperties; private long myTime; @@ -461,6 +499,13 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta return myBreakpoints; } + @Tag("breakpoints-defaults") + @AbstractCollection(surroundWithTag = false, + elementTypes = {BreakpointState.class, LineBreakpointState.class}) + public List getBreakpointsDefaults() { + return myBreakpointsDefaults; + } + @Tag("breakpoints-dialog") public XBreakpointsDialogState getBreakpointsDialogProperties() { return myBreakpointsDialogProperties; @@ -475,6 +520,10 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta myDefaultBreakpoints = defaultBreakpoints; } + public void setBreakpointsDefaults(List breakpointsDefaults) { + myBreakpointsDefaults = breakpointsDefaults; + } + public void setBreakpointsDialogProperties(XBreakpointsDialogState breakpointsDialogProperties) { myBreakpointsDialogProperties = breakpointsDialogProperties; } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XSuspendPolicyPanel.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XSuspendPolicyPanel.java index 1325687fc8f5..b3dcd1302735 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XSuspendPolicyPanel.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XSuspendPolicyPanel.java @@ -19,7 +19,7 @@ import com.intellij.openapi.project.Project; import com.intellij.xdebugger.breakpoints.SuspendPolicy; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.XBreakpointManager; -import com.intellij.xdebugger.impl.breakpoints.BreakpointState; +import com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -89,7 +89,7 @@ public class XSuspendPolicyPanel> extends XBreakpointPr @Override public void actionPerformed(ActionEvent e) { SuspendPolicy suspendPolicy = getSelectedSuspendPolicy(); - BreakpointState.setDefaultSuspendPolicy(myBreakpointType.getId(), suspendPolicy); + ((XBreakpointManagerImpl)myBreakpointManager).getBreakpointDefaults(myBreakpointType).setSuspendPolicy(suspendPolicy); updateSuspendPolicyFont(); if (SuspendPolicy.THREAD == suspendPolicy) { mySuspendThread.requestFocus(); @@ -103,11 +103,11 @@ public class XSuspendPolicyPanel> extends XBreakpointPr } private void updateMakeDefaultEnableState() { - myMakeDefaultButton.setEnabled(!getSelectedSuspendPolicy().equals(BreakpointState.getDefaultSuspendPolicy(myBreakpointType.getId()))); + myMakeDefaultButton.setEnabled(!getSelectedSuspendPolicy().equals(((XBreakpointManagerImpl)myBreakpointManager).getBreakpointDefaults(myBreakpointType).getSuspendPolicy())); } private void updateSuspendPolicyFont() { - SuspendPolicy defaultPolicy = BreakpointState.getDefaultSuspendPolicy(myBreakpointType.getId()); + SuspendPolicy defaultPolicy = ((XBreakpointManagerImpl)myBreakpointManager).getBreakpointDefaults(myBreakpointType).getSuspendPolicy(); Font font = mySuspendAll.getFont().deriveFont(Font.PLAIN); Font boldFont = font.deriveFont(Font.BOLD); From bce82afec01f4cfb865b75bc3f6dc66b2fd9d6ae Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 26 Feb 2014 17:47:44 +0400 Subject: [PATCH 43/95] java-xbreakpoints: do not save empty conditions --- .../jetbrains/java/debugger/JavaDebuggerEditorsProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java b/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java index 36d7170ebe70..ac530ccd4b76 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java @@ -43,7 +43,7 @@ public class JavaDebuggerEditorsProvider extends XDebuggerEditorsProviderBase im @Override public void saveTo(@NotNull XBreakpoint breakpoint) { TextWithImports text = myComboBox.getText(); - final String condition = StringUtil.nullize(text.toExternalForm(), true); + final String condition = !text.getText().isEmpty() ? text.toExternalForm() : null; breakpoint.setCondition(condition); if (condition != null) { myComboBox.addRecent(text); From bb586ed64c1baf57a6e8749c66a3daeb23579acc Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 26 Feb 2014 18:14:41 +0400 Subject: [PATCH 44/95] java-xbreakpoints: do not save empty log message --- .../jetbrains/java/debugger/JavaDebuggerEditorsProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java b/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java index ac530ccd4b76..9815a7fd110d 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/JavaDebuggerEditorsProvider.java @@ -65,8 +65,8 @@ public class JavaDebuggerEditorsProvider extends XDebuggerEditorsProviderBase im return new ExpressionComboBoxPanel(project, historyId, sourcePosition) { @Override public void saveTo(@NotNull XBreakpoint breakpoint) { - TextWithImports text = myComboBox.isEnabled() ? myComboBox.getText() : null; - breakpoint.setLogExpression(text != null ? text.toExternalForm() : null); + TextWithImports text = myComboBox.getText(); + breakpoint.setLogExpression(myComboBox.isEnabled() && !text.getText().isEmpty() ? text.toExternalForm() : null); if (text != null) { myComboBox.addRecent(text); } From 600736cf0b9ede495353e6a6c69619ed67e2d535 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Thu, 27 Feb 2014 17:25:11 +0400 Subject: [PATCH 45/95] preserve non java breakpoints in the BreakpointManager --- .../intellij/debugger/ui/breakpoints/BreakpointManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 02217236f4ed..35e5b86567f2 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -777,9 +777,10 @@ public class BreakpointManager { breakpoint = createJavaBreakpoint(xBreakpoint); myBreakpoints.put(xBreakpoint, breakpoint); } - myBreakpointsListForIteration.add(breakpoint); } } + + myBreakpointsListForIteration.addAll(myBreakpoints.values()); } return myBreakpointsListForIteration; } From d63786dea4d2347d9d9c84e55f1f2f4617ba3db9 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Thu, 27 Feb 2014 18:46:05 +0400 Subject: [PATCH 46/95] allow non java xbreakpoints to be used in debugger-impl --- .../debugger/ui/breakpoints/Breakpoint.java | 39 ++++++++++++------- .../ui/breakpoints/BreakpointManager.java | 20 ++++------ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index 470890d7aa09..d846767b4b8a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -488,64 +488,73 @@ public abstract class Breakpoint

    implements @Override public boolean isCountFilterEnabled() { - return myXBreakpoint.getProperties().COUNT_FILTER_ENABLED; + if (getProperties() == null) { + return false; + } + return getProperties().COUNT_FILTER_ENABLED; } public void setCountFilterEnabled(boolean enabled) { - myXBreakpoint.getProperties().COUNT_FILTER_ENABLED = enabled; + getProperties().COUNT_FILTER_ENABLED = enabled; } @Override public int getCountFilter() { - return myXBreakpoint.getProperties().COUNT_FILTER; + return getProperties().COUNT_FILTER; } public void setCountFilter(int filter) { - myXBreakpoint.getProperties().COUNT_FILTER = filter; + getProperties().COUNT_FILTER = filter; } @Override public boolean isClassFiltersEnabled() { - return myXBreakpoint.getProperties().CLASS_FILTERS_ENABLED; + if (getProperties() == null) { + return false; + } + return getProperties().CLASS_FILTERS_ENABLED; } public void setClassFiltersEnabled(boolean enabled) { - myXBreakpoint.getProperties().CLASS_FILTERS_ENABLED = enabled; + getProperties().CLASS_FILTERS_ENABLED = enabled; } @Override public ClassFilter[] getClassFilters() { - return myXBreakpoint.getProperties().getClassFilters(); + return getProperties().getClassFilters(); } public void setClassFilters(ClassFilter[] filters) { - myXBreakpoint.getProperties().setClassFilters(filters); + getProperties().setClassFilters(filters); } @Override public ClassFilter[] getClassExclusionFilters() { - return myXBreakpoint.getProperties().getClassExclusionFilters(); + return getProperties().getClassExclusionFilters(); } protected void setClassExclusionFilters(ClassFilter[] filters) { - myXBreakpoint.getProperties().setClassExclusionFilters(filters); + getProperties().setClassExclusionFilters(filters); } @Override public boolean isInstanceFiltersEnabled() { - return myXBreakpoint.getProperties().INSTANCE_FILTERS_ENABLED; + if (getProperties() == null) { + return false; + } + return getProperties().INSTANCE_FILTERS_ENABLED; } public void setInstanceFiltersEnabled(boolean enabled) { - myXBreakpoint.getProperties().INSTANCE_FILTERS_ENABLED = enabled; + getProperties().INSTANCE_FILTERS_ENABLED = enabled; } @Override public InstanceFilter[] getInstanceFilters() { - return myXBreakpoint.getProperties().getInstanceFilters(); + return getProperties().getInstanceFilters(); } public void setInstanceFilters(InstanceFilter[] filters) { - myXBreakpoint.getProperties().setInstanceFilters(filters); + getProperties().setInstanceFilters(filters); } private static String getSuspendPolicy(XBreakpoint breakpoint) { @@ -604,6 +613,6 @@ public abstract class Breakpoint

    implements } protected void addInstanceFilter(long l) { - myXBreakpoint.getProperties().addInstanceFilter(l); + getProperties().addInstanceFilter(l); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 35e5b86567f2..d16084dec557 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -153,18 +153,14 @@ public class BreakpointManager { @Override public void breakpointRemoved(@NotNull XBreakpoint xBreakpoint) { - if (isJavaType(xBreakpoint)) { - onBreakpointRemoved(xBreakpoint); - } + onBreakpointRemoved(xBreakpoint); } @Override public void breakpointChanged(@NotNull XBreakpoint xBreakpoint) { - if (isJavaType(xBreakpoint)) { - Breakpoint breakpoint = myBreakpoints.get(xBreakpoint); - if (breakpoint != null) { - fireBreakpointChanged(breakpoint); - } + Breakpoint breakpoint = myBreakpoints.get(xBreakpoint); + if (breakpoint != null) { + fireBreakpointChanged(breakpoint); } } }); @@ -597,16 +593,14 @@ public class BreakpointManager { public synchronized void addBreakpoint(Breakpoint breakpoint) { myBreakpoints.put(breakpoint.myXBreakpoint, breakpoint); myBreakpointsListForIteration = null; + breakpoint.updateUI(); + RequestManagerImpl.createRequests(breakpoint); myDispatcher.getMulticaster().breakpointsChanged(); } private synchronized void onBreakpointAdded(XBreakpoint xBreakpoint) { Breakpoint breakpoint = createJavaBreakpoint(xBreakpoint); - myBreakpoints.put(xBreakpoint, breakpoint); - myBreakpointsListForIteration = null; - breakpoint.updateUI(); - RequestManagerImpl.createRequests(breakpoint); - myDispatcher.getMulticaster().breakpointsChanged(); + addBreakpoint(breakpoint); } public void removeBreakpoint(@Nullable final Breakpoint breakpoint) { From a0f4efcd3dadcc0722816b1aa9cdcc52d8b3e1c6 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Thu, 27 Feb 2014 18:16:09 +0100 Subject: [PATCH 47/95] cleanup after batch folding operation end even in case of exception: to avoid observing invalid fold regions on subsequent batch folding operations --- .../openapi/editor/impl/FoldingModelImpl.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java index 962230e8680e..5cfc4d00facb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java @@ -212,17 +212,20 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedDocumentList myIsBatchFoldingProcessing = true; myFoldTree.myCachedLastIndex = -1; - operation.run(); - myFoldTree.myCachedLastIndex = -1; + try { + operation.run(); + } finally { + myFoldTree.myCachedLastIndex = -1; - if (!oldBatchFlag) { - if (myFoldRegionsProcessed) { - notifyBatchFoldingProcessingDone(moveCaret); - myFoldRegionsProcessed = false; + if (!oldBatchFlag) { + if (myFoldRegionsProcessed) { + notifyBatchFoldingProcessingDone(moveCaret); + myFoldRegionsProcessed = false; + } + myIsBatchFoldingProcessing = false; } - myIsBatchFoldingProcessing = false; + myDoNotCollapseCaret = oldDontCollapseCaret; } - myDoNotCollapseCaret = oldDontCollapseCaret; } @Override From cbe62cc24d361464ae34e72608733960c71884a6 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 10:17:21 +0100 Subject: [PATCH 48/95] new inference: guard fixed --- java/java-psi-api/src/com/intellij/psi/LambdaUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java index 15b3208b7426..aefa768bd2b4 100644 --- a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java @@ -308,7 +308,7 @@ public class LambdaUtil { final int finalLambdaIdx = adjustLambdaIdx(lambdaIdx, (PsiMethod)resolve, parameters); if (finalLambdaIdx < parameters.length) { if (!tryToSubstitute) return getNormalizedType(parameters[finalLambdaIdx]); - return PsiResolveHelper.ourGuard.doPreventingRecursion(expression, true, new Computable() { + return PsiResolveHelper.ourGraphGuard.doPreventingRecursion(expression, true, new Computable() { @Override public PsiType compute() { return resolveResult.getSubstitutor().substitute(getNormalizedType(parameters[finalLambdaIdx])); From fa6672f721f0099fe99a343d1d477df314a2e7f3 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 14:07:56 +0100 Subject: [PATCH 49/95] new inference: simplify target type calculation --- .../impl/source/resolve/JavaResolveUtil.java | 12 ++- .../graphInference/InferenceSession.java | 95 ++++--------------- ...eckedExceptionCompatibilityConstraint.java | 11 --- .../ExpressionCompatibilityConstraint.java | 16 ++-- 4 files changed, 33 insertions(+), 101 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java index 5b76439ef406..3a0192705a19 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java @@ -227,13 +227,19 @@ public class JavaResolveUtil { public static void substituteResults(@NotNull PsiJavaCodeReferenceElement ref, @NotNull JavaResolveResult[] result) { if (result.length > 0 && result[0].getElement() instanceof PsiClass) { - PsiType[] parameters = ref.getTypeParameters(); for (int i = 0; i < result.length; i++) { CandidateInfo resolveResult = (CandidateInfo)result[i]; PsiElement resultElement = resolveResult.getElement(); if (resultElement instanceof PsiClass && ((PsiClass)resultElement).hasTypeParameters()) { - PsiSubstitutor substitutor = resolveResult.getSubstitutor().putAll((PsiClass)resultElement, parameters); - result[i] = new CandidateInfo(resolveResult, substitutor); + PsiSubstitutor substitutor = resolveResult.getSubstitutor(); + result[i] = new CandidateInfo(resolveResult, substitutor) { + @NotNull + @Override + public PsiSubstitutor getSubstitutor() { + final PsiType[] parameters = ref.getTypeParameters(); + return super.getSubstitutor().putAll((PsiClass)resultElement, parameters); + } + }; } } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index abde4616fe77..775fa508d846 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -23,12 +23,6 @@ import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.source.resolve.graphInference.constraints.*; import com.intellij.psi.infos.MethodCandidateInfo; -import com.intellij.psi.scope.MethodProcessorSetupFailedException; -import com.intellij.psi.scope.PsiConflictResolver; -import com.intellij.psi.scope.conflictResolvers.JavaMethodsConflictResolver; -import com.intellij.psi.scope.processor.MethodCandidatesProcessor; -import com.intellij.psi.scope.processor.MethodResolverProcessor; -import com.intellij.psi.scope.util.PsiScopesUtil; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTypesUtil; @@ -174,7 +168,8 @@ public class InferenceSession { return true; } - private static PsiType getParameterType(PsiParameter[] parameters, PsiExpression[] args, int i, PsiSubstitutor substitutor) { + private static PsiType getParameterType(PsiParameter[] parameters, PsiExpression[] args, int i, @Nullable PsiSubstitutor substitutor) { + if (substitutor == null) return null; PsiType parameterType = substitutor.substitute(parameters[i < parameters.length ? i : parameters.length - 1].getType()); if (parameterType instanceof PsiEllipsisType) { final PsiExpression arg = args[i]; @@ -366,19 +361,13 @@ public class InferenceSession { } private void initReturnTypeConstraint(PsiMethod method, final PsiCallExpression context) { - if (PsiPolyExpressionUtil.isMethodCallPolyExpression(context, method) || - context instanceof PsiNewExpression && PsiDiamondType.ourDiamondGuard.currentStack().contains(context)) { + if (PsiPolyExpressionUtil.isMethodCallPolyExpression(context, method)) { PsiType returnType = method.getReturnType(); if (!PsiType.VOID.equals(returnType) && returnType != null) { returnType = PsiImplUtil.normalizeWildcardTypeByPosition(returnType, context); PsiType targetType = PsiTypesUtil.getExpectedTypeByParent(context); if (targetType == null) { - targetType = PsiResolveHelper.ourGraphGuard.doPreventingRecursion(context, false, new Computable() { - @Override - public PsiType compute() { - return getTargetType(context); - } - }); + targetType = getTargetType(context); } if (targetType != null) { registerConstraints(returnType, targetType); @@ -495,7 +484,7 @@ public class InferenceSession { return false; } - private PsiType getTargetType(final PsiExpression context) { + private static PsiType getTargetType(final PsiExpression context) { final PsiElement parent = PsiUtil.skipParenthesizedExprUp(context.getParent()); if (parent instanceof PsiExpressionList) { PsiElement gParent = parent.getParent(); @@ -505,28 +494,8 @@ public class InferenceSession { if (gParent instanceof PsiCallExpression) { final PsiExpressionList argumentList = ((PsiCallExpression)gParent).getArgumentList(); if (argumentList != null) { - final Pair pair = MethodCandidateInfo.getCurrentMethod(argumentList); - final PsiFile placeFile = context.getContainingFile(); - final JavaMethodsConflictResolver conflictResolver = new JavaMethodsConflictResolver(argumentList, PsiUtil.getLanguageLevel(placeFile)){ - @Override - protected PsiType[] getArgumentTypes() { - return InferenceSession.getArgumentTypes(argumentList, context); - } - }; - final MethodCandidatesProcessor processor = new MethodResolverProcessor((PsiCallExpression)gParent, placeFile, new PsiConflictResolver[]{conflictResolver}) { - @Override - protected PsiType[] getExpressionTypes(PsiExpressionList argumentList) { - return getArgumentTypes(argumentList, context); - } - }; - try { - PsiScopesUtil.setupAndRunProcessor(processor, (PsiCallExpression)gParent, false); - } - catch (MethodProcessorSetupFailedException e) { - return null; - } - final JavaResolveResult[] results = processor.getResult(); - return results.length == 1 ? getTypeByMethod(context, argumentList, pair, results[0], results[0].getElement()) : null; + final JavaResolveResult result = ((PsiCallExpression)gParent).resolveMethodGenerics(); + return getTypeByMethod(context, argumentList, result, result.getElement()); } } } else if (parent instanceof PsiConditionalExpression) { @@ -546,30 +515,9 @@ public class InferenceSession { return null; } - private static PsiType[] getArgumentTypes(PsiExpressionList argumentList, PsiExpression context) { - if (argumentList != null) { - final PsiExpression[] expressions = argumentList.getExpressions(); - final int idx = LambdaUtil.getLambdaIdx(argumentList, context); - final PsiType[] types = PsiType.createArray(expressions.length); - for (int i = 0; i < expressions.length; i++) { - if (i != idx) { - types[i] = expressions[i].getType(); - } - else { - types[i] = PsiType.NULL; - } - } - return types; - } - else { - return null; - } - } - - private PsiType getTypeByMethod(PsiExpression context, - PsiExpressionList argumentList, - Pair pair, - JavaResolveResult result, PsiElement parentMethod) { + private static PsiType getTypeByMethod(PsiExpression context, + PsiExpressionList argumentList, + final JavaResolveResult result, PsiElement parentMethod) { if (parentMethod instanceof PsiMethod) { final PsiParameter[] parameters = ((PsiMethod)parentMethod).getParameterList().getParameters(); if (parameters.length == 0) return null; @@ -581,23 +529,12 @@ public class InferenceSession { } final int i = ArrayUtilRt.find(args, arg); if (i < 0) return null; - final PsiCallExpression callExpression = PsiTreeUtil.getParentOfType(argumentList, PsiCallExpression.class); - if (callExpression != null && callExpression.getTypeArguments().length > 0) { - return getParameterType(parameters, args, i, ((MethodCandidateInfo)result).typeArgumentsSubstitutor()); - } - final PsiType parameterType = getParameterType(parameters, args, i, pair != null ? pair.second : PsiSubstitutor.EMPTY); - args[i] = null; - final PsiTypeParameter[] typeParameters = ((PsiMethod)parentMethod).getTypeParameters(); - final InferenceSession session = new InferenceSession(typeParameters, ((MethodCandidateInfo)result).getSiteSubstitutor(), myManager, argumentList); - session.initExpressionConstraints(parameters, args, argumentList, (PsiMethod)parentMethod); - if (session.tryToInfer(parameters, args, callExpression, (PsiMethod)parentMethod) != null) { - return null; - } - final Collection params = session.getTypeParams(); - initBounds(params.toArray(new PsiTypeParameter[params.size()])); - liftBounds(session.getInferenceVariables()); - final PsiSubstitutor substitutor = ((MethodCandidateInfo)result).getSiteSubstitutor(); - return substitutor.substitute(parameterType); + return getParameterType(parameters, args, i, PsiResolveHelper.ourGraphGuard.doPreventingRecursion(argumentList.getParent(), false, new Computable() { + @Override + public PsiSubstitutor compute() { + return result.getSubstitutor(); + } + })); } return null; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java index a67b64eea669..2d67b318d719 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java @@ -48,17 +48,6 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai if (!PsiPolyExpressionUtil.isPolyExpression(myExpression)) { return true; } - if (myExpression instanceof PsiCallExpression) { - final PsiExpressionList argumentList = ((PsiCallExpression)myExpression).getArgumentList(); - if (argumentList != null) { - for (PsiExpression expression : argumentList.getExpressions()) { - if (PsiPolyExpressionUtil.isPolyExpression(expression)) { - //todo additional constraints [JDK-8033488] - } - } - } - return true; - } if (myExpression instanceof PsiParenthesizedExpression) { constraints.add(new CheckedExceptionCompatibilityConstraint(((PsiParenthesizedExpression)myExpression).getExpression(), myT)); return true; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java index 30628e36beb6..26f041340347 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java @@ -103,18 +103,18 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm session.addCapturedVariable(typeParam); } PsiSubstitutor substitutor = PsiSubstitutor.EMPTY; + //typeParams are already included + final Collection params = session.getTypeParams(); + InferenceSession callSession = new InferenceSession(params.toArray(new PsiTypeParameter[params.size()]), resolveResult instanceof MethodCandidateInfo ? ((MethodCandidateInfo)resolveResult).getSiteSubstitutor() + : PsiSubstitutor.EMPTY, myExpression.getManager(), myExpression); if (method != null) { - //typeParams are already included - final Collection params = session.getTypeParams(); - InferenceSession callSession = new InferenceSession(params.toArray(new PsiTypeParameter[params.size()]), resolveResult instanceof MethodCandidateInfo ? ((MethodCandidateInfo)resolveResult).getSiteSubstitutor() - : PsiSubstitutor.EMPTY, myExpression.getManager(), myExpression); final PsiExpression[] args = argumentList.getExpressions(); final PsiParameter[] parameters = method.getParameterList().getParameters(); callSession.initExpressionConstraints(parameters, args, myExpression, method); - callSession.registerConstraints(returnType, myT); - if (callSession.repeatInferencePhases(true)) { - session.liftBounds(callSession.getInferenceVariables()); - } + } + callSession.registerConstraints(returnType, myT); + if (callSession.repeatInferencePhases(true)) { + session.liftBounds(callSession.getInferenceVariables()); } final PsiType capturedReturnType = myExpression instanceof PsiMethodCallExpression ? PsiMethodCallExpressionImpl.captureReturnType((PsiMethodCallExpression)myExpression, method, returnType, substitutor) From 5dd7e0622c00e629f355f23e1f7c581454e81aa0 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 15:29:30 +0100 Subject: [PATCH 50/95] new inference: support for nested same method calls --- .../InferenceIncorporationPhase.java | 17 ---------- .../graphInference/InferenceSession.java | 31 ++++++++++--------- .../ExpressionCompatibilityConstraint.java | 29 ++++++++++++----- .../constraints/TypeEqualityConstraint.java | 5 +++ .../graphInference/NestedCallsSameMethod.java | 15 ++++++++- .../GraphInferenceHighlightingTest.java | 2 +- 6 files changed, 59 insertions(+), 40 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java index cc666815c2d2..f56175af91ba 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java @@ -389,21 +389,4 @@ public class InferenceIncorporationPhase { } } } - - public PsiSubstitutor checkIncorporated(PsiSubstitutor substitutor, Collection variables) { - for (InferenceVariable variable : variables) { //todo equals bounds? - for (PsiType lowerBound : variable.getBounds(InferenceBound.LOWER)) { - lowerBound = substitutor.substitute(lowerBound); - if (mySession.isProperType(lowerBound)) { - for (PsiType upperBound : variable.getBounds(InferenceBound.UPPER)) { - upperBound = substitutor.substitute(upperBound); - if (mySession.isProperType(upperBound) && !TypeConversionUtil.isAssignable(upperBound, lowerBound)) { - return null; - } - } - } - } - } - return substitutor; - } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 775fa508d846..9cdb5bb2281c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -208,7 +208,7 @@ public class InferenceSession { PsiMethod parentMethod) { if (!repeatInferencePhases(true)) { //inferred result would be checked as candidate won't be applicable - return resolveSubset(myInferenceVariables.values(), mySiteSubstitutor, false); + return resolveSubset(myInferenceVariables.values(), mySiteSubstitutor); } if (parentMethod != null) { @@ -294,7 +294,7 @@ public class InferenceSession { } } } else { - return resolveSubset(myInferenceVariables.values(), mySiteSubstitutor, false); + return resolveSubset(myInferenceVariables.values(), mySiteSubstitutor); } return prepareSubstitution(); @@ -386,7 +386,7 @@ public class InferenceSession { public void registerConstraints(PsiType returnType, PsiType targetType) { final InferenceVariable inferenceVariable = shouldResolveAndInstantiate(returnType, targetType); if (inferenceVariable != null) { - final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor, true); + final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor); myConstraints.add(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutor.substitute(inferenceVariable.getParameter()), myContext))); } else { @@ -529,12 +529,13 @@ public class InferenceSession { } final int i = ArrayUtilRt.find(args, arg); if (i < 0) return null; - return getParameterType(parameters, args, i, PsiResolveHelper.ourGraphGuard.doPreventingRecursion(argumentList.getParent(), false, new Computable() { - @Override - public PsiSubstitutor compute() { - return result.getSubstitutor(); - } - })); + return getParameterType(parameters, args, i, PsiResolveHelper.ourGraphGuard.doPreventingRecursion(argumentList.getParent(), false, + new Computable() { + @Override + public PsiSubstitutor compute() { + return result.getSubstitutor(); + } + })); } return null; } @@ -657,7 +658,7 @@ public class InferenceSession { while (!allVars.isEmpty()) { final List vars = InferenceVariablesOrder.resolveOrder(allVars, this); if (!myIncorporationPhase.hasCaptureConstraints(vars)) { - final PsiSubstitutor firstSubstitutor = resolveSubset(vars, substitutor, true); + final PsiSubstitutor firstSubstitutor = resolveSubset(vars, substitutor); if (firstSubstitutor != null) { substitutor = firstSubstitutor; allVars.removeAll(vars); @@ -668,7 +669,7 @@ public class InferenceSession { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(getManager().getProject()); for (InferenceVariable var : vars) { final PsiTypeParameter parameter = var.getParameter(); - final PsiTypeParameter copy = elementFactory.createTypeParameterFromText(parameter.getName(), null); + final PsiTypeParameter copy = elementFactory.createTypeParameterFromText("z" + parameter.getName(), null); final PsiType lub = getLowerBound(var, substitutor); final PsiType glb = getUpperBound(var, substitutor); final InferenceVariable zVariable = new InferenceVariable(copy); @@ -681,6 +682,8 @@ public class InferenceSession { zVariable.addBound(lub, InferenceBound.LOWER); } myInferenceVariables.put(copy, zVariable); + allVars.add(zVariable); + var.addBound(elementFactory.createType(copy), InferenceBound.EQ); } myIncorporationPhase.forgetCaptures(vars); if (!myIncorporationPhase.incorporate()) { @@ -699,7 +702,7 @@ public class InferenceSession { }, substitutor); } - private PsiSubstitutor resolveSubset(Collection vars, PsiSubstitutor substitutor, boolean checkResult) { + private PsiSubstitutor resolveSubset(Collection vars, PsiSubstitutor substitutor) { for (InferenceVariable var : vars) { LOG.assertTrue(var.getInstantiation() == PsiType.NULL); final PsiTypeParameter typeParameter = var.getParameter(); @@ -718,7 +721,7 @@ public class InferenceSession { } } - return checkResult ? myIncorporationPhase.checkIncorporated(substitutor, vars) : substitutor; + return substitutor; } private PsiType getUpperBound(InferenceVariable var, PsiSubstitutor substitutor) { @@ -809,7 +812,7 @@ public class InferenceSession { } //resolve input variables - PsiSubstitutor substitutor = resolveSubset(varsToResolve, mySiteSubstitutor, true); + PsiSubstitutor substitutor = resolveSubset(varsToResolve, mySiteSubstitutor); if (substitutor == null) { return false; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java index 26f041340347..7a29dcfd244c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java @@ -22,6 +22,7 @@ import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil import com.intellij.psi.impl.source.tree.java.PsiMethodCallExpressionImpl; import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.util.TypeConversionUtil; +import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -99,14 +100,28 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm if (typeParams != null) { - for (PsiTypeParameter typeParam : typeParams) { - session.addCapturedVariable(typeParam); - } + session.initBounds(typeParams); PsiSubstitutor substitutor = PsiSubstitutor.EMPTY; - //typeParams are already included - final Collection params = session.getTypeParams(); - InferenceSession callSession = new InferenceSession(params.toArray(new PsiTypeParameter[params.size()]), resolveResult instanceof MethodCandidateInfo ? ((MethodCandidateInfo)resolveResult).getSiteSubstitutor() - : PsiSubstitutor.EMPTY, myExpression.getManager(), myExpression); + final HashSet variables = new HashSet(); + session.collectDependencies(returnType, variables); + final PsiTypeParameter[] params = new PsiTypeParameter[typeParams.length]; + for (int i = 0; i < typeParams.length; i++) { + if (variables.contains(session.getInferenceVariable(typeParams[i]))) { + params[i] = JavaPsiFacade.getElementFactory(myExpression.getProject()).createTypeParameterFromText("copyOf" + myExpression.hashCode() + typeParams[i].getName(), null); + substitutor = substitutor.put(typeParams[i], JavaPsiFacade.getElementFactory(myExpression.getProject()).createType(params[i])); + } + else { + params[i] = typeParams[i]; + } + } + final PsiSubstitutor siteSubstitutor = resolveResult instanceof MethodCandidateInfo ? ((MethodCandidateInfo)resolveResult).getSiteSubstitutor() : PsiSubstitutor.EMPTY; + for (PsiTypeParameter typeParameter : siteSubstitutor.getSubstitutionMap().keySet()) { + substitutor = substitutor.put(typeParameter, substitutor.substitute(siteSubstitutor.substitute(typeParameter))); + } + + final Collection params1 = session.getTypeParams(); + final InferenceSession callSession = new InferenceSession(params1.toArray(new PsiTypeParameter[params1.size()]), substitutor, myExpression.getManager(), myExpression); + callSession.initBounds(params); if (method != null) { final PsiExpression[] args = argumentList.getExpressions(); final PsiParameter[] parameters = method.getParameterList().getParameters(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java index 7e2443a8232f..cbb1db809c4a 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java @@ -109,6 +109,11 @@ public class TypeEqualityConstraint implements ConstraintFormula { return true; } + if (myT instanceof PsiCapturedWildcardType && myS instanceof PsiCapturedWildcardType) { + return new TypeEqualityConstraint(((PsiCapturedWildcardType)myT).getWildcard(), + ((PsiCapturedWildcardType)myS).getWildcard()).reduce(session, constraints); + } + return false; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NestedCallsSameMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NestedCallsSameMethod.java index eaafb1b96716..97c659da0095 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NestedCallsSameMethod.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NestedCallsSameMethod.java @@ -1,3 +1,16 @@ +import java.util.List; + +class Main0 { + List foo(T t){ + return null; + } + + { + foo(foo("")); + } +} + + class Main { static T foo(T t) { return null; } @@ -14,6 +27,6 @@ class Main1 { static B bar(B t) { return null;} static { - long l = foo(bar(1)); + //long l = foo(bar(1)); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java index 1119a0d6d4df..0182af2a8689 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java @@ -28,7 +28,7 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } - public void _testNestedCallsSameMethod() throws Exception { + public void testNestedCallsSameMethod() throws Exception { doTest(); } From b31b23cd0b2a3d33a57c653c041f7c563dfd93ca Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 17:07:37 +0100 Subject: [PATCH 51/95] new inference: temp solution to exclude inference results from nested call of the same method on the outer level --- .../graphInference/InferenceSession.java | 9 +++++-- ...eckedExceptionCompatibilityConstraint.java | 2 +- .../ExpressionCompatibilityConstraint.java | 15 +++++++++-- .../graphInference/NestedCallsSameMethod.java | 25 +++++++++++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 9cdb5bb2281c..d46d56d7d96c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -335,9 +335,13 @@ public class InferenceSession { return false; } - public void initBounds(PsiTypeParameter... typeParameters) { + public boolean initBounds(PsiTypeParameter... typeParameters) { + boolean sameMethodCall = false; for (PsiTypeParameter parameter : typeParameters) { - if (myInferenceVariables.containsKey(parameter)) continue; + if (myInferenceVariables.containsKey(parameter)) { + sameMethodCall = true; + continue; + } InferenceVariable variable = new InferenceVariable(parameter); boolean added = false; final PsiClassType[] extendsListTypes = parameter.getExtendsListTypes(); @@ -354,6 +358,7 @@ public class InferenceSession { } myInferenceVariables.put(parameter, variable); } + return sameMethodCall; } public void addCapturedVariable(PsiTypeParameter param) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java index 2d67b318d719..a629175b9d48 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java @@ -111,7 +111,7 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai final PsiSubstitutor psiSubstitutor = qualifierResolveResult.getSubstitutor(); final PsiMethod method; if (((PsiMethodReferenceExpression)myExpression).isExact()) { - final PsiElement resolve = ((PsiMethodReferenceExpression)myExpression).resolve(); + final PsiElement resolve = ((PsiMethodReferenceExpression)myExpression).getPotentiallyApplicableMember(); if (resolve instanceof PsiMethod) { method = (PsiMethod)resolve; } else { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java index 7a29dcfd244c..bdfdb45a9e0d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java @@ -26,6 +26,7 @@ import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NotNull; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -100,7 +101,8 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm if (typeParams != null) { - session.initBounds(typeParams); + final HashSet oldBounds = new HashSet<>(session.getTypeParams()); + final boolean sameMethodCall = session.initBounds(typeParams); PsiSubstitutor substitutor = PsiSubstitutor.EMPTY; final HashSet variables = new HashSet(); session.collectDependencies(returnType, variables); @@ -129,7 +131,16 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm } callSession.registerConstraints(returnType, myT); if (callSession.repeatInferencePhases(true)) { - session.liftBounds(callSession.getInferenceVariables()); + final Collection inferenceVariables = callSession.getInferenceVariables(); + if (sameMethodCall) { + for (Iterator iterator = inferenceVariables.iterator(); iterator.hasNext(); ) { + InferenceVariable variable = iterator.next(); + if (oldBounds.contains(variable.getParameter())) { + iterator.remove(); + } + } + } + session.liftBounds(inferenceVariables); } final PsiType capturedReturnType = myExpression instanceof PsiMethodCallExpression ? PsiMethodCallExpressionImpl.captureReturnType((PsiMethodCallExpression)myExpression, method, returnType, substitutor) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NestedCallsSameMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NestedCallsSameMethod.java index 97c659da0095..458171f5b51a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NestedCallsSameMethod.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/NestedCallsSameMethod.java @@ -1,5 +1,30 @@ import java.util.List; +import java.util.function.Function; + +abstract class Main2 { + void address(Foo sa) { + String ds = foobar(foobar(sa, Foo::getBar), Bar ::getName); + Function f = null; + String ds1 = foobar(foobar(sa, f), null); + } + + abstract V foobar(T t, Function mapper); + + class Foo { + Bar getBar() { + return new Bar(); + } + } + + class Bar { + String getName(){ + return null; + } + } +} + + class Main0 { List foo(T t){ return null; From e0f2061c1cc546af0899377fa2d64e9165109439 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 18:23:36 +0100 Subject: [PATCH 52/95] select in project view: preserve registration order to prevent select in Packages by default --- .../src/com/intellij/ide/projectView/impl/ProjectViewImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index c7a81cbd0cda..f9d4a757f8a7 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -189,7 +189,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo private final SplitterProportionsData splitterProportions = new SplitterProportionsDataImpl(); private final MessageBusConnection myConnection; private final Map myUninitializedPaneState = new HashMap(); - private final Map mySelectInTargets = new HashMap(); + private final Map mySelectInTargets = new LinkedHashMap(); private ContentManager myContentManager; private boolean myFoldersAlwaysOnTop = true; From 66a8dedb8c0cc91feb6f3f6657a3f5a86bc948db Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 18:29:55 +0100 Subject: [PATCH 53/95] new inference: method refs: accept qualifier substitutor when nothing more could be inferred --- .../java/PsiMethodReferenceExpressionImpl.java | 1 + .../lambda/methodRef/ReturnTypeSpecific.java | 2 +- .../ReturnTypeCheckForRawReceiver.java | 15 +++++++++++++++ .../lambda/NewMethodRefHighlightingTest.java | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/ReturnTypeCheckForRawReceiver.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java index fdd02e86ebb3..08a27c01d799 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java @@ -499,6 +499,7 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase final PsiClass pClass = pResult.getElement(); final PsiSubstitutor receiverSubstitutor = pClass != null ? TypeConversionUtil.getClassSubstitutor(containingClass, pClass, pResult.getSubstitutor()) : null; if (receiverSubstitutor != null) { + if (!method.hasTypeParameters() && signature.getParameterTypes().length == 1) return receiverSubstitutor; psiSubstitutor = receiverSubstitutor; } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/ReturnTypeSpecific.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/ReturnTypeSpecific.java index 848c423302c6..0696aadf6179 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/ReturnTypeSpecific.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/ReturnTypeSpecific.java @@ -29,7 +29,7 @@ class MyTest { } public static void main(String[] args) { - foo(Foo::m); + foo(Foo::m); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/ReturnTypeCheckForRawReceiver.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/ReturnTypeCheckForRawReceiver.java new file mode 100644 index 000000000000..853b02ada009 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/ReturnTypeCheckForRawReceiver.java @@ -0,0 +1,15 @@ +class Test { + + static class Foo { + X m() { return null;} + } + + interface I { + Foo _i(Foo fs); + } + + static void foo(I i) { } + { + foo(Foo::m); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java index e944269c098b..bd6ad47ede42 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java @@ -173,6 +173,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testReturnTypeCheckForRawReceiver() throws Exception { + doTest(); + } + private void doTest() { doTest(false); } From e2c60e59b4a51e3f126b016ede3347ef69afe781 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 19:06:42 +0100 Subject: [PATCH 54/95] compilation fix --- .../constraints/ExpressionCompatibilityConstraint.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java index bdfdb45a9e0d..dcfd45104a25 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java @@ -101,7 +101,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm if (typeParams != null) { - final HashSet oldBounds = new HashSet<>(session.getTypeParams()); + final HashSet oldBounds = new HashSet(session.getTypeParams()); final boolean sameMethodCall = session.initBounds(typeParams); PsiSubstitutor substitutor = PsiSubstitutor.EMPTY; final HashSet variables = new HashSet(); From 22a0e5f1f03493ad44fc5e167389a8b6664df07b Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 19:09:35 +0100 Subject: [PATCH 55/95] compilation fix --- .../intellij/psi/impl/source/resolve/JavaResolveUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java index 3a0192705a19..20db589bef5c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java @@ -225,11 +225,11 @@ public class JavaResolveUtil { return true; } - public static void substituteResults(@NotNull PsiJavaCodeReferenceElement ref, @NotNull JavaResolveResult[] result) { + public static void substituteResults(final @NotNull PsiJavaCodeReferenceElement ref, @NotNull JavaResolveResult[] result) { if (result.length > 0 && result[0].getElement() instanceof PsiClass) { for (int i = 0; i < result.length; i++) { - CandidateInfo resolveResult = (CandidateInfo)result[i]; - PsiElement resultElement = resolveResult.getElement(); + final CandidateInfo resolveResult = (CandidateInfo)result[i]; + final PsiElement resultElement = resolveResult.getElement(); if (resultElement instanceof PsiClass && ((PsiClass)resultElement).hasTypeParameters()) { PsiSubstitutor substitutor = resolveResult.getSubstitutor(); result[i] = new CandidateInfo(resolveResult, substitutor) { From cf7dff45a98470265fd83ef13797b39adea9d3e9 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Thu, 27 Feb 2014 22:38:10 +0400 Subject: [PATCH 56/95] Support segue's --- .../src/com/intellij/designer/model/Property.java | 4 ++++ .../com/intellij/designer/propertyTable/PropertyTable.java | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/designer/model/Property.java b/platform/platform-impl/src/com/intellij/designer/model/Property.java index b44b5991edf1..9f902c8f864e 100644 --- a/platform/platform-impl/src/com/intellij/designer/model/Property.java +++ b/platform/platform-impl/src/com/intellij/designer/model/Property.java @@ -120,6 +120,10 @@ public abstract class Property { return false; } + public boolean closeEditorDuringRefresh() { + return false; + } + ////////////////////////////////////////////////////////////////////////////////////////// // // Presentation diff --git a/platform/platform-impl/src/com/intellij/designer/propertyTable/PropertyTable.java b/platform/platform-impl/src/com/intellij/designer/propertyTable/PropertyTable.java index 9ea80470d7f1..e8deef934e8e 100644 --- a/platform/platform-impl/src/com/intellij/designer/propertyTable/PropertyTable.java +++ b/platform/platform-impl/src/com/intellij/designer/propertyTable/PropertyTable.java @@ -848,7 +848,7 @@ public abstract class PropertyTable extends JBTable { if (isSetValue) { if (property.needRefreshPropertyList() || needRefresh[0]) { - update(myContainers, null, false); + update(myContainers, null, property.closeEditorDuringRefresh()); } else { myModel.fireTableRowsUpdated(row, row); @@ -1113,7 +1113,7 @@ public abstract class PropertyTable extends JBTable { } if (setValueAtRow(editingRow, value)) { - if (!continueEditing) { + if (!continueEditing && editingRow != -1) { PropertyEditor editor = myProperties.get(editingRow).getEditor(); editor.removePropertyEditorListener(myPropertyEditorListener); removeEditor(); From e7cb908c959b618d9e91efb602cbc5b8ffcf2bfa Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 20:35:26 +0100 Subject: [PATCH 57/95] new inference: method refs: apply reference rules first --- .../PsiMethodReferenceExpressionImpl.java | 44 +++++++++++++------ .../lambda/methodRef/AccessModifiers.java | 2 +- .../lambda/methodRef/StaticProblems.java | 16 +++---- .../lambda/methodRef/Varargs.java | 2 +- .../methodRef/VarargsInReceiverPosition.java | 2 +- ...StaticNonStaticReferenceTypeAmbiguity.java | 15 +++++++ .../lambda/NewMethodRefHighlightingTest.java | 4 ++ 7 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/StaticNonStaticReferenceTypeAmbiguity.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java index 08a27c01d799..084be88d7428 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java @@ -639,20 +639,26 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase } } + if (myQualifierResolveResult.isReferenceTypeQualified() && getReferenceNameElement() instanceof PsiIdentifier) { + //If the first search produces a static method, and no non-static method is applicable for the second search, then the result of the first search is the compile-time declaration. + CandidateInfo candidateInfo = filterStaticCorrectCandidates(firstCandidates, secondCandidates, true); + if (candidateInfo != null) { + return candidateInfo; + } + + //If the second search produces a non-static method, and no static method is applicable for the first search, then the result of the second search is the compile-time declaration. + candidateInfo = filterStaticCorrectCandidates(secondCandidates, firstCandidates, false); + if (candidateInfo != null) { + return candidateInfo; + } + } + checkSpecifics(firstCandidates, varargs ? MethodCandidateInfo.ApplicabilityLevel.VARARGS : MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY, myLanguageLevel); checkSpecifics(secondCandidates, varargs ? MethodCandidateInfo.ApplicabilityLevel.VARARGS : MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY, myLanguageLevel); - if (myQualifierResolveResult.isReferenceTypeQualified() && getReferenceNameElement() instanceof PsiIdentifier) { - //If the first search produces a static method, and no non-static method is applicable for the second search, then the result of the first search is the compile-time declaration. - filterStaticCorrectCandidates(firstCandidates, true); - - //If the second search produces a non-static method, and no static method is applicable for the first search, then the result of the second search is the compile-time declaration. - filterStaticCorrectCandidates(secondCandidates, false); - } - final int acceptedCount = firstCandidates.size() + secondCandidates.size(); if (acceptedCount == 1) { return !firstCandidates.isEmpty() ? firstCandidates.get(0) : secondCandidates.get(0); @@ -685,17 +691,29 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase /** * 15.13.1 */ - private void filterStaticCorrectCandidates(List firstCandidates, + private CandidateInfo filterStaticCorrectCandidates(List firstCandidates, + List secondCandidates, boolean shouldBeStatic) { - for (Iterator iterator = firstCandidates.iterator(); iterator.hasNext(); ) { - final PsiElement element = iterator.next().getElement(); + if (firstCandidates.size() == 1) { + final CandidateInfo candidateInfo = firstCandidates.get(0); + final PsiElement element = candidateInfo.getElement(); if (element instanceof PsiMethod) { final boolean isStatic = ((PsiMethod)element).hasModifierProperty(PsiModifier.STATIC); - if (shouldBeStatic && !isStatic || !shouldBeStatic && isStatic) { - iterator.remove(); + if (shouldBeStatic && isStatic || !shouldBeStatic && !isStatic) { + for (CandidateInfo secondCandidate : secondCandidates) { + final PsiElement psiElement = secondCandidate.getElement(); + if (psiElement instanceof PsiMethod) { + final boolean oppositeStatic = ((PsiMethod)psiElement).hasModifierProperty(PsiModifier.STATIC); + if (shouldBeStatic && !oppositeStatic || !shouldBeStatic && oppositeStatic) { + return null; + } + } + } + return candidateInfo; } } } + return null; } private boolean isCorrectAssignment(PsiType[] signatureParameterTypes2, diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AccessModifiers.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AccessModifiers.java index 40811fd1f7a7..bc235b224c31 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AccessModifiers.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AccessModifiers.java @@ -29,7 +29,7 @@ class AlienTest { IInt i2 = MyTest::foo; IInt i3 = MyTest::bar; IIntInt i4 = MyTest::bar; - IInt i5 = MyTest::baz; + IInt i5 = MyTest::baz; IInt i6 = MyTest.foo::foo; IInt i7 = MyTest.Foo::foo; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/StaticProblems.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/StaticProblems.java index 3375ceb2a090..8d482f2920ab 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/StaticProblems.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/StaticProblems.java @@ -41,14 +41,14 @@ class MyTest1 { static void call2(I2 s) { } static void test1() { - I1 s1 = MyTest1 ::m1; - call1(MyTest1::m1); + I1 s1 = MyTest1 ::m1; + call1(MyTest1::m1); I1 s2 = MyTest1 :: m2; call1(MyTest1::m2); I1 s3 = MyTest1::m3; call1(MyTest1::m3); - I1 s4 = MyTest1::m4; - call1(MyTest1::m4); + I1 s4 = MyTest1::m4; + call1(MyTest1::m4); } static void test2() { @@ -90,14 +90,14 @@ class MyTest2 { static void call2(I2 s) { } static void test1() { - I1 s1 = MyTest2 ::m1; - call1(MyTest2::m1); + I1 s1 = MyTest2 ::m1; + call1(MyTest2::m1); I1 s2 = MyTest2 :: m2; call1(MyTest2::m2); I1 s3 = MyTest2::m3; call1(MyTest2::m3); - I1 s4 = MyTest2::m4; - call1(MyTest2::m4); + I1 s4 = MyTest2::m4; + call1(MyTest2::m4); } static void test2() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Varargs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Varargs.java index 66f4e0701b4b..e521df2c2d40 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Varargs.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Varargs.java @@ -55,7 +55,7 @@ class MyTest { { - I1 i_1 = MyTest::_1; + I1 i_1 = MyTest::_1; I1 i_2 = MyTest::_2; I1 i_3 = MyTest::_3; I1 i_4 = MyTest::_4; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/VarargsInReceiverPosition.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/VarargsInReceiverPosition.java index f6c1e3f67c0e..cf2151dc76d8 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/VarargsInReceiverPosition.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/VarargsInReceiverPosition.java @@ -3,7 +3,7 @@ import java.util.*; class Test { void test() { Comparator r2 = Test::yyy; - Comparator1 c1 = Test::yyy; + Comparator1 c1 = Test::yyy; Comparator1 c2 = Test::xxx; } int yyy(Test... p) { return 1; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/StaticNonStaticReferenceTypeAmbiguity.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/StaticNonStaticReferenceTypeAmbiguity.java new file mode 100644 index 000000000000..7430c7c889e9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/StaticNonStaticReferenceTypeAmbiguity.java @@ -0,0 +1,15 @@ +class Test { + + interface I { + void m(Test rec, String s); + } + + void m(Test t, String s) {} + void m(String s) {} + + static void m(Test t, Object s) {} + + static void test() { + I i = Test::m; + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java index bd6ad47ede42..83f0dfac5c1e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java @@ -177,6 +177,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testStaticNonStaticReferenceTypeAmbiguity() throws Exception { + doTest(); + } + private void doTest() { doTest(false); } From 80c776355cab8dd8ccb8482b264a261398526c4f Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 21:00:37 +0100 Subject: [PATCH 58/95] testdata fixed --- .../daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java index f51647ab0a23..e097988ff116 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/DiamondMisc.java @@ -97,14 +97,14 @@ interface I { class FI1 { I i1 = new I<>() { @Override - public String m() { + public String m() { return null; } }; I i2 = new I<>() { @Override - public Object m() { + public Object m() { return null; } }; From fdaed62e1e3be09a6b0041c16acee0bf7ee2eca0 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 27 Feb 2014 22:02:54 +0100 Subject: [PATCH 59/95] use IJ index-building classloader to speedup groovyc resolve when it's advantageous --- .../jps/incremental/groovy/GroovyBuilder.java | 52 ++++++++++---- .../groovy/GroovycOSProcessHandler.java | 8 ++- .../groovy/compiler/rt/GroovyRtConstants.java | 1 + .../compiler/rt/DependentGroovycRunner.java | 6 +- .../compiler/rt/GroovyCompilerUtil.java | 46 ------------- .../groovy/compiler/rt/GroovycRunner.java | 68 +++++++++++++++++-- .../groovy/compiler/GroovyCompilerBase.java | 5 +- 7 files changed, 116 insertions(+), 70 deletions(-) delete mode 100644 plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovyCompilerUtil.java diff --git a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java index d8d32974aef4..7e9264ecd1fc 100644 --- a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java +++ b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java @@ -19,14 +19,18 @@ package org.jetbrains.jps.incremental.groovy; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.Consumer; +import com.intellij.util.Function; import com.intellij.util.SystemProperties; import com.intellij.util.containers.ContainerUtilRt; +import com.intellij.util.lang.UrlClassLoader; import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.asm4.ClassReader; +import org.jetbrains.groovy.compiler.rt.GroovyRtConstants; import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.builders.BuildRootIndex; @@ -63,6 +67,7 @@ import java.util.concurrent.Future; * Date: 10/25/11 */ public class GroovyBuilder extends ModuleLevelBuilder { + private static final int ourOptimizeThreshold = Integer.parseInt(System.getProperty("groovyc.optimized.class.loading.threshold", "10")); private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.incremental.groovy.GroovyBuilder"); private static final Key CHUNK_REBUILD_ORDERED = Key.create("CHUNK_REBUILD_ORDERED"); private static final Key> STUB_TO_SRC = Key.create("STUB_TO_SRC"); @@ -86,6 +91,7 @@ public class GroovyBuilder extends ModuleLevelBuilder { ModuleChunk chunk, DirtyFilesHolder dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException { + long start = 0; try { JpsGroovySettings settings = JpsGroovySettings.getSettings(context.getProjectDescriptor().getProject()); @@ -102,8 +108,10 @@ public class GroovyBuilder extends ModuleLevelBuilder { return ExitCode.ABORT; } + start = System.currentTimeMillis(); final Set toCompilePaths = getPathsToCompile(toCompile); - + boolean optimizeClassLoading = ourOptimizeThreshold != 0 && toCompilePaths.size() >= ourOptimizeThreshold; + Map class2Src = buildClassToSourceMap(chunk, context, toCompilePaths, finalOutputs); final String encoding = context.getProjectDescriptor().getEncodingConfiguration().getPreferredModuleChunkEncoding(chunk); @@ -117,10 +125,18 @@ public class GroovyBuilder extends ModuleLevelBuilder { String compilerOutput = generationOutputs.get(chunk.representativeTarget()); String finalOutput = FileUtil.toSystemDependentName(finalOutputs.get(chunk.representativeTarget())); + + Collection classpath = generateClasspath(context, chunk); + if (LOG.isDebugEnabled()) { + LOG.debug("Optimized class loading: " + optimizeClassLoading); + LOG.debug("Groovyc classpath: " + classpath); + } + final File tempFile = GroovycOSProcessHandler.fillFileWithGroovycParameters( - compilerOutput, toCompilePaths, finalOutput, class2Src, encoding, patchers + compilerOutput, toCompilePaths, finalOutput, class2Src, encoding, patchers, + optimizeClassLoading ? StringUtil.join(classpath, File.pathSeparator) : "" ); - final GroovycOSProcessHandler handler = runGroovyc(context, chunk, tempFile, settings); + final GroovycOSProcessHandler handler = runGroovyc(context, chunk, tempFile, settings, classpath, optimizeClassLoading); Map> compiled = processCompiledFiles(context, chunk, generationOutputs, compilerOutput, handler); @@ -147,8 +163,11 @@ public class GroovyBuilder extends ModuleLevelBuilder { throw new ProjectBuildException(e); } finally { + if (start > 0 && LOG.isDebugEnabled()) { + LOG.debug(myBuilderName + " took " + (System.currentTimeMillis() - start) + " on " + chunk.getName()); + } if (!myForStubs) { - FILES_MARKED_DIRTY_FOR_NEXT_ROUND.set(context, null); + FILES_MARKED_DIRTY_FOR_NEXT_ROUND.set(context, null); } } } @@ -169,15 +188,24 @@ public class GroovyBuilder extends ModuleLevelBuilder { } private GroovycOSProcessHandler runGroovyc(final CompileContext context, - ModuleChunk chunk, + final ModuleChunk chunk, File tempFile, - final JpsGroovySettings settings) throws IOException { - ArrayList classpath = new ArrayList(generateClasspath(context, chunk)); - if (LOG.isDebugEnabled()) { - LOG.debug("Groovyc classpath: " + classpath); + final JpsGroovySettings settings, + Collection compilationClassPath, + boolean optimizeClassLoading) throws IOException { + List classpath = new ArrayList(); + if (optimizeClassLoading) { + classpath.add(getGroovyRtRoot().getPath()); + classpath.add(ClasspathBootstrap.getResourcePath(Function.class)); + classpath.add(ClasspathBootstrap.getResourcePath(UrlClassLoader.class)); + classpath.add(ClasspathBootstrap.getResourceFile(THashMap.class).getPath()); + } else { + classpath.addAll(compilationClassPath); } - List programParams = ContainerUtilRt.newArrayList(myForStubs ? "stubs" : "groovyc", tempFile.getPath()); + List programParams = ContainerUtilRt.newArrayList(optimizeClassLoading ? GroovyRtConstants.OPTIMIZE : "do_not_optimize", + myForStubs ? "stubs" : "groovyc", + tempFile.getPath()); if (settings.invokeDynamic) { programParams.add("--indy"); } @@ -203,7 +231,7 @@ public class GroovyBuilder extends ModuleLevelBuilder { final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmd)); final Consumer updater = new Consumer() { public void consume(String s) { - context.processMessage(new ProgressMessage(s)); + context.processMessage(new ProgressMessage(s + " [" + chunk.getName() + "]")); } }; final GroovycOSProcessHandler handler = new GroovycOSProcessHandler(process, updater) { @@ -403,7 +431,7 @@ public class GroovyBuilder extends ModuleLevelBuilder { callback.associate(outputPath, sourcePath, new ClassReader(FileUtil.loadFileBytes(outputFile))); } catch (Throwable e) { - // need this to make sure that unexpected errors in, for example, ASM will not ruin the compilation + // need this to make sure that unexpected errors in, for example, ASM will not ruin the compilation final String message = "Class dependency information may be incomplete! Error parsing generated class " + item.outputPath; LOG.info(message, e); context.processMessage(new CompilerMessage( diff --git a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovycOSProcessHandler.java b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovycOSProcessHandler.java index 9a5a3d0bce25..c4b40bfb0956 100644 --- a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovycOSProcessHandler.java +++ b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovycOSProcessHandler.java @@ -245,11 +245,17 @@ public class GroovycOSProcessHandler extends BaseOSProcessHandler { public static File fillFileWithGroovycParameters(final String outputDir, final Collection changedSources, String finalOutput, - Map class2Src, @Nullable final String encoding, List patchers) throws IOException { + Map class2Src, + @Nullable final String encoding, + List patchers, + String classpath) throws IOException { File tempFile = FileUtil.createTempFile("ideaGroovyToCompile", ".txt", true); final Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile))); try { + writer.write(classpath); + writer.write("\n"); + for (String file : changedSources) { writer.write(GroovyRtConstants.SRC_FILE + "\n"); writer.write(file); diff --git a/plugins/groovy/rt-constants/src/org/jetbrains/groovy/compiler/rt/GroovyRtConstants.java b/plugins/groovy/rt-constants/src/org/jetbrains/groovy/compiler/rt/GroovyRtConstants.java index d146db0caa35..37583ddc96e4 100644 --- a/plugins/groovy/rt-constants/src/org/jetbrains/groovy/compiler/rt/GroovyRtConstants.java +++ b/plugins/groovy/rt-constants/src/org/jetbrains/groovy/compiler/rt/GroovyRtConstants.java @@ -36,4 +36,5 @@ public class GroovyRtConstants { public static final String PRESENTABLE_MESSAGE = "@#$%@# Presentable:"; public static final String CLEAR_PRESENTABLE = "$@#$%^ CLEAR_PRESENTABLE"; public static final String NO_GROOVY = "Cannot compile Groovy files: no Groovy library is defined"; + public static final String OPTIMIZE = "optimize"; } diff --git a/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/DependentGroovycRunner.java b/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/DependentGroovycRunner.java index 835c91d2d153..bb374cdfcdf4 100644 --- a/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/DependentGroovycRunner.java +++ b/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/DependentGroovycRunner.java @@ -39,7 +39,8 @@ import java.util.*; * @author peter */ public class DependentGroovycRunner { - static boolean runGroovyc(boolean forStubs, File argsFile) { + public static boolean runGroovyc(boolean forStubs, String argsPath) { + File argsFile = new File(argsPath); final CompilerConfiguration config = new CompilerConfiguration(); config.setClasspath(""); config.setOutput(new PrintWriter(System.err)); @@ -113,8 +114,9 @@ public class DependentGroovycRunner { stream = new FileInputStream(argsFile); reader = new BufferedReader(new InputStreamReader(stream)); - String line; + reader.readLine(); // skip classpath + String line; while ((line = reader.readLine()) != null) { if (!GroovyRtConstants.SRC_FILE.equals(line)) { break; diff --git a/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovyCompilerUtil.java b/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovyCompilerUtil.java deleted file mode 100644 index fc7a74c0ec91..000000000000 --- a/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovyCompilerUtil.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2000-2008 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 org.jetbrains.groovy.compiler.rt; - -import org.codehaus.groovy.control.CompilerConfiguration; - -import java.net.URL; -import java.net.MalformedURLException; -import java.util.List; -import java.io.File; - -/** - * @author ilyas - */ -public class GroovyCompilerUtil { - static URL[] convertClasspathToUrls(CompilerConfiguration compilerConfiguration) { - try { - return classpathAsUrls(compilerConfiguration); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - - static URL[] classpathAsUrls(CompilerConfiguration compilerConfiguration) throws MalformedURLException { - List classpath = compilerConfiguration.getClasspath(); - URL[] classpathUrls = new URL[classpath.size()]; - for (int i = 0; i < classpathUrls.length; i++) { - String classpathEntry = (String) classpath.get(i); - classpathUrls[i] = new File(classpathEntry).toURI().toURL(); - } - return classpathUrls; - } -} diff --git a/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovycRunner.java b/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovycRunner.java index 3d7e8eb5dd80..aaa42bca43c3 100644 --- a/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovycRunner.java +++ b/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovycRunner.java @@ -15,7 +15,16 @@ package org.jetbrains.groovy.compiler.rt; +import com.intellij.util.lang.UrlClassLoader; +import sun.misc.URLClassPath; + +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URL; +import java.util.*; /** * @author: Dmitry.Krasilschikov @@ -57,24 +66,28 @@ public class GroovycRunner { } */ - if (args.length != 2) { - if (args.length != 3 || !"--indy".equals(args[2])) { + if (args.length != 3) { + if (args.length != 4 || !"--indy".equals(args[3])) { System.err.println("There is no arguments for groovy compiler"); System.exit(1); } System.setProperty("groovy.target.indy", "true"); } - final boolean forStubs = "stubs".equals(args[0]); - final File argsFile = new File(args[1]); + final boolean optimize = GroovyRtConstants.OPTIMIZE.equals(args[0]); + final boolean forStubs = "stubs".equals(args[1]); + String argPath = args[2]; - if (!argsFile.exists()) { + if (!new File(argPath).exists()) { System.err.println("Arguments file for groovy compiler not found"); System.exit(1); } + ClassLoader loader = optimize ? buildMainLoader(argPath) : GroovycRunner.class.getClassLoader(); + Thread.currentThread().setContextClassLoader(loader); + try { - Class.forName("org.codehaus.groovy.control.CompilationUnit"); + Class.forName("org.codehaus.groovy.control.CompilationUnit", true, loader); } catch (Throwable e) { System.err.println(GroovyRtConstants.NO_GROOVY); @@ -82,7 +95,9 @@ public class GroovycRunner { } try { - DependentGroovycRunner.runGroovyc(forStubs, argsFile); + Class aClass = Class.forName("org.jetbrains.groovy.compiler.rt.DependentGroovycRunner", true, loader); + Method method = aClass.getDeclaredMethod("runGroovyc", boolean.class, String.class); + method.invoke(null, forStubs, argPath); } catch (Throwable e) { e.printStackTrace(); @@ -102,4 +117,43 @@ public class GroovycRunner { } */ } + + private static ClassLoader buildMainLoader(String argsPath) { + Set bootstrapUrls = new HashSet(); + try { + Method method = ClassLoader.class.getDeclaredMethod("getBootstrapClassPath"); + method.setAccessible(true); + URLClassPath ucp = (URLClassPath)method.invoke(null); + Collections.addAll(bootstrapUrls, ucp.getURLs()); + } + catch (Exception e) { + e.printStackTrace(); + } + + final List urls = new ArrayList(); + try { + //noinspection IOResourceOpenedButNotSafelyClosed + BufferedReader reader = new BufferedReader(new FileReader(argsPath)); + String classpath = reader.readLine(); + for (String s : classpath.split(File.pathSeparator)) { + URL url = new File(s).toURI().toURL(); + if (!bootstrapUrls.contains(url)) { + urls.add(url); + } + } + reader.close(); + } + catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + + final ClassLoader[] ref = new ClassLoader[1]; + new Runnable() { + public void run() { + ref[0] = UrlClassLoader.build().urls(urls).useCache().get(); + } + }.run(); + return ref[0]; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java index 69450a8460f4..505d88b0e4dc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java @@ -194,7 +194,7 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler { try { fileWithParameters = GroovycOSProcessHandler .fillFileWithGroovycParameters(outputDir.getPath(), paths2Compile, FileUtil.toSystemDependentName(finalOutputDir.getPath()), - class2Src, encoding, patchers); + class2Src, encoding, patchers, ""); } catch (IOException e) { LOG.info(e); @@ -202,6 +202,7 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler { return; } + parameters.getProgramParametersList().add("do_not_optimize"); parameters.getProgramParametersList().add(forStubs ? "stubs" : "groovyc"); parameters.getProgramParametersList().add(fileWithParameters.getPath()); if (compilerConfiguration.isInvokeDynamic()) { @@ -253,7 +254,7 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler { if (sourceVirtualFile == null) { continue; } - + if (indicator != null) { indicator.setText2(sourceVirtualFile.getName()); } From 13e43be065839e80c9da3b7802c317fe415ceb31 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 27 Feb 2014 22:04:18 +0100 Subject: [PATCH 60/95] more debugging for GroovyCompilerTest --- .../compiler/impl/TranslatingCompilerFilesMonitor.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java index 1bcff3f8bae6..9e89f13c79c0 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java @@ -1616,6 +1616,11 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } private void processNewFile(final VirtualFile file, final boolean notifyServer) { + if (ourDebugMode) { + System.out.println("MyVfsListener.processNewFile"); + System.out.println("file = [" + file + "], notifyServer = [" + notifyServer + "]"); + System.out.println("myWatchedProjectsCount = " + myWatchedProjectsCount); + } if (myWatchedProjectsCount == 0) return; final Ref isInContent = Ref.create(false); ApplicationManager.getApplication().runReadAction(new Runnable() { From 22985e212fb68645fb4b0569897fb02676c97869 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 27 Feb 2014 22:04:49 +0100 Subject: [PATCH 61/95] load document LineSet lazily --- .../openapi/editor/impl/DocumentImpl.java | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java index 3d51b6ba470c..2a2249b60e57 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java @@ -59,7 +59,8 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { private final List myGuardedBlocks = new ArrayList(); private ReadonlyFragmentModificationHandler myReadonlyFragmentModificationHandler; - private final LineSet myLineSet = new LineSet(); + private final Object myLineSetLock = new String("line set lock"); + private volatile LineSet myLineSet; private volatile ImmutableText myText; private volatile SoftReference myTextString; @@ -112,7 +113,6 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { public DocumentImpl(@NotNull CharSequence chars, boolean forUseInNonAWTThread) { assertValidSeparators(chars); myText = ImmutableText.valueOf(chars); - myLineSet.documentCreated(this); setCyclicBufferSize(0); setModificationStamp(LocalTimeCounter.currentTime()); myAssertThreading = !forUseInNonAWTThread; @@ -127,6 +127,22 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { } } + private LineSet getLineSet() { + LineSet lineSet = myLineSet; + if (lineSet == null) { + synchronized (myLineSetLock) { + lineSet = myLineSet; + if (lineSet == null) { + lineSet = new LineSet(); + lineSet.documentCreated(this); + myLineSet = lineSet; + } + } + } + + return lineSet; + } + @Override @NotNull public char[] getChars() { @@ -159,11 +175,12 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { CharSequence text = myText; RangeMarker caretMarker = caretOffset < 0 || caretOffset > getTextLength() ? null : createRangeMarker(caretOffset, caretOffset); try { - for (int line = 0; line < myLineSet.getLineCount(); line++) { - if (inChangedLinesOnly && !myLineSet.isModified(line)) continue; + LineSet lineSet = getLineSet(); + for (int line = 0; line < lineSet.getLineCount(); line++) { + if (inChangedLinesOnly && !lineSet.isModified(line)) continue; int whiteSpaceStart = -1; - final int lineEnd = myLineSet.getLineEnd(line) - myLineSet.getSeparatorLength(line); - int lineStart = myLineSet.getLineStart(line); + final int lineEnd = lineSet.getLineEnd(line) - lineSet.getSeparatorLength(line); + int lineStart = lineSet.getLineStart(line); for (int offset = lineEnd - 1; offset >= lineStart; offset--) { char c = text.charAt(offset); if (c != ' ' && c != '\t') { @@ -228,12 +245,13 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { markers.add(marker); } } + LineSet lineSet = getLineSet(); lineLoop: - for (int line = 0; line < myLineSet.getLineCount(); line++) { - if (inChangedLinesOnly && !myLineSet.isModified(line)) continue; + for (int line = 0; line < lineSet.getLineCount(); line++) { + if (inChangedLinesOnly && !lineSet.isModified(line)) continue; int whiteSpaceStart = -1; - final int lineEnd = myLineSet.getLineEnd(line) - myLineSet.getSeparatorLength(line); - int lineStart = myLineSet.getLineStart(line); + final int lineEnd = lineSet.getLineEnd(line) - lineSet.getSeparatorLength(line); + int lineStart = lineSet.getLineStart(line); for (int offset = lineEnd - 1; offset >= lineStart; offset--) { char c = text.charAt(offset); if (c != ' ' && c != '\t') { @@ -644,19 +662,20 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { @Override public void clearLineModificationFlags() { - myLineSet.clearModificationFlags(); + getLineSet().clearModificationFlags(); } public void clearLineModificationFlagsExcept(@NotNull List caretLines) { List modifiedLines = new ArrayList(caretLines.size()); + LineSet lineSet = getLineSet(); for (Integer line : caretLines) { - if (line != null && line >= 0 && line < myLineSet.getLineCount() && myLineSet.isModified(line)) { + if (line != null && line >= 0 && line < lineSet.getLineCount() && lineSet.isModified(line)) { modifiedLines.add(line); } } clearLineModificationFlags(); for (Integer line : modifiedLines) { - myLineSet.setModified(line); + lineSet.setModified(line); } } @@ -725,7 +744,12 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { try { if (LOG.isDebugEnabled()) LOG.debug(event.toString()); - myLineSet.changedUpdate(event); + synchronized (myLineSetLock) { + LineSet lineSet = myLineSet; + if (lineSet != null) { + lineSet.changedUpdate(event); + } + } setModificationStamp(newModificationStamp); if (!ShutDownTracker.isShutdownHookRunning()) { @@ -847,39 +871,39 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { @Override public int getLineNumber(final int offset) { - return myLineSet.findLineIndex(offset); + return getLineSet().findLineIndex(offset); } @Override @NotNull public LineIterator createLineIterator() { - return myLineSet.createIterator(); + return getLineSet().createIterator(); } @Override public final int getLineStartOffset(final int line) { if (line == 0) return 0; // otherwise it crashed for zero-length document - return myLineSet.getLineStart(line); + return getLineSet().getLineStart(line); } @Override public final int getLineEndOffset(int line) { if (getTextLength() == 0 && line == 0) return 0; - int result = myLineSet.getLineEnd(line) - getLineSeparatorLength(line); + int result = getLineSet().getLineEnd(line) - getLineSeparatorLength(line); assert result >= 0; return result; } @Override public final int getLineSeparatorLength(int line) { - int separatorLength = myLineSet.getSeparatorLength(line); + int separatorLength = getLineSet().getSeparatorLength(line); assert separatorLength >= 0; return separatorLength; } @Override public final int getLineCount() { - int lineCount = myLineSet.getLineCount(); + int lineCount = getLineSet().getLineCount(); assert lineCount >= 0; return lineCount; } From f1fef2c6e6f0b1be0f4170de026d4e0674730798 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Fri, 28 Feb 2014 11:27:46 +0400 Subject: [PATCH 62/95] correction to editor fixture to fix failing tests (IDEA-80056) --- .../src/com/intellij/testFramework/EditorTestUtil.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java index 5d658bfe7e3a..96f5bd812c52 100644 --- a/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java @@ -326,6 +326,9 @@ public class EditorTestUtil { if (caret.selection != null) { editor.getSelectionModel().setSelection(caret.selection.getStartOffset(), caret.selection.getEndOffset()); } + else { + editor.getSelectionModel().removeSelection(); + } } if (caretsState.blockSelection != null) { editor.getSelectionModel().setBlockSelection(editor.offsetToLogicalPosition(caretsState.blockSelection.getStartOffset()), From b6791caa24a30e96b510a81899372b6e99bd49f1 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 27 Feb 2014 15:35:36 +0100 Subject: [PATCH 63/95] overrides --- .../impl/actions/SmartStepIntoAction.java | 3 ++- .../XDebuggerSmartStepIntoHandler.java | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/SmartStepIntoAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/SmartStepIntoAction.java index f886f1f1b80a..3e6a0a1ebb13 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/SmartStepIntoAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/SmartStepIntoAction.java @@ -15,13 +15,14 @@ */ package com.intellij.xdebugger.impl.actions; -import org.jetbrains.annotations.NotNull; import com.intellij.xdebugger.impl.DebuggerSupport; +import org.jetbrains.annotations.NotNull; /** * @author nik */ public class SmartStepIntoAction extends XDebuggerActionBase { + @Override @NotNull protected DebuggerActionHandler getHandler(@NotNull final DebuggerSupport debuggerSupport) { return debuggerSupport.getSmartStepIntoHandler(); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerSmartStepIntoHandler.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerSmartStepIntoHandler.java index 4a933b794aac..6d09b8fd3128 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerSmartStepIntoHandler.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerSmartStepIntoHandler.java @@ -15,21 +15,21 @@ */ package com.intellij.xdebugger.impl.actions.handlers; -import org.jetbrains.annotations.NotNull; -import com.intellij.xdebugger.XDebugSession; -import com.intellij.xdebugger.XSourcePosition; -import com.intellij.xdebugger.stepping.XSmartStepIntoHandler; -import com.intellij.xdebugger.stepping.XSmartStepIntoVariant; -import com.intellij.xdebugger.impl.actions.XDebuggerSuspendedActionHandler; -import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.FileEditor; +import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; import com.intellij.ui.awt.RelativePoint; +import com.intellij.xdebugger.XDebugSession; +import com.intellij.xdebugger.XSourcePosition; +import com.intellij.xdebugger.impl.actions.XDebuggerSuspendedActionHandler; +import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; +import com.intellij.xdebugger.stepping.XSmartStepIntoHandler; +import com.intellij.xdebugger.stepping.XSmartStepIntoVariant; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.util.List; @@ -39,10 +39,12 @@ import java.util.List; */ public class XDebuggerSmartStepIntoHandler extends XDebuggerSuspendedActionHandler { + @Override protected boolean isEnabled(@NotNull XDebugSession session, DataContext dataContext) { return super.isEnabled(session, dataContext) && session.getDebugProcess().getSmartStepIntoHandler() != null; } + @Override protected void perform(@NotNull XDebugSession session, DataContext dataContext) { final XSmartStepIntoHandler handler = session.getDebugProcess().getSmartStepIntoHandler(); final XSourcePosition position = session.getCurrentPosition(); From dda01ac380c66e45bd9bcded593c5993720212e4 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 27 Feb 2014 15:43:19 +0100 Subject: [PATCH 64/95] overrides, notnull --- .../intellij/xdebugger/stepping/XSmartStepIntoHandler.java | 2 +- .../jetbrains/python/debugger/PySmartStepIntoHandler.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/stepping/XSmartStepIntoHandler.java b/platform/xdebugger-api/src/com/intellij/xdebugger/stepping/XSmartStepIntoHandler.java index 46dcaa236651..56b098de99f0 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/stepping/XSmartStepIntoHandler.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/stepping/XSmartStepIntoHandler.java @@ -40,7 +40,7 @@ public abstract class XSmartStepIntoHandlervariant function/method is reached * @param variant selected variant */ - public abstract void startStepInto(Variant variant); + public abstract void startStepInto(@NotNull Variant variant); /** * @return title for popup which will be shown to select method/function diff --git a/python/src/com/jetbrains/python/debugger/PySmartStepIntoHandler.java b/python/src/com/jetbrains/python/debugger/PySmartStepIntoHandler.java index af8b69f3b07e..5b1217072465 100644 --- a/python/src/com/jetbrains/python/debugger/PySmartStepIntoHandler.java +++ b/python/src/com/jetbrains/python/debugger/PySmartStepIntoHandler.java @@ -49,6 +49,7 @@ public class PySmartStepIntoHandler extends XSmartStepIntoHandler computeSmartStepVariants(@NotNull XSourcePosition position) { final Document document = FileDocumentManager.getInstance().getDocument(position.getFile()); @@ -57,6 +58,7 @@ public class PySmartStepIntoHandler extends XSmartStepIntoHandler() { + @Override public boolean process(PsiElement psiElement) { addVariants(document, line, psiElement, variants, visitedCalls); return true; @@ -67,10 +69,11 @@ public class PySmartStepIntoHandler extends XSmartStepIntoHandler Date: Thu, 27 Feb 2014 15:51:11 +0100 Subject: [PATCH 65/95] prepare to fix WEB-4379 Smart step into does not give me all the methods, WEB-4440 Make debugger step inside the anonymous function of the $.each statement by default (or make it at least optional) --- .../intellij/xdebugger/impl/actions/SmartStepIntoAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/SmartStepIntoAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/SmartStepIntoAction.java index 3e6a0a1ebb13..adc2589b645c 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/SmartStepIntoAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/SmartStepIntoAction.java @@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull; /** * @author nik */ -public class SmartStepIntoAction extends XDebuggerActionBase { +final class SmartStepIntoAction extends XDebuggerActionBase { @Override @NotNull protected DebuggerActionHandler getHandler(@NotNull final DebuggerSupport debuggerSupport) { From 39a393c9c6132dcb868f6cb625177b361f728be1 Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 28 Feb 2014 11:36:20 +0400 Subject: [PATCH 66/95] initialize default breakpoints for new project in tests --- .../breakpoints/XBreakpointManagerImpl.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java index 09b8cb44e1b4..233c473fc952 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java @@ -68,14 +68,16 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta myAllBreakpointsDispatcher = EventDispatcher.create(XBreakpointListener.class); myDependentBreakpointManager = new XDependentBreakpointManager(this); myLineBreakpointManager = new XLineBreakpointManager(project, myDependentBreakpointManager, startupManager); - if (!project.isDefault() && !ApplicationManager.getApplication().isUnitTestMode()) { - HttpVirtualFileListener httpVirtualFileListener = new HttpVirtualFileListener() { - @Override - public void fileDownloaded(@NotNull final VirtualFile file) { - updateBreakpointInFile(file); - } - }; - HttpFileSystem.getInstance().addFileListener(httpVirtualFileListener, project); + if (!project.isDefault()) { + if (!ApplicationManager.getApplication().isUnitTestMode()) { + HttpVirtualFileListener httpVirtualFileListener = new HttpVirtualFileListener() { + @Override + public void fileDownloaded(@NotNull final VirtualFile file) { + updateBreakpointInFile(file); + } + }; + HttpFileSystem.getInstance().addFileListener(httpVirtualFileListener, project); + } for (XBreakpointType type : XBreakpointUtil.getBreakpointTypes()) { addDefaultBreakpoint(type); } From 58d0444305dfa174d50fbd8df5bcd4d649d11cc2 Mon Sep 17 00:00:00 2001 From: Vladimir Orlov Date: Fri, 28 Feb 2014 11:46:37 +0400 Subject: [PATCH 67/95] IDEA-121383 Intellij EAP 1342 Does not start on Mac --- build/scripts/utils.gant | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/scripts/utils.gant b/build/scripts/utils.gant index b52405ee7357..806503896c71 100644 --- a/build/scripts/utils.gant +++ b/build/scripts/utils.gant @@ -353,7 +353,7 @@ binding.setVariable("layoutMacApp", { String path, String ch, Map args -> String archs = """ LSArchitecturePriority """ - (args.archs != null ? args.archs : ["64_x86", "i386"]).each { + (args.archs != null ? args.archs : ["x86_64", "i386"]).each { archs += "${it}" } archs +="\n" From 00e2508e86765c8f7f4e8cdf7a292f4800ec0ab5 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 16 Jan 2014 15:38:13 +0400 Subject: [PATCH 68/95] IDEA-119238 Git and Hg Amend Commit: amend message updated for multi-root selection changes *last messaged for all committed repositories stored to map; *amended message reconstructed using current selected repositories --- .../dvcs/DvcsCommitAdditionalComponent.java | 77 ++++++++++++------- .../checkin/GitCheckinEnvironment.java | 24 +++--- .../provider/commit/HgCheckinEnvironment.java | 4 +- .../src/org/zmlx/hg4idea/util/HgUtil.java | 17 ++++ 4 files changed, 80 insertions(+), 42 deletions(-) diff --git a/platform/dvcs/src/com/intellij/dvcs/DvcsCommitAdditionalComponent.java b/platform/dvcs/src/com/intellij/dvcs/DvcsCommitAdditionalComponent.java index 56900785e57b..b891d3ba3814 100644 --- a/platform/dvcs/src/com/intellij/dvcs/DvcsCommitAdditionalComponent.java +++ b/platform/dvcs/src/com/intellij/dvcs/DvcsCommitAdditionalComponent.java @@ -24,10 +24,13 @@ import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.CheckinProjectPanel; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.NonFocusableCheckBox; +import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,8 +39,9 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.Collection; -import java.util.LinkedHashSet; +import java.io.File; +import java.util.*; +import java.util.List; /** * @author Nadya Zabrodina @@ -51,6 +55,7 @@ public abstract class DvcsCommitAdditionalComponent implements RefreshableOnComp @Nullable private String myPreviousMessage; @Nullable private String myAmendedMessage; @NotNull protected final CheckinProjectPanel myCheckinPanel; + @Nullable private Map myMessagesForRoots; public DvcsCommitAdditionalComponent(@NotNull final Project project, @NotNull CheckinProjectPanel panel) { myCheckinPanel = panel; @@ -76,14 +81,16 @@ public abstract class DvcsCommitAdditionalComponent implements RefreshableOnComp @Override public void actionPerformed(ActionEvent e) { if (myAmend.isSelected()) { - if (myPreviousMessage.equals(myCheckinPanel.getCommitMessage())) { // if user has already typed something, don't revert it - if (myAmendedMessage == null) { - loadMessageInModalTask(project); + if (myPreviousMessage.equals(myCheckinPanel.getCommitMessage())) { // if user has already typed something, don't revert it + if (myMessagesForRoots == null) { + loadMessagesInModalTask(project); //load all commit messages for all repositories + } + String message = constructAmendedMessage(); + if (!StringUtil.isEmptyOrSpaces(message)) { + myAmendedMessage = message; + substituteCommitMessage(myAmendedMessage); + } } - else { // checkbox is selected not the first time - substituteCommitMessage(myAmendedMessage); - } - } } else { // there was the amended message, but user has changed it => not reverting @@ -96,6 +103,20 @@ public abstract class DvcsCommitAdditionalComponent implements RefreshableOnComp myPanel.add(myAmend, c); } + private String constructAmendedMessage() { + Set selectedRoots = getVcsRoots(getSelectedFilePaths()); // get only selected files + LinkedHashSet messages = ContainerUtil.newLinkedHashSet(); + if (myMessagesForRoots != null) { + for (VirtualFile root : selectedRoots) { + String message = myMessagesForRoots.get(root); + if (message != null) { + messages.add(message); + } + } + } + return DvcsUtil.joinMessagesOrNull(messages); + } + public JComponent getComponent() { return myPanel; } @@ -104,19 +125,15 @@ public abstract class DvcsCommitAdditionalComponent implements RefreshableOnComp myAmend.setSelected(false); } - private void loadMessageInModalTask(@NotNull Project project) { + private void loadMessagesInModalTask(@NotNull Project project) { try { - String messageFromVcs = - ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable() { + myMessagesForRoots = + ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable, VcsException>() { @Override - public String compute() throws VcsException { - return getLastCommitMessage(); + public Map compute() throws VcsException { + return getLastCommitMessages(); } }, "Reading commit message...", false, project); - if (!StringUtil.isEmptyOrSpaces(messageFromVcs)) { - substituteCommitMessage(messageFromVcs); - myAmendedMessage = messageFromVcs; - } } catch (VcsException e) { Messages.showErrorDialog(getComponent(), "Couldn't load commit message of the commit to amend.\n" + e.getMessage(), @@ -133,24 +150,32 @@ public abstract class DvcsCommitAdditionalComponent implements RefreshableOnComp } @Nullable - private String getLastCommitMessage() throws VcsException { - Collection roots = getRoots(); + private Map getLastCommitMessages() throws VcsException { + Map messagesForRoots = new HashMap(); + Collection roots = myCheckinPanel.getRoots(); //all committed vcs roots, not only selected final Ref exception = Ref.create(); - LinkedHashSet messages = ContainerUtil.newLinkedHashSet(); for (VirtualFile root : roots) { String message = getLastCommitMessage(root); - if (message != null) { - messages.add(message); - } + messagesForRoots.put(root, message); } if (!exception.isNull()) { throw exception.get(); } - return DvcsUtil.joinMessagesOrNull(messages); + return messagesForRoots; } @NotNull - protected abstract Collection getRoots(); + private List getSelectedFilePaths() { + return ContainerUtil.map(myCheckinPanel.getFiles(), new Function() { + @Override + public FilePath fun(File file) { + return new FilePathImpl(file, file.isDirectory()); + } + }); + } + + @NotNull + protected abstract Set getVcsRoots(Collection files); @Nullable protected abstract String getLastCommitMessage(@NotNull VirtualFile repo) throws VcsException; diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java index d5c4b3fa8505..cf26be1cef2a 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java @@ -25,7 +25,10 @@ import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vcs.*; +import com.intellij.openapi.vcs.CheckinProjectPanel; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.ObjectsConvertor; +import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.changes.ui.SelectFilePathsDialog; import com.intellij.openapi.vcs.checkin.CheckinChangeListSpecificComponent; @@ -33,7 +36,10 @@ import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.GuiUtils; -import com.intellij.util.*; +import com.intellij.util.ArrayUtil; +import com.intellij.util.FunctionUtil; +import com.intellij.util.NullableFunction; +import com.intellij.util.PairConsumer; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Convertor; import com.intellij.util.ui.UIUtil; @@ -643,8 +649,8 @@ public class GitCheckinEnvironment implements CheckinEnvironment { @Override @NotNull - protected Set getRoots() { - return GitUtil.gitRoots(getSelectedFilePaths()); + protected Set getVcsRoots(Collection filePaths) { + return GitUtil.gitRoots(filePaths); } @Nullable @@ -665,16 +671,6 @@ public class GitCheckinEnvironment implements CheckinEnvironment { return h.run(); } - @NotNull - private List getSelectedFilePaths() { - return ContainerUtil.map(myCheckinPanel.getFiles(), new Function() { - @Override - public FilePath fun(File file) { - return new FilePathImpl(file, file.isDirectory()); - } - }); - } - private List getUsersList(final Project project) { return NewGitUsersComponent.getInstance(project).get(); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java index aaf9e9dd1c8b..ab721b8a70dc 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java @@ -284,8 +284,8 @@ public class HgCheckinEnvironment implements CheckinEnvironment { @NotNull @Override - protected Collection getRoots() { - return HgUtil.getHgRepositories(myProject); + protected Set getVcsRoots(Collection filePaths) { + return HgUtil.hgRoots(myProject, filePaths); } @Nullable diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java index fd0fc503df7d..c57f61f0e30b 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java @@ -240,6 +240,23 @@ public abstract class HgUtil { return getNearestHgRoot(VcsUtil.getVcsRootFor(project, filePath)); } + /** + * Get hg roots for paths + * + * @param filePaths the context paths + * @return a set of git roots + */ + public static Set hgRoots(@NotNull Project project, final Collection filePaths) { + HashSet rc = new HashSet(); + for (FilePath path : filePaths) { + final VirtualFile root = getHgRootOrNull(project, path); + if (root != null) { + rc.add(root); + } + } + return rc; + } + /** * Gets the Mercurial root for the given file path or null if non exists: * the root should not only be in directory mappings, but also the .hg repository folder should exist. From e79dc612172b276c5fcc5f49897f77b5ce96b4ce Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 27 Feb 2014 20:16:54 +0400 Subject: [PATCH 69/95] style --- .../dvcs/DvcsCommitAdditionalComponent.java | 2 +- .../git4idea/checkin/GitCheckinEnvironment.java | 5 ++++- .../provider/commit/HgCheckinEnvironment.java | 10 ++++++---- .../hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java | 15 +++++++-------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/platform/dvcs/src/com/intellij/dvcs/DvcsCommitAdditionalComponent.java b/platform/dvcs/src/com/intellij/dvcs/DvcsCommitAdditionalComponent.java index b891d3ba3814..26c87c7de627 100644 --- a/platform/dvcs/src/com/intellij/dvcs/DvcsCommitAdditionalComponent.java +++ b/platform/dvcs/src/com/intellij/dvcs/DvcsCommitAdditionalComponent.java @@ -175,7 +175,7 @@ public abstract class DvcsCommitAdditionalComponent implements RefreshableOnComp } @NotNull - protected abstract Set getVcsRoots(Collection files); + protected abstract Set getVcsRoots(@NotNull Collection files); @Nullable protected abstract String getLastCommitMessage(@NotNull VirtualFile repo) throws VcsException; diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java index cf26be1cef2a..013d4cafe836 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java @@ -649,7 +649,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment { @Override @NotNull - protected Set getVcsRoots(Collection filePaths) { + protected Set getVcsRoots(@NotNull Collection filePaths) { return GitUtil.gitRoots(filePaths); } @@ -675,12 +675,14 @@ public class GitCheckinEnvironment implements CheckinEnvironment { return NewGitUsersComponent.getInstance(project).get(); } + @Override public void refresh() { super.refresh(); myAuthor.setSelectedItem(""); reset(); } + @Override public void saveState() { String author = (String)myAuthor.getEditor().getItem(); myNextCommitAuthor = author.length() == 0 ? null : author; @@ -695,6 +697,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment { myNextCommitAuthorDate = myAuthorDate; } + @Override public void restoreState() { refresh(); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java index ab721b8a70dc..87e5e7516929 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java @@ -264,31 +264,33 @@ public class HgCheckinEnvironment implements CheckinEnvironment { public HgCommitAdditionalComponent(@NotNull Project project, @NotNull CheckinProjectPanel panel) { super(project, panel); HgVcs myVcs = HgVcs.getInstance(myProject); - if (myVcs != null && !myVcs.getVersion().isAmendSupported()) { - myAmend.setEnabled(false); - } + myAmend.setEnabled(myVcs != null && myVcs.getVersion().isAmendSupported()); } + @Override public void refresh() { super.refresh(); myNextCommitAmend = false; } + @Override public void saveState() { myNextCommitAmend = myAmend.isSelected(); } + @Override public void restoreState() { myNextCommitAmend = false; } @NotNull @Override - protected Set getVcsRoots(Collection filePaths) { + protected Set getVcsRoots(@NotNull Collection filePaths) { return HgUtil.hgRoots(myProject, filePaths); } @Nullable + @Override protected String getLastCommitMessage(@NotNull VirtualFile repo) throws VcsException { HgCommandExecutor commandExecutor = new HgCommandExecutor(myProject); List args = new ArrayList(); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java index c57f61f0e30b..be28b9171e83 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java @@ -40,6 +40,7 @@ import com.intellij.openapi.wm.StatusBar; import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.impl.status.StatusBarUtil; import com.intellij.ui.GuiUtils; +import com.intellij.util.containers.ContainerUtil; import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -244,17 +245,15 @@ public abstract class HgUtil { * Get hg roots for paths * * @param filePaths the context paths - * @return a set of git roots + * @return a set of hg roots */ - public static Set hgRoots(@NotNull Project project, final Collection filePaths) { - HashSet rc = new HashSet(); + @NotNull + public static Set hgRoots(@NotNull Project project, @NotNull Collection filePaths) { + HashSet roots = new HashSet(); for (FilePath path : filePaths) { - final VirtualFile root = getHgRootOrNull(project, path); - if (root != null) { - rc.add(root); - } + ContainerUtil.addIfNotNull(roots, getHgRootOrNull(project, path)); } - return rc; + return roots; } /** From 018e061307e0cf50f707ef09fc177787cf6f6c9f Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 28 Feb 2014 09:22:23 +0100 Subject: [PATCH 70/95] WEB-4379 Smart step into does not give me all the methods --- .../src/com/intellij/psi/util/PsiTreeUtil.java | 16 +++++++++++++--- .../PsiBackedSmartStepIntoVariant.java | 2 ++ .../xdebugger/impl/XDebuggerUtilImpl.java | 18 +++++++++--------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java b/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java index d33ee461f1cb..bb6273bb5a7c 100644 --- a/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java +++ b/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java @@ -520,17 +520,27 @@ public class PsiTreeUtil { @Nullable @Contract("null, _, _ -> null") public static T getParentOfType(@Nullable PsiElement element, @NotNull Class aClass, boolean strict) { - if (element == null) return null; + return getParentOfType(element, aClass, strict, -1); + } + + @Contract("null, _, _, _ -> null") + public static T getParentOfType(@Nullable PsiElement element, @NotNull Class aClass, boolean strict, int minStartOffset) { + if (element == null) { + return null; + } + if (strict) { element = element.getParent(); } - while (element != null) { + while (element != null && (minStartOffset == -1 || element.getNode().getStartOffset() >= minStartOffset)) { if (aClass.isInstance(element)) { //noinspection unchecked return (T)element; } - if (element instanceof PsiFile) return null; + if (element instanceof PsiFile) { + return null; + } element = element.getParent(); } diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/stepping/PsiBackedSmartStepIntoVariant.java b/platform/xdebugger-api/src/com/intellij/xdebugger/stepping/PsiBackedSmartStepIntoVariant.java index f2728161ef13..d17f8e01271d 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/stepping/PsiBackedSmartStepIntoVariant.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/stepping/PsiBackedSmartStepIntoVariant.java @@ -36,6 +36,7 @@ public class PsiBackedSmartStepIntoVariant processor) { PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); - if (file == null) return; + if (file == null) { + return; + } int lineStart; int lineEnd; - try { lineStart = document.getLineStartOffset(line); lineEnd = document.getLineEndOffset(line); } - catch (IndexOutOfBoundsException e) { + catch (IndexOutOfBoundsException ignored) { return; } PsiElement element; - - int off = lineStart; - while (off < lineEnd) { - element = file.findElementAt(off); + int offset = lineStart; + while (offset < lineEnd) { + element = file.findElementAt(offset); if (element != null) { if (!processor.process(element)) { return; } else { - off = element.getTextRange().getEndOffset(); + offset = element.getTextRange().getEndOffset(); } } else { - off++; + offset++; } } } From 229a0e90b0791efa0638f21ead5528c6401bf597 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 28 Feb 2014 09:29:37 +0100 Subject: [PATCH 71/95] CR-IC-4571 EditorExtensions.xml is overkill --- .../platform-resources/src/META-INF/EditorExtensions.xml | 5 ----- .../platform-resources/src/META-INF/PlatformExtensions.xml | 2 ++ .../platform-resources/src/META-INF/PlatformLangPlugin.xml | 1 - platform/platform-resources/src/META-INF/PlatformPlugin.xml | 1 - resources/src/idea/RichPlatformPlugin.xml | 1 - 5 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 platform/platform-resources/src/META-INF/EditorExtensions.xml diff --git a/platform/platform-resources/src/META-INF/EditorExtensions.xml b/platform/platform-resources/src/META-INF/EditorExtensions.xml deleted file mode 100644 index f2e50a2fde46..000000000000 --- a/platform/platform-resources/src/META-INF/EditorExtensions.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 854e1ce08535..b6189cf69a47 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -190,6 +190,8 @@ + + diff --git a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml index 54a54fc51865..943f3f568d68 100644 --- a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml +++ b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml @@ -21,7 +21,6 @@ - diff --git a/platform/platform-resources/src/META-INF/PlatformPlugin.xml b/platform/platform-resources/src/META-INF/PlatformPlugin.xml index 72d1efc98464..8cca39a37a4f 100644 --- a/platform/platform-resources/src/META-INF/PlatformPlugin.xml +++ b/platform/platform-resources/src/META-INF/PlatformPlugin.xml @@ -17,7 +17,6 @@ - diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index cd22c2f41ea3..e6ab127a6b67 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -108,7 +108,6 @@ - From cf066deca7b64715dcb5f57a6ed1e4933719f9cd Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Feb 2014 21:29:00 +0100 Subject: [PATCH 72/95] default methods: do not warn about protected methods from Object --- .../daemon/impl/analysis/GenericsHighlightUtil.java | 5 +++-- .../DefaultMethodOverrideEquivalentObject.java | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index 324a222a018d..72ad0f26efa1 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -406,8 +406,9 @@ public class GenericsHighlightUtil { if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && aClass.isInterface() && method.hasModifierProperty(PsiModifier.DEFAULT)) { HierarchicalMethodSignature sig = method.getHierarchicalMethodSignature(); for (HierarchicalMethodSignature methodSignature : sig.getSuperSignatures()) { - final PsiClass containingClass = methodSignature.getMethod().getContainingClass(); - if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) { + final PsiMethod objectMethod = methodSignature.getMethod(); + final PsiClass containingClass = objectMethod.getContainingClass(); + if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName()) && objectMethod.hasModifierProperty(PsiModifier.PUBLIC)) { return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR) .descriptionAndTooltip("Default method '" + sig.getName() + "' overrides a member of 'java.lang.Object'") .range(methodIdentifier) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/DefaultMethodOverrideEquivalentObject.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/DefaultMethodOverrideEquivalentObject.java index cb671b7cd6c0..84b2259286fa 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/DefaultMethodOverrideEquivalentObject.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/DefaultMethodOverrideEquivalentObject.java @@ -2,4 +2,5 @@ interface A { default String toString() { return ""; } + default void finalize() throws Throwable { } } \ No newline at end of file From a7c29b4e714f1a857215e79c27fc36f77e87ccf6 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 28 Feb 2014 10:08:40 +0100 Subject: [PATCH 73/95] LanguageConsoleImpl calls createFile during initialization, so, inherited class cannot override it properly --- .../execution/console/LanguageConsoleBuilder.java | 7 ++++--- .../execution/console/LanguageConsoleImpl.java | 15 ++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java index 0d013fbfec1c..4bf7ec23efff 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java @@ -147,7 +147,7 @@ public final class LanguageConsoleBuilder { } public LanguageConsoleView build(@NotNull Project project, @NotNull Language language) { - GutteredLanguageConsole console = new GutteredLanguageConsole(project, language, gutterContentProvider, psiFileFactory); + GutteredLanguageConsole console = new GutteredLanguageConsole(language.getDisplayName() + " Console", project, language, gutterContentProvider, psiFileFactory); LanguageConsoleViewImpl consoleView = new LanguageConsoleViewImpl(console, true); if (executeActionHandler != null) { assert historyType != null; @@ -184,11 +184,12 @@ public final class LanguageConsoleBuilder { @Nullable private final PairFunction psiFileFactory; - public GutteredLanguageConsole(@NotNull Project project, + public GutteredLanguageConsole(@NotNull String title, + @NotNull Project project, @NotNull Language language, @Nullable GutterContentProvider gutterContentProvider, @Nullable PairFunction psiFileFactory) { - super(project, language.getDisplayName() + " Console", language, false); + super(project, title, new LightVirtualFile(title, language, ""), false, psiFileFactory); setShowSeparatorLine(false); diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index da38faf0f8f5..be107d98ab94 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -58,10 +58,7 @@ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.testFramework.LightVirtualFile; import com.intellij.ui.JBColor; import com.intellij.ui.SideBorder; -import com.intellij.util.DocumentUtil; -import com.intellij.util.FileContentUtil; -import com.intellij.util.ObjectUtils; -import com.intellij.util.SingleAlarm; +import com.intellij.util.*; import com.intellij.util.ui.AbstractLayoutManager; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -124,6 +121,14 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { } public LanguageConsoleImpl(@NotNull Project project, @NotNull String title, @NotNull LightVirtualFile lightFile, boolean initComponents) { + this(project, title, lightFile, initComponents, null); + } + + LanguageConsoleImpl(@NotNull Project project, + @NotNull String title, + @NotNull LightVirtualFile lightFile, + boolean initComponents, + @Nullable PairFunction psiFileFactory) { myProject = project; myTitle = title; myVirtualFile = lightFile; @@ -131,7 +136,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { myHistoryFile = new LightVirtualFile(getTitle() + ".history.txt", FileTypes.PLAIN_TEXT, ""); myEditorDocument = FileDocumentManager.getInstance().getDocument(lightFile); assert myEditorDocument != null; - myFile = createFile(myVirtualFile, myEditorDocument, myProject); + myFile = psiFileFactory == null ? createFile(myVirtualFile, myEditorDocument, myProject) : psiFileFactory.fun(myVirtualFile, myProject); myConsoleEditor = (EditorEx)editorFactory.createEditor(myEditorDocument, myProject); myConsoleEditor.addFocusListener(myFocusListener); myCurrentEditor = myConsoleEditor; From df6f6f5c5ef2deb7928f79113929e24a398ba67b Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 28 Feb 2014 12:57:57 +0400 Subject: [PATCH 74/95] do not save empty condition and log message in breakpoints --- .../com/intellij/debugger/ui/breakpoints/Breakpoint.java | 7 ++++++- .../debugger/ui/breakpoints/FilteredRequestorImpl.java | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index d846767b4b8a..90974d82ccc3 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -597,7 +597,12 @@ public abstract class Breakpoint

    implements } protected void setLogMessage(TextWithImports logMessage) { - myXBreakpoint.setLogExpression(logMessage.getText()); + if (!logMessage.getText().isEmpty()) { + myXBreakpoint.setLogExpression(logMessage.getText()); + } + else { + myXBreakpoint.setLogExpression(null); + } } protected boolean isConditionEnabled() { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestorImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestorImpl.java index b83e0e97cb7e..2637773cb0cc 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestorImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestorImpl.java @@ -129,9 +129,7 @@ public class FilteredRequestorImpl implements JDOMExternalizable, FilteredReques breakpoint.setCountFilterEnabled(COUNT_FILTER_ENABLED); breakpoint.setCountFilter(COUNT_FILTER); - if (CONDITION_ENABLED) { - breakpoint.setCondition(myCondition != null ? myCondition.getText() : null); - } + breakpoint.setCondition(CONDITION_ENABLED && myCondition != null && !myCondition.getText().isEmpty() ? myCondition.getText() : null); breakpoint.setClassFiltersEnabled(CLASS_FILTERS_ENABLED); breakpoint.setClassFilters(getClassFilters()); From d37c7a9dcfd5eb19da13ebee2dc589ecad9165fe Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 28 Feb 2014 13:17:23 +0400 Subject: [PATCH 75/95] EA-54432 - IAE: XDependentBreakpointManager.getMasterBreakpoint --- .../debugger/ui/breakpoints/BreakpointManager.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index d16084dec557..5fadb64b8f9a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -389,15 +389,6 @@ public class BreakpointManager { return null; } - private XBreakpoint findXBreakpoint(Breakpoint breakpoint) { - for (Map.Entry entry : myBreakpoints.entrySet()) { - if (entry.getValue().equals(breakpoint)) { - return entry.getKey(); - } - } - return null; - } - public Breakpoint findBreakpoint(XBreakpoint xBreakpoint) { return myBreakpoints.get(xBreakpoint); } @@ -994,7 +985,7 @@ public class BreakpointManager { // copied from XDebugSessionImpl processDependencies public void processBreakpointHit(@NotNull final Breakpoint breakpoint) { XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)getXBreakpointManager()).getDependentBreakpointManager(); - XBreakpoint xBreakpoint = findXBreakpoint(breakpoint); + XBreakpoint xBreakpoint = breakpoint.myXBreakpoint; if (!dependentBreakpointManager.isMasterOrSlave(xBreakpoint)) { return; } @@ -1038,8 +1029,7 @@ public class BreakpointManager { @Nullable public Breakpoint findMasterBreakpoint(@NotNull Breakpoint dependentBreakpoint) { XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl)getXBreakpointManager()).getDependentBreakpointManager(); - XBreakpoint xBreakpoint = findXBreakpoint(dependentBreakpoint); - return myBreakpoints.get(dependentBreakpointManager.getMasterBreakpoint(xBreakpoint)); + return myBreakpoints.get(dependentBreakpointManager.getMasterBreakpoint(dependentBreakpoint.myXBreakpoint)); } @Nullable From 94f163861bc72a3c3dff011adb88ae3776b23299 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 27 Feb 2014 18:52:54 +0400 Subject: [PATCH 76/95] javadoc --- platform/util/src/com/intellij/openapi/util/Key.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/util/src/com/intellij/openapi/util/Key.java b/platform/util/src/com/intellij/openapi/util/Key.java index 949cb3e1ba46..09ef12949ccf 100644 --- a/platform/util/src/com/intellij/openapi/util/Key.java +++ b/platform/util/src/com/intellij/openapi/util/Key.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. @@ -42,6 +42,7 @@ public class Key { allKeys.put(myIndex, this); } + // made final because many classes depend on one-to-one key index <-> key instance relationship. See e.g. UserDataHolderBase public final int hashCode() { return myIndex; } From ed02fc99d8676bec6ed514d1e10c12157f22a744 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 27 Feb 2014 18:54:10 +0400 Subject: [PATCH 77/95] optimisation --- .../intellij/openapi/vfs/newvfs/impl/FileNameCache.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java index ab9655a75c03..3f2c4abebf7f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.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. @@ -42,12 +42,12 @@ public class FileNameCache { public static int storeName(@NotNull String name) { final int idx = FSRecords.getNameId(name); - cacheData(name, idx); + cacheData(name, idx, calcStripeIdFromNameId(idx)); return idx; } @NotNull - private static IntObjectLinkedMap.MapEntry cacheData(String name, int id) { + private static IntObjectLinkedMap.MapEntry cacheData(String name, int id, int stripe) { if (name == null) { ourNames.markCorrupted(); throw new RuntimeException("VFS name enumerator corrupted"); @@ -55,7 +55,6 @@ public class FileNameCache { Object rawName = convertToBytesIfAsciiString(name); IntObjectLinkedMap.MapEntry entry = new IntObjectLinkedMap.MapEntry(id, rawName); - final int stripe = calcStripeIdFromNameId(id); synchronized (ourNameCache[stripe]) { return ourNameCache[stripe].cacheEntry(entry); } @@ -99,7 +98,7 @@ public class FileNameCache { } } - return cacheData(FSRecords.getNameByNameId(id), id); + return cacheData(FSRecords.getNameByNameId(id), id, stripe); } @NotNull From 0b40c676a573b8e1cea1fce2d49d0c93ff79bc48 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 28 Feb 2014 13:28:33 +0400 Subject: [PATCH 78/95] notnull --- .../testFramework/LightVirtualFile.java | 3 ++- .../vfs/impl/jar/CoreJarVirtualFile.java | 9 +++++--- .../openapi/vfs/impl/jar/JarHandlerBase.java | 3 ++- .../vfs/local/CoreLocalVirtualFile.java | 3 ++- .../intellij/dvcs/test/MockVirtualFile.java | 13 +++++------ .../vfs/newvfs/impl/StubVirtualFile.java | 18 ++++++++++++++- .../openapi/vfs/ex/dummy/VirtualFileImpl.java | 4 ++-- .../vfs/impl/http/VirtualFileImpl.java | 1 + .../vfs/newvfs/impl/FakeVirtualFile.java | 3 ++- .../history/integration/TestVirtualFile.java | 7 +++--- .../src/com/intellij/mock/Mock.java | 3 ++- .../com/intellij/mock/MockVirtualFile.java | 4 +++- .../intellij/mock/MockVirtualFileSystem.java | 5 ++-- .../vcs/vfs/AbstractVcsVirtualFile.java | 19 ++++++++++++++- .../TestDataGroupVirtualFile.java | 5 ++-- .../git4idea/tests/SkeletonBuilderTest.java | 3 ++- .../maven/vfs/MavenPropertiesVirtualFile.java | 17 +++++++++++++- .../editor/ResourceBundleAsVirtualFile.java | 23 ++++++++++++++++++- 18 files changed, 113 insertions(+), 30 deletions(-) diff --git a/platform/core-api/src/com/intellij/testFramework/LightVirtualFile.java b/platform/core-api/src/com/intellij/testFramework/LightVirtualFile.java index 158144a369b1..55222cff9448 100644 --- a/platform/core-api/src/com/intellij/testFramework/LightVirtualFile.java +++ b/platform/core-api/src/com/intellij/testFramework/LightVirtualFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 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. @@ -184,6 +184,7 @@ public class LightVirtualFile extends VirtualFile { return myFileType; } + @NotNull @Override public String getPath() { return "/" + getName(); diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java index 3827ecc2da66..1256c54f3f5d 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarVirtualFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -18,11 +18,13 @@ package com.intellij.openapi.vfs.impl.jar; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileSystem; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; +import java.util.List; /** * @author yole @@ -30,10 +32,10 @@ import java.util.ArrayList; public class CoreJarVirtualFile extends VirtualFile { private final CoreJarHandler myHandler; private final VirtualFile myParent; - private final ArrayList myChildren = new ArrayList(); + private final List myChildren = new ArrayList(); private final JarHandlerBase.EntryInfo myEntry; - public CoreJarVirtualFile(CoreJarHandler handler, JarHandlerBase.EntryInfo entry, CoreJarVirtualFile parent) { + public CoreJarVirtualFile(@NotNull CoreJarHandler handler, @NotNull JarHandlerBase.EntryInfo entry, @Nullable CoreJarVirtualFile parent) { myHandler = handler; myParent = parent; myEntry = entry; @@ -56,6 +58,7 @@ public class CoreJarVirtualFile extends VirtualFile { } @Override + @NotNull public String getPath() { if (myParent == null) return myHandler.myBasePath + "!/"; diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandlerBase.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandlerBase.java index 4dba701485a1..0648e3d319e1 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandlerBase.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandlerBase.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,6 +52,7 @@ public class JarHandlerBase { protected static class EntryInfo { protected final boolean isDirectory; + @NotNull protected final String shortName; protected final EntryInfo parent; diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java b/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java index c3b770af072b..016cab9a818b 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -56,6 +56,7 @@ public class CoreLocalVirtualFile extends VirtualFile { return myFileSystem; } + @NotNull @Override public String getPath() { return FileUtil.toSystemIndependentName(myIoFile.getAbsolutePath()); diff --git a/platform/dvcs/testFramework/com/intellij/dvcs/test/MockVirtualFile.java b/platform/dvcs/testFramework/com/intellij/dvcs/test/MockVirtualFile.java index 2b6743c09523..3b36381dcf85 100644 --- a/platform/dvcs/testFramework/com/intellij/dvcs/test/MockVirtualFile.java +++ b/platform/dvcs/testFramework/com/intellij/dvcs/test/MockVirtualFile.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. @@ -39,9 +39,9 @@ import java.io.OutputStream; */ public class MockVirtualFile extends VirtualFile { - private static VirtualFileSystem ourFileSystem = new MockVirtualFileSystem(); + private static final VirtualFileSystem ourFileSystem = new MockVirtualFileSystem(); - private String myPath; + private final String myPath; @NotNull static VirtualFile fromPath(@NotNull String absolutePath) { @@ -84,6 +84,7 @@ public class MockVirtualFile extends VirtualFile { return ourFileSystem; } + @NotNull @Override public String getPath() { return myPath; @@ -179,14 +180,12 @@ public class MockVirtualFile extends VirtualFile { MockVirtualFile file = (MockVirtualFile)o; - if (myPath != null ? !myPath.equals(file.myPath) : file.myPath != null) return false; - - return true; + return myPath.equals(file.myPath); } @Override public int hashCode() { - return myPath != null ? myPath.hashCode() : 0; + return myPath.hashCode(); } } diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/impl/StubVirtualFile.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/impl/StubVirtualFile.java index 48765456e681..7d391758cfdb 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/impl/StubVirtualFile.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/impl/StubVirtualFile.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. @@ -30,69 +30,85 @@ import java.io.InputStream; import java.io.OutputStream; public class StubVirtualFile extends VirtualFile { + @Override @NotNull public byte[] contentsToByteArray() throws IOException { throw new UnsupportedOperationException("contentsToByteArray is not implemented"); } + @Override public VirtualFile[] getChildren() { throw new UnsupportedOperationException("getChildren is not implemented"); } + @Override @NotNull public VirtualFileSystem getFileSystem() { throw new UnsupportedOperationException("getFileSystem is not implemented"); } + @Override public InputStream getInputStream() throws IOException { throw new UnsupportedOperationException("getInputStream is not implemented"); } + @Override public long getLength() { throw new UnsupportedOperationException("getLength is not implemented"); } + @Override @NotNull @NonNls public String getName() { throw new UnsupportedOperationException("getName is not implemented"); } + @Override @NotNull public OutputStream getOutputStream(final Object requestor, final long newModificationStamp, final long newTimeStamp) throws IOException { throw new UnsupportedOperationException("getOutputStream is not implemented"); } + @Override @Nullable public VirtualFile getParent() { throw new UnsupportedOperationException("getParent is not implemented"); } + @Override + @NotNull public String getPath() { throw new UnsupportedOperationException("getPath is not implemented"); } + @Override public long getTimeStamp() { throw new UnsupportedOperationException("getTimeStamp is not implemented"); } + @Override @NotNull public String getUrl() { throw new UnsupportedOperationException("getUrl is not implemented"); } + @Override public boolean isDirectory() { throw new UnsupportedOperationException("isDirectory is not implemented"); } + @Override public boolean isValid() { throw new UnsupportedOperationException("isValid is not implemented"); } + @Override public boolean isWritable() { throw new UnsupportedOperationException("isWritable is not implemented"); } + @Override public void refresh(final boolean asynchronous, final boolean recursive, final Runnable postRunnable) { throw new UnsupportedOperationException("refresh is not implemented"); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/dummy/VirtualFileImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/ex/dummy/VirtualFileImpl.java index 3c1922e29ec8..be96d70a9db3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/dummy/VirtualFileImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/ex/dummy/VirtualFileImpl.java @@ -1,6 +1,5 @@ - /* - * Copyright 2000-2011 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. @@ -45,6 +44,7 @@ abstract class VirtualFileImpl extends VirtualFile implements VirtualFileWithId return myFileSystem; } + @NotNull @Override public String getPath() { if (myParent == null) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/VirtualFileImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/VirtualFileImpl.java index 110d71003867..873ac0200b16 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/VirtualFileImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/VirtualFileImpl.java @@ -102,6 +102,7 @@ class VirtualFileImpl extends HttpVirtualFile { return myFileSystem; } + @NotNull @Override public String getPath() { return myPath; diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FakeVirtualFile.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FakeVirtualFile.java index 24861243f093..5dc589fa7b66 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FakeVirtualFile.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FakeVirtualFile.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. @@ -38,6 +38,7 @@ public class FakeVirtualFile extends StubVirtualFile { return myParent; } + @NotNull @Override public String getPath() { final String basePath = myParent.getPath(); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/TestVirtualFile.java b/platform/platform-tests/testSrc/com/intellij/history/integration/TestVirtualFile.java index 990291816e30..44473dfdfe64 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/TestVirtualFile.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/TestVirtualFile.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. @@ -33,12 +33,12 @@ import java.util.List; // todo get rid of!!!!!!!!!!!!! public class TestVirtualFile extends VirtualFile { - private String myName; + private final String myName; private String myContent; private boolean isReadOnly; private long myTimestamp; - private boolean IsDirectory; + private final boolean IsDirectory; private VirtualFile myParent; private final List myChildren = new ArrayList(); @@ -76,6 +76,7 @@ public class TestVirtualFile extends VirtualFile { return IsDirectory; } + @NotNull @Override public String getPath() { if (myParent == null) return myName; diff --git a/platform/testFramework/src/com/intellij/mock/Mock.java b/platform/testFramework/src/com/intellij/mock/Mock.java index d511f2fd2d35..f0ca6a19e745 100644 --- a/platform/testFramework/src/com/intellij/mock/Mock.java +++ b/platform/testFramework/src/com/intellij/mock/Mock.java @@ -453,9 +453,10 @@ public class Mock { throw new UnsupportedOperationException(); } + @NotNull @Override public String getPath() { - return null; + throw new UnsupportedOperationException(); } @Override diff --git a/platform/testFramework/src/com/intellij/mock/MockVirtualFile.java b/platform/testFramework/src/com/intellij/mock/MockVirtualFile.java index f6c02f5930ee..9f31bbb9b10f 100644 --- a/platform/testFramework/src/com/intellij/mock/MockVirtualFile.java +++ b/platform/testFramework/src/com/intellij/mock/MockVirtualFile.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. @@ -90,6 +90,7 @@ public class MockVirtualFile extends VirtualFile { return ourFileSystem; } + @NotNull @Override public String getPath() { String prefix = myParent == null ? "MOCK_ROOT:" : myParent.getPath(); @@ -101,6 +102,7 @@ public class MockVirtualFile extends VirtualFile { return myIsWritable; } + @Override public void setWritable(boolean b) { myIsWritable = b; } diff --git a/platform/testFramework/src/com/intellij/mock/MockVirtualFileSystem.java b/platform/testFramework/src/com/intellij/mock/MockVirtualFileSystem.java index 2eeee2eb0ac7..19870bfe9b33 100644 --- a/platform/testFramework/src/com/intellij/mock/MockVirtualFileSystem.java +++ b/platform/testFramework/src/com/intellij/mock/MockVirtualFileSystem.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. @@ -113,9 +113,10 @@ public class MockVirtualFileSystem extends DeprecatedVirtualFileSystem { @Override public boolean isDirectory() { - return myChildren.size() != 0; + return !myChildren.isEmpty(); } + @NotNull @Override public String getPath() { final MockVirtualFileSystem.MyVirtualFile parent = getParent(); diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/vfs/AbstractVcsVirtualFile.java b/platform/vcs-api/src/com/intellij/openapi/vcs/vfs/AbstractVcsVirtualFile.java index 94b7e923fa79..a28564df1722 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/vfs/AbstractVcsVirtualFile.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/vfs/AbstractVcsVirtualFile.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. @@ -44,20 +44,25 @@ public abstract class AbstractVcsVirtualFile extends VirtualFile { myParent = null; } + @Override @NotNull public VirtualFileSystem getFileSystem() { return myFileSystem; } + @Override + @NotNull public String getPath() { return myPath; } + @Override @NotNull public String getName() { return myName; } + @Override public String getPresentableName() { if (myRevision == null) return myName; @@ -65,43 +70,53 @@ public abstract class AbstractVcsVirtualFile extends VirtualFile { return myName + " (" + myRevision + ")"; } + @Override public boolean isWritable() { return false; } + @Override public boolean isValid() { return true; } + @Override public VirtualFile getParent() { return myParent; } + @Override public VirtualFile[] getChildren() { return null; } + @Override public InputStream getInputStream() throws IOException { return VfsUtilCore.byteStreamSkippingBOM(contentsToByteArray(), this); } + @Override @NotNull public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { throw new RuntimeException(VcsFileSystem.COULD_NOT_IMPLEMENT_MESSAGE); } + @Override @NotNull public abstract byte[] contentsToByteArray() throws IOException; + @Override public long getModificationStamp() { return myModificationStamp; } + @Override public long getTimeStamp() { return myModificationStamp; } + @Override public long getLength() { try { return contentsToByteArray().length; @@ -110,6 +125,7 @@ public abstract class AbstractVcsVirtualFile extends VirtualFile { } } + @Override public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) { if (postRunnable != null) postRunnable.run(); @@ -123,6 +139,7 @@ public abstract class AbstractVcsVirtualFile extends VirtualFile { myProcessingBeforeContentsChange = true; try { ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override public void run() { ((VcsFileSystem)getFileSystem()).fireBeforeContentsChange(this, AbstractVcsVirtualFile.this); } diff --git a/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataGroupVirtualFile.java b/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataGroupVirtualFile.java index c44b49cd71b9..069ef03c8277 100644 --- a/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataGroupVirtualFile.java +++ b/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataGroupVirtualFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 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. @@ -43,7 +43,7 @@ public class TestDataGroupVirtualFile extends VirtualFile { @Override public String getName() { final String prefix = StringUtil.commonPrefix(myBeforeFile.getName(), myAfterFile.getName()); - if (prefix.length() == 0) { + if (prefix.isEmpty()) { return StringUtil.commonSuffix(myBeforeFile.getName(), myAfterFile.getName()); } return prefix + "." + myBeforeFile.getExtension(); @@ -63,6 +63,7 @@ public class TestDataGroupVirtualFile extends VirtualFile { return LocalFileSystem.getInstance(); } + @NotNull @Override public String getPath() { return myBeforeFile.getPath(); diff --git a/plugins/git4idea/tests/git4idea/tests/SkeletonBuilderTest.java b/plugins/git4idea/tests/git4idea/tests/SkeletonBuilderTest.java index aabf48c54fad..1417a118eacc 100644 --- a/plugins/git4idea/tests/git4idea/tests/SkeletonBuilderTest.java +++ b/plugins/git4idea/tests/git4idea/tests/SkeletonBuilderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 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. @@ -789,6 +789,7 @@ public class SkeletonBuilderTest extends TestCase { return new MockVirtualFileSystem(); } + @NotNull @Override public String getPath() { return "mock"; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/vfs/MavenPropertiesVirtualFile.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/vfs/MavenPropertiesVirtualFile.java index 7a8ccb550b00..000b855c5ac4 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/vfs/MavenPropertiesVirtualFile.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/vfs/MavenPropertiesVirtualFile.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. @@ -52,46 +52,57 @@ public class MavenPropertiesVirtualFile extends VirtualFile { return builder.toString().getBytes(); } + @Override @NotNull public String getName() { return myPath; } + @Override @NotNull public VirtualFileSystem getFileSystem() { return myFS; } + @Override + @NotNull public String getPath() { return myPath; } + @Override public boolean isWritable() { return false; } + @Override public boolean isDirectory() { return false; } + @Override public boolean isValid() { return true; } + @Override public VirtualFile getParent() { return null; } + @Override public VirtualFile[] getChildren() { return null; } + @Override @NotNull public byte[] contentsToByteArray() throws IOException { if (myContent == null) throw new IOException(); return myContent; } + @Override public long getTimeStamp() { return -1; } @@ -101,17 +112,21 @@ public class MavenPropertiesVirtualFile extends VirtualFile { return myContent.hashCode(); } + @Override public long getLength() { return myContent.length; } + @Override public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) { } + @Override public InputStream getInputStream() throws IOException { return VfsUtilCore.byteStreamSkippingBOM(myContent,this); } + @Override @NotNull public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { throw new UnsupportedOperationException(); diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleAsVirtualFile.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleAsVirtualFile.java index 7a48ff9000ba..f61c3b87e80b 100644 --- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleAsVirtualFile.java +++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleAsVirtualFile.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. @@ -42,15 +42,19 @@ public class ResourceBundleAsVirtualFile extends VirtualFile { return myResourceBundle; } + @Override @NotNull public VirtualFileSystem getFileSystem() { return LocalFileSystem.getInstance(); } + @Override + @NotNull public String getPath() { return getName(); } + @Override @NotNull public String getName() { return myResourceBundle.getBaseName(); @@ -71,71 +75,88 @@ public class ResourceBundleAsVirtualFile extends VirtualFile { return myResourceBundle.hashCode(); } + @Override public void rename(Object requestor, @NotNull String newName) throws IOException { } + @Override public boolean isWritable() { return true; } + @Override public boolean isDirectory() { return false; } + @Override public boolean isValid() { return true; } + @Override public VirtualFile getParent() { return myResourceBundle.getBaseDirectory(); } + @Override public VirtualFile[] getChildren() { return EMPTY_ARRAY; } + @Override public VirtualFile createChildDirectory(Object requestor, String name) throws IOException { throw new UnsupportedOperationException(); } + @Override public VirtualFile createChildData(Object requestor, @NotNull String name) throws IOException { throw new UnsupportedOperationException(); } + @Override public void delete(Object requestor) throws IOException { //todo } + @Override public void move(Object requestor, @NotNull VirtualFile newParent) throws IOException { //todo } + @Override public InputStream getInputStream() throws IOException { throw new UnsupportedOperationException(); } + @Override @NotNull public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { throw new UnsupportedOperationException(); } + @Override @NotNull public byte[] contentsToByteArray() throws IOException { throw new UnsupportedOperationException(); } + @Override public long getModificationStamp() { return 0; } + @Override public long getTimeStamp() { return 0; } + @Override public long getLength() { return 0; } + @Override public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) { } From 569077658c471d8b0061c2a5650c5bd805faac3f Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 28 Feb 2014 13:30:00 +0400 Subject: [PATCH 79/95] save memory on detected line separator --- .../com/intellij/openapi/vfs/VirtualFile.java | 11 ++++++++++- .../openapi/fileEditor/impl/LoadTextUtil.java | 9 ++++----- .../vfs/newvfs/impl/VirtualFileImpl.java | 18 +++++++++++++++++- .../newvfs/impl/VirtualFileSystemEntry.java | 11 ++++++----- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java index 8b67321dc6c8..747320136660 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.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. @@ -125,6 +125,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica * @return the path */ @SuppressWarnings("JavadocReference") + @NotNull public abstract String getPath(); /** @@ -727,4 +728,12 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica public static boolean isValidName(@NotNull String name) { return name.indexOf('\\') < 0 && name.indexOf('/') < 0; } + + private static final Key DETECTED_LINE_SEPARATOR_KEY = Key.create("DETECTED_LINE_SEPARATOR_KEY"); + public String getDetectedLineSeparator() { + return getUserData(DETECTED_LINE_SEPARATOR_KEY); + } + public void setDetectedLineSeparator(String separator) { + putUserData(DETECTED_LINE_SEPARATOR_KEY, separator); + } } diff --git a/platform/core-impl/src/com/intellij/openapi/fileEditor/impl/LoadTextUtil.java b/platform/core-impl/src/com/intellij/openapi/fileEditor/impl/LoadTextUtil.java index d621140f132b..4e4114d463ae 100644 --- a/platform/core-impl/src/com/intellij/openapi/fileEditor/impl/LoadTextUtil.java +++ b/platform/core-impl/src/com/intellij/openapi/fileEditor/impl/LoadTextUtil.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. @@ -40,7 +40,6 @@ import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; public final class LoadTextUtil { - private static final Key DETECTED_LINE_SEPARATOR_KEY = Key.create("DETECTED_LINE_SEPARATOR_KEY"); @Nls private static final String AUTO_DETECTED_FROM_BOM = "auto-detected from BOM"; private LoadTextUtil() { @@ -215,7 +214,7 @@ public final class LoadTextUtil { } String newText = StringUtil.convertLineSeparators(currentText.toString(), newSeparator); - file.putUserData(DETECTED_LINE_SEPARATOR_KEY, newSeparator); + file.setDetectedLineSeparator(newSeparator); write(project, file, requestor, newText, -1); } @@ -397,7 +396,7 @@ public final class LoadTextUtil { Pair result = convertBytes(bytes, charset, offset); if (saveDetectedSeparators) { - virtualFile.putUserData(DETECTED_LINE_SEPARATOR_KEY, result.getSecond()); + virtualFile.setDetectedLineSeparator(result.getSecond()); } return result.getFirst(); } @@ -425,7 +424,7 @@ public final class LoadTextUtil { } static String getDetectedLineSeparator(@NotNull VirtualFile file) { - return file.getUserData(DETECTED_LINE_SEPARATOR_KEY); + return file.getDetectedLineSeparator(); } @NotNull diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileImpl.java index 33c024fc5cfe..94f73699ef99 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileImpl.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. @@ -24,6 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; +import com.intellij.util.LineSeparator; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -124,4 +125,19 @@ public class VirtualFileImpl extends VirtualFileSystemEntry { public OutputStream getOutputStream(final Object requestor, final long modStamp, final long timeStamp) throws IOException { return VfsUtilCore.outputStreamAddingBOM(ourPersistence.getOutputStream(this, requestor, modStamp, timeStamp), this); } + + @Override + public String getDetectedLineSeparator() { + if (getFlagInt(SYSTEM_LINE_SEPARATOR_DETECTED)) { + return LineSeparator.getSystemLineSeparator().getSeparatorString(); + } + return super.getDetectedLineSeparator(); + } + + @Override + public void setDetectedLineSeparator(String separator) { + boolean hasSystemSeparator = LineSeparator.getSystemLineSeparator().getSeparatorString().equals(separator); + setFlagInt(SYSTEM_LINE_SEPARATOR_DETECTED, hasSystemSeparator); + super.setDetectedLineSeparator(hasSystemSeparator ? null : separator); + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java index 2d5b5195dad6..29844fb0e1c5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.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,14 +52,15 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { private static final Key SYMLINK_TARGET = Key.create("local.vfs.symlink.target"); + private static final int IS_WRITABLE_FLAG = 0x01000000; + private static final int IS_HIDDEN_FLAG = 0x02000000; + private static final int INDEXED_FLAG = 0x04000000; + static final int CHILDREN_CACHED = 0x08000000; // makes sense for directory only private static final int DIRTY_FLAG = 0x10000000; private static final int IS_SYMLINK_FLAG = 0x20000000; private static final int HAS_SYMLINK_FLAG = 0x40000000; private static final int IS_SPECIAL_FLAG = 0x80000000; - private static final int IS_WRITABLE_FLAG = 0x01000000; - private static final int IS_HIDDEN_FLAG = 0x02000000; - private static final int INDEXED_FLAG = 0x04000000; - static final int CHILDREN_CACHED = 0x08000000; + static final int SYSTEM_LINE_SEPARATOR_DETECTED = CHILDREN_CACHED; // makes sense only for non-directory file private static final int ALL_FLAGS_MASK = DIRTY_FLAG | IS_SYMLINK_FLAG | HAS_SYMLINK_FLAG | IS_SPECIAL_FLAG | IS_WRITABLE_FLAG | IS_HIDDEN_FLAG | INDEXED_FLAG | CHILDREN_CACHED; From 0a6c9ae60082feaafd993ef4535dec6f30f0d498 Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 28 Feb 2014 14:01:55 +0400 Subject: [PATCH 80/95] test fixed --- .../xdebugger/XBreakpointManagerTest.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java index 38e9154d936e..a4cd467e1627 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java @@ -32,23 +32,26 @@ import java.util.List; public class XBreakpointManagerTest extends XBreakpointsTestCase { public void testAddRemove() { + XBreakpoint defaultBreakpoint = myBreakpointManager.getDefaultBreakpoint(MY_SIMPLE_BREAKPOINT_TYPE); + assertSameElements(getAllBreakpoints(), defaultBreakpoint); + XLineBreakpoint lineBreakpoint = myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, "url", 239, new MyBreakpointProperties("123")); XBreakpoint breakpoint = myBreakpointManager.addBreakpoint(MY_SIMPLE_BREAKPOINT_TYPE, new MyBreakpointProperties("abc")); - assertSameElements(getAllBreakpoints(), breakpoint, lineBreakpoint); + assertSameElements(getAllBreakpoints(), breakpoint, lineBreakpoint, defaultBreakpoint); assertSame(lineBreakpoint, assertOneElement(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE))); - assertSame(breakpoint, getSingleBreakpoint()); + assertSameElements(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE), breakpoint, defaultBreakpoint); myBreakpointManager.removeBreakpoint(lineBreakpoint); - assertSame(breakpoint, assertOneElement(getAllBreakpoints())); + assertSameElements(getAllBreakpoints(), breakpoint, defaultBreakpoint); assertTrue(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE).isEmpty()); - assertSame(breakpoint, getSingleBreakpoint()); + assertSameElements(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE), breakpoint, defaultBreakpoint); myBreakpointManager.removeBreakpoint(breakpoint); - assertEmpty(getAllBreakpoints()); - assertTrue(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE).isEmpty()); + assertSameElements(getAllBreakpoints(), defaultBreakpoint); + assertSameElements(myBreakpointManager.getBreakpoints(MY_SIMPLE_BREAKPOINT_TYPE), defaultBreakpoint); } public void testSerialize() { From ba5925eb4095d1795f707732f9fa365e9aee30eb Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 28 Feb 2014 14:04:32 +0400 Subject: [PATCH 81/95] fixed ContextTest.testXDebugger test --- .../test/com/intellij/tasks/context/ContextTest.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/tasks/tasks-tests/test/com/intellij/tasks/context/ContextTest.java b/plugins/tasks/tasks-tests/test/com/intellij/tasks/context/ContextTest.java index 029b9a7d208e..db609abb2b85 100644 --- a/plugins/tasks/tasks-tests/test/com/intellij/tasks/context/ContextTest.java +++ b/plugins/tasks/tasks-tests/test/com/intellij/tasks/context/ContextTest.java @@ -21,13 +21,15 @@ import com.intellij.openapi.project.impl.ProjectImpl; import com.intellij.openapi.util.io.FileUtil; import com.intellij.tasks.TaskManagerTestCase; import com.intellij.xdebugger.XDebuggerManager; -import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.XBreakpointManager; import com.intellij.xdebugger.breakpoints.XBreakpointProperties; +import com.intellij.xdebugger.breakpoints.XBreakpointType; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl; import org.intellij.plugins.xsltDebugger.XsltBreakpointType; import java.io.File; +import java.util.Collection; import java.util.List; /** @@ -78,10 +80,12 @@ public class ContextTest extends TaskManagerTestCase { final WorkingContextManager manager = getContextManager(); final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(getProject()).getBreakpointManager(); + final XsltBreakpointType type = XBreakpointType.EXTENSION_POINT_NAME.findExtension(XsltBreakpointType.class); + ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { XLineBreakpointImpl breakpoint = - (XLineBreakpointImpl)breakpointManager.addLineBreakpoint(new XsltBreakpointType(), "foo", 0, null); + (XLineBreakpointImpl)breakpointManager.addLineBreakpoint(type, "foo", 0, null); final String name = "foo"; manager.saveContext(name, null); @@ -89,8 +93,8 @@ public class ContextTest extends TaskManagerTestCase { } }); manager.loadContext("foo"); - XBreakpoint[] breakpoints = breakpointManager.getAllBreakpoints(); - assertEquals(1, breakpoints.length); + Collection> breakpoints = breakpointManager.getBreakpoints(type); + assertEquals(1, breakpoints.size()); manager.clearContext(); } From a8412d20b455da6cb2a847b27de87ee34860be07 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 28 Feb 2014 11:38:20 +0100 Subject: [PATCH 82/95] plugin advertiser disabled for broken plugins (IDEA-121374) --- .../impl/pluginsAdvertisement/PluginsAdvertiser.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java index aa7b6b3874e7..4a3c268d25e2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiser.java @@ -280,7 +280,9 @@ public class PluginsAdvertiser implements StartupActivity { for (IdeaPluginDescriptor loadedPlugin : myAllPlugins) { final PluginId pluginId = loadedPlugin.getPluginId(); - if (ids.containsKey(pluginId.getIdString()) && !disabledPlugins.contains(pluginId.getIdString())) { + if (ids.containsKey(pluginId.getIdString()) && + !disabledPlugins.contains(pluginId.getIdString()) && + !PluginManagerCore.isBrokenPlugin(loadedPlugin)) { myPlugins.add(PluginDownloader.createDownloader(loadedPlugin)); } } From bcf9217a541cdc7a075259c130832cb4beb8d356 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 28 Feb 2014 11:09:10 +0100 Subject: [PATCH 83/95] remove VariableAccessUtils duplication --- .../ig/psiutils/VariableAccessUtils.java | 44 +++- .../ig/psiutils/VariableAssignedVisitor.java | 36 +++- .../ReverseForLoopDirectionIntention.java | 2 +- .../ReverseForLoopDirectionPredicate.java | 112 +++++++++- ...ignmentWithPostfixExpressionPredicate.java | 4 +- .../ipp/psiutils/VariableAccessUtils.java | 195 ----------------- .../ipp/psiutils/VariableAssignedVisitor.java | 199 ------------------ .../trivialif/MergeParallelIfsPredicate.java | 6 +- 8 files changed, 183 insertions(+), 415 deletions(-) delete mode 100644 plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java delete mode 100644 plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAssignedVisitor.java diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariableAccessUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariableAccessUtils.java index e097d58f8301..b8e7b7c183d8 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariableAccessUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariableAccessUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,9 @@ import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; import java.util.Set; public class VariableAccessUtils { @@ -446,4 +449,43 @@ public class VariableAccessUtils { } return child; } + + public static Set collectUsedVariables(PsiElement context) { + if (context == null) { + return Collections.emptySet(); + } + final VariableCollectingVisitor visitor = new VariableCollectingVisitor(); + context.accept(visitor); + return visitor.getUsedVariables(); + } + + public static boolean isAnyVariableAssigned(@NotNull Collection variables, @Nullable PsiElement context) { + if (context == null) { + return false; + } + final VariableAssignedVisitor visitor = new VariableAssignedVisitor(variables, true); + context.accept(visitor); + return visitor.isAssigned(); + } + + private static class VariableCollectingVisitor extends JavaRecursiveElementVisitor { + + private final Set usedVariables = new HashSet(); + + @Override + public void visitReferenceExpression( + PsiReferenceExpression expression) { + super.visitReferenceExpression(expression); + final PsiElement target = expression.resolve(); + if (!(target instanceof PsiVariable)) { + return; + } + final PsiVariable variable = (PsiVariable)target; + usedVariables.add(variable); + } + + public Set getUsedVariables() { + return usedVariables; + } + } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariableAssignedVisitor.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariableAssignedVisitor.java index 0a22ef3fde97..279400f3a653 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariableAssignedVisitor.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariableAssignedVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,16 +20,25 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.TypeConversionUtil; import org.jetbrains.annotations.NotNull; +import java.util.Collection; +import java.util.Collections; + public class VariableAssignedVisitor extends JavaRecursiveElementWalkingVisitor { - @NotNull private final PsiVariable variable; + @NotNull private final Collection variables; private final boolean recurseIntoClasses; private final boolean checkUnaryExpressions; private boolean assigned = false; private PsiElement excludedElement = null; + public VariableAssignedVisitor(@NotNull Collection variables, boolean recurseIntoClasses) { + this.variables = variables; + checkUnaryExpressions = true; + this.recurseIntoClasses = recurseIntoClasses; + } + public VariableAssignedVisitor(@NotNull PsiVariable variable, boolean recurseIntoClasses) { - this.variable = variable; + variables = Collections.singleton(variable); final PsiType type = variable.getType(); checkUnaryExpressions = TypeConversionUtil.isNumericType(type); this.recurseIntoClasses = recurseIntoClasses; @@ -58,8 +67,11 @@ public class VariableAssignedVisitor extends JavaRecursiveElementWalkingVisitor } super.visitAssignmentExpression(assignment); final PsiExpression lhs = assignment.getLExpression(); - if (VariableAccessUtils.evaluatesToVariable(lhs, variable)) { - assigned = true; + for (PsiVariable variable : variables) { + if (VariableAccessUtils.evaluatesToVariable(lhs, variable)) { + assigned = true; + break; + } } } @@ -85,8 +97,11 @@ public class VariableAssignedVisitor extends JavaRecursiveElementWalkingVisitor return; } final PsiExpression operand = prefixExpression.getOperand(); - if (VariableAccessUtils.evaluatesToVariable(operand, variable)) { - assigned = true; + for (PsiVariable variable : variables) { + if (VariableAccessUtils.evaluatesToVariable(operand, variable)) { + assigned = true; + break; + } } } @@ -104,8 +119,11 @@ public class VariableAssignedVisitor extends JavaRecursiveElementWalkingVisitor return; } final PsiExpression operand = postfixExpression.getOperand(); - if (VariableAccessUtils.evaluatesToVariable(operand, variable)) { - assigned = true; + for (PsiVariable variable : variables) { + if (VariableAccessUtils.evaluatesToVariable(operand, variable)) { + assigned = true; + break; + } } } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionIntention.java index 35404ae2f77d..d76eaaffc86c 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionIntention.java @@ -22,9 +22,9 @@ import com.intellij.util.IncorrectOperationException; import com.siyeh.ig.psiutils.ComparisonUtils; import com.siyeh.ig.psiutils.ExpressionUtils; import com.siyeh.ig.psiutils.ParenthesesUtils; +import com.siyeh.ig.psiutils.VariableAccessUtils; import com.siyeh.ipp.base.Intention; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.VariableAccessUtils; import org.jetbrains.annotations.NotNull; public class ReverseForLoopDirectionIntention extends Intention { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionPredicate.java index f37d90013490..ef8b6d73093c 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2013 Bas Leijdekkers + * Copyright 2009-2014 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,14 @@ */ package com.siyeh.ipp.forloop; +import com.siyeh.ig.psiutils.ComparisonUtils; +import com.siyeh.ig.psiutils.ParenthesesUtils; +import com.siyeh.ig.psiutils.VariableAccessUtils; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.VariableAccessUtils; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; class ReverseForLoopDirectionPredicate implements PsiElementPredicate { @@ -57,11 +61,109 @@ class ReverseForLoopDirectionPredicate implements PsiElementPredicate { return false; } final PsiExpression condition = forStatement.getCondition(); - if (!VariableAccessUtils.isVariableCompared(variable, condition)) { + if (!isVariableCompared(variable, condition)) { return false; } final PsiStatement update = forStatement.getUpdate(); - return VariableAccessUtils.isVariableIncrementOrDecremented(variable, - update); + return isVariableIncrementOrDecremented(variable, update); + } + + public static boolean isVariableCompared( + @NotNull PsiVariable variable, @Nullable PsiExpression expression) { + if (!(expression instanceof PsiBinaryExpression)) { + return false; + } + final PsiBinaryExpression binaryExpression = + (PsiBinaryExpression)expression; + final IElementType tokenType = binaryExpression.getOperationTokenType(); + if (!ComparisonUtils.isComparisonOperation(tokenType)) { + return false; + } + final PsiExpression lhs = binaryExpression.getLOperand(); + final PsiExpression rhs = binaryExpression.getROperand(); + if (rhs == null) { + return false; + } + if (VariableAccessUtils.evaluatesToVariable(lhs, variable)) { + return true; + } + else if (VariableAccessUtils.evaluatesToVariable(rhs, variable)) { + return true; + } + return false; + } + + public static boolean isVariableIncrementOrDecremented( + @NotNull PsiVariable variable, @Nullable PsiStatement statement) { + if (!(statement instanceof PsiExpressionStatement)) { + return false; + } + final PsiExpressionStatement expressionStatement = + (PsiExpressionStatement)statement; + PsiExpression expression = expressionStatement.getExpression(); + expression = ParenthesesUtils.stripParentheses(expression); + if (expression instanceof PsiPrefixExpression) { + final PsiPrefixExpression prefixExpression = + (PsiPrefixExpression)expression; + final IElementType tokenType = prefixExpression.getOperationTokenType(); + if (!tokenType.equals(JavaTokenType.PLUSPLUS) && + !tokenType.equals(JavaTokenType.MINUSMINUS)) { + return false; + } + final PsiExpression operand = prefixExpression.getOperand(); + return VariableAccessUtils.evaluatesToVariable(operand, variable); + } + else if (expression instanceof PsiPostfixExpression) { + final PsiPostfixExpression postfixExpression = + (PsiPostfixExpression)expression; + final IElementType tokenType = postfixExpression.getOperationTokenType(); + if (!tokenType.equals(JavaTokenType.PLUSPLUS) && + !tokenType.equals(JavaTokenType.MINUSMINUS)) { + return false; + } + final PsiExpression operand = postfixExpression.getOperand(); + return VariableAccessUtils.evaluatesToVariable(operand, variable); + } + else if (expression instanceof PsiAssignmentExpression) { + final PsiAssignmentExpression assignmentExpression = + (PsiAssignmentExpression)expression; + final IElementType tokenType = + assignmentExpression.getOperationTokenType(); + PsiExpression lhs = assignmentExpression.getLExpression(); + lhs = ParenthesesUtils.stripParentheses(lhs); + if (!VariableAccessUtils.evaluatesToVariable(lhs, variable)) { + return false; + } + PsiExpression rhs = assignmentExpression.getRExpression(); + rhs = ParenthesesUtils.stripParentheses(rhs); + if (tokenType == JavaTokenType.EQ) { + if (!(rhs instanceof PsiBinaryExpression)) { + return false; + } + final PsiBinaryExpression binaryExpression = + (PsiBinaryExpression)rhs; + final IElementType token = + binaryExpression.getOperationTokenType(); + if (!token.equals(JavaTokenType.PLUS) && + !token.equals(JavaTokenType.MINUS)) { + return false; + } + PsiExpression lOperand = binaryExpression.getLOperand(); + lOperand = ParenthesesUtils.stripParentheses(lOperand); + PsiExpression rOperand = binaryExpression.getROperand(); + rOperand = ParenthesesUtils.stripParentheses(rOperand); + if (VariableAccessUtils.evaluatesToVariable(rOperand, variable)) { + return true; + } + else if (VariableAccessUtils.evaluatesToVariable(lOperand, variable)) { + return true; + } + } + else if (tokenType == JavaTokenType.PLUSEQ || + tokenType == JavaTokenType.MINUSEQ) { + return true; + } + } + return false; } } \ No newline at end of file diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceAssignmentWithPostfixExpressionPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceAssignmentWithPostfixExpressionPredicate.java index e239e85893af..89cd997e6822 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceAssignmentWithPostfixExpressionPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceAssignmentWithPostfixExpressionPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2013 Bas Leijdekkers + * Copyright 2009-2014 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ package com.siyeh.ipp.opassign; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; import com.siyeh.ig.psiutils.ParenthesesUtils; +import com.siyeh.ig.psiutils.VariableAccessUtils; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.VariableAccessUtils; class ReplaceAssignmentWithPostfixExpressionPredicate implements PsiElementPredicate { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java deleted file mode 100644 index 2ac8500bad4a..000000000000 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright 2009-2014 Bas Leijdekkers - * - * 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.siyeh.ipp.psiutils; - -import com.intellij.psi.*; -import com.intellij.psi.tree.IElementType; -import com.siyeh.ig.psiutils.ComparisonUtils; -import com.siyeh.ig.psiutils.ParenthesesUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -public class VariableAccessUtils { - - private VariableAccessUtils() { - } - - public static boolean isVariableCompared( - @NotNull PsiVariable variable, @Nullable PsiExpression expression) { - if (!(expression instanceof PsiBinaryExpression)) { - return false; - } - final PsiBinaryExpression binaryExpression = - (PsiBinaryExpression)expression; - final IElementType tokenType = binaryExpression.getOperationTokenType(); - if (!ComparisonUtils.isComparisonOperation(tokenType)) { - return false; - } - final PsiExpression lhs = binaryExpression.getLOperand(); - final PsiExpression rhs = binaryExpression.getROperand(); - if (rhs == null) { - return false; - } - if (evaluatesToVariable(lhs, variable)) { - return true; - } - else if (evaluatesToVariable(rhs, variable)) { - return true; - } - return false; - } - - public static boolean isVariableIncrementOrDecremented( - @NotNull PsiVariable variable, @Nullable PsiStatement statement) { - if (!(statement instanceof PsiExpressionStatement)) { - return false; - } - final PsiExpressionStatement expressionStatement = - (PsiExpressionStatement)statement; - PsiExpression expression = expressionStatement.getExpression(); - expression = ParenthesesUtils.stripParentheses(expression); - if (expression instanceof PsiPrefixExpression) { - final PsiPrefixExpression prefixExpression = - (PsiPrefixExpression)expression; - final IElementType tokenType = prefixExpression.getOperationTokenType(); - if (!tokenType.equals(JavaTokenType.PLUSPLUS) && - !tokenType.equals(JavaTokenType.MINUSMINUS)) { - return false; - } - final PsiExpression operand = prefixExpression.getOperand(); - return evaluatesToVariable(operand, variable); - } - else if (expression instanceof PsiPostfixExpression) { - final PsiPostfixExpression postfixExpression = - (PsiPostfixExpression)expression; - final IElementType tokenType = postfixExpression.getOperationTokenType(); - if (!tokenType.equals(JavaTokenType.PLUSPLUS) && - !tokenType.equals(JavaTokenType.MINUSMINUS)) { - return false; - } - final PsiExpression operand = postfixExpression.getOperand(); - return evaluatesToVariable(operand, variable); - } - else if (expression instanceof PsiAssignmentExpression) { - final PsiAssignmentExpression assignmentExpression = - (PsiAssignmentExpression)expression; - final IElementType tokenType = - assignmentExpression.getOperationTokenType(); - PsiExpression lhs = assignmentExpression.getLExpression(); - lhs = ParenthesesUtils.stripParentheses(lhs); - if (!evaluatesToVariable(lhs, variable)) { - return false; - } - PsiExpression rhs = assignmentExpression.getRExpression(); - rhs = ParenthesesUtils.stripParentheses(rhs); - if (tokenType == JavaTokenType.EQ) { - if (!(rhs instanceof PsiBinaryExpression)) { - return false; - } - final PsiBinaryExpression binaryExpression = - (PsiBinaryExpression)rhs; - final IElementType token = - binaryExpression.getOperationTokenType(); - if (!token.equals(JavaTokenType.PLUS) && - !token.equals(JavaTokenType.MINUS)) { - return false; - } - PsiExpression lOperand = binaryExpression.getLOperand(); - lOperand = ParenthesesUtils.stripParentheses(lOperand); - PsiExpression rOperand = binaryExpression.getROperand(); - rOperand = ParenthesesUtils.stripParentheses(rOperand); - if (evaluatesToVariable(rOperand, variable)) { - return true; - } - else if (evaluatesToVariable(lOperand, variable)) { - return true; - } - } - else if (tokenType == JavaTokenType.PLUSEQ || - tokenType == JavaTokenType.MINUSEQ) { - return true; - } - } - return false; - } - - public static boolean evaluatesToVariable( - @Nullable PsiExpression expression, - @NotNull PsiVariable variable) { - final PsiExpression strippedExpression = - ParenthesesUtils.stripParentheses(expression); - if (strippedExpression == null) { - return false; - } - if (!(expression instanceof PsiReferenceExpression)) { - return false; - } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)expression; - final PsiElement referent = referenceExpression.resolve(); - return variable.equals(referent); - } - - public static boolean isAnyVariableAssigned( - @NotNull Collection variables, - @Nullable PsiElement context) { - if (context == null) { - return false; - } - final VariableAssignedVisitor visitor = - new VariableAssignedVisitor(variables, true); - context.accept(visitor); - return visitor.isAssigned(); - } - - public static Set collectUsedVariables( - PsiElement context) { - if (context == null) { - return Collections.emptySet(); - } - final VariableCollectingVisitor visitor = - new VariableCollectingVisitor(); - context.accept(visitor); - return visitor.getUsedVariables(); - } - - private static class VariableCollectingVisitor - extends JavaRecursiveElementVisitor { - - private final Set usedVariables = new HashSet(); - - @Override - public void visitReferenceExpression( - PsiReferenceExpression expression) { - super.visitReferenceExpression(expression); - final PsiElement target = expression.resolve(); - if (!(target instanceof PsiVariable)) { - return; - } - final PsiVariable variable = (PsiVariable)target; - usedVariables.add(variable); - } - - public Set getUsedVariables() { - return usedVariables; - } - } -} diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAssignedVisitor.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAssignedVisitor.java deleted file mode 100644 index 8352febe9861..000000000000 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAssignedVisitor.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers - * - * 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.siyeh.ipp.psiutils; - -import com.intellij.psi.*; -import com.intellij.psi.tree.IElementType; -import com.siyeh.ig.psiutils.ParenthesesUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; - -class VariableAssignedVisitor extends JavaRecursiveElementVisitor { - - @NotNull private final Collection variables; - private final boolean recurseIntoClasses; - private boolean assigned = false; - - public VariableAssignedVisitor(@NotNull Collection variables, - boolean recurseIntoClasses) { - this.variables = variables; - this.recurseIntoClasses = recurseIntoClasses; - } - - @Override - public void visitElement(@NotNull PsiElement element) { - if (assigned) { - return; - } - super.visitElement(element); - } - - @Override - public void visitAssignmentExpression( - @NotNull PsiAssignmentExpression assignment) { - if (assigned) { - return; - } - super.visitAssignmentExpression(assignment); - final PsiExpression lhs = assignment.getLExpression(); - for (PsiVariable variable : variables) { - if (mayEvaluateToVariable(lhs, variable)) { - assigned = true; - } - } - } - - @Override - public void visitClass(PsiClass aClass) { - if (!recurseIntoClasses) { - return; - } - if (assigned) { - return; - } - super.visitClass(aClass); - } - - @Override - public void visitPrefixExpression( - @NotNull PsiPrefixExpression prefixExpression) { - if (assigned) { - return; - } - super.visitPrefixExpression(prefixExpression); - final IElementType tokenType = prefixExpression.getOperationTokenType(); - if (!tokenType.equals(JavaTokenType.PLUSPLUS) && - !tokenType.equals(JavaTokenType.MINUSMINUS)) { - return; - } - final PsiExpression operand = prefixExpression.getOperand(); - for (PsiVariable variable : variables) { - if (mayEvaluateToVariable(operand, variable)) { - assigned = true; - } - } - } - - @Override - public void visitPostfixExpression( - @NotNull PsiPostfixExpression postfixExpression) { - if (assigned) { - return; - } - super.visitPostfixExpression(postfixExpression); - final IElementType tokenType = postfixExpression.getOperationTokenType(); - if (!tokenType.equals(JavaTokenType.PLUSPLUS) && - !tokenType.equals(JavaTokenType.MINUSMINUS)) { - return; - } - final PsiExpression operand = postfixExpression.getOperand(); - for (PsiVariable variable : variables) { - if (mayEvaluateToVariable(operand, variable)) { - assigned = true; - } - } - } - - public static boolean mayEvaluateToVariable( - @Nullable PsiExpression expression, - @NotNull PsiVariable variable) { - if (expression == null) { - return false; - } - if (expression instanceof PsiBinaryExpression) { - final PsiBinaryExpression binaryExpression = - (PsiBinaryExpression)expression; - final PsiExpression lOperand = binaryExpression.getLOperand(); - final PsiExpression rOperand = binaryExpression.getROperand(); - return mayEvaluateToVariable(lOperand, variable) || - mayEvaluateToVariable(rOperand, variable); - } - if (expression instanceof PsiParenthesizedExpression) { - final PsiParenthesizedExpression parenthesizedExpression = - (PsiParenthesizedExpression)expression; - final PsiExpression containedExpression = - parenthesizedExpression.getExpression(); - return mayEvaluateToVariable(containedExpression, variable); - } - if (expression instanceof PsiTypeCastExpression) { - final PsiTypeCastExpression typeCastExpression = - (PsiTypeCastExpression)expression; - final PsiExpression containedExpression = - typeCastExpression.getOperand(); - return mayEvaluateToVariable(containedExpression, variable); - } - if (expression instanceof PsiConditionalExpression) { - final PsiConditionalExpression conditional = - (PsiConditionalExpression)expression; - final PsiExpression thenExpression = conditional.getThenExpression(); - final PsiExpression elseExpression = conditional.getElseExpression(); - return mayEvaluateToVariable(thenExpression, variable) || - mayEvaluateToVariable(elseExpression, variable); - } - if (expression instanceof PsiArrayAccessExpression) { - final PsiElement parent = expression.getParent(); - if (parent instanceof PsiArrayAccessExpression) { - return false; - } - final PsiType type = variable.getType(); - if (!(type instanceof PsiArrayType)) { - return false; - } - final PsiArrayType arrayType = (PsiArrayType)type; - final int dimensions = arrayType.getArrayDimensions(); - if (dimensions <= 1) { - return false; - } - PsiArrayAccessExpression arrayAccessExpression = - (PsiArrayAccessExpression)expression; - PsiExpression arrayExpression = - arrayAccessExpression.getArrayExpression(); - int count = 1; - while (arrayExpression instanceof PsiArrayAccessExpression) { - arrayAccessExpression = - (PsiArrayAccessExpression)arrayExpression; - arrayExpression = arrayAccessExpression.getArrayExpression(); - count++; - } - return count != dimensions && - mayEvaluateToVariable(arrayExpression, variable); - } - return evaluatesToVariable(expression, variable); - } - - public static boolean evaluatesToVariable( - @Nullable PsiExpression expression, - @NotNull PsiVariable variable) { - final PsiExpression strippedExpression = - ParenthesesUtils.stripParentheses(expression); - if (strippedExpression == null) { - return false; - } - if (!(expression instanceof PsiReferenceExpression)) { - return false; - } - final PsiReferenceExpression referenceExpression = - (PsiReferenceExpression)expression; - final PsiElement referent = referenceExpression.resolve(); - return variable.equals(referent); - } - - public boolean isAssigned() { - return assigned; - } -} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeParallelIfsPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeParallelIfsPredicate.java index f2e889316400..57a78912c100 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeParallelIfsPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeParallelIfsPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,11 @@ package com.siyeh.ipp.trivialif; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; +import com.siyeh.ig.psiutils.ControlFlowUtils; import com.siyeh.ig.psiutils.EquivalenceChecker; +import com.siyeh.ig.psiutils.VariableAccessUtils; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.ControlFlowUtils; import com.siyeh.ipp.psiutils.ErrorUtil; -import com.siyeh.ipp.psiutils.VariableAccessUtils; import java.util.Collection; import java.util.HashSet; From 7b53c99b08834623a2deb4b0baa490bbea27389a Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 28 Feb 2014 11:15:36 +0100 Subject: [PATCH 84/95] remove SideEffectChecker duplication --- .../siyeh/ig/psiutils/SideEffectChecker.java | 4 +- ...ceableWithOperatorAssignmentPredicate.java | 6 +- .../siyeh/ipp/psiutils/SideEffectChecker.java | 87 ------------------- 3 files changed, 5 insertions(+), 92 deletions(-) delete mode 100644 plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/SideEffectChecker.java diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/SideEffectChecker.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/SideEffectChecker.java index af04c02d6e79..5063ef7c2ea7 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/SideEffectChecker.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/SideEffectChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ public class SideEffectChecker { return visitor.mayHaveSideEffects(); } - private static class SideEffectsVisitor extends JavaRecursiveElementVisitor { + private static class SideEffectsVisitor extends JavaRecursiveElementWalkingVisitor { private boolean mayHaveSideEffects = false; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceableWithOperatorAssignmentPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceableWithOperatorAssignmentPredicate.java index 959c858c05f0..34a2d0851d24 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceableWithOperatorAssignmentPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceableWithOperatorAssignmentPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ package com.siyeh.ipp.opassign; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiUtil; -import com.siyeh.ipp.base.PsiElementPredicate; import com.siyeh.ig.psiutils.EquivalenceChecker; +import com.siyeh.ig.psiutils.SideEffectChecker; +import com.siyeh.ipp.base.PsiElementPredicate; import com.siyeh.ipp.psiutils.ErrorUtil; -import com.siyeh.ipp.psiutils.SideEffectChecker; class ReplaceableWithOperatorAssignmentPredicate implements PsiElementPredicate { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/SideEffectChecker.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/SideEffectChecker.java deleted file mode 100644 index 7940dd739ecb..000000000000 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/SideEffectChecker.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2003-2005 Dave Griffith - * - * 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.siyeh.ipp.psiutils; - -import com.intellij.psi.*; -import com.intellij.psi.tree.IElementType; - -public class SideEffectChecker { - - private SideEffectChecker() { - super(); - } - - public static boolean mayHaveSideEffects(PsiExpression exp) { - final SideEffectsVisitor visitor = new SideEffectsVisitor(); - exp.accept(visitor); - return visitor.mayHaveSideEffects(); - } - - private static class SideEffectsVisitor extends JavaRecursiveElementWalkingVisitor { - - private boolean mayHaveSideEffects = false; - - @Override - public void visitElement(PsiElement element) { - if (!mayHaveSideEffects) { - super.visitElement(element); - } - } - - @Override - public void visitMethodCallExpression( - PsiMethodCallExpression expression) { - mayHaveSideEffects = true; - } - - @Override - public void visitNewExpression(PsiNewExpression expression) { - mayHaveSideEffects = true; - } - - @Override - public void visitAssignmentExpression( - PsiAssignmentExpression expression) { - mayHaveSideEffects = true; - } - - @Override - public void visitPrefixExpression(PsiPrefixExpression expression) { - super.visitPrefixExpression(expression); - final IElementType tokenType = expression.getOperationTokenType(); - - if (tokenType.equals(JavaTokenType.PLUSPLUS) || - tokenType.equals(JavaTokenType.MINUSMINUS)) { - mayHaveSideEffects = true; - } - } - - @Override - public void visitPostfixExpression(PsiPostfixExpression expression) { - super.visitPostfixExpression(expression); - final IElementType tokenType = expression.getOperationTokenType(); - - if (tokenType.equals(JavaTokenType.PLUSPLUS) || - tokenType.equals(JavaTokenType.MINUSMINUS)) { - mayHaveSideEffects = true; - } - } - - public boolean mayHaveSideEffects() { - return mayHaveSideEffects; - } - } -} \ No newline at end of file From a1e2bb8b9c4f467e502092ee6f0309c969e4efc6 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 28 Feb 2014 11:23:03 +0100 Subject: [PATCH 85/95] Remove unused ConditionalUtils --- .../siyeh/ipp/psiutils/ConditionalUtils.java | 69 ------------------- 1 file changed, 69 deletions(-) delete mode 100644 plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConditionalUtils.java diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConditionalUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConditionalUtils.java deleted file mode 100644 index 8d13fe20bee8..000000000000 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConditionalUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers - * - * 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.siyeh.ipp.psiutils; - -import com.intellij.psi.*; -import org.jetbrains.annotations.NonNls; - -public class ConditionalUtils { - - private ConditionalUtils() {} - - public static boolean isReturn(PsiStatement statement, - @NonNls String value) { - if (statement == null) { - return false; - } - if (!(statement instanceof PsiReturnStatement)) { - return false; - } - final PsiReturnStatement returnStatement = - (PsiReturnStatement)statement; - if (returnStatement.getReturnValue() == null) { - return false; - } - final PsiExpression returnValue = returnStatement.getReturnValue(); - if (returnValue == null) { - return false; - } - final String returnValueText = returnValue.getText(); - return value.equals(returnValueText); - } - - public static boolean isAssignment(PsiStatement statement, - @NonNls String value) { - if (statement == null) { - return false; - } - if (!(statement instanceof PsiExpressionStatement)) { - return false; - } - final PsiExpressionStatement expressionStatement = - (PsiExpressionStatement)statement; - final PsiExpression expression = expressionStatement.getExpression(); - if (!(expression instanceof PsiAssignmentExpression)) { - return false; - } - final PsiAssignmentExpression assignment = - (PsiAssignmentExpression)expression; - final PsiExpression rhs = assignment.getRExpression(); - if (rhs == null) { - return false; - } - final String rhsText = rhs.getText(); - return value.equals(rhsText); - } -} From 3ca96289affdabd1bfba465eea490a41946608a7 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 28 Feb 2014 11:40:54 +0100 Subject: [PATCH 86/95] remove ControlFlowUtils duplication --- .../siyeh/ig/psiutils/ControlFlowUtils.java | 23 +- .../siyeh/ipp/psiutils/ControlFlowUtils.java | 296 ------------------ .../ReplaceIfWithSwitchIntention.java | 4 +- .../ipp/trivialif/MergeIfOrPredicate.java | 4 +- 4 files changed, 12 insertions(+), 315 deletions(-) delete mode 100644 plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ControlFlowUtils.java diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java index 278c07e980c0..3741d260dae6 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ public class ControlFlowUtils { } else if (statement instanceof PsiExpressionListStatement || statement instanceof PsiEmptyStatement || statement instanceof PsiAssertStatement || statement instanceof PsiDeclarationStatement || - statement instanceof PsiSwitchLabelStatement) { + statement instanceof PsiSwitchLabelStatement || statement instanceof PsiForeachStatement) { return true; } else if (statement instanceof PsiExpressionStatement) { @@ -63,9 +63,6 @@ public class ControlFlowUtils { else if (statement instanceof PsiForStatement) { return forStatementMayCompleteNormally((PsiForStatement)statement); } - else if (statement instanceof PsiForeachStatement) { - return foreachStatementMayCompleteNormally((PsiForeachStatement)statement); - } else if (statement instanceof PsiWhileStatement) { return whileStatementMayCompleteNormally((PsiWhileStatement)statement); } @@ -130,10 +127,6 @@ public class ControlFlowUtils { return Boolean.TRUE != value; } - private static boolean foreachStatementMayCompleteNormally(@NotNull PsiForeachStatement loopStatement) { - return true; - } - private static boolean switchStatementMayCompleteNormally(@NotNull PsiSwitchStatement switchStatement) { if (statementIsBreakTarget(switchStatement)) { return true; @@ -524,7 +517,7 @@ public class ControlFlowUtils { } } - private static class SystemExitFinder extends JavaRecursiveElementVisitor { + private static class SystemExitFinder extends JavaRecursiveElementWalkingVisitor { private boolean m_found = false; @@ -564,7 +557,7 @@ public class ControlFlowUtils { } } - private static class ReturnFinder extends JavaRecursiveElementVisitor { + private static class ReturnFinder extends JavaRecursiveElementWalkingVisitor { private boolean m_found = false; @@ -587,7 +580,7 @@ public class ControlFlowUtils { } } - private static class BreakFinder extends JavaRecursiveElementVisitor { + private static class BreakFinder extends JavaRecursiveElementWalkingVisitor { private boolean m_found = false; private final PsiStatement m_target; @@ -637,7 +630,7 @@ public class ControlFlowUtils { } } - private static class ContinueFinder extends JavaRecursiveElementVisitor { + private static class ContinueFinder extends JavaRecursiveElementWalkingVisitor { private boolean m_found = false; private final PsiStatement m_target; @@ -687,7 +680,7 @@ public class ControlFlowUtils { } } - private static class MethodCallFinder extends JavaRecursiveElementVisitor { + private static class MethodCallFinder extends JavaRecursiveElementWalkingVisitor { private final String containingClassName; private final PsiType returnType; @@ -728,7 +721,7 @@ public class ControlFlowUtils { } } - private static class ContinueToAncestorFinder extends JavaRecursiveElementVisitor { + private static class ContinueToAncestorFinder extends JavaRecursiveElementWalkingVisitor { private final PsiStatement statement; private boolean found = false; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ControlFlowUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ControlFlowUtils.java deleted file mode 100644 index 668444bd22c1..000000000000 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ControlFlowUtils.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers - * - * 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.siyeh.ipp.psiutils; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; - -public class ControlFlowUtils { - - private ControlFlowUtils() { - } - - public static boolean statementMayCompleteNormally(PsiStatement statement) { - if (statement instanceof PsiBreakStatement || - statement instanceof PsiContinueStatement || - statement instanceof PsiReturnStatement || - statement instanceof PsiThrowStatement) { - return false; - } - else if (statement instanceof PsiExpressionListStatement || - statement instanceof PsiExpressionStatement || - statement instanceof PsiEmptyStatement || - statement instanceof PsiAssertStatement || - statement instanceof PsiDeclarationStatement) { - return true; - } - else if (statement instanceof PsiForStatement) { - final PsiForStatement loopStatement = (PsiForStatement)statement; - final PsiExpression test = loopStatement.getCondition(); - return test != null && !isBooleanConstant(test, true) || - statementIsBreakTarget(loopStatement); - } - else if (statement instanceof PsiForeachStatement) { - return true; - } - else if (statement instanceof PsiWhileStatement) { - final PsiWhileStatement loopStatement = - (PsiWhileStatement)statement; - final PsiExpression test = loopStatement.getCondition(); - return !isBooleanConstant(test, true) - || statementIsBreakTarget(loopStatement); - } - else if (statement instanceof PsiDoWhileStatement) { - final PsiDoWhileStatement loopStatement = - (PsiDoWhileStatement)statement; - final PsiExpression test = loopStatement.getCondition(); - final PsiStatement body = loopStatement.getBody(); - return statementMayCompleteNormally(body) && - !isBooleanConstant(test, true) - || statementIsBreakTarget(loopStatement); - } - else if (statement instanceof PsiSynchronizedStatement) { - final PsiCodeBlock body = - ((PsiSynchronizedStatement)statement).getBody(); - return codeBlockMayCompleteNormally(body); - } - else if (statement instanceof PsiBlockStatement) { - final PsiCodeBlock codeBlock = - ((PsiBlockStatement)statement).getCodeBlock(); - return codeBlockMayCompleteNormally(codeBlock); - } - else if (statement instanceof PsiLabeledStatement) { - final PsiLabeledStatement labeledStatement = - (PsiLabeledStatement)statement; - final PsiStatement body = labeledStatement.getStatement(); - return statementMayCompleteNormally(body) - || statementIsBreakTarget(body); - } - else if (statement instanceof PsiIfStatement) { - final PsiIfStatement ifStatement = (PsiIfStatement)statement; - final PsiStatement thenBranch = ifStatement.getThenBranch(); - if (statementMayCompleteNormally(thenBranch)) { - return true; - } - final PsiStatement elseBranch = ifStatement.getElseBranch(); - return elseBranch == null || - statementMayCompleteNormally(elseBranch); - } - else if (statement instanceof PsiTryStatement) { - final PsiTryStatement tryStatement = (PsiTryStatement)statement; - - final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock(); - if (finallyBlock != null) { - if (!codeBlockMayCompleteNormally(finallyBlock)) { - return false; - } - } - final PsiCodeBlock tryBlock = tryStatement.getTryBlock(); - if (codeBlockMayCompleteNormally(tryBlock)) { - return true; - } - final PsiCodeBlock[] catchBlocks = tryStatement.getCatchBlocks(); - for (final PsiCodeBlock catchBlock : catchBlocks) { - if (codeBlockMayCompleteNormally(catchBlock)) { - return true; - } - } - return false; - } - else if (statement instanceof PsiSwitchStatement) { - final PsiSwitchStatement switchStatement = - (PsiSwitchStatement)statement; - if (statementIsBreakTarget(switchStatement)) { - return true; - } - final PsiCodeBlock body = switchStatement.getBody(); - if (body == null) { - return true; - } - final PsiStatement[] statements = body.getStatements(); - int lastNonLabelOffset = -1; - final int lastStatementIndex = statements.length - 1; - for (int i = lastStatementIndex; i >= 0; i--) { - if (!(statements[i] instanceof PsiSwitchLabelStatement)) { - lastNonLabelOffset = i; - break; - } - } - if (lastNonLabelOffset == -1) { - return true; // it's all labels - } - else if (lastNonLabelOffset == lastStatementIndex) { - return statementMayCompleteNormally( - statements[lastStatementIndex]); - } - else { - return true; // the last statement is a label - } - } - else { - return false; - } - } - - private static boolean codeBlockMayCompleteNormally(PsiCodeBlock block) { - if (block == null) { - return true; - } - final PsiStatement[] statements = block.getStatements(); - for (final PsiStatement statement : statements) { - if (!statementMayCompleteNormally(statement)) { - return false; - } - } - return true; - } - - private static boolean isBooleanConstant(PsiExpression expression, - boolean b) { - if (expression == null) { - return false; - } - final Project project = expression.getProject(); - final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); - final PsiConstantEvaluationHelper constantEvaluationHelper = - psiFacade.getConstantEvaluationHelper(); - final Object value = - constantEvaluationHelper.computeConstantExpression - (expression, false); - if (!(value instanceof Boolean)) { - return false; - } - final Boolean aBoolean = (Boolean)value; - return aBoolean.booleanValue() == b; - } - - private static boolean statementIsBreakTarget(PsiStatement statement) { - if (statement == null) { - return false; - } - final BreakTargetFinder breakFinder = new BreakTargetFinder(statement); - statement.accept(breakFinder); - return breakFinder.breakFound(); - } - - public static boolean statementContainsNakedBreak(PsiStatement statement) { - if (statement == null) { - return false; - } - final NakedBreakFinder breakFinder = new NakedBreakFinder(); - statement.accept(breakFinder); - return breakFinder.breakFound(); - } - - private static class BreakTargetFinder - extends JavaRecursiveElementWalkingVisitor { - - private boolean m_found = false; - private final PsiStatement m_target; - - private BreakTargetFinder(PsiStatement target) { - m_target = target; - } - - public boolean breakFound() { - return m_found; - } - - @Override - public void visitElement(PsiElement element) { - if (m_found) { - return; - } - super.visitElement(element); - } - - @Override - public void visitReferenceExpression( - PsiReferenceExpression expression) { - } - - @Override - public void visitBreakStatement(PsiBreakStatement statement) { - super.visitBreakStatement(statement); - final PsiStatement exitedStatement = - statement.findExitedStatement(); - if (exitedStatement == null) { - return; - } - if (exitedStatement.equals(m_target)) { - m_found = true; - } - } - } - - private static class NakedBreakFinder - extends JavaRecursiveElementWalkingVisitor { - - private boolean m_found = false; - - public boolean breakFound() { - return m_found; - } - - @Override - public void visitElement(PsiElement element) { - if (m_found) { - return; - } - super.visitElement(element); - } - - @Override - public void visitReferenceExpression( - PsiReferenceExpression expression) { - } - - @Override - public void visitBreakStatement(PsiBreakStatement statement) { - if (statement.getLabelIdentifier() != null) { - return; - } - m_found = true; - } - - @Override - public void visitDoWhileStatement( - PsiDoWhileStatement statement) { - // don't drill down - } - - @Override - public void visitForStatement(PsiForStatement statement) { - // don't drill down - } - - @Override - public void visitForeachStatement(PsiForeachStatement statement) { - // don't drill down - } - - @Override - public void visitWhileStatement(PsiWhileStatement statement) { - // don't drill down - } - - @Override - public void visitSwitchStatement( - PsiSwitchStatement statement) { - // don't drill down - } - } -} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceIfWithSwitchIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceIfWithSwitchIntention.java index cde03e1aeb1c..9f40b4b36a13 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceIfWithSwitchIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceIfWithSwitchIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,12 @@ package com.siyeh.ipp.switchtoif; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; +import com.siyeh.ig.psiutils.ControlFlowUtils; import com.siyeh.ig.psiutils.EquivalenceChecker; import com.siyeh.ig.psiutils.SwitchUtils; import com.siyeh.ig.psiutils.SwitchUtils.IfStatementBranch; import com.siyeh.ipp.base.Intention; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.ControlFlowUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeIfOrPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeIfOrPredicate.java index b2c5aa87a3fb..3dfd039fec5c 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeIfOrPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeIfOrPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 Dave Griffith + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,9 @@ package com.siyeh.ipp.trivialif; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; +import com.siyeh.ig.psiutils.ControlFlowUtils; import com.siyeh.ig.psiutils.EquivalenceChecker; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.ControlFlowUtils; import com.siyeh.ipp.psiutils.ErrorUtil; class MergeIfOrPredicate implements PsiElementPredicate { From 780a50be213d53476aa7322efe923a45f152a214 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Fri, 28 Feb 2014 15:24:13 +0400 Subject: [PATCH 87/95] IDEA-111432 Mnemonics changed for "Preserve case" and "Whole project" --- .../TogglePreserveCaseAction.java | 17 ++++++++++++++++- .../src/messages/FindBundle.properties | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/TogglePreserveCaseAction.java b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/TogglePreserveCaseAction.java index 1ceb62447573..755e2323c57c 100644 --- a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/TogglePreserveCaseAction.java +++ b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/TogglePreserveCaseAction.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.intellij.find.editorHeaderActions; import com.intellij.find.EditorSearchComponent; @@ -5,7 +20,7 @@ import com.intellij.find.FindModel; import com.intellij.openapi.actionSystem.AnActionEvent; public class TogglePreserveCaseAction extends EditorHeaderToggleAction implements SecondaryHeaderAction { - private static final String TEXT = "Preser&ve Case"; + private static final String TEXT = "&Preserve Case"; public TogglePreserveCaseAction(EditorSearchComponent editorSearchComponent) { super(editorSearchComponent, TEXT); diff --git a/platform/platform-resources-en/src/messages/FindBundle.properties b/platform/platform-resources-en/src/messages/FindBundle.properties index 26959ba14d4b..2c17b13d459d 100644 --- a/platform/platform-resources-en/src/messages/FindBundle.properties +++ b/platform/platform-resources-en/src/messages/FindBundle.properties @@ -76,7 +76,7 @@ find.empty.match.regular.expression.error=Regular expression matches empty strin find.filter.invalid.file.mask.error=Bad file mask \"{0}\" find.filter.empty.file.mask.error=Empty file mask find.options.case.sensitive=&Case sensitive -find.options.replace.preserve.case=Preser&ve case +find.options.replace.preserve.case=&Preserve case find.options.whole.words.only=Whole wo&rds only (may be faster) find.options.string.literals.only=S&tring literals only find.options.comments.only=Comm&ents only @@ -85,7 +85,7 @@ find.direction.group=Direction find.direction.forward.radio=F&orward find.direction.backward.radio=&Backward find.scope.group=Scope -find.scope.whole.project.radio=Whole &project +find.scope.whole.project.radio=W&hole project find.scope.all.projects.radio=All &projects find.scope.module.radio=&Module: find.scope.project.radio=Pro&ject From e7fd0b6bbd1d15d3d9dbc495544f901e3db9b36a Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 28 Feb 2014 15:37:42 +0400 Subject: [PATCH 88/95] IDEA-121392 Breakpoint popup: click aside popup loses Suspend = Yes value --- .../src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java index abce43b858ec..dbc7b35ebcb4 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java @@ -141,6 +141,7 @@ public class DebuggerUIUtil { final Ref balloonRef = Ref.create(null); final Ref isLoading = Ref.create(Boolean.FALSE); + final Ref moreOptionsRequested = Ref.create(Boolean.FALSE); propertiesPanel.setDelegate(new XLightBreakpointPropertiesPanel.Delegate() { @Override @@ -152,6 +153,7 @@ public class DebuggerUIUtil { balloonRef.get().hide(); } showXBreakpointEditorBalloon(project, point, component, true, breakpoint); + moreOptionsRequested.set(true); } }); @@ -159,6 +161,10 @@ public class DebuggerUIUtil { propertiesPanel.loadProperties(); isLoading.set(Boolean.FALSE); + if (moreOptionsRequested.get()) { + return; + } + Runnable showMoreOptions = new Runnable() { @Override public void run() { From f4ca6144e3c70cd953cd118e3a54b1ee4e5c2374 Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Fri, 28 Feb 2014 16:03:00 +0400 Subject: [PATCH 89/95] Rename undo selection action --- .../openapi/editor/actions/SelectNextOccurrenceAction.java | 4 ++-- ...renceAction.java => UnselectPreviousOccurrenceAction.java} | 4 ++-- .../src/com/intellij/openapi/actionSystem/IdeActions.java | 2 +- .../src/messages/ActionsBundle.properties | 2 +- platform/platform-resources/src/idea/Keymap_Default.xml | 2 +- platform/platform-resources/src/idea/Keymap_Eclipse.xml | 2 +- platform/platform-resources/src/idea/Keymap_Mac.xml | 2 +- platform/platform-resources/src/idea/Keymap_MacClassic.xml | 2 +- platform/platform-resources/src/idea/PlatformActions.xml | 2 +- .../editor/actions/SelectUnselectOccurrenceActionsTest.java | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) rename platform/lang-impl/src/com/intellij/openapi/editor/actions/{UnselectLastOccurrenceAction.java => UnselectPreviousOccurrenceAction.java} (93%) diff --git a/platform/lang-impl/src/com/intellij/openapi/editor/actions/SelectNextOccurrenceAction.java b/platform/lang-impl/src/com/intellij/openapi/editor/actions/SelectNextOccurrenceAction.java index 81a7851da874..69512b3576f9 100644 --- a/platform/lang-impl/src/com/intellij/openapi/editor/actions/SelectNextOccurrenceAction.java +++ b/platform/lang-impl/src/com/intellij/openapi/editor/actions/SelectNextOccurrenceAction.java @@ -23,11 +23,11 @@ import com.intellij.find.FindBundle; import com.intellij.find.FindManager; import com.intellij.find.FindModel; import com.intellij.find.FindResult; -import com.intellij.openapi.editor.EditorLastActionTracker; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorLastActionTracker; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; @@ -145,7 +145,7 @@ public class SelectNextOccurrenceAction extends EditorAction { private static boolean isRepeatedActionInvocation() { String lastActionId = EditorLastActionTracker.getInstance().getLastActionId(); - return IdeActions.ACTION_SELECT_NEXT_OCCURENCE.equals(lastActionId) || IdeActions.ACTION_UNSELECT_LAST_OCCURENCE.equals(lastActionId); + return IdeActions.ACTION_SELECT_NEXT_OCCURENCE.equals(lastActionId) || IdeActions.ACTION_UNSELECT_PREVIOUS_OCCURENCE.equals(lastActionId); } } } diff --git a/platform/lang-impl/src/com/intellij/openapi/editor/actions/UnselectLastOccurrenceAction.java b/platform/lang-impl/src/com/intellij/openapi/editor/actions/UnselectPreviousOccurrenceAction.java similarity index 93% rename from platform/lang-impl/src/com/intellij/openapi/editor/actions/UnselectLastOccurrenceAction.java rename to platform/lang-impl/src/com/intellij/openapi/editor/actions/UnselectPreviousOccurrenceAction.java index 192e41cdfdb6..8db261e6336a 100644 --- a/platform/lang-impl/src/com/intellij/openapi/editor/actions/UnselectLastOccurrenceAction.java +++ b/platform/lang-impl/src/com/intellij/openapi/editor/actions/UnselectPreviousOccurrenceAction.java @@ -23,8 +23,8 @@ import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import org.jetbrains.annotations.Nullable; -public class UnselectLastOccurrenceAction extends EditorAction { - protected UnselectLastOccurrenceAction() { +public class UnselectPreviousOccurrenceAction extends EditorAction { + protected UnselectPreviousOccurrenceAction() { super(new Handler()); } diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java index b515b84e8f3f..22f9be634721 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java @@ -115,7 +115,7 @@ public interface IdeActions { @NonNls String ACTION_FIND_NEXT = "FindNext"; @NonNls String ACTION_FIND_PREVIOUS = "FindPrevious"; @NonNls String ACTION_SELECT_NEXT_OCCURENCE = "SelectNextOccurrence"; - @NonNls String ACTION_UNSELECT_LAST_OCCURENCE = "UnselectLastOccurrence"; + @NonNls String ACTION_UNSELECT_PREVIOUS_OCCURENCE = "UnselectPreviousOccurrence"; @NonNls String ACTION_COMPILE = "Compile"; @NonNls String ACTION_COMPILE_PROJECT = "CompileProject"; @NonNls String ACTION_MAKE_MODULE = "MakeModule"; diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index 2c4adec5a674..88d691d7ccdc 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -108,7 +108,7 @@ action.EditorMoveDownAndScrollWithSelection.text=Move Down and Scroll with Selec action.EditorCloneCaretBelow.text=Clone Caret Below action.EditorCloneCaretAbove.text=Clone Caret Above action.SelectNextOccurrence.text=Select Next Occurrence -action.UnselectLastOccurrence.text=Unselect Last Occurrence +action.UnselectPreviousOccurrence.text=Unselect Occurrence action.EditorToggleStickySelection.text=Toggle Sticky Selection action.EditorSwapSelectionBoundaries.text=Swap selection boundaries action.EditorLineStart.text=Move Caret to Line Start diff --git a/platform/platform-resources/src/idea/Keymap_Default.xml b/platform/platform-resources/src/idea/Keymap_Default.xml index 447d4abfb649..1127d78f3ae3 100644 --- a/platform/platform-resources/src/idea/Keymap_Default.xml +++ b/platform/platform-resources/src/idea/Keymap_Default.xml @@ -115,7 +115,7 @@ - + diff --git a/platform/platform-resources/src/idea/Keymap_Eclipse.xml b/platform/platform-resources/src/idea/Keymap_Eclipse.xml index 2a28414bd583..ddc2dbc1b5ca 100644 --- a/platform/platform-resources/src/idea/Keymap_Eclipse.xml +++ b/platform/platform-resources/src/idea/Keymap_Eclipse.xml @@ -124,7 +124,7 @@ - + diff --git a/platform/platform-resources/src/idea/Keymap_Mac.xml b/platform/platform-resources/src/idea/Keymap_Mac.xml index 044d5b91c7c7..a66911c122d4 100644 --- a/platform/platform-resources/src/idea/Keymap_Mac.xml +++ b/platform/platform-resources/src/idea/Keymap_Mac.xml @@ -353,7 +353,7 @@ - + diff --git a/platform/platform-resources/src/idea/Keymap_MacClassic.xml b/platform/platform-resources/src/idea/Keymap_MacClassic.xml index 9d2b440f2797..7e3278859504 100644 --- a/platform/platform-resources/src/idea/Keymap_MacClassic.xml +++ b/platform/platform-resources/src/idea/Keymap_MacClassic.xml @@ -262,7 +262,7 @@ - + diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index e0e136024f2a..fdd3809aed95 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -226,7 +226,7 @@ - + diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java index 90a82e972379..51653510c331 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java @@ -182,6 +182,6 @@ public class SelectUnselectOccurrenceActionsTest extends LightPlatformCodeInsigh } private void executeReverseAction() { - myFixture.performEditorAction(IdeActions.ACTION_UNSELECT_LAST_OCCURENCE); + myFixture.performEditorAction(IdeActions.ACTION_UNSELECT_PREVIOUS_OCCURENCE); } } From 8fd91117c489fbf5c8213879737b988bdaa7a5ac Mon Sep 17 00:00:00 2001 From: Vassiliy Date: Fri, 28 Feb 2014 16:11:14 +0400 Subject: [PATCH 90/95] Fix for JToggleButton (we had no specific UI for Darcula/IntelliJ before) --- .../ui/laf/darcula/ui/DarculaButtonUI.java | 4 +-- .../laf/darcula/ui/DarculaToggleButtonUI.java | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaToggleButtonUI.java diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaButtonUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaButtonUI.java index f4fbc75dd935..8deb957d21f1 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaButtonUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaButtonUI.java @@ -50,7 +50,7 @@ public class DarculaButtonUI extends BasicButtonUI { final Insets ins = border.getBorderInsets(c); final int yOff = (ins.top + ins.bottom) / 4; if (!square) { - if (((JButton)c).isDefaultButton()) { + if (c instanceof JButton && ((JButton)c).isDefaultButton()) { ((Graphics2D)g).setPaint(UIUtil.getGradientPaint(0, 0, getSelectedButtonColor1(), 0, c.getHeight(), getSelectedButtonColor2())); } else { @@ -100,7 +100,7 @@ public class DarculaButtonUI extends BasicButtonUI { @Override public void update(Graphics g, JComponent c) { super.update(g, c); - if (((JButton)c).isDefaultButton() && !SystemInfo.isMac) { + if (c instanceof JButton && ((JButton)c).isDefaultButton() && !SystemInfo.isMac) { if (!c.getFont().isBold()) { c.setFont(c.getFont().deriveFont(Font.BOLD)); } diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaToggleButtonUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaToggleButtonUI.java new file mode 100644 index 000000000000..b35ac61ca8c1 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaToggleButtonUI.java @@ -0,0 +1,26 @@ +/* + * 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.intellij.ide.ui.laf.darcula.ui; + +import javax.swing.*; +import javax.swing.plaf.ComponentUI; + +public class DarculaToggleButtonUI extends DarculaButtonUI { + @SuppressWarnings("MethodOverridesStaticMethodOfSuperclass") + public static ComponentUI createUI(JComponent c) { + return new DarculaToggleButtonUI(); + } +} From 88b3931ffa96dbf9e18f7b1cfdbd28d09d980889 Mon Sep 17 00:00:00 2001 From: Vassiliy Date: Fri, 28 Feb 2014 16:11:38 +0400 Subject: [PATCH 91/95] License dialog: we don't need JBA availability check if actual license is JBA. --- .../src/com/intellij/ide/ui/laf/darcula/darcula.properties | 3 +++ .../src/com/intellij/ide/ui/laf/intellijlaf.properties | 3 +++ 2 files changed, 6 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties index b975ff8a666d..1f29a08d8612 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/darcula.properties @@ -122,6 +122,9 @@ Button.darcula.selection.color2=233143 Button.darcula.selectedButtonForeground=bbbbbb Button.darcula.disabledText.shadow=00000000 +ToggleButton.border=com.intellij.ide.ui.laf.darcula.ui.DarculaButtonPainter +ToggleButtonUI=com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI + MenuItem.acceleratorForeground=eeeeee PopupMenu.translucentBackground=3c3f41 diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellijlaf.properties b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellijlaf.properties index 116adfe47398..cd99cb129fd0 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellijlaf.properties +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellijlaf.properties @@ -130,6 +130,9 @@ Button.darcula.selection.color2=3a6bc6 Button.darcula.selectedButtonForeground=f0f0f0 Button.darcula.disabledText.shadow=ffffff +ToggleButton.border=com.intellij.ide.ui.laf.darcula.ui.DarculaButtonPainter +ToggleButtonUI=com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI + MenuItem.acceleratorForeground=505050 PopupMenu.translucentBackground=e8e8e8 From 99d35bfb08eb98d66a5b1d9bb5e63d61f55d5d22 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 28 Feb 2014 16:20:07 +0400 Subject: [PATCH 92/95] IDEA-121393 Breakpoint: enabled breakpoint does not update its icon appearance --- .../com/intellij/debugger/ui/breakpoints/BreakpointManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 5fadb64b8f9a..aac9ffd510c3 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -917,6 +917,7 @@ public class BreakpointManager { private final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); public void fireBreakpointChanged(Breakpoint breakpoint) { breakpoint.reload(); + breakpoint.updateUI(); RequestManagerImpl.updateRequests(breakpoint); if (myAllowMulticasting) { // can be invoked from non-AWT thread From 0ca53000cee62cc5af322c0735d9651aa1e891c0 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 28 Feb 2014 13:19:41 +0100 Subject: [PATCH 93/95] more tracing for myWatchedProjectsCount --- .../compiler/impl/TranslatingCompilerFilesMonitor.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java index 9e89f13c79c0..5b208a6d165e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java @@ -197,6 +197,9 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } FileUtil.createIfDoesntExist(CompilerPaths.getRebuildMarkerFile(project)); --myWatchedProjectsCount; + if (ourDebugMode) { + System.out.println("After suspend for project:"+projectId + "," + myWatchedProjectsCount); + } // cleanup internal structures to free memory mySourcesToRecompile.remove(projectId); myOutputsToDelete.remove(projectId); @@ -217,8 +220,12 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { public void watchProject(Project project) { synchronized (myDataLock) { - mySuspendedProjects.remove(getProjectId(project)); + int projectId = getProjectId(project); + mySuspendedProjects.remove(projectId); ++myWatchedProjectsCount; + if (ourDebugMode) { + System.out.println("After watch for project:"+projectId + "," + myWatchedProjectsCount); + } } } From 833bcfd8a29c18a4676fc873ac130fa091679c60 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 28 Feb 2014 13:28:28 +0100 Subject: [PATCH 94/95] initialize LineSet before document changes --- .../com/intellij/openapi/editor/impl/DocumentImpl.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java index 2a2249b60e57..c3424e3bc51f 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java @@ -713,6 +713,8 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { } assertInsideCommand(); + getLineSet(); // initialize line set to track changed lines + DocumentEvent event = new DocumentEventImpl(this, offset, oldString, newString, myModificationStamp, wholeTextReplaced); if (!ShutDownTracker.isShutdownHookRunning()) { @@ -744,12 +746,7 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { try { if (LOG.isDebugEnabled()) LOG.debug(event.toString()); - synchronized (myLineSetLock) { - LineSet lineSet = myLineSet; - if (lineSet != null) { - lineSet.changedUpdate(event); - } - } + getLineSet().changedUpdate(event); setModificationStamp(newModificationStamp); if (!ShutDownTracker.isShutdownHookRunning()) { From 69cc1efd960485934e2ff9c8e86f89d625e51c90 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 28 Feb 2014 13:29:16 +0100 Subject: [PATCH 95/95] remove GppCompilerTest --- .../plugins/groovy/FastGroovyTestSuite.java | 4 +- .../groovy/compiler/GppCompilerTest.groovy | 136 ------------------ 2 files changed, 1 insertion(+), 139 deletions(-) delete mode 100644 plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GppCompilerTest.groovy diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/FastGroovyTestSuite.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/FastGroovyTestSuite.java index 11597e915fe4..42404baeec57 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/FastGroovyTestSuite.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/FastGroovyTestSuite.java @@ -19,7 +19,6 @@ import com.intellij.TestAll; import com.intellij.TestCaseLoader; import junit.framework.Test; import junit.framework.TestSuite; -import org.jetbrains.plugins.groovy.compiler.GppCompilerTest; import org.jetbrains.plugins.groovy.compiler.GroovyCompilerTest; import org.jetbrains.plugins.groovy.compiler.GroovyDebuggerTest; import org.jetbrains.plugins.groovy.lang.GroovyStressPerformanceTest; @@ -46,8 +45,7 @@ public class FastGroovyTestSuite { private static boolean isSlow(Class aClass) { return aClass.equals(GroovyDebuggerTest.class) || aClass.equals(GroovyStressPerformanceTest.class) || - aClass.getName().startsWith(GroovyCompilerTest.class.getName()) || - aClass.getName().startsWith(GppCompilerTest.class.getName()); + aClass.getName().startsWith(GroovyCompilerTest.class.getName()); } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GppCompilerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GppCompilerTest.groovy deleted file mode 100644 index 316de960091c..000000000000 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GppCompilerTest.groovy +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2000-2013 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 org.jetbrains.plugins.groovy.compiler - -import com.intellij.compiler.CompilerConfiguration -import com.intellij.compiler.CompilerConfigurationImpl -import com.intellij.compiler.server.BuildManager -import com.intellij.openapi.util.io.FileUtil -import com.intellij.openapi.vfs.VfsUtil -import com.intellij.testFramework.PsiTestUtil -import org.jetbrains.plugins.groovy.util.TestUtils -/** - * @author peter - */ -public abstract class GppCompilerTest extends GroovyCompilerTestCase { - String[] oldPatterns - - @Override protected void setUp() { - super.setUp(); - PsiTestUtil.addLibrary myFixture.module, "gpp", TestUtils.absoluteTestDataPath + "/realGroovypp/", "groovy-all-1.8.2.jar", "groovypp-all-0.9.0_1.8.2.jar" - CompilerConfigurationImpl conf = CompilerConfiguration.getInstance(project) - oldPatterns = conf.resourceFilePatterns - conf.addResourceFilePattern("!*.gpp") - } - - @Override - protected void tearDown() { - CompilerConfigurationImpl conf = CompilerConfiguration.getInstance(project) - conf.removeResourceFilePatterns() - oldPatterns.each { conf.addResourceFilePattern(it) } - super.tearDown() - } - - public void testRecompileDependentGroovyClasses() throws Exception { - def a = myFixture.addFileToProject("A.gpp", """ -class A { - void foo() { - print "239" - } -} -""") - myFixture.addFileToProject("b.gpp", """ -new A().foo() -""") - assertEmpty make() - assertOutput "b", "239" - - VfsUtil.saveText a.virtualFile, """ -class A { - def foo() { - print "239" - } -} -""" - - assertEmpty make() - assertOutput "b", "239" - } - - public void testRecompileDependentJavaClasses() throws Exception { - def a = myFixture.addFileToProject("A.gpp", """ -class A { - void foo() { - print "239" - } -} -""") - myFixture.addFileToProject("B.java", """ -public class B { - public static void main(String[] args) { - new A().foo(); - } -} -""") - assertEmpty make() - assertOutput "B", "239" - - VfsUtil.saveText a.virtualFile, """ -class A { - def foo() { - print "239" - } -} -""" - - assertEmpty make() - assertOutput "B", "239" - } - - public static class IdeaModeTest extends GppCompilerTest { - @Override - protected boolean useJps() { false } - } - - public static class JpsModeTest extends GppCompilerTest { - @Override - protected boolean useJps() { true } - - @Override - void testRecompileDependentJavaClasses() { - super.testRecompileDependentJavaClasses() - } - - @Override - void testRecompileDependentGroovyClasses() { - super.testRecompileDependentGroovyClasses() - } - - @Override - protected void tearDown() { - File systemRoot = BuildManager.getInstance().getBuildSystemDirectory() - try { - super.tearDown() - } - finally { - FileUtil.delete(systemRoot); - } - } - } - - -}