From ebba02b55f3113336c8652d5c97c381718722e52 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Wed, 7 Aug 2013 18:54:25 +0200 Subject: [PATCH 01/29] IDEA-111497 Darcula theme lighter since the new update --- .../ide/projectView/impl/ProjectViewTree.java | 16 +++++++--------- .../ide/ui/laf/darcula/darcula.properties | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewTree.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewTree.java index 38f74c34ec73..9341e52f00db 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewTree.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewTree.java @@ -31,12 +31,10 @@ import com.intellij.ui.JBTreeWithHintProvider; import com.intellij.ui.tabs.FileColorManagerImpl; import com.intellij.util.Function; import com.intellij.util.NullableFunction; -import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.plaf.ColorUIResource; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeModel; import java.awt.*; @@ -85,13 +83,13 @@ public abstract class ProjectViewTree extends JBTreeWithHintProvider { return super.getToggleClickCount(); } - @Override - public Color getBackground() { - if (!UIUtil.isUnderDarcula()) { - return super.getBackground(); - } - return new ColorUIResource(0x414750); - } + //@Override + //public Color getBackground() { + // if (!UIUtil.isUnderDarcula()) { + // return super.getBackground(); + // } + // return new ColorUIResource(0x414750); + //} @Override public boolean isFileColorsEnabled() { 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 555ad5a7e954..5922749915bf 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 @@ -104,10 +104,10 @@ SplitPane.highlight=3c3f41 Hyperlink.linkColor=589df6 -List.background=45494A -Table.background=45494A +#List.background=45494A +#Table.background=45494A -Tree.background=45494A +#Tree.background=45494A Tree.collapsedIcon=AllIcons.Mac.Tree_white_right_arrow Tree.expandedIcon=AllIcons.Mac.Tree_white_down_arrow From b7a7cccf7e4427bf06d9caae99adad67622afbf5 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 6 Aug 2013 20:59:13 +0200 Subject: [PATCH 02/29] =?UTF-8?q?cleanup=20=E2=80=94=20don't=20implement?= =?UTF-8?q?=20deprecated=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xdebugger/breakpoints/XLineBreakpointType.java | 2 +- .../breakpoints/RemoveBreakpointGutterIconAction.java | 10 +++------- .../xdebugger/impl/breakpoints/XBreakpointBase.java | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java b/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java index 78bf3fcb7c6e..48fdb829460f 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java @@ -74,7 +74,7 @@ public abstract class XLineBreakpointType

exten return fileLineDisplayText(breakpoint.getPresentableFilePath(), breakpoint.getLine()); } - private String fileLineDisplayText(String path, int line) { + private static String fileLineDisplayText(String path, int line) { return XDebuggerBundle.message("xbreakpoint.default.display.text", line + 1, path); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/RemoveBreakpointGutterIconAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/RemoveBreakpointGutterIconAction.java index ba91f761ab15..7bcc401fb759 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/RemoveBreakpointGutterIconAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/RemoveBreakpointGutterIconAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * 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. @@ -19,12 +19,8 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.xdebugger.XDebuggerBundle; import com.intellij.xdebugger.XDebuggerUtil; -import com.intellij.xdebugger.breakpoints.XBreakpointProperties; -/** -* @author nik -*/ -class RemoveBreakpointGutterIconAction

extends AnAction { +class RemoveBreakpointGutterIconAction extends AnAction { private XBreakpointBase myBreakpoint; RemoveBreakpointGutterIconAction(XBreakpointBase breakpoint) { @@ -35,4 +31,4 @@ class RemoveBreakpointGutterIconAction

extends public void actionPerformed(final AnActionEvent e) { XDebuggerUtil.getInstance().removeBreakpoint(myBreakpoint.getProject(), myBreakpoint); } -} +} \ No newline at end of file diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java index 044682be27be..fe2bfea10f00 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java @@ -345,7 +345,7 @@ public class XBreakpointBase, P extends XBreakpointP } @Override - public int compareTo(Self self) { + public int compareTo(@NotNull Self self) { return myType.getBreakpointComparator().compare((Self)this, self); } From a2768662a1ae81e8f379ae5d5d46daeb588ae133 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 7 Aug 2013 19:28:31 +0200 Subject: [PATCH 03/29] don't look for usage targets in dumb mode, take 2 (EA-48509) --- .../usageView/src/com/intellij/usages/UsageTargetUtil.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/usageView/src/com/intellij/usages/UsageTargetUtil.java b/platform/usageView/src/com/intellij/usages/UsageTargetUtil.java index 7050dbbceca0..9e841dfa53c5 100644 --- a/platform/usageView/src/com/intellij/usages/UsageTargetUtil.java +++ b/platform/usageView/src/com/intellij/usages/UsageTargetUtil.java @@ -21,10 +21,13 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.project.DumbService; +import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -60,7 +63,9 @@ public class UsageTargetUtil { public static UsageTarget[] findUsageTargets(PsiElement psiElement) { List result = new ArrayList(); - for (UsageTargetProvider provider : Extensions.getExtensions(EP_NAME)) { + UsageTargetProvider[] providers = Extensions.getExtensions(EP_NAME); + Project project = psiElement.getProject(); + for (UsageTargetProvider provider : DumbService.getInstance(project).filterByDumbAwareness(Arrays.asList(providers))) { UsageTarget[] targets = provider.getTargets(psiElement); if (targets != null) Collections.addAll(result, targets); } From 92f991b1bdd29925f5186d5389c2c5eb34045539 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Wed, 7 Aug 2013 19:35:12 +0200 Subject: [PATCH 04/29] IDEA-111734 Debug tab labels are always white --- .../openapi/wm/impl/content/ContentTabLabel.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentTabLabel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentTabLabel.java index 06750e5c69a7..7eebc674c8b0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentTabLabel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentTabLabel.java @@ -71,18 +71,18 @@ class ContentTabLabel extends BaseLabel { @Override protected Color getActiveFg(boolean selected) { - if (contentManager().getContentCount() > 1 && selected) { - return Gray._255; - } - return super.getActiveFg(selected); + if (contentManager().getContentCount() > 1) { + return selected ? Color.white : UIUtil.isUnderDarcula() ? UIUtil.getLabelForeground() : Color.black; + } + return super.getActiveFg(selected); } @Override protected Color getPassiveFg(boolean selected) { - if (contentManager().getContentCount() > 1 && selected && !UIUtil.isUnderDarcula()) { - return Gray._255; - } - return super.getPassiveFg(selected); + if (contentManager().getContentCount() > 1) { + return selected && !UIUtil.isUnderDarcula() ? Gray._255 : UIUtil.isUnderDarcula()? UIUtil.getLabelDisabledForeground() : Gray._75; + } + return super.getPassiveFg(selected); } protected void paintComponent(final Graphics g) { From 5c8b98126932dc87f42a63d1c70c4d087592454a Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 7 Aug 2013 19:54:35 +0200 Subject: [PATCH 05/29] EA-48529 (dead loop avoided) --- .../src/com/intellij/psi/impl/source/PsiParameterImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java index bafbd37eac87..9216b164fb66 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java @@ -101,7 +101,7 @@ public class PsiParameterImpl extends JavaStubPsiElement imple @NotNull private PsiElement getParameterIdentifier() { PsiJavaToken identifier = PsiTreeUtil.getChildOfAnyType(this, PsiIdentifier.class, PsiKeyword.class); - assert identifier != null : this; + assert identifier != null : getClass() + ":" + getText(); return identifier; } From 046b65731814eba32f177ecf2521f0c669d72483 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 7 Aug 2013 20:07:34 +0200 Subject: [PATCH 06/29] IDEA-111456 An inspection to check method contract well-formedness --- .../dataFlow/ControlFlowAnalyzer.java | 4 +-- .../dataFlow/DataFlowInspectionBase.java | 30 +++++++++++++++++++ .../psi/PsiConstantEvaluationHelper.java | 2 ++ .../dataFlow/fixture/ContractAnnotation.java | 6 ++++ .../ConstantConditions.html | 19 +++++++----- 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index d927d8cb78a4..bf0fc63be2a2 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -1485,7 +1485,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { return Collections.emptyList(); } - private static List parseContract(String text) throws ParseException { + public static List parseContract(String text) throws ParseException { List result = ContainerUtil.newArrayList(); for (String clause : StringUtil.replace(text, " ", "").split(";")) { String arrow = "->"; @@ -1516,7 +1516,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { throw new ParseException("Constraint should be one of: null, !null, true, false, exit, fail, _. Found: " + name); } - private static class ParseException extends Exception { + public static class ParseException extends Exception { private ParseException(String message) { super(message); } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java index fc58969f5122..7edeb3ac30b7 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java @@ -48,6 +48,7 @@ import com.intellij.util.ArrayUtilRt; import com.intellij.util.IncorrectOperationException; import com.intellij.util.SmartList; import org.jdom.Element; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -98,6 +99,35 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool { public void visitClassInitializer(PsiClassInitializer initializer) { analyzeCodeBlock(initializer.getBody(), holder); } + + @Override + public void visitAnnotation(PsiAnnotation annotation) { + if (!Contract.class.getName().equals(annotation.getQualifiedName())) return; + + PsiMethod method = PsiTreeUtil.getParentOfType(annotation, PsiMethod.class); + if (method == null) return; + + PsiAnnotationMemberValue value = annotation.findAttributeValue(null); + Object text = JavaPsiFacade.getInstance(annotation.getProject()).getConstantEvaluationHelper().computeConstantExpression(value); + if (!(text instanceof String)) return; + + List contracts; + try { + contracts = ControlFlowAnalyzer.parseContract((String)text); + } + catch (ControlFlowAnalyzer.ParseException e) { + holder.registerProblem(value, e.getMessage()); + return; + } + int paramCount = method.getParameterList().getParametersCount(); + for (int i = 0; i < contracts.size(); i++) { + MethodContract contract = contracts.get(i); + if (contract.arguments.length != paramCount) { + holder.registerProblem(value, "Method takes " + paramCount + " parameters, while contract clause " + i + " expects " + contract.arguments.length); + return; + } + } + } }; } diff --git a/java/java-psi-api/src/com/intellij/psi/PsiConstantEvaluationHelper.java b/java/java-psi-api/src/com/intellij/psi/PsiConstantEvaluationHelper.java index 3c377f7da610..290d1bf11b70 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiConstantEvaluationHelper.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiConstantEvaluationHelper.java @@ -15,6 +15,7 @@ */ package com.intellij.psi; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import java.util.concurrent.ConcurrentMap; @@ -33,6 +34,7 @@ public abstract class PsiConstantEvaluationHelper { * @return the result of the evaluation, or null if the expression is not a constant expression. */ @Nullable + @Contract("null -> null") public Object computeConstantExpression(PsiElement expression) { return computeConstantExpression(expression, false); } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/ContractAnnotation.java b/java/java-tests/testData/inspection/dataFlow/fixture/ContractAnnotation.java index f86d79733c73..64bfd011fed6 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/ContractAnnotation.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/ContractAnnotation.java @@ -32,4 +32,10 @@ public class AssertIsNotNull { } Object call() {return new Object();} + + @Contract("a") + void malformedContract() {} + + @Contract("null -> _") + void wrongParameterCount(Object a, boolean b) {} } diff --git a/resources-en/src/inspectionDescriptions/ConstantConditions.html b/resources-en/src/inspectionDescriptions/ConstantConditions.html index 351ad1491158..1e2dd7644de7 100644 --- a/resources-en/src/inspectionDescriptions/ConstantConditions.html +++ b/resources-en/src/inspectionDescriptions/ConstantConditions.html @@ -1,11 +1,16 @@ -This inspection reports those conditions in the specified inspection scope that are -always true or false, -as well as points out where a RuntimeException may be thrown, -based on data flow analysis of the code.
-This inspection also reports Nullable/NotNull contract violations. -Annotations to support the contract can be configured (by default @Nullable/@NotNull annotations from annotations.jar will be used) -
+This inspection analyzes method control and data flow to report possible conditions that are always true or false, +expressions whose value is statically proven to be constant, and situations that can lead to nullability contract violations.

+ +Variables, method parameters and return values marked as @Nullable or @NotNull are treated as nullable (or not-null, respectively) +and used during the analysis to check nullability contracts, e.g. report possible NullPointerException errors.

+ +More complex contracts can be defined using @Contract annotation, for example:

+@Contract("_, null -> null") — method returns null if its second argument is null
+@Contract("_, null -> null; _, !null -> !null") — method returns null if its second argument is null and not-null otherwise
+@Contract("true -> fail") — a typical assertFalse method which throws an exception if true is passed to it
+

+The inspection can be configured to use custom @Nullable/@NotNull annotations (by default the ones from annotations.jar will be used) From 72028347f7d9b9d941f6e64466a6df24eb0df671 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 7 Aug 2013 20:02:42 +0200 Subject: [PATCH 07/29] EA-47867 (diagnostic) --- .../openapi/components/impl/stores/DirectoryBasedStorage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java index 9a066058f8ee..827896f46ae8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java @@ -61,7 +61,7 @@ public class DirectoryBasedStorage implements StateStorage, Disposable { final StateSplitter splitter, Disposable parentDisposable, final PicoContainer picoContainer) { - assert dir.indexOf("$") < 0; + assert !dir.contains("$") : dir; myPathMacroSubstitutor = pathMacroSubstitutor; myDir = FILE_SYSTEM.createFile(dir); mySplitter = splitter; From e777a6d77d0c854c196f7823741710f3d14548c4 Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 6 Aug 2013 21:55:11 +0200 Subject: [PATCH 08/29] ambiguity: forgotten check on class type when check for type args (IDEA-67865) --- .../JavaMethodsConflictResolver.java | 22 ++++++++++++++----- .../genericsHighlighting/IDEA67865.java | 11 ++++++++++ .../daemon/GenericsHighlightingTest.java | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA67865.java diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java index 50218fe92adf..4e6fa6c6cec0 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java @@ -616,19 +616,31 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ final Map map1 = classSubstitutor1.getSubstitutionMap(); final Map map2 = classSubstitutor2.getSubstitutionMap(); if (map1.size() == 1 && map2.size() == 1) { + boolean leftAssignable = InheritanceUtil.isInheritorOrSelf(aClass2, aClass1, true); + boolean rightAssignable = InheritanceUtil.isInheritorOrSelf(aClass1, aClass2, true); final PsiType t1 = map1.values().iterator().next(); final PsiType t2 = map2.values().iterator().next(); boolean raw1 = t1 instanceof PsiClassType && ((PsiClassType)t1).hasParameters(); boolean raw2 = t2 instanceof PsiClassType && ((PsiClassType)t2).hasParameters(); - if (!raw1 && raw2) return Specifics.FIRST; - if (raw1 && !raw2) return Specifics.SECOND; + if (!raw1 && raw2) return leftAssignable ? Specifics.FIRST : Specifics.NEITHER; + if (raw1 && !raw2) return rightAssignable ? Specifics.SECOND : Specifics.NEITHER; final PsiTypeParameter p1 = map1.keySet().iterator().next(); final PsiTypeParameter p2 = map2.keySet().iterator().next(); - final Specifics specifics = checkTypeParams(method1, method2, classSubstitutor1, classSubstitutor2, type1, type2, p1, p2); - if (specifics != null) return specifics; - return chooseHigherDimension(t1, t2); + Specifics specifics = checkTypeParams(method1, method2, classSubstitutor1, classSubstitutor2, type1, type2, p1, p2); + if (specifics == null) { + specifics = chooseHigherDimension(t1, t2); + } + if (specifics != null) { + if (specifics == Specifics.FIRST) { + if (leftAssignable && !rightAssignable) return Specifics.NEITHER; + } + else if (specifics == Specifics.SECOND) { + if (rightAssignable && !leftAssignable) return Specifics.NEITHER; + } + } + return specifics; } return null; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA67865.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA67865.java new file mode 100644 index 000000000000..ab7d8cf9cc2d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA67865.java @@ -0,0 +1,11 @@ +import java.util.*; + +abstract class A { + static void foo(List x) { } + static > void foo(Collection x) { } + public static void main(String[] args){ + List> x = null; + foo(x); + foo(null); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index dda5aecf3a81..efc253f27847 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -309,6 +309,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIDEA57289() { doTest5(false); } public void testIDEA57439() { doTest5(false); } public void testIDEA57312() { doTest5(false); } + public void testIDEA67865() { doTest5(false); } public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule())); From 055fcbce5316782d65c1143432aa8babb4ec4963 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 8 Aug 2013 08:18:28 +0200 Subject: [PATCH 09/29] hopefully more stable JavaAutoPopupTest --- .../codeInsight/completion/JavaAutoPopupTest.groovy | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 a4686a857c9e..0a31d5eb15f4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -63,14 +63,19 @@ class JavaAutoPopupTest extends CompletionAutoPopupTestCase { } """) type('i') - assertContains("iterable", "if", "int") + def les = myFixture.lookupElementStrings + assert 'iterable' in les + assert 'if' in les + assert 'int' in les type('t') assertContains "iterable" assertEquals 'iterable', lookup.currentItem.lookupString type('er') - assertContains "iterable", "iter" + les = myFixture.lookupElementStrings + assert 'iterable' in les + assert 'iter' in les assertEquals 'iterable', lookup.currentItem.lookupString assert lookup.focused From 12ce2489b755f83119672a5865527f9a36b1404d Mon Sep 17 00:00:00 2001 From: Evgeny Pasynkov Date: Wed, 7 Aug 2013 12:58:41 +0200 Subject: [PATCH 10/29] fix MemberImplementorExplorer/MethodImplementor extension points duality --- ...emberImplementorExplorersProviderImpl.java | 25 +++++++++++++++ .../MemberImplementorExplorer.java | 6 +--- .../OverrideImplementExploreUtil.java | 31 ++++++++++++++----- resources/src/META-INF/IdeaPlugin.xml | 3 ++ 4 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 java/java-impl/src/com/intellij/codeInsight/generation/MemberImplementorExplorersProviderImpl.java diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/MemberImplementorExplorersProviderImpl.java b/java/java-impl/src/com/intellij/codeInsight/generation/MemberImplementorExplorersProviderImpl.java new file mode 100644 index 000000000000..704115d2a793 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/generation/MemberImplementorExplorersProviderImpl.java @@ -0,0 +1,25 @@ +/* + * 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 com.intellij.codeInsight.generation; + +import com.intellij.codeInsight.MemberImplementorExplorer; + +public class MemberImplementorExplorersProviderImpl implements OverrideImplementExploreUtil.MemberImplementorExplorersProvider { + @Override + public MemberImplementorExplorer[] getExplorers() { + return OverrideImplementUtil.getImplementors(); + } +} diff --git a/java/java-psi-api/src/com/intellij/codeInsight/MemberImplementorExplorer.java b/java/java-psi-api/src/com/intellij/codeInsight/MemberImplementorExplorer.java index 55b3c493db7c..288b81238854 100644 --- a/java/java-psi-api/src/com/intellij/codeInsight/MemberImplementorExplorer.java +++ b/java/java-psi-api/src/com/intellij/codeInsight/MemberImplementorExplorer.java @@ -1,13 +1,9 @@ package com.intellij.codeInsight; -import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiMethod; import org.jetbrains.annotations.NotNull; public interface MemberImplementorExplorer { - ExtensionPointName EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.methodImplementor"); - - @NotNull - PsiMethod[] getMethodsToImplement(PsiClass aClass); + @NotNull PsiMethod[] getMethodsToImplement(PsiClass aClass); } diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java b/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java index 6c273b2b8316..f8991e62cbc5 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java @@ -1,8 +1,10 @@ package com.intellij.codeInsight.generation; import com.intellij.codeInsight.MemberImplementorExplorer; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.util.NullableLazyValue; +import com.intellij.openapi.util.VolatileNullableLazyValue; import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; @@ -111,6 +113,17 @@ public class OverrideImplementExploreUtil { } } + public interface MemberImplementorExplorersProvider { + MemberImplementorExplorer[] getExplorers(); + } + + private static final NullableLazyValue ourExplorersProvider = new VolatileNullableLazyValue() { + @Override + protected MemberImplementorExplorersProvider compute() { + return ServiceManager.getService(MemberImplementorExplorersProvider.class); + } + }; + public static void collectMethodsToImplement(PsiClass aClass, Map abstracts, Map finals, @@ -132,12 +145,16 @@ public class OverrideImplementExploreUtil { } } - for (final MemberImplementorExplorer implementor : Extensions.getExtensions(MemberImplementorExplorer.EXTENSION_POINT_NAME)) { - for (final PsiMethod method : implementor.getMethodsToImplement(aClass)) { - MethodSignature signature = MethodSignatureUtil.createMethodSignature(method.getName(), method.getParameterList(), - method.getTypeParameterList(), PsiSubstitutor.EMPTY, method.isConstructor()); - CandidateInfo info = new CandidateInfo(method, PsiSubstitutor.EMPTY); - result.put(signature, info); + MemberImplementorExplorersProvider explorersProvider = ourExplorersProvider.getValue(); + if (explorersProvider != null) { + for (final MemberImplementorExplorer implementor : explorersProvider.getExplorers()) { + for (final PsiMethod method : implementor.getMethodsToImplement(aClass)) { + MethodSignature signature = MethodSignatureUtil.createMethodSignature(method.getName(), method.getParameterList(), + method.getTypeParameterList(), PsiSubstitutor.EMPTY, + method.isConstructor()); + CandidateInfo info = new CandidateInfo(method, PsiSubstitutor.EMPTY); + result.put(signature, info); + } } } } diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 9c1d4fc51fe8..27c7454722e6 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -399,6 +399,9 @@ + + Date: Thu, 8 Aug 2013 10:38:26 +0400 Subject: [PATCH 11/29] Github: IDEA-111656 remove useless checkbox --- .../jetbrains/plugins/github/tasks/GithubRepositoryEditor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java index d2b4a8728ba1..0a4f52f1077d 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java +++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java @@ -42,6 +42,7 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor Date: Thu, 8 Aug 2013 10:40:27 +0400 Subject: [PATCH 12/29] Github: autodetect private repo in token generation --- .../plugins/github/api/GithubApiUtil.java | 12 ++++- .../github/tasks/GithubRepositoryEditor.java | 52 +++---------------- 2 files changed, 17 insertions(+), 47 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java index 107476f56160..4d76d327e7fd 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java @@ -409,6 +409,16 @@ public class GithubApiUtil { return response.getToken(); } + @NotNull + public static String getReadOnlyToken(@NotNull GithubAuthData auth, @NotNull String user, @NotNull String repo, @Nullable String note) + throws IOException { + GithubRepo repository = getDetailedRepoInfo(auth, user, repo); + + List scopes = repository.isPrivate() ? Collections.singletonList("repo") : Collections.emptyList(); + + return getScopedToken(auth, scopes, note); + } + @NotNull public static GithubUser getCurrentUser(@NotNull GithubAuthData auth) throws IOException { JsonElement result = getRequest(auth, "/user"); @@ -643,4 +653,4 @@ public class GithubApiUtil { return null; } -} \ No newline at end of file +} diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java index 0a4f52f1077d..8f36399ff444 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java +++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java @@ -13,16 +13,16 @@ import com.intellij.util.ThrowableConvertor; import com.intellij.util.ui.FormBuilder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.github.*; import org.jetbrains.plugins.github.GithubAuthData; +import org.jetbrains.plugins.github.GithubAuthenticationCanceledException; +import org.jetbrains.plugins.github.GithubNotifications; +import org.jetbrains.plugins.github.GithubUtil; import org.jetbrains.plugins.github.api.GithubApiUtil; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; -import java.util.Collection; -import java.util.Collections; /** * @author Dennis.Ushakov @@ -34,7 +34,6 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor changeListener) { super(project, repository, changeListener); @@ -47,7 +46,6 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor> scopesRef = new Ref>(); - final Ref exceptionRef = new Ref(); - ProgressManager.getInstance().run(new Task.Modal(myProject, "Access to GitHub", true) { - public void run(@NotNull ProgressIndicator indicator) { - try { - scopesRef - .set(GithubApiUtil.getTokenScopes(GithubAuthData.createTokenAuth(myURLText.getText().trim(), myToken.getText().trim()))); - } - catch (IOException e) { - exceptionRef.set(e); - } - } - }); - if (!exceptionRef.isNull()) { - GithubNotifications.showErrorDialog(myProject, "Can't check token scopes", exceptionRef.get()); - return; - } - Collection scopes = scopesRef.get(); - if (myPrivateRepo.isSelected()) { - scopes.remove("repo"); - } - if (scopes.isEmpty()) { - return; - } - GithubNotifications - .showWarningDialog(myProject, "Unneeded token scopes detected", "Unneeded scopes: " + StringUtil.join(scopes, ", ")); - } - } - private void generateToken() { final Ref tokenRef = new Ref(); final Ref exceptionRef = new Ref(); - final Collection scopes = myPrivateRepo.isSelected() ? Collections.singleton("repo") : Collections.emptyList(); ProgressManager.getInstance().run(new Task.Modal(myProject, "Access to GitHub", true) { public void run(@NotNull ProgressIndicator indicator) { try { tokenRef.set(GithubUtil.runWithValidBasicAuth(myProject, indicator, new ThrowableConvertor() { - @Nullable + @NotNull @Override public String convert(GithubAuthData auth) throws IOException { - return GithubApiUtil.getScopedToken(auth, scopes, "Intellij tasks plugin"); - + return GithubApiUtil.getReadOnlyToken(auth, myRepoAuthor.getText(), myRepoName.getText(), "Intellij tasks plugin"); } })); } From a7ff79c23a2297bbc649c46a4a0c8323b4bce4fa Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 8 Aug 2013 10:40:55 +0400 Subject: [PATCH 13/29] Github: IDEA-111659 Use separate "Create token" button --- .../github/tasks/GithubRepositoryEditor.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java index 8f36399ff444..6205b0408db0 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java +++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java @@ -20,6 +20,7 @@ import org.jetbrains.plugins.github.GithubUtil; import org.jetbrains.plugins.github.api.GithubApiUtil; import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; @@ -34,6 +35,7 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor changeListener) { super(project, repository, changeListener); @@ -55,7 +57,7 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor Date: Thu, 8 Aug 2013 10:41:29 +0400 Subject: [PATCH 14/29] Github: don't throw AuthentificationException on IOException --- .../src/org/jetbrains/plugins/github/GithubUtil.java | 10 +++------- .../jetbrains/plugins/github/api/GithubApiUtil.java | 1 - 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java index a6edc0229575..9a175739cf4b 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java @@ -35,7 +35,8 @@ import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.github.api.*; +import org.jetbrains.plugins.github.api.GithubApiUtil; +import org.jetbrains.plugins.github.api.GithubUserDetailed; import org.jetbrains.plugins.github.ui.GithubBasicLoginDialog; import org.jetbrains.plugins.github.ui.GithubLoginDialog; @@ -232,12 +233,7 @@ public class GithubUtil { throw new GithubAuthenticationException("Anonymous connection not allowed"); } - try { - return testConnection(auth); - } - catch (JsonException e) { - throw new GithubAuthenticationException("Can't get user info", e); - } + return testConnection(auth); } @NotNull diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java index 4d76d327e7fd..946d1c3fdff6 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java @@ -207,7 +207,6 @@ public class GithubApiUtil { case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_PAYMENT_REQUIRED: case HttpStatus.SC_FORBIDDEN: - case HttpStatus.SC_NOT_FOUND: throw new GithubAuthenticationException("Request response: " + getErrorMessage(method)); default: throw new HttpException(code + ": " + getErrorMessage(method)); From c6e5317091cb680146eff2cf9186095438f44bdf Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 8 Aug 2013 10:42:07 +0400 Subject: [PATCH 15/29] Github: remember status code for exception caused by server reply --- .../plugins/github/api/GithubApiUtil.java | 2 +- .../github/api/GithubStatusCodeException.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 plugins/github/src/org/jetbrains/plugins/github/api/GithubStatusCodeException.java diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java index 946d1c3fdff6..67373a0f6351 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java @@ -209,7 +209,7 @@ public class GithubApiUtil { case HttpStatus.SC_FORBIDDEN: throw new GithubAuthenticationException("Request response: " + getErrorMessage(method)); default: - throw new HttpException(code + ": " + getErrorMessage(method)); + throw new GithubStatusCodeException(code + ": " + getErrorMessage(method), code); } } diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubStatusCodeException.java b/plugins/github/src/org/jetbrains/plugins/github/api/GithubStatusCodeException.java new file mode 100644 index 000000000000..3b15c000d900 --- /dev/null +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubStatusCodeException.java @@ -0,0 +1,34 @@ +/* + * 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.github.api; + +import java.io.IOException; + +/** + * @author Aleksey Pivovarov + */ +public class GithubStatusCodeException extends IOException { + private final int myStatusCode; + + public GithubStatusCodeException(String message, int statusCode) { + super(message); + myStatusCode = statusCode; + } + + public int getStatusCode() { + return myStatusCode; + } +} From be7803469a72e3e9f17bc0ba43689205f0e27aad Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 8 Aug 2013 10:42:30 +0400 Subject: [PATCH 16/29] Github: disable button on empty parameters --- .../github/tasks/GithubRepositoryEditor.java | 62 +++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java index 6205b0408db0..86751e2da714 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java +++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java @@ -20,6 +20,8 @@ import org.jetbrains.plugins.github.GithubUtil; import org.jetbrains.plugins.github.api.GithubApiUtil; import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -49,6 +51,27 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor Date: Thu, 8 Aug 2013 10:42:54 +0400 Subject: [PATCH 17/29] Github: ask for credentials for correct host --- .../jetbrains/plugins/github/GithubUtil.java | 22 ++++++++++++------- .../github/tasks/GithubRepositoryEditor.java | 17 ++++++++------ .../plugins/github/ui/GithubLoginDialog.java | 5 ++++- .../plugins/github/ui/GithubLoginPanel.java | 7 +++++- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java index 9a175739cf4b..9e2e8ac5a315 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java @@ -110,12 +110,15 @@ public class GithubUtil { } @NotNull - public static T runWithValidBasicAuth(@Nullable Project project, - @NotNull ProgressIndicator indicator, - @NotNull ThrowableConvertor task) throws IOException { + public static T runWithValidBasicAuthForHost(@Nullable Project project, + @NotNull ProgressIndicator indicator, + @NotNull String host, + @NotNull ThrowableConvertor task) throws IOException { + GithubSettings settings = GithubSettings.getInstance(); GithubAuthData auth; - if (GithubSettings.getInstance().getAuthType() == GithubAuthData.AuthType.BASIC) { - auth = GithubSettings.getInstance().getAuthData(); + if (settings.getAuthType() == GithubAuthData.AuthType.BASIC && + StringUtil.equalsIgnoreCase(GithubUrlUtil.getApiUrl(host), GithubUrlUtil.getApiUrl(settings.getHost()))) { + auth = settings.getAuthData(); } else { auth = GithubAuthData.createAnonymous(); @@ -127,7 +130,7 @@ public class GithubUtil { return task.convert(auth); } catch (GithubAuthenticationException e) { - auth = getValidBasicAuthData(project, indicator); + auth = getValidBasicAuthDataForHost(project, indicator, host); if (auth == null) { throw new GithubAuthenticationCanceledException("Can't get valid credentials"); } @@ -135,7 +138,7 @@ public class GithubUtil { } catch (IOException e) { if (checkSSLCertificate(e, auth.getHost(), indicator)) { - return runWithValidBasicAuth(project, indicator, task); + return runWithValidBasicAuthForHost(project, indicator, host, task); } throw e; } @@ -178,8 +181,11 @@ public class GithubUtil { * @return null if user canceled login dialog. Valid GithubAuthData otherwise. */ @Nullable - public static GithubAuthData getValidBasicAuthData(@Nullable Project project, @NotNull ProgressIndicator indicator) { + public static GithubAuthData getValidBasicAuthDataForHost(@Nullable Project project, + @NotNull ProgressIndicator indicator, + @NotNull String host) { final GithubLoginDialog dialog = new GithubBasicLoginDialog(project); + dialog.lockHost(host); ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java index 86751e2da714..df1fd7f38515 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java +++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java @@ -122,13 +122,16 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor() { - @NotNull - @Override - public String convert(GithubAuthData auth) throws IOException { - return GithubApiUtil.getReadOnlyToken(auth, getRepoAuthor(), getRepoName(), "Intellij tasks plugin"); - } - })); + tokenRef.set(GithubUtil.runWithValidBasicAuthForHost(myProject, indicator, getHost(), + new ThrowableConvertor() { + @NotNull + @Override + public String convert(GithubAuthData auth) throws IOException { + return GithubApiUtil + .getReadOnlyToken(auth, getRepoAuthor(), getRepoName(), + "Intellij tasks plugin"); + } + })); } catch (IOException e) { exceptionRef.set(e); diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java index 402cb4eb1a9a..fc21d6be7429 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java @@ -6,7 +6,6 @@ import com.intellij.openapi.ui.DialogWrapper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.github.GithubAuthData; -import org.jetbrains.plugins.github.GithubAuthenticationException; import org.jetbrains.plugins.github.GithubSettings; import org.jetbrains.plugins.github.GithubUtil; import org.jetbrains.plugins.github.api.GithubUserDetailed; @@ -102,4 +101,8 @@ public class GithubLoginDialog extends DialogWrapper { public GithubAuthData getAuthData() { return myGithubLoginPanel.getAuthData(); } + + public void lockHost(String host) { + myGithubLoginPanel.lockHost(host); + } } \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java index 226265546db1..c4a975a52a03 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java @@ -31,7 +31,7 @@ import javax.swing.event.HyperlinkEvent; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -import java.util.*; +import java.util.ArrayList; import java.util.List; /** @@ -125,6 +125,11 @@ public class GithubLoginPanel { myAuthTypeComboBox.setEnabled(false); } + public void lockHost(@NotNull String host) { + setHost(host); + myHostTextField.setEnabled(false); + } + public void setSavePasswordSelected(boolean savePassword) { mySavePasswordCheckBox.setSelected(savePassword); } From 263784cab91ff89eb1aa2b4d9101f35935bbd0d7 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 8 Aug 2013 10:43:12 +0400 Subject: [PATCH 18/29] Github: fix javadoc --- .../src/org/jetbrains/plugins/github/api/DataConstructor.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/DataConstructor.java b/plugins/github/src/org/jetbrains/plugins/github/api/DataConstructor.java index d0005c12a858..20a957ccf746 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/DataConstructor.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/DataConstructor.java @@ -19,9 +19,7 @@ import org.jetbrains.annotations.NotNull; /** * @author Aleksey Pivovarov - */ - -/** + * * All fields of the raw type are nullable by the nature of GSon parser; * but some of them are required, so we want them to be @NotNull in the actual data class, * otherwise there is an error in JSon data received from the server From 581293a32309959a5b2da0f6929b7a16ea6f7806 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 8 Aug 2013 10:43:37 +0400 Subject: [PATCH 19/29] Github: use string constant --- .../plugins/github/api/GithubApiUtil.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java index 67373a0f6351..01579097139e 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java @@ -43,6 +43,7 @@ public class GithubApiUtil { public static final String DEFAULT_GITHUB_HOST = "github.com"; private static final int CONNECTION_TIMEOUT = 5000; + private static final String PER_PAGE = "per_page=100"; private static final Logger LOG = GithubUtil.LOG; private static final Header ACCEPT_HTML_BODY_MARKUP = new Header("Accept", "application/vnd.github.v3.html+json"); @@ -442,7 +443,7 @@ public class GithubApiUtil { @NotNull private static List doGetAvailableRepos(@NotNull GithubAuthData auth, @Nullable String user) throws IOException { - String path = user == null ? "/user/repos" : "/users/" + user + "/repos?per_page=100"; + String path = user == null ? "/user/repos" : "/users/" + user + "/repos?" + PER_PAGE; PagedRequest request = new PagedRequest(path, GithubRepo.class, GithubRepoRaw[].class); @@ -518,10 +519,10 @@ public class GithubApiUtil { @Nullable String assigned) throws IOException { String path; if (StringUtil.isEmptyOrSpaces(assigned)) { - path = "/repos/" + user + "/" + repo + "/issues?per_page=100"; + path = "/repos/" + user + "/" + repo + "/issues?" + PER_PAGE; } else { - path = "/repos/" + user + "/" + repo + "/issues?assignee=" + assigned + "&per_page=100"; + path = "/repos/" + user + "/" + repo + "/issues?assignee=" + assigned + "&" + PER_PAGE; } PagedRequest request = new PagedRequest(path, GithubIssue.class, GithubIssueRaw[].class); @@ -558,7 +559,7 @@ public class GithubApiUtil { @NotNull public static List getIssueComments(@NotNull GithubAuthData auth, @NotNull String user, @NotNull String repo, long id) throws IOException { - String path = "/repos/" + user + "/" + repo + "/issues/" + id + "/comments?per_page=100"; + String path = "/repos/" + user + "/" + repo + "/issues/" + id + "/comments?" + PER_PAGE; PagedRequest request = new PagedRequest(path, GithubIssueComment.class, GithubIssueCommentRaw[].class, ACCEPT_HTML_BODY_MARKUP); @@ -588,7 +589,7 @@ public class GithubApiUtil { @NotNull public static List getPullRequests(@NotNull GithubAuthData auth, @NotNull String user, @NotNull String repo) throws IOException { - String path = "/repos/" + user + "/" + repo + "/pulls?per_page=100"; + String path = "/repos/" + user + "/" + repo + "/pulls?" + PER_PAGE; PagedRequest request = new PagedRequest(path, GithubPullRequest.class, GithubPullRequestRaw[].class, ACCEPT_HTML_BODY_MARKUP); @@ -598,7 +599,7 @@ public class GithubApiUtil { @NotNull public static PagedRequest getPullRequests(@NotNull String user, @NotNull String repo) { - String path = "/repos/" + user + "/" + repo + "/pulls?per_page=100"; + String path = "/repos/" + user + "/" + repo + "/pulls?" + PER_PAGE; return new PagedRequest(path, GithubPullRequest.class, GithubPullRequestRaw[].class, ACCEPT_HTML_BODY_MARKUP); } @@ -606,7 +607,7 @@ public class GithubApiUtil { @NotNull public static List getPullRequestCommits(@NotNull GithubAuthData auth, @NotNull String user, @NotNull String repo, long id) throws IOException { - String path = "/repos/" + user + "/" + repo + "/pulls/" + id + "/commits?per_page=100"; + String path = "/repos/" + user + "/" + repo + "/pulls/" + id + "/commits?" + PER_PAGE; PagedRequest request = new PagedRequest(path, GithubCommit.class, GithubCommitRaw[].class); @@ -616,7 +617,7 @@ public class GithubApiUtil { @NotNull public static List getPullRequestFiles(@NotNull GithubAuthData auth, @NotNull String user, @NotNull String repo, long id) throws IOException { - String path = "/repos/" + user + "/" + repo + "/pulls/" + id + "/files?per_page=100"; + String path = "/repos/" + user + "/" + repo + "/pulls/" + id + "/files?" + PER_PAGE; PagedRequest request = new PagedRequest(path, GithubFile.class, GithubFileRaw[].class); @@ -626,7 +627,7 @@ public class GithubApiUtil { @NotNull public static List getRepoBranches(@NotNull GithubAuthData auth, @NotNull String user, @NotNull String repo) throws IOException { - String path = "/repos/" + user + "/" + repo + "/branches?per_page=100"; + String path = "/repos/" + user + "/" + repo + "/branches?" + PER_PAGE; PagedRequest request = new PagedRequest(path, GithubBranch.class, GithubBranchRaw[].class); @@ -638,7 +639,7 @@ public class GithubApiUtil { @NotNull String user, @NotNull String repo, @NotNull String forkUser) throws IOException { - String path = "/repos/" + user + "/" + repo + "/forks?per_page=100"; + String path = "/repos/" + user + "/" + repo + "/forks?" + PER_PAGE; PagedRequest request = new PagedRequest(path, GithubRepo.class, GithubRepoRaw[].class); From 22cc63937c8978850b65c9769a93bdb4767295ae Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 8 Aug 2013 10:44:03 +0400 Subject: [PATCH 20/29] Github: IDEA-92009 update repository before search for upstream remote --- .../src/org/jetbrains/plugins/github/GithubRebaseAction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java index e2f00946629f..a233c06a634f 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java @@ -115,6 +115,7 @@ public class GithubRebaseAction extends DumbAwareAction { new Task.Backgroundable(project, "Rebasing GitHub fork...") { @Override public void run(@NotNull ProgressIndicator indicator) { + gitRepository.update(); String upstreamRemoteUrl = GithubUtil.findUpstreamRemote(gitRepository); if (upstreamRemoteUrl == null) { From 512c017efc5b4c5fac8d2568bebf19edb9cb938e Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 8 Aug 2013 10:44:33 +0400 Subject: [PATCH 21/29] Github: IDEA-111654 IDEA-111653 Remove login field for token authentication --- .../github/GithubCreatePullRequestAction.java | 2 +- .../plugins/github/GithubRebaseAction.java | 7 ++- .../plugins/github/GithubSettings.java | 29 +++++---- .../github/ui/GithubBasicLoginDialog.java | 3 +- .../plugins/github/ui/GithubLoginDialog.java | 10 +-- .../plugins/github/ui/GithubLoginPanel.form | 40 ++++++------ .../plugins/github/ui/GithubLoginPanel.java | 21 ++++++- .../github/ui/GithubSettingsConfigurable.java | 2 +- .../github/ui/GithubSettingsPanel.form | 2 +- .../github/ui/GithubSettingsPanel.java | 62 +++++++++++-------- .../plugins/github/test/GithubTest.java | 2 +- 11 files changed, 102 insertions(+), 78 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java index 60e6bb91ea4d..50b3a0f20ae7 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java @@ -71,7 +71,7 @@ public class GithubCreatePullRequestAction extends DumbAwareAction { return; } - if (StringUtil.isEmptyOrSpaces(GithubSettings.getInstance().getLogin())) { + if (!GithubSettings.getInstance().isAuthConfigured()) { setVisibleEnabled(e, false, false); return; } diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java index a233c06a634f..bdbf6b0dc635 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java @@ -23,7 +23,6 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ThrowableConvertor; @@ -42,7 +41,9 @@ import git4idea.util.GitPreservingProcess; import icons.GithubIcons; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.github.api.*; +import org.jetbrains.plugins.github.api.GithubApiUtil; +import org.jetbrains.plugins.github.api.GithubFullPath; +import org.jetbrains.plugins.github.api.GithubRepoDetailed; import java.io.IOException; import java.util.Collections; @@ -71,7 +72,7 @@ public class GithubRebaseAction extends DumbAwareAction { return; } - if (StringUtil.isEmptyOrSpaces(GithubSettings.getInstance().getLogin())) { + if (!GithubSettings.getInstance().isAuthConfigured()) { setVisibleEnabled(e, false, false); return; } diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubSettings.java b/plugins/github/src/org/jetbrains/plugins/github/GithubSettings.java index 6ac53c59a92f..eea92d913e53 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubSettings.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubSettings.java @@ -23,9 +23,11 @@ import com.intellij.openapi.components.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.github.api.GithubApiUtil; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; import static org.jetbrains.plugins.github.GithubAuthData.AuthType; @@ -52,15 +54,15 @@ public class GithubSettings implements PersistentStateComponent TRUSTED_HOSTS = new ArrayList(); - public String CREATE_PULL_REQUEST_DEFAULT_BRANCH = ""; + @NotNull public Collection TRUSTED_HOSTS = new ArrayList(); + @NotNull public String CREATE_PULL_REQUEST_DEFAULT_BRANCH = ""; } public static GithubSettings getInstance() { @@ -72,8 +74,7 @@ public class GithubSettings implements PersistentStateComponent - + - - - - - - - - - - - - - - - - @@ -71,7 +55,7 @@ - + @@ -80,7 +64,7 @@ - + @@ -91,7 +75,7 @@ - + @@ -105,6 +89,22 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java index c4a975a52a03..ea565e03c5c9 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginPanel.java @@ -21,6 +21,7 @@ import com.intellij.ui.HyperlinkAdapter; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.table.ComponentsListFocusTraversalPolicy; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.github.GithubAuthData; import org.jetbrains.plugins.github.GithubUtil; @@ -47,6 +48,7 @@ public class GithubLoginPanel { private JCheckBox mySavePasswordCheckBox; private JComboBox myAuthTypeComboBox; private JLabel myPasswordLabel; + private JLabel myLoginLabel; private final static String AUTH_PASSWORD = "Password"; private final static String AUTH_TOKEN = "Token"; @@ -79,8 +81,21 @@ public class GithubLoginPanel { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { String item = e.getItem().toString(); - myPasswordLabel.setText(item + ":"); - mySavePasswordCheckBox.setText("Save " + item.toLowerCase()); + if (AUTH_PASSWORD.equals(item)) { + myPasswordLabel.setText("Password:"); + mySavePasswordCheckBox.setText("Save password"); + myLoginLabel.setVisible(true); + myLoginTextField.setVisible(true); + } + if (AUTH_TOKEN.equals(item)) { + myPasswordLabel.setText("Token:"); + mySavePasswordCheckBox.setText("Save token"); + myLoginLabel.setVisible(false); + myLoginTextField.setVisible(false); + } + if (dialog.isShowing()) { + dialog.pack(); + } } } }); @@ -103,7 +118,7 @@ public class GithubLoginPanel { myHostTextField.setText(host); } - public void setLogin(@NotNull String login) { + public void setLogin(@Nullable String login) { myLoginTextField.setText(login); } diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsConfigurable.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsConfigurable.java index 03e3b08801ef..f4c312d11b13 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsConfigurable.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsConfigurable.java @@ -46,7 +46,7 @@ public class GithubSettingsConfigurable implements SearchableConfigurable, VcsCo public void apply() throws ConfigurationException { if (mySettingsPane != null) { - mySettings.setCredentials(mySettingsPane.getHost(), mySettingsPane.getLogin(), mySettingsPane.getAuthData(), true); + mySettings.setCredentials(mySettingsPane.getHost(), mySettingsPane.getAuthData(), true); mySettingsPane.resetCredentialsModification(); } } diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form index 81400ae3000e..cc283855bc64 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form @@ -16,7 +16,7 @@ - + diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java index c6a18378802e..c1f2037bb481 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java @@ -22,8 +22,11 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.HyperlinkAdapter; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.github.*; -import org.jetbrains.plugins.github.api.GithubUserDetailed; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.github.GithubAuthData; +import org.jetbrains.plugins.github.GithubAuthenticationException; +import org.jetbrains.plugins.github.GithubSettings; +import org.jetbrains.plugins.github.GithubUtil; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -53,6 +56,7 @@ public class GithubSettingsPanel { private JButton myTestButton; private JTextField myHostTextField; private JComboBox myAuthTypeComboBox; + private JLabel myLoginLabel; private boolean myCredentialsModified; @@ -71,18 +75,11 @@ public class GithubSettingsPanel { myAuthTypeComboBox.addItem(AUTH_PASSWORD); myAuthTypeComboBox.addItem(AUTH_TOKEN); - reset(); - myTestButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { - GithubUserDetailed user = GithubUtil.checkAuthData(getAuthData()); - if (!getLogin().equalsIgnoreCase(user.getLogin())) { - setLogin(user.getLogin()); - Messages.showInfoMessage(myPane, "Login doesn't match credentials. Fixed", "Success"); - return; - } + GithubUtil.checkAuthData(getAuthData()); Messages.showInfoMessage(myPane, "Connection successful", "Success"); } catch (GithubAuthenticationException ex) { @@ -116,24 +113,21 @@ public class GithubSettingsPanel { @Override public void insertUpdate(DocumentEvent e) { if (!myCredentialsModified) { - setPassword(""); - myCredentialsModified = true; + erasePassword(); } } @Override public void removeUpdate(DocumentEvent e) { if (!myCredentialsModified) { - setPassword(""); - myCredentialsModified = true; + erasePassword(); } } @Override public void changedUpdate(DocumentEvent e) { if (!myCredentialsModified) { - setPassword(""); - myCredentialsModified = true; + erasePassword(); } } }; @@ -145,8 +139,7 @@ public class GithubSettingsPanel { @Override public void focusGained(FocusEvent e) { if (!myCredentialsModified && !getPassword().isEmpty()) { - setPassword(""); - myCredentialsModified = true; + erasePassword(); } } @@ -158,10 +151,28 @@ public class GithubSettingsPanel { myAuthTypeComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { - setPassword(""); - myCredentialsModified = true; + if (e.getStateChange() == ItemEvent.SELECTED) { + String item = e.getItem().toString(); + if (AUTH_PASSWORD.equals(item)) { + myLoginLabel.setVisible(true); + myLoginTextField.setVisible(true); + } + if (AUTH_TOKEN.equals(item)) { + myLoginLabel.setVisible(false); + myLoginTextField.setVisible(false); + } + myPane.validate(); + erasePassword(); + } } }); + + reset(); + } + + private void erasePassword() { + setPassword(""); + myCredentialsModified = true; } public JComponent getPanel() { @@ -182,7 +193,7 @@ public class GithubSettingsPanel { myHostTextField.setText(host); } - public void setLogin(@NotNull final String login) { + public void setLogin(@Nullable final String login) { myLoginTextField.setText(login); } @@ -232,18 +243,15 @@ public class GithubSettingsPanel { } public void reset() { - String login = mySettings.getLogin(); setHost(mySettings.getHost()); - setLogin(login); - setPassword(login.isEmpty() ? "" : DEFAULT_PASSWORD_TEXT); + setLogin(mySettings.getLogin()); + setPassword(mySettings.isAuthConfigured() ? DEFAULT_PASSWORD_TEXT : ""); setAuthType(mySettings.getAuthType()); resetCredentialsModification(); } public boolean isModified() { - return !Comparing.equal(mySettings.getHost(), getHost()) || - !Comparing.equal(mySettings.getLogin(), getLogin()) || - myCredentialsModified; + return !Comparing.equal(mySettings.getHost(), getHost()) || myCredentialsModified; } public void resetCredentialsModification() { diff --git a/plugins/github/test/org/jetbrains/plugins/github/test/GithubTest.java b/plugins/github/test/org/jetbrains/plugins/github/test/GithubTest.java index 21c78af951dd..ee5233c8057e 100644 --- a/plugins/github/test/org/jetbrains/plugins/github/test/GithubTest.java +++ b/plugins/github/test/org/jetbrains/plugins/github/test/GithubTest.java @@ -173,7 +173,7 @@ public abstract class GithubTest extends UsefulTestCase { myAuth = GithubAuthData.createBasicAuth(host, login1, password); myGitHubSettings = GithubSettings.getInstance(); - myGitHubSettings.setCredentials(myHost, myLogin1, myAuth, false); + myGitHubSettings.setCredentials(myHost, myAuth, false); myDialogManager = (TestDialogManager)ServiceManager.getService(DialogManager.class); myNotificator = (TestNotificator)ServiceManager.getService(myProject, Notificator.class); From c1218f19f14313ada047bc434527604e1684e60b Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 8 Aug 2013 10:44:55 +0400 Subject: [PATCH 22/29] Github: fix issue with enterprise server (406: Not Acceptable) --- .../src/org/jetbrains/plugins/github/api/GithubApiUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java index 01579097139e..26e75d66d402 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java @@ -375,7 +375,7 @@ public class GithubApiUtil { public static Collection getTokenScopes(@NotNull GithubAuthData auth) throws IOException { HttpMethod method = null; try { - method = doREST(auth, "", null, null, HttpVerb.HEAD); + method = doREST(auth, "/user", null, null, HttpVerb.HEAD); checkStatusCode(method); @@ -653,4 +653,4 @@ public class GithubApiUtil { return null; } -} +} \ No newline at end of file From bdeb0a945f3a1e02246dbeefdaff56dd5931e584 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 8 Aug 2013 10:26:58 +0200 Subject: [PATCH 23/29] =?UTF-8?q?PsiUtilBase.asVirtualFile,=20Overrides,?= =?UTF-8?q?=20remove=20duplicated=20code=20=E2=80=94=20please=20use=20PsiU?= =?UTF-8?q?tilCore.getVirtualFile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fileTypes/ImageDocumentationProvider.java | 3 +- .../impl/ClassesTreeStructureProvider.java | 2 +- .../JavaCodeBlockModificationListener.java | 2 +- .../providers/FilePathReferenceProvider.java | 6 +-- .../com/intellij/psi/util/PsiUtilCore.java | 3 +- .../impl/search/CachesBasedRefSearcher.java | 9 ++-- .../ide/projectView/ProjectViewNode.java | 27 ++++++------ .../com/intellij/psi/util/PsiUtilBase.java | 11 +++++ .../preview/ImagePreviewComponent.java | 3 +- .../com/intellij/ide/PsiCopyPasteManager.java | 4 +- .../projectView/BaseProjectTreeBuilder.java | 22 +++------- .../AbstractMvcPsiNodeDescriptor.java | 15 ++++--- .../mvc/projectView/MvcProjectViewPane.java | 42 +++++++++++++------ .../relaxNG/references/FileReferenceUtil.java | 5 +++ 14 files changed, 90 insertions(+), 64 deletions(-) diff --git a/images/src/org/intellij/images/fileTypes/ImageDocumentationProvider.java b/images/src/org/intellij/images/fileTypes/ImageDocumentationProvider.java index e0698ed140b1..ef0e14aa4515 100644 --- a/images/src/org/intellij/images/fileTypes/ImageDocumentationProvider.java +++ b/images/src/org/intellij/images/fileTypes/ImageDocumentationProvider.java @@ -43,6 +43,7 @@ public class ImageDocumentationProvider extends AbstractDocumentationProvider { final VirtualFile file = ((PsiFileSystemItem)element).getVirtualFile(); if (file instanceof VirtualFileWithId && !DumbService.isDumb(element.getProject())) { ImageInfoIndex.processValues(file, new FileBasedIndex.ValueProcessor() { + @Override public boolean process(VirtualFile file, ImageInfoIndex.ImageInfo value) { int imageWidth = value.width; int imageHeight = value.height; @@ -62,7 +63,7 @@ public class ImageDocumentationProvider extends AbstractDocumentationProvider { result[0] = String.format("

%sx%s, %sbpp

", url, imageWidth, imageHeight, value.width, value.height, value.bpp); } - catch (URISyntaxException e) { + catch (URISyntaxException ignored) { // nothing } return true; diff --git a/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java b/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java index e8197bbefb47..570e42e58f34 100644 --- a/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java +++ b/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java @@ -125,7 +125,7 @@ public class ClassesTreeStructureProvider implements SelectableTreeStructureProv return current != null ? current : baseRootFile; } - private boolean isSelectable(PsiElement element) { + private static boolean isSelectable(PsiElement element) { if (element instanceof PsiFileSystemItem) return true; if (element instanceof PsiField || element instanceof PsiClass || element instanceof PsiMethod) { diff --git a/java/java-impl/src/com/intellij/psi/impl/JavaCodeBlockModificationListener.java b/java/java-impl/src/com/intellij/psi/impl/JavaCodeBlockModificationListener.java index 5ab99de764ed..ac8de81cf0f0 100644 --- a/java/java-impl/src/com/intellij/psi/impl/JavaCodeBlockModificationListener.java +++ b/java/java-impl/src/com/intellij/psi/impl/JavaCodeBlockModificationListener.java @@ -84,7 +84,7 @@ public class JavaCodeBlockModificationListener implements PsiTreeChangePreproces myModificationTracker.incCounter(); } } - catch (PsiInvalidElementAccessException e) { + catch (PsiInvalidElementAccessException ignored) { myModificationTracker.incCounter(); // Shall not happen actually, just a pre-release paranoia } } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FilePathReferenceProvider.java b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FilePathReferenceProvider.java index 604b90e896d6..c23cf728f500 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FilePathReferenceProvider.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FilePathReferenceProvider.java @@ -16,7 +16,7 @@ package com.intellij.psi.impl.source.resolve.reference.impl.providers; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.TextRange; @@ -87,7 +87,7 @@ public class FilePathReferenceProvider extends PsiReferenceProvider { systemItems.addAll(getRoots(forModule, true)); } } else { - systemItems.addAll(getRoots(ModuleUtil.findModuleForPsiElement(getElement()), true)); + systemItems.addAll(getRoots(ModuleUtilCore.findModuleForPsiElement(getElement()), true)); } return systemItems; } @@ -144,7 +144,7 @@ public class FilePathReferenceProvider extends PsiReferenceProvider { if (thisModule == null) return Collections.emptyList(); Set modules = new com.intellij.util.containers.HashSet(); ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(thisModule); - ModuleUtil.getDependencies(thisModule, modules); + ModuleUtilCore.getDependencies(thisModule, modules); List result = new ArrayList(); final PsiManager psiManager = PsiManager.getInstance(thisModule.getProject()); if (includingClasses) { diff --git a/platform/core-api/src/com/intellij/psi/util/PsiUtilCore.java b/platform/core-api/src/com/intellij/psi/util/PsiUtilCore.java index 334feb7f5a21..897cefcf59b7 100644 --- a/platform/core-api/src/com/intellij/psi/util/PsiUtilCore.java +++ b/platform/core-api/src/com/intellij/psi/util/PsiUtilCore.java @@ -348,7 +348,8 @@ public class PsiUtilCore { } @Nullable - public static VirtualFile getVirtualFile(@Nullable PsiElement element) { + public static VirtualFile getVirtualFile(@Nullable Object object) { + PsiElement element = object instanceof PsiElement ? (PsiElement)object : null; if (element == null || !element.isValid()) { return null; } diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/search/CachesBasedRefSearcher.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/CachesBasedRefSearcher.java index b430c0d65095..6e4a27e8559e 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/search/CachesBasedRefSearcher.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/CachesBasedRefSearcher.java @@ -3,7 +3,10 @@ package com.intellij.psi.impl.search; import com.intellij.openapi.application.QueryExecutorBase; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFileSystemItem; +import com.intellij.psi.PsiNamedElement; +import com.intellij.psi.PsiReference; import com.intellij.psi.meta.PsiMetaData; import com.intellij.psi.meta.PsiMetaOwner; import com.intellij.psi.search.SearchScope; @@ -44,9 +47,7 @@ public class CachesBasedRefSearcher extends QueryExecutorBase extends AbstractTreeNode im public static AbstractTreeNode createTreeNode(Class nodeClass, Project project, Object value, - ViewSettings settings) throws NoSuchMethodException, - InstantiationException, - IllegalAccessException, - InvocationTargetException { + ViewSettings settings) throws + InstantiationException { Object[] parameters = new Object[]{project, value, settings}; for (Constructor constructor : (Constructor[])nodeClass.getConstructors()) { if (constructor.getParameterTypes().length != 3) continue; try { return constructor.newInstance(parameters); } - catch (InstantiationException e) { + catch (InstantiationException ignored) { } - catch (IllegalAccessException e) { + catch (IllegalAccessException ignored) { } - catch (IllegalArgumentException e) { + catch (IllegalArgumentException ignored) { } - catch (InvocationTargetException e) { + catch (InvocationTargetException ignored) { } } throw new InstantiationException("no constructor found in " + nodeClass); @@ -142,7 +143,7 @@ public abstract class ProjectViewNode extends AbstractTreeNode im break; } - if (VfsUtil.isAncestor(eachRoot, file, true)) { + if (VfsUtilCore.isAncestor(eachRoot, file, true)) { mayContain = true; break; } @@ -193,7 +194,7 @@ public abstract class ProjectViewNode extends AbstractTreeNode im public boolean value(final VirtualFile virtualFile) { return contains(virtualFile) // in case of flattened packages, when package node a.b.c contains error file, node a.b might not. - && (getValue() instanceof PsiElement && Comparing.equal(PsiUtilBase.getVirtualFile((PsiElement)getValue()), virtualFile) || + && (getValue() instanceof PsiElement && Comparing.equal(PsiUtilCore.getVirtualFile(getValue()), virtualFile) || someChildContainsFile(virtualFile)); } }); diff --git a/platform/lang-api/src/com/intellij/psi/util/PsiUtilBase.java b/platform/lang-api/src/com/intellij/psi/util/PsiUtilBase.java index 659f52777ed0..066e2027cb32 100644 --- a/platform/lang-api/src/com/intellij/psi/util/PsiUtilBase.java +++ b/platform/lang-api/src/com/intellij/psi/util/PsiUtilBase.java @@ -288,4 +288,15 @@ public class PsiUtilBase extends PsiUtilCore { final VirtualFile virtualFile = element.getVirtualFile(); return virtualFile != null && virtualFile.is(VFileProperty.SYMLINK); } + + @Nullable + public static VirtualFile asVirtualFile(@Nullable Object element) { + if (element instanceof PsiFileSystemItem) { + PsiFileSystemItem psiFileSystemItem = (PsiFileSystemItem)element; + return psiFileSystemItem.isValid() ? psiFileSystemItem.getVirtualFile() : null; + } + else { + return null; + } + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImagePreviewComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImagePreviewComponent.java index 3645028717e1..3baa777939ce 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImagePreviewComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImagePreviewComponent.java @@ -70,6 +70,7 @@ public class ImagePreviewComponent extends JPanel implements PreviewHintComponen setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black), BorderFactory.createEmptyBorder(5, 5, 5, 5))); } + @Override @TestOnly public boolean isEqualTo(@Nullable PreviewHintComponent other) { if (!(other instanceof ImagePreviewComponent)) { @@ -159,7 +160,7 @@ public class ImagePreviewComponent extends JPanel implements PreviewHintComponen } } } - catch (IOException e) { + catch (IOException ignored) { // nothing } } diff --git a/platform/lang-impl/src/com/intellij/ide/PsiCopyPasteManager.java b/platform/lang-impl/src/com/intellij/ide/PsiCopyPasteManager.java index 3a4fb08f33d8..f42623be4218 100644 --- a/platform/lang-impl/src/com/intellij/ide/PsiCopyPasteManager.java +++ b/platform/lang-impl/src/com/intellij/ide/PsiCopyPasteManager.java @@ -31,7 +31,7 @@ import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; -import com.intellij.util.ArrayUtil; +import com.intellij.util.ArrayUtilRt; import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; @@ -322,7 +322,7 @@ public class PsiCopyPasteManager { @Override public boolean isDataFlavorSupported(DataFlavor flavor) { - return ArrayUtil.find(getTransferDataFlavors(), flavor) != -1; + return ArrayUtilRt.find(getTransferDataFlavors(), flavor) != -1; } public PsiElement[] getElements() { diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/BaseProjectTreeBuilder.java b/platform/lang-impl/src/com/intellij/ide/projectView/BaseProjectTreeBuilder.java index 5f4d6d903cb6..ea265433ccb8 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/BaseProjectTreeBuilder.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/BaseProjectTreeBuilder.java @@ -32,9 +32,8 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.FocusRequestor; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiFileSystemItem; +import com.intellij.psi.util.PsiUtilCore; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -68,26 +67,15 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder { if (element instanceof AbstractTreeNode) { AbstractTreeNode node = (AbstractTreeNode)element; final Object value = node.getValue(); - VirtualFile vFile = null; - if (value instanceof PsiFileSystemItem) { - vFile = ((PsiFileSystemItem)value).getVirtualFile(); - } - else if (value instanceof PsiElement) { - PsiFile psiFile = ((PsiElement)value).getContainingFile(); - if (psiFile != null) { - vFile = psiFile.getVirtualFile(); - } - } - final ActionCallback cb = new ActionCallback(); - - final VirtualFile finalVFile = vFile; + final ActionCallback callback = new ActionCallback(); + final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(value); final FocusRequestor focusRequestor = IdeFocusManager.getInstance(myProject).getFurtherRequestor(); batch(new Progressive() { @Override public void run(@NotNull ProgressIndicator indicator) { final Ref target = new Ref(); - _select(value, finalVFile, false, Conditions.alwaysTrue(), cb, indicator, target, focusRequestor, false); - cb.doWhenDone(new Runnable() { + _select(value, virtualFile, false, Conditions.alwaysTrue(), callback, indicator, target, focusRequestor, false); + callback.doWhenDone(new Runnable() { @Override public void run() { result.setDone(target.get()); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/AbstractMvcPsiNodeDescriptor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/AbstractMvcPsiNodeDescriptor.java index e1639e4b0774..b7e19ba80012 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/AbstractMvcPsiNodeDescriptor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/AbstractMvcPsiNodeDescriptor.java @@ -10,7 +10,7 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.problems.WolfTheProblemSolver; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFileSystemItem; +import com.intellij.psi.util.PsiUtilCore; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -59,6 +59,7 @@ public abstract class AbstractMvcPsiNodeDescriptor extends AbstractPsiBasedNode< return super.contains(file); } + @Override @Nullable protected PsiElement extractPsiFromValue() { final NodeId nodeId = getValue(); @@ -86,15 +87,10 @@ public abstract class AbstractMvcPsiNodeDescriptor extends AbstractPsiBasedNode< if (!isValid()) { return null; } - final PsiElement psiElement = extractPsiFromValue(); - assert psiElement != null; - - if (psiElement instanceof PsiFileSystemItem) { - return ((PsiFileSystemItem)psiElement).getVirtualFile(); - } - return psiElement.getContainingFile().getVirtualFile(); + return PsiUtilCore.getVirtualFile(extractPsiFromValue()); } + @Override protected void updateImpl(final PresentationData data) { final PsiElement psiElement = extractPsiFromValue(); if (psiElement instanceof NavigationItem) { @@ -110,14 +106,17 @@ public abstract class AbstractMvcPsiNodeDescriptor extends AbstractPsiBasedNode< return myWeight; } + @Override protected boolean hasProblemFileBeneath() { return WolfTheProblemSolver.getInstance(getProject()).hasProblemFilesBeneath(new Condition() { + @Override public boolean value(final VirtualFile virtualFile) { return contains(virtualFile); } }); } + @Override public boolean isValid() { final PsiElement psiElement = extractPsiFromValue(); return psiElement != null && psiElement.isValid(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/MvcProjectViewPane.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/MvcProjectViewPane.java index 6af5356a51aa..e50be1749d92 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/MvcProjectViewPane.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/MvcProjectViewPane.java @@ -34,11 +34,11 @@ import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.actions.ModuleDeleteProvider; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowManager; @@ -169,19 +169,23 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id toolWindow.setTitleActions(new AnAction[]{new ScrollFromSourceAction(), collapseAction}); } + @Override public String getTitle() { throw new UnsupportedOperationException(); } + @Override public Icon getIcon() { return myDescriptor.getFramework().getIcon(); } + @Override @NotNull public String getId() { return myId; } + @Override public int getWeight() { throw new UnsupportedOperationException(); } @@ -191,6 +195,7 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id throw new UnsupportedOperationException(); } + @Override public SelectInTarget createSelectInTarget() { throw new UnsupportedOperationException(); } @@ -199,12 +204,14 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id @Override protected BaseProjectTreeBuilder createBuilder(final DefaultTreeModel treeModel) { return new ProjectTreeBuilder(myProject, myTree, treeModel, null, (ProjectAbstractTreeStructureBase)myTreeStructure) { + @Override protected AbstractTreeUpdater createUpdater() { return createTreeUpdater(this); } }; } + @Override protected ProjectAbstractTreeStructureBase createStructure() { final Project project = myProject; final String id = getId(); @@ -215,28 +222,33 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id return myViewState.hideEmptyMiddlePackages; } + @Override protected AbstractTreeNode createRoot(final Project project, ViewSettings settings) { return new MvcProjectNode(project, this, myDescriptor); } }; } + @Override protected ProjectViewTree createTree(final DefaultTreeModel treeModel) { return new ProjectViewTree(myProject, treeModel) { public String toString() { return myDescriptor.getFramework().getDisplayName() + " " + super.toString(); } + @Override public DefaultMutableTreeNode getSelectedNode() { return MvcProjectViewPane.this.getSelectedNode(); } }; } + @Override protected AbstractTreeUpdater createTreeUpdater(final AbstractTreeBuilder treeBuilder) { return new AbstractTreeUpdater(treeBuilder); } + @Override @Nullable protected PsiElement getPSIElement(@Nullable final Object element) { // E.g is used by Project View's DataProvider @@ -305,20 +317,23 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id return content == null ? null : (MvcProjectViewPane)content.getDisposer(); } + @Override public void selectElement(PsiElement element) { PsiFileSystemItem psiFile; - - if (!(element instanceof PsiFileSystemItem)) { - psiFile = element.getContainingFile(); - } - else { + if (element instanceof PsiFileSystemItem) { psiFile = (PsiFileSystemItem)element; } - - if (psiFile == null) return; + else { + psiFile = element.getContainingFile(); + if (psiFile == null) { + return; + } + } VirtualFile virtualFile = psiFile.getVirtualFile(); - if (virtualFile == null) return; + if (virtualFile == null) { + return; + } selectFile(virtualFile, false); @@ -337,10 +352,12 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id } } + @Override public PsiDirectory[] getDirectories() { return getSelectedDirectories(); } + @Override public PsiDirectory getOrChooseDirectory() { return DirectoryChooserUtil.getOrChooseDirectory(this); } @@ -360,7 +377,7 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id return null; } - final Module module = ModuleUtil.findModuleForFile(file, project); + final Module module = ModuleUtilCore.findModuleForFile(file, project); if (module == null || !framework.hasSupport(module)) { return null; } @@ -386,7 +403,7 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id if (descriptor instanceof AbstractFolderNode) { final AbstractFolderNode folderNode = (AbstractFolderNode)descriptor; final VirtualFile dir = folderNode.getVirtualFile(); - if (dir != null && VfsUtil.isAncestor(dir, file, false)) { + if (dir != null && VfsUtilCore.isAncestor(dir, file, false)) { cur = folderNode; result.add(folderNode); if (dir.equals(file)) { @@ -506,6 +523,7 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id return myViewState.hideEmptyMiddlePackages; } + @Override public void setSelected(AnActionEvent event, boolean flag) { myViewState.hideEmptyMiddlePackages = flag; TreeUtil.collapseAll(myTree, 1); diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/references/FileReferenceUtil.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/references/FileReferenceUtil.java index 13ca07e55c3f..a5295ed4e32d 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/references/FileReferenceUtil.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/references/FileReferenceUtil.java @@ -44,6 +44,7 @@ public class FileReferenceUtil { final FileReference[] references = set.getAllReferences(); return ContainerUtil.map2Array(references, PsiReference.class, new NotNullFunction() { + @Override @NotNull public PsiReference fun(FileReference fileReference) { return new MyFileReference(fileReference, cond, soft); @@ -66,6 +67,7 @@ public class FileReferenceUtil { myType = type; } + @Override public boolean value(PsiFile file) { return file.getFileType() == myType; } @@ -78,6 +80,7 @@ public class FileReferenceUtil { myPattern = pattern; } + @Override public boolean value(PsiFile o) { return myPattern.accepts(o); } @@ -113,6 +116,7 @@ public class FileReferenceUtil { protected ResolveResult[] innerResolve() { final ResolveResult[] results = super.innerResolve(); return ContainerUtil.findAll(results, new Condition() { + @Override public boolean value(ResolveResult resolveResult) { final PsiElement e = resolveResult.getElement(); return match(e, myCond); @@ -125,6 +129,7 @@ public class FileReferenceUtil { public Object[] getVariants() { final Object[] variants = super.getVariants(); return ContainerUtil.findAll(variants, new Condition() { + @Override public boolean value(Object o) { /*if (o instanceof CandidateInfo) { o = ((CandidateInfo)o).getElement(); From ec4e86342766bf0065cc08672ae0990f7529dba5 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Thu, 8 Aug 2013 13:33:26 +0400 Subject: [PATCH 24/29] CompilerOutputIndexer on CompilationStatusListener --- .../api/indexer/CompilerOutputIndexer.java | 48 +++++++------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/java/java-impl/src/com/intellij/compilerOutputIndex/api/indexer/CompilerOutputIndexer.java b/java/java-impl/src/com/intellij/compilerOutputIndex/api/indexer/CompilerOutputIndexer.java index 83da82862c22..e8c5ebc9a771 100644 --- a/java/java-impl/src/com/intellij/compilerOutputIndex/api/indexer/CompilerOutputIndexer.java +++ b/java/java-impl/src/com/intellij/compilerOutputIndex/api/indexer/CompilerOutputIndexer.java @@ -3,13 +3,11 @@ package com.intellij.compilerOutputIndex.api.indexer; import com.intellij.compilerOutputIndex.api.fs.CompilerOutputFilesUtil; import com.intellij.compilerOutputIndex.api.fs.FileVisitorService; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.compiler.CompileContext; -import com.intellij.openapi.compiler.CompileTask; +import com.intellij.openapi.compiler.CompilationStatusAdapter; import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.components.AbstractProjectComponent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; @@ -19,6 +17,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.registry.RegistryValue; import com.intellij.openapi.util.registry.RegistryValueListener; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Consumer; import com.intellij.util.indexing.ID; import com.intellij.util.indexing.IndexInfrastructure; @@ -111,39 +110,22 @@ public class CompilerOutputIndexer extends AbstractProjectComponent { catch (IOException e) { throw new RuntimeException(e); } - CompilerManager.getInstance(myProject).addAfterTask(new CompileTask() { + CompilerManager.getInstance(myProject).addCompilationStatusListener(new CompilationStatusAdapter() { @Override - public boolean execute(final CompileContext context) { - if (myEnabled.get() && myInProgress.compareAndSet(false, true)) { - myLock.lock(); + public void fileGenerated(final String outputRoot, final String relativePath) { + if (myEnabled.get() && StringUtil.endsWith(relativePath, CompilerOutputFilesUtil.CLASS_FILES_SUFFIX)) { try { - context.getProgressIndicator().setText("Compiler output indexing in progress"); - final Consumer fileConsumer = new Consumer() { - @Override - public void consume(final File file) { - try { - doIndexing(file, context.getProgressIndicator()); - } - catch (ProcessCanceledException e0) { - throw e0; - } - catch (RuntimeException e) { - LOG.error(e); - } - } - }; - for (final Module module : context.getCompileScope().getAffectedModules()) { - CompilerOutputFilesUtil.iterateModuleClassFiles(module, fileConsumer); - } + doIndexing(new File(outputRoot, relativePath), null); } - finally { - myLock.unlock(); - myInProgress.set(false); + catch (ProcessCanceledException e0) { + throw e0; + } + catch (RuntimeException e) { + LOG.error(e); } } - return true; } - }); + }, myProject); if (needReindex) { reindexAllProjectInBackground(); } @@ -233,7 +215,7 @@ public class CompilerOutputIndexer extends AbstractProjectComponent { } @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") - private void doIndexing(@NotNull final File file, @NotNull final ProgressIndicator indicator) { + private void doIndexing(@NotNull final File file, @Nullable final ProgressIndicator indicator) { final String filePath; try { filePath = file.getCanonicalPath(); @@ -267,7 +249,9 @@ public class CompilerOutputIndexer extends AbstractProjectComponent { } } try { - indicator.setText2(filePath); + if (indicator != null) { + indicator.setText2(filePath); + } final int id = myFileEnumerator.enumerate(filePath); for (final CompilerOutputBaseIndex index : myIndexes) { index.update(id, reader); From 1a67a3bfffe3fdae58e83f2f6bb710b2d30f636b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Thu, 8 Aug 2013 11:36:27 +0200 Subject: [PATCH 25/29] remove garbage --- .../src/com/intellij/util/xml/PsiClassConverter.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/util/xml/PsiClassConverter.java b/java/java-impl/src/com/intellij/util/xml/PsiClassConverter.java index 8a2ed8be9d12..da53cb27bb92 100644 --- a/java/java-impl/src/com/intellij/util/xml/PsiClassConverter.java +++ b/java/java-impl/src/com/intellij/util/xml/PsiClassConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -122,8 +122,6 @@ public class PsiClassConverter extends Converter implements CustomRefe extendClass); provider.setOption(JavaClassReferenceProvider.CLASS_KIND, ClassKind.ANNOTATION); - //provider.setOption(JavaClassReferenceProvider.EXTEND_CLASS_NAMES, new String[] {"org.springframework.samples.petclinic.jsr330.Foo"}); - // return provider; } } From 38b17dbe122b54751f3463219d15b17e774b209e Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 8 Aug 2013 15:01:09 +0400 Subject: [PATCH 26/29] restored old order of attributes (IDEA-111730) --- .../execution/impl/RunnerAndConfigurationSettingsImpl.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.java index da2cf118495c..4aef3a91afec 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.java @@ -21,7 +21,10 @@ import com.intellij.execution.configurations.*; import com.intellij.execution.runners.ProgramRunner; import com.intellij.ide.plugins.IdeaPluginDescriptorImpl; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Factory; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.JDOMExternalizable; +import com.intellij.openapi.util.WriteExternalException; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -276,10 +279,10 @@ public class RunnerAndConfigurationSettingsImpl implements JDOMExternalizable, C for (ProgramRunner runner : myConfigurationPerRunnerSettings.keySet()) { ConfigurationPerRunnerSettings settings = myConfigurationPerRunnerSettings.get(runner); Element runnerElement = new Element(CONFIGURATION_ELEMENT); - runnerElement.setAttribute(RUNNER_ID, runner.getRunnerId()); if (settings != null) { settings.writeExternal(runnerElement); } + runnerElement.setAttribute(RUNNER_ID, runner.getRunnerId()); configurationPerRunnerSettings.add(runnerElement); } if (myUnloadedConfigurationPerRunnerSettings != null) { From 52a97cf368ada424f06354f1c7b2ab544166018d Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 2 Aug 2013 15:45:14 +0200 Subject: [PATCH 27/29] EA-47284 --- .../com/intellij/ide/navigationToolbar/NavBarUpdateQueue.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarUpdateQueue.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarUpdateQueue.java index e9e0e127d6e3..297334710c06 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarUpdateQueue.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarUpdateQueue.java @@ -117,7 +117,9 @@ public class NavBarUpdateQueue extends MergingUpdateQueue { void restartRebuild() { myUserActivityAlarm.cancelAllRequests(); - myUserActivityAlarm.addRequest(myUserActivityAlarmRunnable, Registry.intValue("navBar.userActivityMergeTime")); + if (!myUserActivityAlarm.isDisposed()) { + myUserActivityAlarm.addRequest(myUserActivityAlarmRunnable, Registry.intValue("navBar.userActivityMergeTime")); + } } private void processUserActivity() { From f09cc85f17573e9b29a7f2980e155eb1189803bb Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Thu, 8 Aug 2013 13:02:11 +0200 Subject: [PATCH 28/29] more IElementType allowed for registration (EA-46744) --- platform/core-api/src/com/intellij/psi/tree/IElementType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/core-api/src/com/intellij/psi/tree/IElementType.java b/platform/core-api/src/com/intellij/psi/tree/IElementType.java index b64d76112220..ed349f7ee449 100644 --- a/platform/core-api/src/com/intellij/psi/tree/IElementType.java +++ b/platform/core-api/src/com/intellij/psi/tree/IElementType.java @@ -51,7 +51,7 @@ public class IElementType { }; public static final short FIRST_TOKEN_INDEX = 1; - public static final short MAX_INDEXED_TYPES = 15000; + public static final short MAX_INDEXED_TYPES = 20000; private static short ourCounter = FIRST_TOKEN_INDEX; private static IElementType[] ourRegistry = new IElementType[700]; From e18de3202db9cce6154df5fbd66efd079a0cc9f4 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 8 Aug 2013 13:26:06 +0200 Subject: [PATCH 29/29] fix memory leak --- .../ide/actions/SearchEverywhereAction.java | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java index ab0d03419143..36f458509555 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java @@ -44,6 +44,7 @@ import com.intellij.openapi.progress.util.ProgressIndicatorBase; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.ui.popup.PopupChooserBuilder; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; @@ -59,6 +60,7 @@ import com.intellij.psi.codeStyle.NameUtil; import com.intellij.psi.util.PsiUtilCore; import com.intellij.ui.*; import com.intellij.ui.border.CustomLineBorder; +import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.components.OnOffButton; import com.intellij.util.Alarm; import com.intellij.util.ArrayUtil; @@ -222,6 +224,12 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA } myAlarm.cancelAllRequests(); myList.setModel(new DefaultListModel()); + myClassModel = null; + myFileModel = null; + myActionModel = null; + myClasses = null; + myFiles = null; + myActions = null; //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @@ -373,7 +381,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA String title = getTitle(index, value, index == 0 ? null : list.getModel().getElementAt(index -1)); myTitle.setText(title == null ? "" : title); myLeftPanel.removeAll(); - myLeftPanel.setBackground(Gray._242); + myLeftPanel.setBackground(new JBColor(Gray._242, JBColor.background())); myMainPanel.removeAll(); myLeftPanel.add(myTitle, BorderLayout.EAST); myMainPanel.add(myLeftPanel, BorderLayout.WEST); @@ -501,7 +509,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA myLeftWidth += 10; myTitle.setForeground(Gray._122); myTitle.setAlignmentY(BOTTOM_ALIGNMENT); - myLeftPanel.setBorder(new CompoundBorder(new CustomLineBorder(Gray._206, 0,0,0,1), new EmptyBorder(0,0,0,5))); + myLeftPanel.setBorder(new CompoundBorder(new CustomLineBorder(new JBColor(Gray._206, Gray._75), 0,0,0,1), new EmptyBorder(0,0,0,5))); } private Font getTitleFont() { @@ -631,10 +639,9 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA for (MatchResult o : classes) { if (clsCounter > 15) break; - myProgressIndicator.checkCanceled(); - Object[] objects = myClassModel.getElementsByName(o.elementName, false, pattern); + + Object[] objects = myClassModel.getElementsByName(o.elementName, false, pattern, myProgressIndicator); for (Object object : objects) { - myProgressIndicator.checkCanceled(); if (!listModel.contains(object)) { listModel.addElement(object); clsCounter++; @@ -650,16 +657,13 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA } for (MatchResult o : files) { if (filesCounter > 15) break; - myProgressIndicator.checkCanceled(); Object[] objects = myFileModel.getElementsByName(o.elementName, false, pattern, myProgressIndicator); for (Object object : objects) { - myProgressIndicator.checkCanceled(); if (!listModel.contains(object)) { if (object instanceof PsiFile) { object = ((PsiFile)object).getVirtualFile(); } if (object instanceof VirtualFile && !alreadyAddedFiles.contains((VirtualFile)object) && !((VirtualFile)object).isDirectory()) { - myProgressIndicator.checkCanceled(); listModel.addElement(object); filesCounter++; } @@ -767,10 +771,8 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA myRenderer.recalculateWidth(); if (myPopup == null || !myPopup.isVisible()) { final ActionCallback callback = ListDelegationUtil.installKeyboardDelegation(field.getTextEditor(), myList); - myPopup = JBPopupFactory.getInstance() - .createListPopupBuilder(myList) - .setRequestFocus(false) - .createPopup(); + final PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(myList); + myPopup = builder.setRequestFocus(false).createPopup(); Disposer.register(myPopup, new Disposable() { @Override public void dispose() { @@ -793,7 +795,18 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA myPopup.cancel(); } else { final Dimension size = myList.getPreferredSize(); - myPopup.setSize(new Dimension(Math.min(600, Math.max(field.getWidth(), size.width + 15)), Math.min(600, size.height + 10))); + Dimension sz = new Dimension(Math.max(field.getWidth(), size.width), size.height); + if (sz.width > 800 || sz.height > 800) { + final int extra = new JBScrollPane().getVerticalScrollBar().getWidth(); + sz = new Dimension(Math.min(800, Math.max(field.getWidth(), size.width + extra)), Math.min(800, size.height + extra)); + sz.width += 16; + } else { + sz.height++; + sz.height++; + sz.width++; + sz.width++; + } + myPopup.setSize(sz); final Point screen = field.getLocationOnScreen(); final int x = screen.x + field.getWidth() - myPopup.getSize().width; @@ -823,7 +836,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA MatchResult result; for (String name : names) { - myProgressIndicator.checkCanceled(); + //myProgressIndicator.checkCanceled(); result = null; if (model instanceof CustomMatcherModel) { try {