diff options
author | Tor Norbye <tnorbye@google.com> | 2014-01-17 14:04:48 -0800 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2014-01-17 14:04:53 -0800 |
commit | e2d6089d43d7ac1f62bafe06638d5ac2c21f5283 (patch) | |
tree | 82793a3124b69b74c3ced64e35aaa9e613ff0198 /plugins | |
parent | f2f7178ad6915927d918481b911e57a49785e4c4 (diff) | |
download | idea-e2d6089d43d7ac1f62bafe06638d5ac2c21f5283.tar.gz |
Snapshot b9931c55d2175b6552f90b2225eb09c13bd6dfed from idea/133.609 of git://git.jetbrains.org/idea/community.git
b9931c5: [git log] IDEA-119247 Use "--date-order" when requesting filtered results
a425d83: [vcs-log] user-filter: treat empty user name as no filter.
54b87b7: [log] IDEA-116242 Allow multiple users selection in the log filter
75057c2: [^Evdokimov] IDEA-118027 Groovy: constructors with mixed privacy are flagged as errors
f6f884e: [^Vishnyakov] IDEA-119085 Code style does not recognize Groovy spaceship operator <=>
d1d61a1: [^Peter]IDEA-117982 correct classpath for groovy scripts
448557f: [^Peter]IDEA-118920 introduce local var intention should not start in write action
3e0ac06: IDEA-118521 Latest 13.0.1 keeps locking up. Editor becomes unresponsive. Various file types... using allScope() (cherry picked from commit a7d5dd0)
d3978ef: IDEA-118521 Latest 13.0.1 keeps locking up. Editor becomes unresponsive. Various file types. Using XmlPropertiesIndex to avoid getting xml file content (cherry picked from commit 602db68)
d0a2612: IDEA-119344 (Incorrect "Unnecessary call toString()" inspection when super is used) (cherry picked from commit ed03022)[CR-IC-4005]
d719338: IDEA-118429 (IDEA incorrectly suggests to remove unboxing) (cherry picked from commit c450665)[CR-IC-3938]
0ae5316: IDEA-118743 (False positive "Number of placeholders does not match number of arguments in logging call") (cherry picked from commit 8f76e73)[CR-IC-3854]
c641c52: IDEA-118181 (false positive "number of placeholders does not match number of arguments" for multi-catch) (cherry picked from commit bbc19f5)[CR-IC-3855]
4a5654f: IDEA-118588 (Concatenation with empty string fails to fix an expression) (cherry picked from commit 01753c7)[CR-IC-3801]
3bdf7c6: fix quickfix breaking code when non-static inner class was used from an other file (cherry picked from commit 5e9c2c3)[CR-IC-3659]
2ddc8f5: IDEA-118004 (Find's Regex Help Popup table header bad color with darcula) (cherry picked from commit 95399a1)[CR-IC-3634]
39b0f0c: IDEA-117863 (Package with disjoint dependency graph ignores interfaces) (cherry picked from commit 1257700)[CR-IC-3623]
8805c17: fix and clarify "Cyclic class dependency" inspection warning (cherry picked from commit 68b7ce4)[CR-IC-3800]
4a1b901: EA-52499 - NPE: BraceHighlightingHandler.highlightBraces
365533d: EA-53134 - IOE: DocumentImpl.doBeforeChangedUpdate
186cc36: unused code
81af309: extract DummyCachingFileSystem: put all the weirdness in one place
754c063: Merge branch '133' of git.labs.intellij.net:idea/community into 133
eee267b: Update Python plugin
a3fbc3a: IDEA-118989 Code Formatting broken in 13.0.2 EAP [CR-IC-3927] (cherry picked from commit 4d2a597)
96c57db: IDEA-118616 Lens mode with tool windows on the right side (cherry picked from commit 56738b2) [reviewed by kb]
2b06e76: IDEA-117831 After deleting last live template in a group, I can't click OK. (cherry picked from commit 41f6f85)
187d6b1: get rid of psi/doc inconsistency before reparse by not relying on TextBlock information (cherry picked from commit c7a0408)
42f85ee: IDEA-113344 An easy way to exit from full screen mode using mouse (cherry picked from commit 458c964) [reviewed by kb]
ace88bd: Merge branch '133' of git.labs.intellij.net:idea/community into 133
c9bad57: Update Python plugin
43cf538: IDEA-94950 Code Style | Arrangement: AIOOBE at ArrangementMatchingRulesModel.removeRow() on removing the last rule that is in edit mode (cherry picked from commit 9a60903)
b06982f: introduce AbstractNavBarExtension with processChildren(..) API
15a665c: unwrap: allow to unwrap catch for try-with-resources statement
5b9a6c0: strip @SuppressWarning on delegating (IDEA-118528)
2d0486c: IDEA-111535 Edit Language Fragment: Synchronization is broken after tab drag
ebfaf78: true -> false!
84434d5: avoid NPE for non-text editors
204395c: Merge remote-tracking branch 'origin/133' into 133
8a44e62: delete catch fix: introduce ARM
79b66a1: can be final: ensure non final for base of anonymous class (IDEA-118493)
dc2a67b: IDEA-118496 disable boolean param inspection for library overriders
1469417: run manager: do not override shared status from default configuration when existing configuration is checked e.g. run from tests view
c03e718: junit: reject to start when no tests were found in package
81b8ea2: refactoring listeners: missed after data (IDEA-119118)
b9535cd: refactoringIDs: IDEA-119121;IDEA-119122
429cc6e: IDEA-118487 IDEA should suggest downloading missing plug-ins for unrecognised artifact configuration
1e49463: plugin advertiser: do not suggest to update from ultimate to ultimate when 'bundled' plugin is not yet available for current version
12185dd: ensure public inner inside interface (IDEA-118564) (cherry picked from commit 3d7a8fb)
fbe5a3a: Fix maven tests. (cherry picked from commit 1e4e54d)
fd30aa3: detect the plugin responsible for run configuration AbstractMethodError (IDEA-119173) (cherry picked from commit 70b8663)
fe4dd2e: make show usages consistent with Find usages
28194cd: IDEA-97930
41ad9e0: Merge branch '133' of git.labs.intellij.net:idea/community into 133
d89f761: rename while we still can
c484ee3: backported IDEA-118742 and IDEA-112104
e5ccd29: Fix blink maven test.
a1e1aab: Add retina version for executeMavenGoal.png icon. (cherry picked from commit 1466df4)
785932d: IDEA-112104 "Find Usages Settings Dialog" button re-emerged in "Find in Path" results
c5cdb6d: do not allow slash in the middle of the child name
88c56dd: correctly handle request for the not-canonically named child
b52c02a: mac file chooser must respect FileChooserDescriptor.isFileSelectable +review
b48ed4b: WEB-10360 Javascript debugger with non unique file names
32e35af: prevent cancellation upon removing data from indices, to avoid state data in e.g. stub index IDEA-117290 (cherry picked from commit 4ec42a6) [r=Peter.Gromov]
dfb6509: IDEA-118675 - Errors in app server run configs not shown in UI (cherry picked from commit 3feff30)
72e247a: cleanup (commented code) (cherry picked from commit 0063990)
e175aab: Merge remote-tracking branch 'origin/133' into 133
4c89b6f: allow external documentation over references with multiple resolve (cherry picked from commit 7b239df) [r=Roman.Shevchenko]
fd46f79: remove unwanted registry.properties changes
54d3383: - fixed serialization for DOM indexes - DOM indices work without exception about stub mismatch (cherry picked from commit cff5c6c)
47af646: DOM index: @StubbedOccurrence (cherry picked from commit 3a22d6f)
d7ada2a: IDEA-115702 DomAnchorImpl exception: element stubs indexed (cherry picked from commit d0b977b)
ae79e45: [^romka] make IDEA-94683 fix controllable via registry (Completion popup loses focus when viewing documentation (sometimes, almost always))
0681b33: fixwd a few IndexNotReadyExceptions
b98216f: extract checkDisposed() with verbose reporting
751194e: Database navbar extension
0a4129c: EditorSplitters: update shortcuts on keymap change
c23ada7: IDEA-118970 (external URL formatting for Javadoc 8)
72f30cb: IDEA-118970 (preparation, cleanup, minor optimization)
41dfb6c: [log] simplify loading details around selected commit
ed79a3b: IDEA-118763 (handle project component initialization errors)
0e2378a: preselect exact prefix match in autopopup completion (RUBY-14617) (cherry picked from commit 6a771e7)
d50fe83: IDEA-119047 (MidnightBSD test)
2f72a0b: Fixed tips of the day.
07ec483: New PyCharm tips of the day.
1d0f380: Cut out escapes from vagrant output in message dialogs.
58e844c: Make setters return this to encourage functional style.
73d7b88: [git] IDEA-116738 Don't eat newlines when amending
ee2f349: [git] IDEA-115594 Don't join equal commit messages from different roots
a9a0505: IDEA-118330 (kill unresponsive environment reader after timeout)
b59cdcf: fix performance problem on 'new Object() {}' test code (cherry picked from commit 3d634e4)[CR-IC-3799]
cca9a90: LOG.debug which file is currently checked when running inspections globally (IDEA-118567) (cherry picked from commit c78d7e4)
7e7469c: Make the constant final
b2158f1: [git] Understand renames in the log
ff04982: [log] IDEA-117680 IDEA-116207 Fix showing Changes for multi-selection
482ab9e: [log] Flush the Hash->Int persistent map more often
8ab87771: [git log] Don't display "index" and "stash" pseudo-commits in the log
5918341: [vcs] IDEA-118644 Fix apply patch for new file in new folder + test
8fc76f5: [log] IDEA-115423 Limit number of commits requested when filtering
0183fd2: [log] simplify
96ad748: [log] Take END_COMMIT_NODE as well as COMMIT_NODE
6ca69c0: [log] Fix identifying root of Node
532cf87: [log] Supply correct commit object to getCommitData in DetailsPanel
9f4eb47: [log] Correctly load details of commits around the selected commit
edf55a4: take words from other files if there is no variants from current file at all (IDEA-117511) (cherry picked from commit 64575f6) [r=Peter.Gromov]
6a00485: IOBE fix IDEA-118696 (cherry picked from commit b1a787f)
5b2b564: performance fix IDEA-116803 (cherry picked from commit 5bd84de)
4f7e1f2: nonempty check (cherry picked from commit eead8f1) [r=Peter.Gromov]
13d7e20: project disposed check (cherry picked from commit ab602cb) [r=Peter.Gromov]
7437593: IDEA-118718 Occasionally seeing "Low disk space on a IntelliJ IDEA system directory partition" (cherry picked from commit 22c7a4f) [r=Peter.Gromov/Roman.Shevchenko]
2d1303f: IDEA-111684 Quick Documentation should resolve values for aggregated / indirect constants (cherry picked from commit 065fa6d) [r=Anna.Kozlova]
281a9fc: slightly better fix for IDEA-118691 (cherry picked from commit e87a766) [r=Anna.Kozlova]
d55d31a: IDEA-118745 Show directory in editor tabs for non-unique filenames doesn't work for non-project files (cherry picked from commit e560ee2) [r=Peter.Gromov]
c9d6d82: IDEA-118446 Installation and plugin update (patch) download ignores Settings / HTTP Proxy (cherry picked from commit 90f2e9c) [r=Anna.Kozlova]
0083f07: IDEA-118787 IAE: Argument 0 for @NotNull parameter of com/intellij/codeInspection/dataFlow/value/DfaPsiType.<init> must not be null (with testcase) (cherry picked from commit 2f26745)
1e2b2ce: Merge branch '133' of git.labs.intellij.net:idea/community into 133
2267ace: updated code compatibility inspection
fd4da08: IDEA-116910 (Invalid "unnecessary explicit numeric cast" warning) (cherry picked from commit 7c80f38)[CR-IC-3747]
cd2e961: IDEA-116758 ('equals()' between objects of inconvertible types - not working for ...= equals("differentClass")); (cherry picked from commit faa180a)[CR-IC-3355]
e235284: new in 13, because these inspections were not actually integrated into 12.1 (cherry picked from commit 3b6f9bf)
dd4e427: IDEA-92545 (Type maybe weakened does not always work) (cherry picked from commit 4d5bfb7)[CR-IC-3791]
565054e: IDEA-55970 (Erroneous "type may be weakened to 'null'" in generic method) (cherry picked from commit db52690)[CR-IC-3749]
e2f6fea: IDEA-116682 ("Collection declared by class, not interface" suggests abstract classes) (cherry picked from commit 240a1ff)[CR-IC-3748]
a2e586e: fixed PY-11673 Error on project creation
6dac33f: Prefer highlighting passes for the selected editor (IDEA-23831)
f3ea46e: updated test data for python3.4
3eb3a59: Added error message for missing python-skeletons diagnostics (PY-10411)
c134015: Made builtins cache valid only if it has a valid reference to the builtins file (PY-11665)
d8d5d79: Switched back to char-based triple quotes detection for docstring element types (PY-11585)
60a4ea9: fixed PY-11654 Move Statement: IOE at com.intellij.openapi.editor.impl.DocumentImpl.d
1b780fe: fixed PY-11610 Django johnny-cache breaks django_test_manage.py
fa9d315: fixed PY-11581 RST: Header is not highlighted if there is a space after separator
32c1775: fixed PY-11588 "Instance attribute %s defined outside __init__" in static method
cfd8060: fixed PY-11617 Nosetest runner: simple function tests cannot jump to source
540f5a9: Switched to synchronized count of running Python skeleton generators
8f167a4: Don't add python-skeletons to Python paths during skeletons generation
41c891b: Don't show python-skeletons path in the Python interpreter paths tab (PY-11218)
42ee478: Don't report unresolved references and unused imports during skeletons generation
017accd: Return unknown return type for generator functions if the built-in generator type is not found
115af20: Don't report unresolved references and unused imports if the project interpreter is not selected (PY-11589)
daf47ee: Call a static method via its defining class, not its subclass
baf4d9e: Removed unused PythonSdkType.switchPathToInterpreter()
4257828: Nullity annotations for overridden methods
ec6753c: Moved skeleton generation progress on adding a Python interpreter to background
9901a18: Switched from showing balloons to logging errors for serious skeleton generation exceptions
6d2c9c0: Added ellipses for skeleton processing progress messages
7ba1d4f: Merge branch '133' of git.labs.intellij.net:idea/community into 133
f0918d5: Fixed PIEAE in referencing obsolete cached PSI elements for built-in 'str | unicode' type
9bd03d9: Rearranged fields and constructors
85295da: Removed unused PyBuiltinCache.isValid()
8603b21: Removed stdlib type cache unused after the switch to python-skeletons
2e2a3ee: Call static methods via classes where they are actually defined
d0deed6: fixed PY-11594 New Project: selected interpreter is not set as project interpreter when attaching project to already opened one
dd98a8e: fixed PY-11595 Unable to move lines within Python doc strings
Change-Id: I389125baa54f7a0f40ce6a7e7c059241e3a4ff0c
Diffstat (limited to 'plugins')
63 files changed, 825 insertions, 414 deletions
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties index 0915e5105cbe..eb6ec6c8333f 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1512,6 +1512,8 @@ class.with.too.many.transitive.dependencies.max.option=Maximum number of transit class.with.too.many.transitive.dependents.max.option=Maximum number of transitive dependents cyclic.class.dependency.display.name=Cyclic class dependency cyclic.class.dependency.problem.descriptor=Class ''{0}'' is cyclically dependent on {1} other classes +cyclic.class.dependency.1.problem.descriptor=Class ''{0}'' is cyclically dependent on class ''{1}'' +cyclic.class.dependency.2.problem.descriptor=Class ''{0}'' is cyclically dependent on classes ''{1}'' and ''{2}'' cyclic.package.dependency.display.name=Cyclic package dependency cyclic.package.dependency.problem.descriptor=Package ''{0}'' is cyclically dependent on {1} other packages class.unconnected.to.package.display.name=Class independent of its package diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/BooleanParameterInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/BooleanParameterInspection.java index d328f49b1cbf..1621331169e7 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/BooleanParameterInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/BooleanParameterInspection.java @@ -21,6 +21,7 @@ import com.intellij.psi.util.PropertyUtil; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.psiutils.LibraryUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -82,7 +83,7 @@ public class BooleanParameterInspection extends BaseInspection { return; } } - if (PropertyUtil.isSimpleSetter(method)) { + if (PropertyUtil.isSimpleSetter(method) || LibraryUtil.isOverrideOfLibraryMethod(method)) { return; } final PsiParameterList parameterList = method.getParameterList(); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java index a9f6d14e9848..96836a7b0c2f 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/DeclareCollectionAsInterfaceInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -202,10 +202,7 @@ public class DeclareCollectionAsInterfaceInspection extends BaseInspection { } } final PsiType type = variable.getType(); - if (!CollectionUtils.isCollectionClass(type)) { - return; - } - if (LibraryUtil.isOverrideOfLibraryMethodParameter(variable)) { + if (!CollectionUtils.isCollectionClass(type) || LibraryUtil.isOverrideOfLibraryMethodParameter(variable)) { return; } final PsiTypeElement typeElement = variable.getTypeElement(); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspection.java index 717e10e98cbd..fc0a72508c81 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,13 @@ package com.siyeh.ig.bugs; import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.TypeConversionUtil; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.psiutils.MethodCallUtils; +import com.siyeh.ig.psiutils.TypeUtils; import org.jetbrains.annotations.NotNull; public class EqualsBetweenInconvertibleTypesInspection @@ -64,31 +66,34 @@ public class EqualsBetweenInconvertibleTypesInspection if (!MethodCallUtils.isEqualsCall(expression)) { return; } - final PsiReferenceExpression methodExpression = - expression.getMethodExpression(); + final PsiReferenceExpression methodExpression = expression.getMethodExpression(); final PsiExpressionList argumentList = expression.getArgumentList(); - final PsiExpression[] args = argumentList.getExpressions(); - if (args.length != 1) { + final PsiExpression[] arguments = argumentList.getExpressions(); + if (arguments.length != 1) { return; } - final PsiExpression expression1 = args[0]; - final PsiExpression expression2 = - methodExpression.getQualifierExpression(); + final PsiExpression expression1 = arguments[0]; + final PsiExpression expression2 = methodExpression.getQualifierExpression(); + final PsiType comparisonType; if (expression2 == null) { + final PsiClass aClass = PsiTreeUtil.getParentOfType(expression, PsiClass.class); + if (aClass == null) { + return; + } + comparisonType = TypeUtils.getType(aClass); + } else { + comparisonType = expression2.getType(); + } + if (comparisonType == null) { return; } final PsiType comparedType = expression1.getType(); if (comparedType == null) { return; } - final PsiType comparisonType = expression2.getType(); - if (comparisonType == null) { - return; - } final PsiType comparedTypeErasure = TypeConversionUtil.erasure(comparedType); final PsiType comparisonTypeErasure = TypeConversionUtil.erasure(comparisonType); - if (comparedTypeErasure == null || - comparisonTypeErasure == null || + if (comparedTypeErasure == null || comparisonTypeErasure == null || TypeConversionUtil.areTypesConvertible(comparedTypeErasure, comparisonTypeErasure)) { return; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dependency/CyclicClassDependencyInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dependency/CyclicClassDependencyInspection.java index 355d5933d511..cb512f97ecbd 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dependency/CyclicClassDependencyInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/dependency/CyclicClassDependencyInspection.java @@ -16,17 +16,19 @@ package com.siyeh.ig.dependency; import com.intellij.analysis.AnalysisScope; -import com.intellij.codeInspection.CommonProblemDescriptor; -import com.intellij.codeInspection.GlobalInspectionContext; -import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.*; import com.intellij.codeInspection.reference.RefClass; import com.intellij.codeInspection.reference.RefEntity; +import com.intellij.codeInspection.util.RefEntityAlphabeticalComparator; +import com.intellij.psi.PsiAnonymousClass; import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseGlobalInspection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -35,8 +37,7 @@ public class CyclicClassDependencyInspection extends BaseGlobalInspection { @NotNull @Override public String getDisplayName() { - return InspectionGadgetsBundle.message( - "cyclic.class.dependency.display.name"); + return InspectionGadgetsBundle.message("cyclic.class.dependency.display.name"); } @Override @@ -54,22 +55,42 @@ public class CyclicClassDependencyInspection extends BaseGlobalInspection { if (aClass == null || aClass.getContainingClass() != null) { return null; } - final Set<RefClass> dependencies = - DependencyUtils.calculateTransitiveDependenciesForClass(refClass); - final Set<RefClass> dependents = - DependencyUtils.calculateTransitiveDependentsForClass(refClass); - final Set<RefClass> mutualDependents = - new HashSet<RefClass>(dependencies); + final Set<RefClass> dependencies = DependencyUtils.calculateTransitiveDependenciesForClass(refClass); + final Set<RefClass> dependents = DependencyUtils.calculateTransitiveDependentsForClass(refClass); + final Set<RefClass> mutualDependents = new HashSet<RefClass>(dependencies); mutualDependents.retainAll(dependents); final int numMutualDependents = mutualDependents.size(); - if (numMutualDependents <= 1) { + if (numMutualDependents == 0) { return null; } - final String errorString = InspectionGadgetsBundle.message( - "cyclic.class.dependency.problem.descriptor", - refEntity.getName(), Integer.valueOf(numMutualDependents - 1)); + final String errorString; + if (numMutualDependents == 1) { + final RefClass[] classes = mutualDependents.toArray(new RefClass[1]); + errorString = InspectionGadgetsBundle.message("cyclic.class.dependency.1.problem.descriptor", + refEntity.getName(), classes[0].getExternalName()); + } + else if (numMutualDependents == 2) { + final RefClass[] classes = mutualDependents.toArray(new RefClass[2]); + Arrays.sort(classes, RefEntityAlphabeticalComparator.getInstance()); + errorString = InspectionGadgetsBundle.message("cyclic.class.dependency.2.problem.descriptor", + refEntity.getName(), classes[0].getExternalName(), classes[1].getExternalName()); + } + else { + errorString = InspectionGadgetsBundle.message("cyclic.class.dependency.problem.descriptor", + refEntity.getName(), Integer.valueOf(numMutualDependents)); + } + final PsiElement anchor; + if (aClass instanceof PsiAnonymousClass) { + final PsiAnonymousClass anonymousClass = (PsiAnonymousClass)aClass; + anchor = anonymousClass.getBaseClassReference(); + } + else { + anchor = aClass.getNameIdentifier(); + if (anchor == null) return null; + } return new CommonProblemDescriptor[]{ - inspectionManager.createProblemDescriptor(errorString) + inspectionManager.createProblemDescriptor(anchor, errorString, (LocalQuickFix)null, + ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false) }; } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java index 0a6ef31fcc7e..660a88f81a4a 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java @@ -43,9 +43,9 @@ public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspecti @NotNull @Override protected String buildErrorString(Object... infos) { - final int argumentCount = ((Integer)infos[0]).intValue(); - final int placeholderCount = ((Integer)infos[1]).intValue(); - if (argumentCount > placeholderCount) { + final Integer argumentCount = (Integer)infos[0]; + final Integer placeholderCount = (Integer)infos[1]; + if (argumentCount.intValue() > placeholderCount.intValue()) { return InspectionGadgetsBundle.message("placeholder.count.matches.argument.count.more.problem.descriptor", argumentCount, placeholderCount); } @@ -70,6 +70,14 @@ public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspecti if (!loggingMethodNames.contains(name)) { return; } + final PsiMethod method = expression.resolveMethod(); + if (method == null) { + return; + } + final PsiClass aClass = method.getContainingClass(); + if (!InheritanceUtil.isInheritor(aClass, "org.slf4j.Logger")) { + return; + } final PsiExpressionList argumentList = expression.getArgumentList(); final PsiExpression[] arguments = argumentList.getExpressions(); if (arguments.length == 0) { @@ -106,11 +114,21 @@ public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspecti if (placeholderCount == argumentCount) { return; } - registerMethodCallError(expression, argumentCount, placeholderCount); + registerMethodCallError(expression, Integer.valueOf(argumentCount), Integer.valueOf(placeholderCount)); } private static boolean hasThrowableType(PsiExpression lastArgument) { - return InheritanceUtil.isInheritor(lastArgument.getType(), "java.lang.Throwable"); + final PsiType type = lastArgument.getType(); + if (type instanceof PsiDisjunctionType) { + final PsiDisjunctionType disjunctionType = (PsiDisjunctionType)type; + for (PsiType disjunction : disjunctionType.getDisjunctions()) { + if (!InheritanceUtil.isInheritor(disjunction, CommonClassNames.JAVA_LANG_THROWABLE)) { + return false; + } + } + return true; + } + return InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_LANG_THROWABLE); } public static int countPlaceholders(String value) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryUnboxingInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryUnboxingInspection.java index 87fac79b8a02..96194b784e9b 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryUnboxingInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryUnboxingInspection.java @@ -159,7 +159,19 @@ public class UnnecessaryUnboxingInspection extends BaseInspection { if (isPossibleObjectComparison(expression, containingExpression)) { return; } - if (containingExpression instanceof PsiConditionalExpression) { + if (containingExpression instanceof PsiTypeCastExpression) { + final PsiTypeCastExpression typeCastExpression = (PsiTypeCastExpression)containingExpression; + final PsiTypeElement typeElement = typeCastExpression.getCastType(); + if (typeElement == null) { + return; + } + final PsiType castType = typeElement.getType(); + final PsiType expressionType = expression.getType(); + if (expressionType == null || !castType.isAssignableFrom(expressionType)) { + return; + } + } + else if (containingExpression instanceof PsiConditionalExpression) { final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)containingExpression; final PsiExpression thenExpression = conditionalExpression.getThenExpression(); if (thenExpression == null) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CastThatLosesPrecisionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CastThatLosesPrecisionInspection.java index d45abb156159..01829b05d6cb 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CastThatLosesPrecisionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CastThatLosesPrecisionInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,29 +24,13 @@ import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.psiutils.ClassUtils; import com.siyeh.ig.psiutils.ExpressionUtils; import com.siyeh.ig.psiutils.MethodUtils; +import com.siyeh.ig.psiutils.TypeUtils; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import java.util.HashMap; -import java.util.Map; public class CastThatLosesPrecisionInspection extends BaseInspection { - /** - * @noinspection StaticCollection - */ - private static final Map<PsiType, Integer> typePrecisions = new HashMap<PsiType, Integer>(7); - - static { - typePrecisions.put(PsiType.BYTE, 1); - typePrecisions.put(PsiType.CHAR, 2); - typePrecisions.put(PsiType.SHORT, 2); - typePrecisions.put(PsiType.INT, 3); - typePrecisions.put(PsiType.LONG, 4); - typePrecisions.put(PsiType.FLOAT, 5); - typePrecisions.put(PsiType.DOUBLE, 6); - } - @SuppressWarnings({"PublicField"}) public boolean ignoreIntegerCharCasts = false; @@ -81,8 +65,7 @@ public class CastThatLosesPrecisionInspection extends BaseInspection { return new CastThatLosesPrecisionVisitor(); } - private class CastThatLosesPrecisionVisitor - extends BaseInspectionVisitor { + private class CastThatLosesPrecisionVisitor extends BaseInspectionVisitor { @Override public void visitTypeCastExpression(@NotNull PsiTypeCastExpression expression) { @@ -95,10 +78,7 @@ public class CastThatLosesPrecisionInspection extends BaseInspection { return; } final PsiType operandType = operand.getType(); - if (!ClassUtils.isPrimitiveNumericType(operandType)) { - return; - } - if (hasLowerPrecision(operandType, castType)) { + if (!ClassUtils.isPrimitiveNumericType(operandType) || !TypeUtils.isNarrowingConversion(operandType, castType)) { return; } if (ignoreIntegerCharCasts) { @@ -129,12 +109,6 @@ public class CastThatLosesPrecisionInspection extends BaseInspection { registerError(castTypeElement, operandType); } - private boolean hasLowerPrecision(PsiType operandType, PsiType castType) { - final Integer operandPrecision = typePrecisions.get(operandType); - final Integer castPrecision = typePrecisions.get(castType); - return operandPrecision.intValue() <= castPrecision.intValue(); - } - private boolean valueIsContainableInType(Number value, PsiType type) { final long longValue = value.longValue(); final double doubleValue = value.doubleValue(); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java index 86a1eb27d0b3..57ef313693c3 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java @@ -28,6 +28,7 @@ import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.psiutils.ClassUtils; import com.siyeh.ig.psiutils.ExpectedTypeUtils; import com.siyeh.ig.psiutils.ExpressionUtils; +import com.siyeh.ig.psiutils.TypeUtils; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -158,17 +159,21 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection { final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)parent; final IElementType tokenType = polyadicExpression.getOperationTokenType(); if (binaryPromotionOperators.contains(tokenType)) { + if (TypeUtils.isNarrowingConversion(operandType, castType)) { + return true; + } if (PsiType.INT.equals(castType)) { return PsiType.LONG.equals(operandType) || PsiType.FLOAT.equals(operandType) || PsiType.DOUBLE.equals(operandType); } if (PsiType.LONG.equals(castType) || PsiType.FLOAT.equals(castType) || PsiType.DOUBLE.equals(castType)) { final PsiExpression[] operands = polyadicExpression.getOperands(); for (PsiExpression operand1 : operands) { - if (!PsiTreeUtil.isAncestor(operand1, expression, false)) { - final PsiType type = operand1.getType(); - if (castType.equals(type)) { - return false; - } + if (PsiTreeUtil.isAncestor(operand1, expression, false)) { + continue; + } + final PsiType type = operand1.getType(); + if (castType.equals(type)) { + return false; } } } @@ -285,49 +290,31 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection { static boolean isLegalAssignmentConversion(PsiExpression expression, PsiType assignmentType) { // JLS 5.2 Assignment Conversion - final PsiType operandType = expression.getType(); if (isLegalWideningConversion(expression, assignmentType)) { return true; } - else if (PsiType.SHORT.equals(assignmentType)) { - if (PsiType.INT.equals(operandType)) { - final Object constant = ExpressionUtils.computeConstantExpression(expression); - if (!(constant instanceof Integer)) { - return false; - } - final int i = ((Integer)constant).intValue(); - if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) { - // narrowing - return true; - } - } + if (PsiType.SHORT.equals(assignmentType)) { + return canValueBeContained(expression, Short.MIN_VALUE, Short.MAX_VALUE); } else if (PsiType.CHAR.equals(assignmentType)) { - if (PsiType.INT.equals(operandType)) { - final Object constant = ExpressionUtils.computeConstantExpression(expression); - if (!(constant instanceof Integer)) { - return false; - } - final int i = ((Integer)constant).intValue(); - if (i >= Character.MIN_VALUE && i <= Character.MAX_VALUE) { - // narrowing - return true; - } - } + return canValueBeContained(expression, Character.MIN_VALUE, Character.MAX_VALUE); } else if (PsiType.BYTE.equals(assignmentType)) { - if (PsiType.INT.equals(operandType)) { - final Object constant = ExpressionUtils.computeConstantExpression(expression); - if (!(constant instanceof Integer)) { - return false; - } - final int i = ((Integer)constant).intValue(); - if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) { - // narrowing - return true; - } - } + return canValueBeContained(expression, Byte.MIN_VALUE, Byte.MAX_VALUE); } return false; } + + private static boolean canValueBeContained(PsiExpression expression, int lowerBound, int upperBound) { + final PsiType expressionType = expression.getType(); + if (!PsiType.INT.equals(expressionType)) { + return false; + } + final Object constant = ExpressionUtils.computeConstantExpression(expression); + if (!(constant instanceof Integer)) { + return false; + } + final int i = ((Integer)constant).intValue(); + return i >= lowerBound && i <= upperBound; + } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/InnerClassMayBeStaticInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/InnerClassMayBeStaticInspection.java index f4c3a3072a8c..0c199c465ffa 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/InnerClassMayBeStaticInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/InnerClassMayBeStaticInspection.java @@ -15,9 +15,11 @@ */ package com.siyeh.ig.performance; +import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.util.Query; @@ -27,7 +29,9 @@ import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; public class InnerClassMayBeStaticInspection extends BaseInspection { @@ -67,13 +71,30 @@ public class InnerClassMayBeStaticInspection extends BaseInspection { } @Override + protected boolean prepareForWriting() { + return false; + } + + @Override public void doFix(Project project, ProblemDescriptor descriptor) { final PsiJavaToken classNameToken = (PsiJavaToken)descriptor.getPsiElement(); final PsiClass innerClass = (PsiClass)classNameToken.getParent(); - assert innerClass != null; + if (innerClass == null) { + return; + } final SearchScope useScope = innerClass.getUseScope(); final Query<PsiReference> query = ReferencesSearch.search(innerClass, useScope); final Collection<PsiReference> references = query.findAll(); + final List<PsiElement> elements = new ArrayList(references); + for (PsiReference reference : references) { + elements.add(reference.getElement()); + } + elements.add(innerClass); + if (!FileModificationService.getInstance().preparePsiElementsForWrite(elements)) { + return; + } + final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); + final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); for (final PsiReference reference : references) { final PsiElement element = reference.getElement(); final PsiElement parent = element.getParent(); @@ -81,11 +102,17 @@ public class InnerClassMayBeStaticInspection extends BaseInspection { continue; } final PsiNewExpression newExpression = (PsiNewExpression)parent; - final PsiExpression qualifier = newExpression.getQualifier(); - if (qualifier == null) { + final PsiJavaCodeReferenceElement classReference = newExpression.getClassReference(); + if (classReference == null) { + continue; + } + final PsiExpressionList argumentList = newExpression.getArgumentList(); + if (argumentList == null) { continue; } - qualifier.delete(); + final PsiExpression expression = + factory.createExpressionFromText("new " + classReference.getQualifiedName() + argumentList.getText(), innerClass); + codeStyleManager.shortenClassReferences(newExpression.replace(expression)); } final PsiModifierList modifiers = innerClass.getModifierList(); if (modifiers == null) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TrivialStringConcatenationInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TrivialStringConcatenationInspection.java index 43516f16abba..628503df238e 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TrivialStringConcatenationInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TrivialStringConcatenationInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,7 +91,7 @@ public class TrivialStringConcatenationInspection extends BaseInspection { replaced = true; continue; } - if (operand == expression) { + if (ParenthesesUtils.stripParentheses(operand) == expression) { seenEmpty = true; continue; } @@ -114,6 +114,7 @@ public class TrivialStringConcatenationInspection extends BaseInspection { return text.toString(); } + @NonNls static String buildReplacement(@NotNull PsiExpression operandToReplace, boolean seenString) { if (ExpressionUtils.isNullLiteral(operandToReplace)) { if (seenString) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/TypeUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/TypeUtils.java index 5bb992dbbc90..51a650461481 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/TypeUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/TypeUtils.java @@ -23,8 +23,23 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.HashMap; +import java.util.Map; + public class TypeUtils { + private static final Map<PsiType, Integer> typePrecisions = new HashMap<PsiType, Integer>(7); + + static { + typePrecisions.put(PsiType.BYTE, 1); + typePrecisions.put(PsiType.CHAR, 2); + typePrecisions.put(PsiType.SHORT, 2); + typePrecisions.put(PsiType.INT, 3); + typePrecisions.put(PsiType.LONG, 4); + typePrecisions.put(PsiType.FLOAT, 5); + typePrecisions.put(PsiType.DOUBLE, 6); + } + private TypeUtils() {} public static boolean typeEquals(@NonNls @NotNull String typeName, @Nullable PsiType targetType) { @@ -38,6 +53,10 @@ public class TypeUtils { return factory.createTypeByFQClassName(fqName, scope); } + public static PsiClassType getType(@NotNull PsiClass aClass) { + return JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory().createType(aClass); + } + public static PsiClassType getObjectType(@NotNull PsiElement context) { return getType(CommonClassNames.JAVA_LANG_OBJECT, context); } @@ -46,6 +65,12 @@ public class TypeUtils { return getType(CommonClassNames.JAVA_LANG_STRING, context); } + public static boolean isNarrowingConversion(PsiType operandType, PsiType castType) { + final Integer operandPrecision = typePrecisions.get(operandType); + final Integer castPrecision = typePrecisions.get(castType); + return operandPrecision.intValue() > castPrecision.intValue(); + } + public static boolean isJavaLangObject(@Nullable PsiType targetType) { return typeEquals(CommonClassNames.JAVA_LANG_OBJECT, targetType); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java index da190753b191..432df2b39874 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java @@ -21,11 +21,14 @@ import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.searches.DirectClassInheritorsSearch; import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.search.searches.SuperMethodsSearch; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.InheritanceUtil; +import com.intellij.psi.util.MethodSignatureBackedByPsiMethod; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.util.ArrayUtil; +import com.intellij.util.Processor; import com.intellij.util.Query; import com.siyeh.HardcodedMethodConstants; import org.jetbrains.annotations.NonNls; @@ -62,7 +65,7 @@ public class WeakestTypeFinder { } final PsiClassType variableOrMethodClassType = (PsiClassType)variableOrMethodType; final PsiClass variableOrMethodClass = variableOrMethodClassType.resolve(); - if (variableOrMethodClass == null) { + if (variableOrMethodClass == null || variableOrMethodClass instanceof PsiTypeParameter) { return Collections.emptyList(); } Set<PsiClass> weakestTypeClasses = new HashSet<PsiClass>(); @@ -345,12 +348,10 @@ public class WeakestTypeFinder { } private static boolean findWeakestType(PsiMethodCallExpression methodCallExpression, Set<PsiClass> weakestTypeClasses) { - final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); - final PsiElement target = methodExpression.resolve(); - if (!(target instanceof PsiMethod)) { + final PsiMethod method = methodCallExpression.resolveMethod(); + if (method == null) { return false; } - final PsiMethod method = (PsiMethod)target; final PsiReferenceList throwsList = method.getThrowsList(); final PsiClassType[] classTypes = throwsList.getReferencedTypes(); final Collection<PsiClassType> thrownTypes = new HashSet<PsiClassType>(Arrays.asList(classTypes)); @@ -360,7 +361,14 @@ public class WeakestTypeFinder { final PsiType expectedType = ExpectedTypeUtils.findExpectedType(methodCallExpression, false); for (PsiMethod superMethod : superMethods) { final PsiType returnType = superMethod.getReturnType(); - if (expectedType != null && returnType != null && !expectedType.isAssignableFrom(returnType)) { + if (expectedType instanceof PsiClassType) { + if (!(returnType instanceof PsiClassType)) { + continue; + } + final PsiClassType expectedClassType = (PsiClassType)expectedType; + expectedClassType.rawType().isAssignableFrom(returnType); + } + else if (expectedType != null && returnType != null && !expectedType.isAssignableFrom(returnType)) { continue; } if (throwsIncompatibleException(superMethod, thrownTypes)) { @@ -370,8 +378,10 @@ public class WeakestTypeFinder { continue; } final PsiClass containingClass = superMethod.getContainingClass(); - checkClass(containingClass, weakestTypeClasses); - checked = true; + if (checkClass(containingClass, weakestTypeClasses)) { + checked = true; + break; + } } } if (!checked) { @@ -390,17 +400,30 @@ public class WeakestTypeFinder { } private static List<PsiMethod> findAllSuperMethods(PsiMethod method) { - final List<PsiMethod> methods = findAllSuperMethods(method, new ArrayList()); - Collections.reverse(methods); - return methods; - } + final List<PsiMethod> result = new ArrayList(); + SuperMethodsSearch.search(method, null, true, false).forEach(new Processor<MethodSignatureBackedByPsiMethod>() { - private static List<PsiMethod> findAllSuperMethods(PsiMethod method, List<PsiMethod> result) { - final PsiMethod[] superMethods = method.findSuperMethods(); - Collections.addAll(result, superMethods); - for (PsiMethod superMethod : superMethods) { - findAllSuperMethods(superMethod, result); - } + @Override + public boolean process(MethodSignatureBackedByPsiMethod method) { + result.add(method.getMethod()); + return true; + } + }); + Collections.sort(result, new Comparator<PsiMethod>() { + @Override + public int compare(PsiMethod method1, PsiMethod method2) { + // methods from deepest super classes first + final PsiClass aClass1 = method1.getContainingClass(); + final PsiClass aClass2 = method2.getContainingClass(); + if (aClass1 == null || aClass2 == null || aClass1.equals(aClass2)) { + return 0; + } else if (aClass1.isInheritor(aClass2, true)) { + return 1; + } else { + return -1; + } + } + }); return result; } @@ -534,7 +557,7 @@ public class WeakestTypeFinder { @Nullable private static PsiClass getVisibleInheritor(@NotNull PsiClass superClass, PsiElement context) { final Query<PsiClass> search = DirectClassInheritorsSearch.search(superClass, context.getResolveScope()); - Project project = superClass.getProject(); + final Project project = superClass.getProject(); for (PsiClass aClass : search) { if (superClass.isInheritor(aClass, true)) { if (PsiUtil.isAccessible(project, aClass, context, null)) { @@ -548,31 +571,31 @@ public class WeakestTypeFinder { return null; } - private static void checkClass(@Nullable PsiClass aClass, @NotNull Collection<PsiClass> weakestTypeClasses) { + private static boolean checkClass(@Nullable PsiClass aClass, @NotNull Collection<PsiClass> weakestTypeClasses) { if (aClass == null) { - return; + return false; } boolean shouldAdd = true; - for (Iterator<PsiClass> iterator = weakestTypeClasses.iterator(); iterator.hasNext(); ) { + for (final Iterator<PsiClass> iterator = weakestTypeClasses.iterator(); iterator.hasNext(); ) { final PsiClass weakestTypeClass = iterator.next(); - if (!weakestTypeClass.equals(aClass)) { - if (aClass.isInheritor(weakestTypeClass, true)) { - iterator.remove(); - } - else if (weakestTypeClass.isInheritor(aClass, true)) { - shouldAdd = false; - } - else { - iterator.remove(); - shouldAdd = false; - } + if (weakestTypeClass.equals(aClass)) { + return true; + } + if (aClass.isInheritor(weakestTypeClass, true)) { + iterator.remove(); + } + else if (weakestTypeClass.isInheritor(aClass, true)) { + shouldAdd = false; } else { + iterator.remove(); shouldAdd = false; } } - if (shouldAdd) { - weakestTypeClasses.add(aClass); + if (!shouldAdd) { + return false; } + weakestTypeClasses.add(aClass); + return true; } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryToStringCallInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryToStringCallInspection.java index 1d2a26dadcb2..d920c31bbad7 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryToStringCallInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryToStringCallInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2013 Bas Leijdekkers + * Copyright 2008-2014 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -114,9 +114,14 @@ public class UnnecessaryToStringCallInspection extends BaseInspection { return; } final PsiExpression qualifier = methodExpression.getQualifierExpression(); - if (qualifier != null && qualifier.getType() instanceof PsiArrayType) { - // do not warn on nonsensical code - return; + if (qualifier != null) { + if (qualifier.getType() instanceof PsiArrayType) { + // do not warn on nonsensical code + return; + } + else if (qualifier instanceof PsiSuperExpression) { + return; + } } registerMethodCallError(expression, calculateReplacementText(qualifier)); } diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html b/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html index c9708f2437c8..186e523f4e59 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html @@ -4,6 +4,6 @@ Reports any assignments to fields from a superclass from within a constructor. I superclass to initialize the fields. <!-- tooltip end --> <p> -<small>New in 12.1</small> +<small>New in 13</small> </body> </html>
\ No newline at end of file diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html b/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html index aaa60cd4e395..11af3ae7d689 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html @@ -4,6 +4,6 @@ Reports SLF4J logging calls where the number of {}-placeholders in the string co does not match the number of other arguments to the logging call. <!-- tooltip end --> <p> -<small>New in 12.1</small> +<small>New in 13</small> </body> </html>
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/inner_class_static/Simple.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/inner_class_static/Simple.after.java new file mode 100644 index 000000000000..973bfc5b6e06 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/inner_class_static/Simple.after.java @@ -0,0 +1,18 @@ +package performance.inner_class_static; + +class Simple { + static class Inner {} + + void m() { + new Inner(); + } + + static void s(Simple s) { + new Inner(); + } +} +class X { + X() { + new Simple.Inner(); + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/inner_class_static/Simple.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/inner_class_static/Simple.java new file mode 100644 index 000000000000..c183bdb0986f --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/inner_class_static/Simple.java @@ -0,0 +1,18 @@ +package performance.inner_class_static; + +class Simple { + class Inner<caret> {} + + void m() { + new Inner(); + } + + static void s(Simple s) { + s.new Inner(); + } +} +class X { + X() { + new Simple().new Inner(); + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/trivial_string_concatenation/Parentheses2.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/trivial_string_concatenation/Parentheses2.after.java new file mode 100644 index 000000000000..159a763849ac --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/trivial_string_concatenation/Parentheses2.after.java @@ -0,0 +1,7 @@ +package com.siyeh.igfixes.performance.trivial_string_concatenation; + +class Parentheses2 { + void m(String version) { + final String s = " (" + "Groovy " + (version) + ")"; + } +}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/trivial_string_concatenation/Parentheses2.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/trivial_string_concatenation/Parentheses2.java new file mode 100644 index 000000000000..344093c17cfa --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/trivial_string_concatenation/Parentheses2.java @@ -0,0 +1,7 @@ +package com.siyeh.igfixes.performance.trivial_string_concatenation; + +class Parentheses2 { + void m(String version) { + final String s = " (" + (""<caret>) + "Groovy " + (version) + ")"; + } +}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/cyclic_class_dependency/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/cyclic_class_dependency/expected.xml new file mode 100644 index 000000000000..9a82ac1597c4 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/cyclic_class_dependency/expected.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<problems> + <problem> + <file>Cyclic.java</file> + <line>9</line> + <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Cyclic class dependency</problem_class> + <description>Class 'anonymous (java.lang.Object)' is cyclically dependent on 3 other classes</description> + </problem> + + <problem> + <file>Cyclic.java</file> + <line>17</line> + <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Cyclic class dependency</problem_class> + <description>Class 'Base' is cyclically dependent on classes 'com.siyeh.igtest.abstraction.cyclic_class_dependency.src.Cyclic' and 'com.siyeh.igtest.abstraction.cyclic_class_dependency.src.Top'</description> + </problem> + + <problem> + <file>Cyclic.java</file> + <line>29</line> + <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Cyclic class dependency</problem_class> + <description>Class 'Coffee' is cyclically dependent on class 'com.siyeh.igtest.abstraction.cyclic_class_dependency.src.FiveOClock'</description> + </problem> + + <problem> + <file>Cyclic.java</file> + <line>25</line> + <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Cyclic class dependency</problem_class> + <description>Class 'FiveOClock' is cyclically dependent on class 'com.siyeh.igtest.abstraction.cyclic_class_dependency.src.Coffee'</description> + </problem> + + <problem> + <file>Cyclic.java</file> + <line>22</line> + <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Cyclic class dependency</problem_class> + <description>Class 'Top' is cyclically dependent on classes 'com.siyeh.igtest.abstraction.cyclic_class_dependency.src.Base' and 'com.siyeh.igtest.abstraction.cyclic_class_dependency.src.Cyclic'</description> + </problem> + + <problem> + <file>Cyclic.java</file> + <line>6</line> + <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Cyclic class dependency</problem_class> + <description>Class 'Cyclic' is cyclically dependent on classes 'com.siyeh.igtest.abstraction.cyclic_class_dependency.src.Base' and 'com.siyeh.igtest.abstraction.cyclic_class_dependency.src.Top'</description> + </problem> +</problems>
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/cyclic_class_dependency/src/Cyclic.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/cyclic_class_dependency/src/Cyclic.java new file mode 100644 index 000000000000..adf929840c41 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/cyclic_class_dependency/src/Cyclic.java @@ -0,0 +1,29 @@ +package com.siyeh.igtest.abstraction.cyclic_class_dependency.src; + +/** + * @author Bas Leijdekkers + */ +public class Cyclic extends Base { + + Cyclic() { + new Object() {{ + foo(); + }}; + } + + void foo() {} + +} +class Base { + void a() { + Top.m(); + } +} +class Top extends Cyclic { + public static void m() {} +} +interface FiveOClock { + void m(Coffee c); + +} +interface Coffee extends FiveOClock {} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/DeclareCollectionsAsInterfaceInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/DeclareCollectionAsInterface.java index 23329c6d42ac..1e04a2ab41c6 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/DeclareCollectionsAsInterfaceInspection.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/DeclareCollectionAsInterface.java @@ -2,13 +2,13 @@ package com.siyeh.igtest.abstraction.declare_collection_as_interface; import java.util.*; -public class DeclareCollectionsAsInterfaceInspection +public class DeclareCollectionAsInterface { private HashMap<String, String> m_mapThree = new HashMap<String, String>(2); private HashMap m_setOne = new HashMap(2); private Map m_setTwo = new HashMap(2); - public DeclareCollectionsAsInterfaceInspection() + public DeclareCollectionAsInterface() { m_setOne.put("foo", "foo"); m_setTwo.put("bar", "bar"); @@ -47,4 +47,12 @@ public class DeclareCollectionsAsInterfaceInspection HashMap theRoad() { return null; } + + void makeItRight() { + ArrayList list22 = new ArrayList(); + System.out.println(list22.get(0)); + + ArrayList<String> list33 = new ArrayList(); + System.out.println(list33.get(0)); + } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/expected.xml index 40b14989373a..8c108ed1ef1a 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/declare_collection_as_interface/expected.xml @@ -2,37 +2,51 @@ <problems> <problem> - <file>DeclareCollectionsAsInterfaceInspection.java</file> + <file>DeclareCollectionAsInterface.java</file> <line>8</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Collection declared by class, not interface</problem_class> <description>Declaration of <code>HashMap</code> should probably be weakened to 'java.util.Map' #loc</description> </problem> <problem> - <file>DeclareCollectionsAsInterfaceInspection.java</file> + <file>DeclareCollectionAsInterface.java</file> <line>25</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Collection declared by class, not interface</problem_class> <description>Declaration of <code>HashMap</code> should probably be weakened to 'java.util.Map' #loc</description> </problem> <problem> - <file>DeclareCollectionsAsInterfaceInspection.java</file> + <file>DeclareCollectionAsInterface.java</file> <line>19</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Collection declared by class, not interface</problem_class> <description>Declaration of <code>HashMap</code> should probably be weakened to 'java.util.Map' #loc</description> </problem> <problem> - <file>DeclareCollectionsAsInterfaceInspection.java</file> + <file>DeclareCollectionAsInterface.java</file> <line>37</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Collection declared by class, not interface</problem_class> <description>Declaration of <code>HashMap</code> should probably be weakened to 'java.util.Map' #loc</description> </problem> <problem> - <file>DeclareCollectionsAsInterfaceInspection.java</file> + <file>DeclareCollectionAsInterface.java</file> <line>47</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Collection declared by class, not interface</problem_class> <description>Declaration of <code>HashMap</code> should probably be weakened to 'java.util.Map' #loc</description> </problem> + + <problem> + <file>DeclareCollectionAsInterface.java</file> + <line>52</line> + <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Collection declared by class, not interface</problem_class> + <description>Declaration of <code>ArrayList</code> should probably be weakened to 'java.util.List' #loc</description> + </problem> + + <problem> + <file>DeclareCollectionAsInterface.java</file> + <line>55</line> + <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Collection declared by class, not interface</problem_class> + <description>Declaration of <code>ArrayList</code> should probably be weakened to 'java.util.List' #loc</description> + </problem> </problems>
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java index 74b93d69d4be..aeb2e1a5f811 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java @@ -120,4 +120,34 @@ public class TypeMayBeWeakened { Integer simpleConditional(Boolean condition, Integer value1, Integer value2) { return condition ? value1 : value2; } + + private static <T, V extends T> java.util.concurrent.atomic.AtomicReference<T> nullSafeReference(java.util.concurrent.atomic.AtomicReference<T> ref, V value) { + if (ref != null) ref.set(value); + return ref; + } +} +class MyClass { + + public MyClass(java.util.Date date, String[] classNames) {} + + static MyClass readMyClass(final ObjectInputStream objectInput) { + final long time = objectInput.readLong(); + final int size = objectInput.readInt(); + final String[] classNames = new String[size]; + for (int i = 0; i < size; i++) { + classNames[i] = objectInput.readUTF(); + } + return new MyClass(new java.util.Date(time), classNames); + } +} +interface DataInput { + long readLong(); + int readInt(); + String readUTF(); +} +abstract class ObjectInputStream implements DataInput { + + public String readUTF() { + return null; + } }
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml index 599595a7163a..577f33646869 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml @@ -23,6 +23,13 @@ </problem> <problem> + <file>TypeMayBeWeakened.java</file> + <line>133</line> + <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Type may be weakened</problem_class> + <description>Type of parameter <code>objectInput</code> may be weakened to 'com.siyeh.igtest.abstraction.weaken_type.DataInput' #loc</description> + </problem> + + <problem> <file>AutoClosableTest.java</file> <line>34</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Type may be weakened</problem_class> diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/EqualsBetweenInconvertibleTypesInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/EqualsBetweenInconvertibleTypesInspection.java deleted file mode 100644 index 5a99f5bbd026..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/EqualsBetweenInconvertibleTypesInspection.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.siyeh.igtest.bugs; - -public class EqualsBetweenInconvertibleTypesInspection { - - public void foo() - { - final Integer foo = new Integer(3); - final Double bar = new Double(3); - foo.equals(bar); - } -} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/unnecessary_unboxing/UnnecessaryUnboxing.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/unnecessary_unboxing/UnnecessaryUnboxing.java index a73273dc24c5..366d21ddbae8 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/unnecessary_unboxing/UnnecessaryUnboxing.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/unnecessary_unboxing/UnnecessaryUnboxing.java @@ -39,4 +39,8 @@ public class UnnecessaryUnboxing { System.out.println((byte)b.byteValue()); } + + byte cast(Integer v) { + return (byte)v.intValue(); + } }
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/UnnecessaryExplicitNumericCast.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/UnnecessaryExplicitNumericCast.java index 9468de1baf32..26cc95afef11 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/UnnecessaryExplicitNumericCast.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/UnnecessaryExplicitNumericCast.java @@ -53,4 +53,14 @@ public class UnnecessaryExplicitNumericCast { float x = 2; target((int) x); // this line complains: 'x' unnecessarily cast to 'int' } + + void a(float angleFromTo) { + float f = (float) Math.cos(0.5) * 1.0f; // necessary + final long l = (long) i() * 9L; + float angle2 = angleFromTo + (float) (Math.PI / 2); + } + + int i() { + return 10; + } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/expected.xml index 19f2cadeff52..1e24f7ab3d58 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/expected.xml @@ -100,4 +100,11 @@ <problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class> <description>''b'' unnecessarily cast to <code>int</code> #loc</description> </problem> + + <problem> + <file>UnnecessaryExplicitNumericCast.java</file> + <line>59</line> + <problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class> + <description>'i()' unnecessarily cast to <code>long</code> #loc</description> + </problem> </problems>
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/expected.xml new file mode 100644 index 000000000000..e8f00e82629f --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/expected.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<problems> + +</problems>
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/extends_implements_reference/Ferrari.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/extends_implements_reference/Ferrari.java new file mode 100644 index 000000000000..7bbeb16c20ef --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/packaging/disjoint_package/extends_implements_reference/Ferrari.java @@ -0,0 +1,8 @@ +package extends_implements_reference; + +public class Ferrari implements Car { + public void start() {} +} +interface Car { + void start(); +}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_tostring/UnnecessaryToString.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_tostring/UnnecessaryToString.java index 6482a19423bc..155b24f4755a 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_tostring/UnnecessaryToString.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_tostring/UnnecessaryToString.java @@ -35,4 +35,15 @@ public class UnnecessaryToString { static void foo(String s) { System.out.println(s); } + + class A { + public String toString() { + return "A"; + } + } + class B extends A { + public String toString() { + return "B" + super.toString(); + } + } }
\ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/CyclicClassDependencyInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/CyclicClassDependencyInspectionTest.java new file mode 100644 index 000000000000..08e2faa28d11 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/abstraction/CyclicClassDependencyInspectionTest.java @@ -0,0 +1,29 @@ +/* + * 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.siyeh.ig.abstraction; + +import com.siyeh.ig.IGInspectionTestCase; +import com.siyeh.ig.dependency.CyclicClassDependencyInspection; + +/** + * @author Bas Leijdekkers + */ +public class CyclicClassDependencyInspectionTest extends IGInspectionTestCase { + + public void test() { + doTest("com/siyeh/igtest/abstraction/cyclic_class_dependency", new CyclicClassDependencyInspection()); + } +} diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java new file mode 100644 index 000000000000..3168d9ec5b0b --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java @@ -0,0 +1,46 @@ +/* + * 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.siyeh.ig.bugs; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; + +/** + * @author Bas Leijdekkers + */ +public class EqualsBetweenInconvertibleTypesInspectionTest extends LightInspectionTestCase { + + public void testSimple() { + doMemberTest("public void foo() {\n" + + " final Integer foo = new Integer(3);\n" + + " final Double bar = new Double(3);\n" + + " foo./*'equals()' between objects of inconvertible types 'Double' and 'Integer'*/equals/**/(bar);\n" + + "}\n"); + } + + public void testWithoutQualifier() { + doTest("class Clazz {\n" + + " void foo() {\n" + + " boolean bar = /*'equals()' between objects of inconvertible types 'String' and 'Clazz'*/equals/**/(\"differentClass\");\n" + + " }\n" + + "}"); + } + + @Override + protected InspectionProfileEntry getInspection() { + return new EqualsBetweenInconvertibleTypesInspection(); + } +} diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/InnerClassMayBeStaticFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/InnerClassMayBeStaticFixTest.java new file mode 100644 index 000000000000..92a27c5ac236 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/InnerClassMayBeStaticFixTest.java @@ -0,0 +1,37 @@ +/* + * 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.siyeh.ig.fixes.performance; + +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.IGQuickFixesTestCase; +import com.siyeh.ig.performance.InnerClassMayBeStaticInspection; + +/** + * @author Bas Leijdekkers + */ +public class InnerClassMayBeStaticFixTest extends IGQuickFixesTestCase { + + @Override + protected void setUp() throws Exception { + super.setUp(); + myFixture.enableInspections(new InnerClassMayBeStaticInspection()); + myRelativePath = "performance/inner_class_static"; + myDefaultHint = InspectionGadgetsBundle.message("make.static.quickfix"); + } + + public void testSimple() { doTest(); } + +} diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/TrivialStringConcatenationFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/TrivialStringConcatenationFixTest.java index ac3c0a54007b..b99500e7eca1 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/TrivialStringConcatenationFixTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/TrivialStringConcatenationFixTest.java @@ -13,6 +13,7 @@ public class TrivialStringConcatenationFixTest extends IGQuickFixesTestCase { } public void testParentheses() { doTest("Replace concatenation with 'completedTiles + \" , \" + (totalTiles - completedTiles)'"); } + public void testParentheses2() { doTest("Replace concatenation with '\" (\" + \"Groovy \" + (version) + \")\"'"); } public void testBinaryNull() { doTest("Replace concatenation with 'String.valueOf((Object)null)'"); } public void testAtTheEnd() { doTest("Replace concatenation with '\"asdf\" + 1 + o'"); } }
\ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java index a5a246170b43..c122583ee586 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java @@ -59,4 +59,32 @@ public class PlaceholderCountMatchesArgumentCountInspectionTest extends LightIns "}" ); } + + public void testMultiCatch() { + doTest("import org.slf4j.*;\n" + + "class X {\n" + + " private static final Logger logger = LoggerFactory.getLogger( X.class );\n" + + " public void multiCatch() {\n" + + " try {\n" + + " method();\n" + + " } catch ( FirstException|SecondException e ) {\n" + + " logger.info( \"failed with first or second\", e );\n" + + " }\n" + + " }\n" + + " public void method() throws FirstException, SecondException {}\n" + + " public static class FirstException extends Exception { }\n" + + " public static class SecondException extends Exception { }\n" + + "}"); + } + + public void testNoSlf4j() { + doTest("class FalsePositiveSLF4J {\n" + + " public void method( DefinitelyNotSLF4J definitelyNotSLF4J ) {\n" + + " definitelyNotSLF4J.trace( \"not a trace message\", \"not a trace parameter\" );\n" + + " }\n" + + " public interface DefinitelyNotSLF4J {\n" + + " void trace( String firstParameter, Object secondParameter );\n" + + " }\n" + + "}"); + } }
\ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/packaging/DisjointPackageInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/packaging/DisjointPackageInspectionTest.java new file mode 100644 index 000000000000..93c53b504337 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/packaging/DisjointPackageInspectionTest.java @@ -0,0 +1,29 @@ +/* + * 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.siyeh.ig.packaging; + +import com.siyeh.ig.IGInspectionTestCase; + +/** + * @author Bas Leijdekkers + */ +public class DisjointPackageInspectionTest extends IGInspectionTestCase { + + public void test() { + doTest("com/siyeh/igtest/packaging/disjoint_package", new DisjointPackageInspection(), false, true); + } + +} diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java index bc54939ff202..18f4c0147b12 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java @@ -96,7 +96,7 @@ public class InjectLanguageAction implements IntentionAction { if (injectedPsi == null || injectedPsi.isEmpty()) { return !InjectedReferencesContributor.isInjected(file.findReferenceAt(editor.getCaretModel().getOffset())); } - return true; + return false; } @Nullable diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java index a7f6719bdd67..ee75d19d7e71 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java @@ -43,10 +43,12 @@ import com.intellij.vcsUtil.VcsFileUtil; import com.intellij.vcsUtil.VcsUtil; import git4idea.GitPlatformFacade; import git4idea.GitUtil; +import git4idea.GitVcs; import git4idea.commands.GitCommand; import git4idea.commands.GitSimpleHandler; import git4idea.config.GitConfigUtil; import git4idea.config.GitVcsSettings; +import git4idea.config.GitVersionSpecialty; import git4idea.history.NewGitUsersComponent; import git4idea.i18n.GitBundle; import git4idea.push.GitPusher; @@ -107,7 +109,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment { @Nullable public String getDefaultMessageFor(FilePath[] filesToCheckin) { - StringBuilder rc = new StringBuilder(); + LinkedHashSet<String> messages = ContainerUtil.newLinkedHashSet(); for (VirtualFile root : GitUtil.gitRoots(Arrays.asList(filesToCheckin))) { VirtualFile mergeMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_MERGE_MSG); VirtualFile squashMsg = root.findFileByRelativePath(GitRepositoryFiles.GIT_SQUASH_MSG); @@ -120,13 +122,13 @@ public class GitCheckinEnvironment implements CheckinEnvironment { String encoding = GitConfigUtil.getCommitEncoding(myProject, root); if (mergeMsg != null) { - rc.append(loadMessage(mergeMsg, encoding)); + messages.add(loadMessage(mergeMsg, encoding)); } else if (squashMsg != null) { - rc.append(loadMessage(squashMsg, encoding)); + messages.add(loadMessage(squashMsg, encoding)); } else { - rc.append(loadMessage(normalMsg, encoding)); + messages.add(loadMessage(normalMsg, encoding)); } } catch (IOException e) { @@ -135,14 +137,11 @@ public class GitCheckinEnvironment implements CheckinEnvironment { } } } - if (rc.length() != 0) { - return rc.toString(); - } - return null; + return joinOrNull(messages); } - private static char[] loadMessage(@NotNull VirtualFile messageFile, @NotNull String encoding) throws IOException { - return FileUtil.loadFileText(new File(messageFile.getPath()), encoding); + private static String loadMessage(@NotNull VirtualFile messageFile, @NotNull String encoding) throws IOException { + return FileUtil.loadFile(new File(messageFile.getPath()), encoding); } public String getHelpId() { @@ -603,6 +602,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment { * Checkin options for git */ private class GitCheckinOptions implements CheckinChangeListSpecificComponent { + private final GitVcs myVcs; /** * A container panel */ @@ -628,6 +628,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment { * @param panel */ GitCheckinOptions(@NotNull final Project project, @NotNull CheckinProjectPanel panel) { + myVcs = GitVcs.getInstance(project); myCheckinPanel = panel; myPanel = new JPanel(new GridBagLayout()); final Insets insets = new Insets(2, 2, 2, 2); @@ -735,30 +736,31 @@ public class GitCheckinEnvironment implements CheckinEnvironment { private String getLastCommitMessage() throws VcsException { Set<VirtualFile> roots = GitUtil.gitRoots(getSelectedFilePaths()); final Ref<VcsException> exception = Ref.create(); - String joined = StringUtil.join(roots, new Function<VirtualFile, String>() { - @Override - public String fun(VirtualFile root) { - try { - return getLastCommitMessage(root); - } - catch (VcsException e) { - exception.set(e); - return null; - } + LinkedHashSet<String> messages = ContainerUtil.newLinkedHashSet(); + for (VirtualFile root : roots) { + String message = getLastCommitMessage(root); + if (message != null) { + messages.add(message); } - }, "\n"); + } if (!exception.isNull()) { throw exception.get(); } - return joined; + return joinOrNull(messages); } @Nullable private String getLastCommitMessage(@NotNull VirtualFile root) throws VcsException { GitSimpleHandler h = new GitSimpleHandler(myProject, root, GitCommand.LOG); h.addParameters("--max-count=1"); - // only message: subject + body; "%-b" means that preceding line-feeds will be deleted if the body is empty - h.addParameters("--pretty=%s%n%n%-b"); + if (GitVersionSpecialty.STARTED_USING_RAW_BODY_IN_FORMAT.existsIn(myVcs.getVersion())) { + h.addParameters("--pretty=%B"); + } + else { + // only message: subject + body; "%-b" means that preceding line-feeds will be deleted if the body is empty + // %s strips newlines from subject; there is no way to work around it before 1.7.2 with %B (unless parsing some fixed format) + h.addParameters("--pretty=%s%n%n%-b"); + } return h.run(); } @@ -828,6 +830,12 @@ public class GitCheckinEnvironment implements CheckinEnvironment { } } + @Nullable + private static String joinOrNull(@NotNull Collection<String> messages) { + String joined = StringUtil.join(messages, "\n"); + return StringUtil.isEmptyOrSpaces(joined) ? null : joined; + } + public void setNextCommitIsPushed(Boolean nextCommitIsPushed) { myNextCommitIsPushed = nextCommitIsPushed; } diff --git a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java index 4844c6124607..c1353e769313 100644 --- a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java +++ b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java @@ -69,7 +69,13 @@ import static git4idea.history.GitLogParser.GitLogOption.*; * A collection of methods for retrieving history information from native Git. */ public class GitHistoryUtils { - private final static Logger LOG = Logger.getInstance("#git4idea.history.GitHistoryUtils"); + + /** + * A parameter to {@code git log} which is equivalent to {@code --all}, but doesn't show the stuff from index or stash. + */ + public static final List<String> LOG_ALL = Arrays.asList("HEAD", "--branches", "--remotes", "--tags"); + + private static final Logger LOG = Logger.getInstance("#git4idea.history.GitHistoryUtils"); private GitHistoryUtils() { } @@ -197,9 +203,8 @@ public class GitHistoryUtils { final GitLineHandler h = new GitLineHandler(project, root, GitCommand.LOG); h.setSilent(true); - h.addParameters("HEAD", "--branches", "--remotes", "--tags", - "--pretty=format:%H%x20%ct%x0A", "--date-order", "--reverse", "--encoding=UTF-8", "--full-history", - "--sparse"); + h.addParameters(LOG_ALL); + h.addParameters("--pretty=format:%H%x20%ct%x0A", "--date-order", "--reverse", "--encoding=UTF-8", "--full-history", "--sparse"); h.endOptions(); final OutputStream[] stream = new OutputStream[1]; @@ -485,7 +490,7 @@ public class GitHistoryUtils { AUTHOR_EMAIL, AUTHOR_TIME, SUBJECT); h.setStdoutSuppressed(true); h.addParameters(parser.getPretty(), "--encoding=UTF-8"); - h.addParameters("HEAD", "--branches", "--remotes", "--tags"); + h.addParameters(LOG_ALL); h.addParameters("--full-history", "--sparse"); h.endOptions(); @@ -544,7 +549,7 @@ public class GitHistoryUtils { AUTHOR_NAME, AUTHOR_EMAIL); h.setStdoutSuppressed(true); h.addParameters(parser.getPretty(), "--encoding=UTF-8"); - h.addParameters("HEAD", "--branches", "--remotes", "--tags"); + h.addParameters(LOG_ALL); h.addParameters("--full-history", "--sparse"); h.addParameters("--date-order"); h.endOptions(); @@ -758,7 +763,7 @@ public class GitHistoryUtils { AUTHOR_EMAIL, COMMITTER_NAME, COMMITTER_EMAIL, PARENTS, SUBJECT, BODY, RAW_BODY); h.setStdoutSuppressed(true); h.addParameters(parameters); - h.addParameters("--name-status", parser.getPretty(), "--encoding=UTF-8"); + h.addParameters("-M", "--name-status", parser.getPretty(), "--encoding=UTF-8"); h.addParameters("--full-history", "--sparse"); h.endOptions(); diff --git a/plugins/git4idea/src/git4idea/log/GitLogProvider.java b/plugins/git4idea/src/git4idea/log/GitLogProvider.java index 0a76d10008fa..0a8bc3723d3f 100644 --- a/plugins/git4idea/src/git4idea/log/GitLogProvider.java +++ b/plugins/git4idea/src/git4idea/log/GitLogProvider.java @@ -82,8 +82,8 @@ public class GitLogProvider implements VcsLogProvider { return Collections.emptyList(); } - String[] params = {"HEAD", "--branches", "--remotes", "--tags", "--encoding=UTF-8", "--full-history", "--sparse", - "--max-count=" + commitCount}; + String[] params = ArrayUtil.mergeArrays(ArrayUtil.toStringArray(GitHistoryUtils.LOG_ALL), + "--encoding=UTF-8", "--full-history", "--sparse", "--max-count=" + commitCount); if (ordered) { params = ArrayUtil.append(params, "--date-order"); } @@ -189,7 +189,8 @@ public class GitLogProvider implements VcsLogProvider { @NotNull @Override public List<? extends VcsFullCommitDetails> getFilteredDetails(@NotNull final VirtualFile root, - @NotNull Collection<VcsLogFilter> filters) throws VcsException { + @NotNull Collection<VcsLogFilter> filters, + int maxCount) throws VcsException { if (!isRepositoryReady(root)) { return Collections.emptyList(); } @@ -207,7 +208,7 @@ public class GitLogProvider implements VcsLogProvider { filterParameters.add(branchFilter.getBranchName()); } else { - filterParameters.add("--all"); + filterParameters.addAll(GitHistoryUtils.LOG_ALL); } List<VcsLogUserFilter> userFilters = ContainerUtil.findAll(filters, VcsLogUserFilter.class); @@ -243,6 +244,10 @@ public class GitLogProvider implements VcsLogProvider { } filterParameters.add("--regexp-ignore-case"); // affects case sensitivity of any filter (except file filter) + if (maxCount > 0) { + filterParameters.add("--max-count=" + maxCount); + } + filterParameters.add("--date-order"); // note: this filter must be the last parameter, because it uses "--" which separates parameters from paths List<VcsLogStructureFilter> structureFilters = ContainerUtil.findAll(filters, VcsLogStructureFilter.class); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java index 136839183d14..cea5b5bc0b6c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -399,7 +399,9 @@ public class GroovyAnnotator extends GroovyElementVisitor { private static void checkSameNameMethodsWithDifferentAccessModifiers(AnnotationHolder holder, GrMethod[] methods) { MultiMap<String, GrMethod> map = MultiMap.create(); for (GrMethod method : methods) { - map.putValue(method.getName(), method); + if (!method.isConstructor()) { + map.putValue(method.getName(), method); + } } for (Map.Entry<String, Collection<GrMethod>> entry : map.entrySet()) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java index ab26e68ff8d5..bbeb15b49e4f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeStyle/GroovyLanguageCodeStyleSettingsProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -223,8 +223,9 @@ public class GroovyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe "SPACE_BEFORE_ANOTATION_PARAMETER_LIST", "SPACE_WITHIN_ANNOTATION_PARENTHESES" ); - consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_IN_NAMED_ARGUMENT", "In named argument after ':'", - CodeStyleSettingsCustomizable.SPACES_OTHER); + consumer.renameStandardOption("SPACE_AROUND_RELATIONAL_OPERATORS", "Relational operators (<, >, <=, >=, <=>)"); + + consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_IN_NAMED_ARGUMENT", "In named argument after ':'", CodeStyleSettingsCustomizable.SPACES_OTHER); consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_WITHIN_LIST_OR_MAP", "List and maps literals", CodeStyleSettingsCustomizable.SPACES_WITHIN); consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_BEFORE_CLOSURE_LBRACE", "Closure left brace in method calls", CodeStyleSettingsCustomizable.SPACES_BEFORE_LEFT_BRACE); consumer.showCustomOption(GroovyCodeStyleSettings.class, "SPACE_WITHIN_GSTRING_INJECTION_BRACES", "GString injection braces", CodeStyleSettingsCustomizable.SPACES_WITHIN); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/models/spacing/SpacingTokens.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/models/spacing/SpacingTokens.java index f786f3167b8d..9dde8fff5625 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/models/spacing/SpacingTokens.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/models/spacing/SpacingTokens.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ public interface SpacingTokens extends GroovyElementTypes { TokenSet LOGICAL_OPERATORS = TokenSet.create(mLAND, mLOR); TokenSet EQUALITY_OPERATORS = TokenSet.create(mEQUAL, mNOT_EQUAL); - TokenSet RELATIONAL_OPERATORS = TokenSet.create(mGT, mGE, mLT, mLE); + TokenSet RELATIONAL_OPERATORS = TokenSet.create(mGT, mGE, mLT, mLE, mCOMPARE_TO); TokenSet BITWISE_OPERATORS = TokenSet.create(mBAND, mBOR, mBXOR); TokenSet ADDITIVE_OPERATORS = TokenSet.create(mPLUS, mMINUS); TokenSet MULTIPLICATIVE_OPERATORS = TokenSet.create(mSTAR, mDIV, mMOD); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/declaration/GrIntroduceLocalVariableIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/declaration/GrIntroduceLocalVariableIntention.java index ac459d01d722..a099692b7e3f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/declaration/GrIntroduceLocalVariableIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/declaration/GrIntroduceLocalVariableIntention.java @@ -46,6 +46,12 @@ public class GrIntroduceLocalVariableIntention extends Intention { editor.getSelectionModel().setSelection(offset, offset + length); } + + @Override + public boolean startInWriteAction() { + return false; + } + @Override protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { setSelection(editor, getTargetExpression(element)); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/navbar/GrNavBarModelExtension.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/navbar/GrNavBarModelExtension.java index 71d99c11b8a2..e5b5681fc4fa 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/navbar/GrNavBarModelExtension.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/navbar/GrNavBarModelExtension.java @@ -15,35 +15,22 @@ */ package org.jetbrains.plugins.groovy.navbar; -import com.intellij.ide.navigationToolbar.NavBarModelExtension; -import com.intellij.openapi.project.Project; +import com.intellij.ide.navigationToolbar.AbstractNavBarModelExtension; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; import org.jetbrains.plugins.groovy.GroovyFileType; import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; -import java.util.Collection; - /** * Created by Max Medvedev on 9/5/13 */ -public class GrNavBarModelExtension implements NavBarModelExtension { - @Override - public String getPresentableText(Object object) { - return null; - } - - @Override - public PsiElement getParent(PsiElement psiElement) { - return null; - } +public class GrNavBarModelExtension extends AbstractNavBarModelExtension { @Override public PsiElement adjustElement(PsiElement psiElement) { @@ -69,11 +56,6 @@ public class GrNavBarModelExtension implements NavBarModelExtension { return containingFile; } - return psiElement.isPhysical() ? psiElement : null; - } - - @Override - public Collection<VirtualFile> additionalRoots(Project project) { - return ContainerUtil.emptyList(); + return psiElement; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java index dff59a8df2a7..fa12c816f96c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -119,6 +119,8 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner { params.getProgramParametersList().add("--main"); params.getProgramParametersList().add(mainClass); + addClasspathFromRootModel(module, tests, params, true); + if (params.getVMParametersList().getPropertyValue(GroovycOSProcessHandler.GRAPE_ROOT) == null) { String sysRoot = System.getProperty(GroovycOSProcessHandler.GRAPE_ROOT); if (sysRoot != null) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy index f31fa1461810..a7ded292fefa 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ public class FormatterTest extends GroovyFormatterTestCase { public void testArg2() throws Throwable { doTest(); } public void testBin1() throws Throwable { doTest(); } public void testBin2() throws Throwable { doTest(); } + public void testBin3() throws Throwable { doTest(); } public void testBlockExpr1() throws Throwable { //groovySettings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE = false groovySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy index e5692615da6c..87f7ba7e73ae 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy @@ -1704,6 +1704,11 @@ class E { <error>private foo()</error>{} <error>def foo(int x)</error> {} } + +class Z { + private Z() {} //correct + private Z(x) {} //correct +} ''') } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceVariable/IntroduceLocalVariableTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceVariable/IntroduceLocalVariableTest.groovy index 5d307b4edf59..63e5a759e505 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceVariable/IntroduceLocalVariableTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceVariable/IntroduceLocalVariableTest.groovy @@ -62,7 +62,7 @@ public class IntroduceLocalVariableTest extends GrIntentionTestCase { static class MockGrIntroduceLocalVariableIntention extends GrIntroduceLocalVariableIntention { @Override - protected void processIntention(PsiElement element, Project project, Editor editor) throws IncorrectOperationException { + protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { setSelection(editor, getTargetExpression(element)); MockSettings settings = new MockSettings(false, "varName", null, false) new MockGrIntroduceVariableHandler(settings).invoke(project, editor, element.containingFile, null); diff --git a/plugins/groovy/testdata/groovy/formatter/bin3.test b/plugins/groovy/testdata/groovy/formatter/bin3.test new file mode 100644 index 000000000000..bb943d5cfb62 --- /dev/null +++ b/plugins/groovy/testdata/groovy/formatter/bin3.test @@ -0,0 +1,3 @@ +a<=>b +----- +a <=> b
\ No newline at end of file diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java index 388456c75255..53cb43d9e457 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java @@ -162,7 +162,8 @@ public class HgLogProvider implements VcsLogProvider { @NotNull @Override public List<? extends VcsFullCommitDetails> getFilteredDetails(@NotNull final VirtualFile root, - @NotNull Collection<VcsLogFilter> filters) throws VcsException { + @NotNull Collection<VcsLogFilter> filters, + int maxCount) throws VcsException { List<String> filterParameters = ContainerUtil.newArrayList(); List<VcsLogBranchFilter> branchFilters = ContainerUtil.findAll(filters, VcsLogBranchFilter.class); @@ -225,7 +226,7 @@ public class HgLogProvider implements VcsLogProvider { } } - return HgHistoryUtil.history(myProject, root, -1, ArrayUtil.toStringArray(filterParameters)); + return HgHistoryUtil.history(myProject, root, maxCount, ArrayUtil.toStringArray(filterParameters)); } @Nullable diff --git a/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestRunnerUtil.java b/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestRunnerUtil.java index b56056955983..106e0b2f20b7 100644 --- a/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestRunnerUtil.java +++ b/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestRunnerUtil.java @@ -15,6 +15,7 @@ */ package com.intellij.junit4; +import com.intellij.junit3.TestRunnerUtil; import org.junit.Ignore; import org.junit.internal.AssumptionViolatedException; import org.junit.internal.requests.ClassRequest; @@ -76,6 +77,10 @@ public class JUnit4TestRunnerUtil { } String suiteName = packageName.length() == 0 ? "<default package>": packageName; Class[] classes = getArrayOfClasses(result); + if (classes.length == 0) { + System.out.println(TestRunnerUtil.testsFoundInPackageMesage(0, suiteName)); + return null; + } Request allClasses; try { Class.forName("org.junit.runner.Computer"); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/references/MavenPropertyPsiReferenceProvider.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/references/MavenPropertyPsiReferenceProvider.java index f839a4392b6c..3c2e7e1dc026 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/references/MavenPropertyPsiReferenceProvider.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/references/MavenPropertyPsiReferenceProvider.java @@ -114,7 +114,7 @@ public class MavenPropertyPsiReferenceProvider extends PsiReferenceProvider { ref = new MavenPropertyPsiReference(mavenProject, element, propertyName, range, isSoft); } else { - ref = new MavenContextlessPropertyReference(propertiesTag, element, range, isSoft); + ref = new MavenContextlessPropertyReference(propertiesTag, element, range, true); } result.add(ref); diff --git a/plugins/maven/src/main/resources/images/executeMavenGoal@2x.png b/plugins/maven/src/main/resources/images/executeMavenGoal@2x.png Binary files differnew file mode 100644 index 000000000000..d40fd0814ead --- /dev/null +++ b/plugins/maven/src/main/resources/images/executeMavenGoal@2x.png diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDontCheckDependencyInManagementSectionTest.groovy b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDontCheckDependencyInManagementSectionTest.groovy index 69c440369683..0a81133fa015 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDontCheckDependencyInManagementSectionTest.groovy +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDontCheckDependencyInManagementSectionTest.groovy @@ -28,18 +28,18 @@ class MavenDontCheckDependencyInManagementSectionTest extends MavenDomTestCase { <dependencies> <dependency> - <groupId>xxxx</groupId> - <artifactId>yyyy</artifactId> - <version>zzzz</version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>777</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> - <groupId>xxxx</groupId> - <artifactId>yyyy</artifactId> - <version>zzzz</version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>777</version> </dependency> </dependencies> </dependencyManagement> @@ -47,18 +47,18 @@ class MavenDontCheckDependencyInManagementSectionTest extends MavenDomTestCase { <build> <plugins> <plugin> - <groupId>xxxx</groupId> - <artifactId>yyyy</artifactId> - <version>zzzz</version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>777</version> </plugin> </plugins> <pluginManagement> <plugins> <plugin> - <groupId>xxxx</groupId> - <artifactId>yyyy</artifactId> - <version>zzzz</version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>777</version> </plugin> </plugins> </pluginManagement> @@ -72,18 +72,18 @@ class MavenDontCheckDependencyInManagementSectionTest extends MavenDomTestCase { <dependencies> <dependency> - <groupId><error>xxxx</error></groupId> - <artifactId><error>yyyy</error></artifactId> - <version><error>zzzz</error></version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version><error>777</error></version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> - <groupId>xxxx</groupId> - <artifactId>yyyy</artifactId> - <version>zzzz</version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>777</version> </dependency> </dependencies> </dependencyManagement> @@ -91,18 +91,18 @@ class MavenDontCheckDependencyInManagementSectionTest extends MavenDomTestCase { <build> <plugins> <plugin> - <groupId><error>xxxx</error></groupId> - <artifactId><error>yyyy</error></artifactId> - <version><error>zzzz</error></version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version><error>777</error></version> </plugin> </plugins> <pluginManagement> <plugins> <plugin> - <groupId>xxxx</groupId> - <artifactId>yyyy</artifactId> - <version>zzzz</version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>777</version> </plugin> </plugins> </pluginManagement> diff --git a/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesFile.java b/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesFile.java index efd5b47d7626..aeb607d89cb0 100644 --- a/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesFile.java +++ b/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesFile.java @@ -32,10 +32,9 @@ import com.intellij.psi.util.CachedValueProvider; import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; -import com.intellij.util.IncorrectOperationException; import com.intellij.reference.SoftLazyValue; +import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.MultiMap; -import com.intellij.util.text.CharArrayUtil; import gnu.trove.THashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -82,14 +81,7 @@ public class XmlPropertiesFile implements PropertiesFile { new CachedValueProvider<PropertiesFile>() { @Override public Result<PropertiesFile> compute() { - CharSequence contents = file.getViewProvider().getContents(); - PropertiesFile value = null; - if (CharArrayUtil.indexOf(contents, XmlPropertiesIndex.HTTP_JAVA_SUN_COM_DTD_PROPERTIES_DTD, 0) != -1 && - XmlPropertiesIndex.isAccepted(contents) - ) { - value = new XmlPropertiesFile(file); - } - + PropertiesFile value = XmlPropertiesIndex.isPropertiesFile(file) ? new XmlPropertiesFile(file) : null; return Result.create(value, file); } }, false); diff --git a/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesIndex.java b/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesIndex.java index 467f656aeb71..370f07fab505 100644 --- a/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesIndex.java +++ b/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesIndex.java @@ -2,12 +2,19 @@ package com.intellij.lang.properties.xml; import com.intellij.ide.highlighter.XmlFileType; import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.project.DumbService; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.StreamUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.xml.XmlFile; import com.intellij.util.Consumer; import com.intellij.util.indexing.*; -import com.intellij.util.io.*; +import com.intellij.util.io.DataExternalizer; +import com.intellij.util.io.EnumeratorStringDescriptor; +import com.intellij.util.io.IOUtil; +import com.intellij.util.io.KeyDescriptor; import com.intellij.util.text.CharArrayUtil; import com.intellij.util.xml.NanoXmlUtil; import net.n3.nanoxml.StdXMLReader; @@ -31,7 +38,7 @@ public class XmlPropertiesIndex extends FileBasedIndexExtension<XmlPropertiesInd public static final ID<Key,String> NAME = ID.create("xmlProperties"); private static final EnumeratorStringDescriptor ENUMERATOR_STRING_DESCRIPTOR = new EnumeratorStringDescriptor(); - public static final String HTTP_JAVA_SUN_COM_DTD_PROPERTIES_DTD = "http://java.sun.com/dtd/properties.dtd"; + private static final String HTTP_JAVA_SUN_COM_DTD_PROPERTIES_DTD = "http://java.sun.com/dtd/properties.dtd"; @NotNull @Override @@ -94,7 +101,23 @@ public class XmlPropertiesIndex extends FileBasedIndexExtension<XmlPropertiesInd return map; } - static boolean isAccepted(CharSequence bytes) { + static boolean isPropertiesFile(XmlFile file) { + Project project = file.getProject(); + if (DumbService.isDumb(project)) { + CharSequence contents = file.getViewProvider().getContents(); + return CharArrayUtil.indexOf(contents, HTTP_JAVA_SUN_COM_DTD_PROPERTIES_DTD, 0) != -1 && + isAccepted(contents); + } + return !FileBasedIndex.getInstance().processValues(NAME, MARKER_KEY, file.getVirtualFile(), + new FileBasedIndex.ValueProcessor<String>() { + @Override + public boolean process(VirtualFile file, String value) { + return false; + } + }, GlobalSearchScope.allScope(project)); + } + + private static boolean isAccepted(CharSequence bytes) { MyIXMLBuilderAdapter builder = parse(bytes, true); return builder != null && builder.accepted; } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/RootUrlInfo.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/RootUrlInfo.java index 73ec70bfd518..2f7c9ffb67fb 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/RootUrlInfo.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/RootUrlInfo.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. @@ -43,7 +43,7 @@ public class RootUrlInfo implements RootUrlPair { myNode = node; myFormat = format; myRoot = root; - myRepositoryUrl = UriUtil.trimLastSlash(node.getRepositoryRootUrl().toString()); + myRepositoryUrl = UriUtil.trimTrailingSlashes(node.getRepositoryRootUrl().toString()); myType = type; } diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisRepositoryEditor.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisRepositoryEditor.java index 7af64faeabfb..3d45b11ccb6e 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisRepositoryEditor.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/mantis/MantisRepositoryEditor.java @@ -1,3 +1,18 @@ +/* + * 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.tasks.mantis; import com.intellij.openapi.project.Project; @@ -32,7 +47,7 @@ public class MantisRepositoryEditor extends BaseRepositoryEditor<MantisRepositor @Override public void apply() { - if (!myRepository.getUrl().equals(UriUtil.trimLastSlash(myURLText.getText())) || + if (!myRepository.getUrl().equals(UriUtil.trimTrailingSlashes(myURLText.getText())) || !myRepository.getUsername().equals(myUserNameText.getText()) || !myRepository.getPassword().equals(myPasswordText.getText())) { resetComboBoxes(); diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/vfs/TerminalSessionsVFS.java b/plugins/terminal/src/org/jetbrains/plugins/terminal/vfs/TerminalSessionsVFS.java deleted file mode 100644 index b1439ccd069c..000000000000 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/vfs/TerminalSessionsVFS.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.plugins.terminal.vfs; - -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; -import com.intellij.openapi.project.ProjectManagerAdapter; -import com.intellij.openapi.startup.StartupManager; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.openapi.vfs.ex.dummy.DummyFileSystem; -import com.intellij.util.containers.BidirectionalMap; -import com.intellij.util.containers.HashMap; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.IOException; -import java.util.Map; - -/** - * @author traff - */ -public class TerminalSessionsVFS extends DummyFileSystem { - @NonNls private static final String PROTOCOL = "terminalDummy"; - @NonNls private static final String PATH_PREFIX = "terminal"; - @NonNls private static final String PROTOCOL_SEPARATOR = ":/"; - - private final BidirectionalMap<Project, String> myProject2Id = new BidirectionalMap<Project, String>(); - private final Map<String, VirtualFile> myCachedFiles = new HashMap<String, VirtualFile>(); - - private ProjectManagerAdapter myProjectManagerListener; - - public static TerminalSessionsVFS getTerminalSessionVFS() { - return (TerminalSessionsVFS)VirtualFileManager.getInstance().getFileSystem(PROTOCOL); - } - - @Override - @Nullable - public VirtualFile createRoot(String name) { - return null; - } - - public void initListener() { - if (myProjectManagerListener == null || ApplicationManager.getApplication().isUnitTestMode()) { - myCachedFiles.clear(); - myProject2Id.clear(); - for (Project project : ProjectManager.getInstance().getOpenProjects()) { - onProjectOpened(project); - } - } - if (myProjectManagerListener == null) { - myProjectManagerListener = new ProjectManagerAdapter() { - @Override - public void projectOpened(final Project project) { - onProjectOpened(project); - } - - @Override - public void projectClosed(final Project project) { - onProjectClosed(project); - } - }; - ProjectManager.getInstance().addProjectManagerListener(myProjectManagerListener); - } - } - - public void onProjectClosed(final Project project) { - myCachedFiles.clear(); - myProject2Id.remove(project); - } - - public void onProjectOpened(final Project project) { - myProject2Id.put(project, project.getLocationHash()); - StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() { - @Override - public void run() { -// DatabaseEditorHelper.installEditorFactoryListener(project); TODO:? - } - }); - } - - @Override - public VirtualFile findFileByPath(@NotNull String path) { - throw new UnsupportedOperationException("not implemented yet"); //TODO: implement TerminalSessionManager and store there terminal sessions by handle ID - } - - public static String getPath(Project project, final String dataSourceId, final String tableName, String typeName) { - return PATH_PREFIX + typeName + PROTOCOL_SEPARATOR + project.getLocationHash() + "/" + dataSourceId + "/" + tableName; - } - - @Override - @NotNull - public String getProtocol() { - return PROTOCOL; - } - - @Override - public boolean isReadOnly() { - return false; - } - - @Override - public void renameFile(Object requestor, @NotNull VirtualFile vFile, @NotNull String newName) throws IOException { - throw new UnsupportedOperationException("renameFile not supported"); - } - - @Override - @NotNull - public String extractPresentableUrl(@NotNull String path) { - VirtualFile file = findFileByPath(path); - return file != null ? file.getPresentableName() : super.extractPresentableUrl(path); - } -} |