diff options
author | Tor Norbye <tnorbye@google.com> | 2014-04-25 07:38:52 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2014-04-25 07:38:58 -0700 |
commit | 0f831a730c50607e2ffd95020875af6185e17734 (patch) | |
tree | 3caf947bbfceeb37eda9c4a1bee319fdd7678fe5 /plugins/InspectionGadgets | |
parent | 92584642bab4fdb27ac1067c124f4636be762978 (diff) | |
download | idea-0f831a730c50607e2ffd95020875af6185e17734.tar.gz |
Snapshot idea/136.1761 from git://git.jetbrains.org/idea/community.git
3608216: Merge remote-tracking branch 'origin/master'
0d16248: Django inspection HTMLs moved to appropriate place
1ed8715: PY-1194 Provide completion and navigation for url tag in django template Inspection added.
4c6ec52: Naive fix for EA-53569
44c2a03: Do not wrap border with TitledBorder if there is not title
8591130: omg2 [r=ignatov]
dce57e7: omg
3b164b9: Merge remote-tracking branch 'origin/master'
9c04fe7: Ctrl-Q: process java 8 signature style as 1.8 javadoc could also be run on sources 1.6 (IDEA-124175)
b073132: javadoc: ensure that generic arguments are shown in error presentation
b8fb550: IDEA-124271
209d176: disable stream api conversion on iterable (IDEA-124222)
6ca89eb: default external javadoc url for java 8 fixed (IDEA-124175)
2fe28f0: Merge remote-tracking branch 'origin/master'
f65712c: Merge remote-tracking branch 'origin/master'
7de60e2f: Don't escape spaces as it brakes mappings and they are escaped later in GeneralCommandLine (PY-12550).
2bd67bc: IDEA-90194 Ability to disable drag & drop in Project View
f772fb2: Merge remote-tracking branch 'origin/master'
817908d: fixed importing for the iron python
053b716: Merge remote-tracking branch 'origin/master'
1d04dc7: fixed unittest folder tests
76f35f3: suppress doCancelAction
0d9b47d: IDEA-124260 Data Sources and Drivers: can't apply changes to schemas that are shown and used to resolve
f72e4f5: testdata for IDEA-124148
1c431a8: create meth reference from usage: substitute param types (IDEA-124322)
c160fc5: copy to temp/array for non-effectively final variables used in lambda expressions
265f0dc: lambda -> anonymous: static calls (IDEA-124187)
2200bba: method hierarchy: search functional expressions by current method only (IDEA-124320); navigation (IDEA-124319)
54ced00: highlight all pairs of methods with same erasures (IDEA-124116)
f3efd90: IDEA-120865 jre7 osx fullscreen: "space" is not freed when project is closed
6924cc4: IDEA-118062 Gradle Run Configuration: 'working directory' is set incorrectly
09333b1: External system: source package prefix support added; fix for out-of-process mode support
6de52dc: Gradle: update Tooling API version up to 1.12-rc-1, fix classpath for out-of-process mode
4ff20d5: InconsistentResourceBundle test fixed
90bb5ab: IDEA-124301 jdk9 builds cannot be used for project/module compilation
1236318: always go to file if nothing found
43f40bf: Merge remote-tracking branch 'origin/master'
b2d0942: Add default mapping to /vagrant only in case of absent mappings in Vagrantfile (PY-12700).
fc31680: IDEA-124290
773f103: Offer to launch Vagrant if it is down on getting ssh-config (PY-12672).
460ef41: DumbService.smartInvokeLater(...)
577579d: cleanup after extracting java postfix template provider
214f99b: IDEA-103836
a41e7d8: Merge remote-tracking branch 'origin/master'
4076596: fixed memory leak
c5207b2: fixed PY-12543 Project Interpreters: too big or too small details popup
40d91f5: IDEA-63106 new inspections added to InconsistentResourceBundleInspection
4bc9f42: fixed PY-12690 Detected from creating virtualenv interpreter has invalid slashes
e6d8c98: extract right arrow
43b861b: don't use borders and insets in output html/rtf (IDEA-67767)
6c4dbea: use service instead of application component (IDEA-67767)
aa6fb9f: remove 'Strip common indent' setting from UI (IDEA-67767)
5651ab5: IDEA-123775 (String.equals("") inspection fixes code incorrectly)
c1d9f5f: fixed PY-12696 Create VirtualEnv: when adding first base interpreter it is not selected right away
482491a: Platform: Local History can survive for more than 30 days now (int overflow fixed)
a0125dc: Platform: always allow writing module files (IDEA-123899)
3a294e9: removed unused component methods
7cc124e: optimisation: avoid containingfile calculation
06f574a: readable toString()
60f2a36: perforce tests fixed
46fea0f: fewer create/delete operations
7269bce: drain file type detection queue in tests
d0c6ef5: cleanup
9df7136: Gradle: installer build fix
152c230: Platform: Local History can survive for more than 30 days now
f5e7215: do not rely on memory index storage isBufferedFlag to process physical file contents
ebe62cf: customize password field labels
97ade8d: ability to enable only visible components
3541938: introduce beforeOKAction()
13bf7e1: cleanup
4a12b1f: junit: workaround for old junit versions (IDEA-124201)
21003e0: Merge remote-tracking branch 'origin/master'
c2067ff: PY-1194 Provide completion and navigation for url tag in django template PY-3591 Support {% url %} tag arguments completion
5f295fe: do not cancel offline inspections
2b8e2e8: add unchecked warning calls also for method references
57e886f: testdata: check that method ref on static interface method is accepted
8bad807: lambda: do not skip generic method when non-generic method exist in the same class
7d74b9d: NPE
0da9f91: testdata: ensure overload resolution prefer correct one from methods with boxed types
2c49817: NPE
d5107d6: testdata: ensure intersection type is not missed during inference
7898108: testdata: ensure lambda can't be inferred from type parameter
5b91054: testdata: ensure overload resolution by return type should not take place for interrupted control flow
9aa2f3a: testdata: ensure correct parameters number in functional interface method
1698f7b: testdata: ensure method ref qualified are checked over static problems
b49d8e75: testdata
f1f6fcf: functional interfaces: ignore methods with type parameters during abstract method choosing
a55db18: lambda: accept intersection type when exactly one conjunct is functional
4a34bd5: do not report unrelated return type error only for generics methods
76a9293: testdata
17b020f: new overload resolution: covariant comparison of return types
98ab76f: new overload resolution: most specific check on invalid class exceptions fixed
552dfe9: lambda: intersection type produces conjunction of abstract methods
bd9dbfc: testdata
9914757: warn about underscore identifier
72ae579: IDEA-109187 new HgReference validator implemented
d86307e: tip reference moved as a separated static constant to HgUtil
71cd276: Fix scrolling in module aware configurables [r=ushakov]
37ed33e: Missed commit for IDEA-79312
da52f84: IDEA-79312 text cursor gets lost - could bee disabled by focus.fix.lost.cursor key
a39b289: [git log] IDEA-122305 Fix structure filter.
339dd23: beforeShown() & preselect laf-default editor scheme 2
f9d8704: PY-1194 Provide completion and navigation for url tag in django template PY-3591 Support {% url %} tag arguments completion
17e8b30: ctrl+delete/ctrl+backspace enhancements IDEA-100906 Ruby-Editor: CTRL+BACKSPACE Could Not Delete A String
a95fd00: remove copyright messages
bf06d9d: read-action for getFilesForFastWordSearch
cdcd770: IDEA-123687 Velocity formatter inserts wrong linebreak
562443f: Fixed WI-17474 Custom Folding: defaultstate="collapsed" does not seem to have any effect (the node itself is already a line comment)
d86998d: Cleanup warnings
4bbd22c: jb v8 debug protocol: evaluate
46eaf0b: NPE
4101b8c: cleanup
399e745: write action required
004dfc4: IDEA-124220 Auto-popup parameter info should work after smart completion which inserted a comma
0bd06e5: More on comparison that is always false due to being out of type range on implicit type conversion (IDEA-124210)
b6bccb7: AppCode: minimum OS X version specified in .app
ca8a657: add aliases for Lafs
e254ebf: Merge branch 'master' of git.labs.intellij.net:idea/community
5c594f6: Gradle: update Tooling API version up to 1.12-rc-1
17fcca3: Merge remote-tracking branch 'origin/master'
5248eb0: IDEA-119996 FilePathImpl: avoid VFS refresh from getVirtualFile etc.
9c69111: [vcs] Reuse the VirtualFile instead of creating FilePathImpl on File
c08f50b: fixed EA-54835 - NPE: PythonNoseTestConfigurationProducer.isAvailable
d627711: fixed EA-55749 - AIOOBE: PyStructuredDocstringFormatter.formatDocstring
c9a1c11: apply laf once, fix stale bg, add beforeShown() & preselect laf-default editor scheme
3e576c2: fixed EA-55872 - NPE: PyProtectedMemberInspection$Visitor.checkReference
147c647: use ValueType enum instead of plain numbers
2e517c5: IDEA-112050 vcs: fix ByteBuffer to array conversion
97a6a21: possible race condition fixed
cb20ef5: Prevent horizontal scrollbar appearance if an error message is too long
cbb86d4: IDEA-124021 Cannot resolve method 'print(int)' with JSP custom tags: comment
362b4d7: IDEA-123986 New project wizard: remove highlighting from disabled templates
cc57b39: do not include runtime dependencies to compilation scope (ZD-25927)
7ac3c11: paste rich-text data: NPE fixed
89ca157: Extract Java live postfix templates provider
e5eb7aa: EA-31437 - assert: DocumentFoldingInfo.writeExternal
e2461d5: use JBImageIcon
e9eb171: initial
ed33f35: fix Keymap page on Mac/Darcula. see same in LafManager for more info.
99bc2e9: open some API
d9aed3f: process class names just once in completion
094f040: IDEA-122362 'getClass()' should be suggested in smart completion if Class<? extends SomeAncestorOfCurrentClass> is expected
1a34573: IDEA-120139 Autopopup doesn't popup sometimes after completion
e8c981a: create LookupUi and move there some ui-related code from LookupImpl; skip this code in tests
89d771e: @NotNull
8d25ba3: Merge remote-tracking branch 'origin/master'
7fcce27: fix darcula lafinfo
bfef59e: Start plugins wizard #19 usability improvements
5cbd491: minor fix
58d2f15: fix bg
40fa260: don't create content entry for temp directory of temp project when opening single file
e31a4c1: Correctly handle custom folding "desc" attribute followed by "defaultstate"
448e9f8: don't report on incomplete code or comparisons that are already reported by "Constant conditions & exceptions"
6e68111: remove superfluous inspection
a2cc5ba: expand description
814378f: Gradle: gradle distribution pattern updated
e9485f0: use TransparentPanel
db66426: initial
a712571: suppress unused params inspection
640ddf3: make labels have constant height to avoid relayout and blinking
921f39e: don't fill bg if component is not opaque
a43d7f8: added new test for live postfix templates
50addd3: IDEA-123935 New Project wizard: no project/global libraries are created on new module adding via project structure
6021da6: Merge remote-tracking branch 'origin/master'
36848a5: fixed test data
7a63d2b: Gradle: tooling extensions integration tests, avoid dependency for explicit distributions downloading in a separate run configuration (like this one http://buildserver.labs.intellij.net/viewType.html?buildTypeId=IDEATrunk_GradleDownloads)
405332a: make richCopy functionality work properly on Linux (IDEA-67767)
3dca908: some 'finally' blocks
00a4968: reverted content-dependent flag
6064460: Merge remote-tracking branch 'origin/master'
5f203cb: Fixed IDEA-124191 Code style preference : space within empty method call/declaration parentheses are not saved
0419dcc: EA-56035 - NCDFE: UnixProcessManager.<clinit>
0285ece: cleanup: use ordinary invokeLater and avoid unnecessary synchronization
0922a97: Vagrant error messaging fixed.
2676330: Save vagrant executable path to application settings (PY-12680).
947d8ab: missing test data
6154126: IDEA-124137 (Inspection: "equals() between objects of inconvertible types" should support java.util.Objects.equals() or com.google.common.base.Objects.equal())
c9fd1bb: fix name
f3ec0f7: lookup arranger tweak [zolotov, shrago] relates to IDEA-121998 SQL code completion too aggressive
c324511: fix escaping, parse decimal literals #WEB-11938 fixed
a5bcae9: Github: fix error message
95d057d: Github: fix invalid condition
dda5341: Github: log invalid requests
d493d76: it is even better to store deltas for direct mapping values
a67ac0b: proper unpacking code
3ea5951: Properties AST factory moved to impl
c0550f7: save keys of particular snapshot before and out of index update optimistically load keys of particular snapshot before and out of index update
d6a5968: custom implementation for IdIndex inputs mapping: -20% for saving deltas
b52691e: saving / reading longs in compact variable byte format + using it for simplier code in PersistentHashMapValueStorage
0ae869e: cleanup
3222cd0: cleanup
e96aa7b: use Gray.TRANSPARENT
2861f10: use Gray.TRANSPARENT
c009821: Merge remote-tracking branch 'origin/master'
caa86fc: what a nice NPE!
3c769ac: goto popup calculations should be cancellable even after Ctrl+Space (IDEA-123714 ?)
c6fcabf: IDEA-122250 New Package: qualified name is checked against ignored directories as a whole
3af306c: IDEA-55556 Inspection suggestion: Comparison that is always false due to being out of type range on implicit type conversion
996d0c6: IDEA-123782 "Complete current statement" doesn't put colon for case branches
7a2cc54: IDEA-122383 PageUp/PageDown don't work in ShowUsages popup (Ctrl-Alt-F7)
29fec22: IDEA-123948 Constant condition and exceptions: false positive on MappedByteBuffer.getInt
0fd86de: IDEA-122946 final modifier not inserted when completing a sequence of parameters from an inner method IDEA-123493 Smart completion makes completed variable final
019a68b: IDEA-123289 Infer nullability of 'for each' variable from type annotations of the collection parameter
c18c4ff: IDEA-120964 Make it more obvious that background compiler is disabled in power save mode
dc2f64a: use superclass for inner class variable name suggestion (IDEA-122109)
c47713f: prefer T if Class<? extends T> is expected (IDEA-121339)
c960901: OC-9559 IDEA-107592
64fc873: cleanup
c159a1a: Start plugins wizard #17
043fa14: extra assert
7eac40c: larger btree block size / load factor increased for better space utilization
a4598a1: enable snapshot mapping
e80c2b3: trigram index enabled in internal mode
527f139: delta encoding of file id set to decrease output size ~3x
a47785b: move to MnemonicHelper
5b12f32: cleanup
27ef5f4: bg progresses for presentation mode
656e311: add transparent color
ddce960: EA-55788 - assert: GitRepositoryImpl
dfc2ef7: external-system: project import fixed to use correct fileToImport
675d14e: OC-9559 IDEA-107592
e6d5ea6: IDEA-86665 hg annotate: ignore whitespace changes
6e551ba: test hg executor updated with ignoreNonZeroExitCode addition option
8798162d: cleanup
45f98c5: IDEA-124021 Cannot resolve method 'print(int)' with JSP custom tags
67f1d44: Better fix for IDEA-124096 open commit actions popup on ctrl+alt+P
8aab4ce: IDEA-123691 Minor project wizard edits: moving settings to the first page
9cb1c40: IDEA-122845 Try to fetch issues, if resource with information about user is not available in this version of Redmine
a2c9393: Add key to JiraRepository to enable old behavior where credentials were sent with every request via basic auth
ce17994: Add special type of exception to indicate request failure from response handlers and other callbacks. ResponseHandler has option to suppress exceptions, if requested resource was not found.
de0f3df: notnull, toString
10c30e2: IDEA-123886, dropped UTF guessing setting
bf14e11: remove obsolete cruft
7b15687: notnull
c82fb9d: mem leak
de48566: test
8a9b3d0: doc leak
d163e52: comment
1274dba: removed confusing createTempPath()
057c5f9: do not expand usage tree if there are too many nodes
e7f245f: debugging IDEA-120167 Phantom eternal Ant task on make
6bf1671: Merge remote-tracking branch 'origin/master'
be70ee8: PY-2880: Django: provide completion for context_object_name value in django template * test added * fixture:complete() is reenterable now
1a99a14: Start plugins wizard #16 and it works
30f6e0e: fix false positive with smart tabs
76fcb91: use provided value description instead of just classname don't compute object presentation by custom configured properties if value description is not equals to class name
014c0e3: jb v8 debug protocol: load full string value
223f19a: typo
339e7d6: WEB-11834 IIS ACL Permissions when creating foundation/bootstrap projects from templates
b875e62: remove freemarker leftovers from html lexer #WEB-11907 fixed
b84c236: push language levels synchronously for non-refresh vfs events (IDEA-123876)
a32e2eb: code style
a593533: Github: mark invalid password as invalid
10d5070: [git] IDEA-124081 implement IDEA-98189 for clone
a9fa3a2: IDEA-124096 open commit actions popup on ctrl+alt+P
83bc60b: AppCode: Xcode keymap tunes for tool windows +review CR-IC-5162
c976200: Merge remote-tracking branch 'origin/master'
48d5f8c: Refactoring: getImportSourceQName() is used
d324bc0: GeneratedFolder icon
5d90886: Add "try-with-resources" live postfix template
cfec5b0: cleanup
e587000: Platform: bug-typo in DnDSupport
814a79a: Unify prefix calculation rules for live templates
f447531: IDEA-124005 Reading resources out of a source directory doesn't make it a resource directory
Change-Id: Ie2989b1157ae12b92c48d9556db64999ea68e83e
Diffstat (limited to 'plugins/InspectionGadgets')
17 files changed, 202 insertions, 328 deletions
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml index a9bfaa130c66..2b47e3a3c33d 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml @@ -394,10 +394,6 @@ <localInspection language="JAVA" shortName="AnonymousInnerClass" bundle="com.siyeh.InspectionGadgetsBundle" key="anonymous.inner.class.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.class.structure" enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.classlayout.AnonymousInnerClassInspection"/> - <localInspection language="JAVA" suppressId="ClassWithoutPackageStatement" shortName="ClassInTopLevelPackage" bundle="com.siyeh.InspectionGadgetsBundle" - key="class.in.top.level.package.display.name" groupBundle="messages.InspectionsBundle" - groupKey="group.names.class.structure" enabledByDefault="false" level="WARNING" - implementationClass="com.siyeh.ig.classlayout.ClassInTopLevelPackageInspection"/> <localInspection language="JAVA" suppressId="NonStaticInitializer" shortName="ClassInitializer" bundle="com.siyeh.InspectionGadgetsBundle" key="class.initializer.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.class.structure" enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.classlayout.ClassInitializerInspection"/> 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 fc0a72508c81..090280531a78 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-2013 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,20 +60,51 @@ public class EqualsBetweenInconvertibleTypesInspection extends BaseInspectionVisitor { @Override - public void visitMethodCallExpression( - @NotNull PsiMethodCallExpression expression) { + public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) { super.visitMethodCallExpression(expression); - if (!MethodCallUtils.isEqualsCall(expression)) { - return; - } final PsiReferenceExpression methodExpression = expression.getMethodExpression(); + final boolean staticEqualsCall; + if (MethodCallUtils.isEqualsCall(expression)) { + staticEqualsCall = false; + } + else { + final String name = methodExpression.getReferenceName(); + if (!"equals".equals(name) && !"equal".equals(name)) { + return; + } + final PsiMethod method = expression.resolveMethod(); + if (method == null) { + return; + } + final PsiClass aClass = method.getContainingClass(); + if (aClass == null) { + return; + } + final String qualifiedName = aClass.getQualifiedName(); + if (!"java.util.Objects".equals(qualifiedName) && !"com.google.common.base.Objects".equals(qualifiedName)) { + return; + } + staticEqualsCall = true; + } final PsiExpressionList argumentList = expression.getArgumentList(); final PsiExpression[] arguments = argumentList.getExpressions(); - if (arguments.length != 1) { - return; + final PsiExpression expression1; + final PsiExpression expression2; + if (staticEqualsCall) { + if (arguments.length != 2) { + return; + } + expression1 = arguments[0]; + expression2 = arguments[1]; } - final PsiExpression expression1 = arguments[0]; - final PsiExpression expression2 = methodExpression.getQualifierExpression(); + else { + if (arguments.length != 1) { + return; + } + expression1 = arguments[0]; + expression2 = methodExpression.getQualifierExpression(); + } + final PsiType comparisonType; if (expression2 == null) { final PsiClass aClass = PsiTreeUtil.getParentOfType(expression, PsiClass.class); @@ -94,7 +125,7 @@ public class EqualsBetweenInconvertibleTypesInspection final PsiType comparedTypeErasure = TypeConversionUtil.erasure(comparedType); final PsiType comparisonTypeErasure = TypeConversionUtil.erasure(comparisonType); if (comparedTypeErasure == null || comparisonTypeErasure == null || - TypeConversionUtil.areTypesConvertible(comparedTypeErasure, comparisonTypeErasure)) { + TypeConversionUtil.areTypesConvertible(comparedType, comparisonType)) { return; } registerMethodCallError(expression, comparedType, comparisonType); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspectionBase.java deleted file mode 100644 index dec9e2e662d2..000000000000 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspectionBase.java +++ /dev/null @@ -1,81 +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 com.siyeh.ig.classlayout; - -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiJavaFile; -import com.intellij.psi.util.FileTypeUtils; -import com.siyeh.InspectionGadgetsBundle; -import com.siyeh.ig.BaseInspection; -import com.siyeh.ig.BaseInspectionVisitor; -import com.siyeh.ig.psiutils.ClassUtils; -import org.jetbrains.annotations.NotNull; - -public class ClassInTopLevelPackageInspectionBase extends BaseInspection { - @Override - @NotNull - public String getID() { - return "ClassWithoutPackageStatement"; - } - - @Override - @NotNull - public String getDisplayName() { - return InspectionGadgetsBundle.message( - "class.in.top.level.package.display.name"); - } - - @Override - @NotNull - protected String buildErrorString(Object... infos) { - return InspectionGadgetsBundle.message( - "class.in.top.level.package.problem.descriptor"); - } - - @Override - protected boolean buildQuickFixesOnlyForOnTheFlyErrors() { - return true; - } - - @Override - public BaseInspectionVisitor buildVisitor() { - return new ClassInTopLevelPackageVisitor(); - } - - private static class ClassInTopLevelPackageVisitor - extends BaseInspectionVisitor { - - @Override - public void visitClass(@NotNull PsiClass aClass) { - // no call to super, so that it doesn't drill down to inner classes - if (FileTypeUtils.isInServerPageFile(aClass)) { - return; - } - if (ClassUtils.isInnerClass(aClass)) { - return; - } - final PsiFile file = aClass.getContainingFile(); - if (!(file instanceof PsiJavaFile)) { - return; - } - if (((PsiJavaFile)file).getPackageStatement() != null) { - return; - } - registerClassError(aClass); - } - } -} diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspection.java index e4f77e0fbea9..b9f43f708b77 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspection.java @@ -75,7 +75,7 @@ public class InterfaceMayBeAnnotatedFunctionalInspection extends BaseInspection if (LambdaHighlightingUtil.checkInterfaceFunctional(aClass) != null) { return; } - final List<MethodSignature> candidates = LambdaUtil.findFunctionCandidates(aClass); + final List<HierarchicalMethodSignature> candidates = LambdaUtil.findFunctionCandidates(aClass); if (candidates == null || candidates.size() != 1) { return; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java index 6b2f34b1aa47..bebf5a559d15 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java @@ -20,8 +20,8 @@ import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; -import com.intellij.psi.util.ConstantExpressionUtil; import com.intellij.psi.util.PsiUtil; +import com.intellij.psi.util.PsiUtilCore; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; @@ -116,20 +116,19 @@ public class PointlessArithmeticExpressionInspection } else if (tokenType.equals(JavaTokenType.ASTERISK) && isZero(operand) || tokenType.equals(JavaTokenType.PERC) && (isOne(operand) || EquivalenceChecker.expressionsAreEquivalent(previousOperand, operand))) { - return PsiType.LONG.equals(polyadicExpression.getType()) ? "0L" : "0"; - } - else if (tokenType.equals(JavaTokenType.LE) || tokenType.equals(JavaTokenType.GE) || - tokenType.equals(JavaTokenType.LT) || tokenType.equals(JavaTokenType.GT)) { - return (tokenType.equals(JavaTokenType.LT) || tokenType.equals(JavaTokenType.GT)) ? "false" : "true"; + fromTarget = operands[0]; + untilTarget = operands[length - 1]; + replacement = PsiType.LONG.equals(polyadicExpression.getType()) ? "0L" : "0"; + break; } previousOperand = operand; } - return buildReplacementExpression(polyadicExpression, fromTarget, untilTarget, replacement).trim(); + return getText(polyadicExpression, fromTarget, untilTarget, replacement).trim(); } - public static String buildReplacementExpression(PsiPolyadicExpression expression, PsiElement fromTarget, PsiElement untilTarget, - String replacement) { + public static String getText(PsiPolyadicExpression expression, PsiElement fromTarget, PsiElement untilTarget, + @NotNull @NonNls String replacement) { final StringBuilder result = new StringBuilder(); boolean stop = false; for (PsiElement child : expression.getChildren()) { @@ -198,13 +197,10 @@ public class PointlessArithmeticExpressionInspection if (!arithmeticTokens.contains(expression.getOperationTokenType())) { return; } - if (ExpressionUtils.hasStringType(expression)) { + if (ExpressionUtils.hasStringType(expression) || PsiUtilCore.hasErrorElementChild(expression)) { return; } final PsiExpression[] operands = expression.getOperands(); - if (operands.length < 2) { - return; - } final IElementType tokenType = expression.getOperationTokenType(); final boolean isPointless; if (tokenType.equals(JavaTokenType.PLUS)) { @@ -222,14 +218,6 @@ public class PointlessArithmeticExpressionInspection else if (tokenType.equals(JavaTokenType.PERC)) { isPointless = modExpressionIsPointless(operands); } - else if (tokenType.equals(JavaTokenType.LE) || - tokenType.equals(JavaTokenType.GE) || - tokenType.equals(JavaTokenType.GT) || - tokenType.equals(JavaTokenType.LT)) { - final PsiExpression lhs = operands[0]; - final PsiExpression rhs = operands[1]; - isPointless = comparisonExpressionIsPointless(lhs, rhs, tokenType); - } else { isPointless = false; } @@ -292,45 +280,6 @@ public class PointlessArithmeticExpressionInspection } return false; } - - private boolean comparisonExpressionIsPointless( - PsiExpression lhs, PsiExpression rhs, IElementType comparison) { - if (PsiType.INT.equals(lhs.getType()) && - PsiType.INT.equals(rhs.getType())) { - return intComparisonIsPointless(lhs, rhs, comparison); - } - else if (PsiType.LONG.equals(lhs.getType()) && - PsiType.LONG.equals(rhs.getType())) { - return longComparisonIsPointless(lhs, rhs, comparison); - } - return false; - } - - private boolean intComparisonIsPointless( - PsiExpression lhs, PsiExpression rhs, IElementType comparison) { - if (isMaxInt(lhs) || isMinInt(rhs)) { - return JavaTokenType.GE.equals(comparison) || - JavaTokenType.LT.equals(comparison); - } - if (isMinInt(lhs) || isMaxInt(rhs)) { - return JavaTokenType.LE.equals(comparison) || - JavaTokenType.GT.equals(comparison); - } - return false; - } - - private boolean longComparisonIsPointless( - PsiExpression lhs, PsiExpression rhs, IElementType comparison) { - if (isMaxLong(lhs) || isMinLong(rhs)) { - return JavaTokenType.GE.equals(comparison) || - JavaTokenType.LT.equals(comparison); - } - if (isMinLong(lhs) || isMaxLong(rhs)) { - return JavaTokenType.LE.equals(comparison) || - JavaTokenType.GT.equals(comparison); - } - return false; - } } boolean isZero(PsiExpression expression) { @@ -346,32 +295,4 @@ public class PointlessArithmeticExpressionInspection } return ExpressionUtils.isOne(expression); } - - private static boolean isMinInt(PsiExpression expression) { - final Integer value = (Integer) - ConstantExpressionUtil.computeCastTo( - expression, PsiType.INT); - return value != null && value.intValue() == Integer.MIN_VALUE; - } - - private static boolean isMaxInt(PsiExpression expression) { - final Integer value = (Integer) - ConstantExpressionUtil.computeCastTo( - expression, PsiType.INT); - return value != null && value.intValue() == Integer.MAX_VALUE; - } - - private static boolean isMinLong(PsiExpression expression) { - final Long value = (Long) - ConstantExpressionUtil.computeCastTo( - expression, PsiType.LONG); - return value != null && value.longValue() == Long.MIN_VALUE; - } - - private static boolean isMaxLong(PsiExpression expression) { - final Long value = (Long) - ConstantExpressionUtil.computeCastTo( - expression, PsiType.LONG); - return value != null && value.longValue() == Long.MAX_VALUE; - } }
\ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringEqualsEmptyStringInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringEqualsEmptyStringInspection.java index ebd8449909e6..69c2bad8242b 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringEqualsEmptyStringInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringEqualsEmptyStringInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ package com.siyeh.ig.performance; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.HardcodedMethodConstants; @@ -27,6 +29,7 @@ import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.PsiReplacementUtil; import com.siyeh.ig.psiutils.BoolUtils; +import com.siyeh.ig.psiutils.EquivalenceChecker; import com.siyeh.ig.psiutils.ExpressionUtils; import com.siyeh.ig.psiutils.TypeUtils; import org.jetbrains.annotations.NonNls; @@ -97,19 +100,19 @@ public class StringEqualsEmptyStringInspection extends BaseInspection { } final PsiExpression qualifier = expression.getQualifierExpression(); final PsiExpression argument = arguments[0]; - final String variableText; + final PsiExpression checkedExpression; final boolean addNullCheck; if (ExpressionUtils.isEmptyStringLiteral(argument)) { - variableText = getRemainingText(qualifier); + checkedExpression = getCheckedExpression(qualifier); addNullCheck = false; } else { - variableText = getRemainingText(argument); - addNullCheck = true; + checkedExpression = getCheckedExpression(argument); + addNullCheck = !isCheckedForNull(checkedExpression); } - StringBuilder newExpression; + final StringBuilder newExpression; if (addNullCheck) { - newExpression = new StringBuilder(variableText); + newExpression = new StringBuilder(checkedExpression.getText()); newExpression.append("!=null&&"); } else { newExpression = new StringBuilder(""); @@ -121,38 +124,81 @@ public class StringEqualsEmptyStringInspection extends BaseInspection { if (BoolUtils.isNegation(parentExpression)) { expressionToReplace = parentExpression; if (useIsEmpty) { - newExpression.append('!').append(variableText).append(".isEmpty()"); + newExpression.append('!').append(checkedExpression.getText()).append(".isEmpty()"); } else { - newExpression.append(variableText).append(".length()!=0"); + newExpression.append(checkedExpression.getText()).append(".length()!=0"); } } else { expressionToReplace = call; if (useIsEmpty) { - newExpression.append(variableText).append(".isEmpty()"); + newExpression.append(checkedExpression.getText()).append(".isEmpty()"); } else { - newExpression.append(variableText).append(".length()==0"); + newExpression.append(checkedExpression.getText()).append(".length()==0"); } } } else { expressionToReplace = call; if (useIsEmpty) { - newExpression.append(variableText).append(".isEmpty()"); + newExpression.append(checkedExpression.getText()).append(".isEmpty()"); } else { - newExpression.append(variableText).append(".length()==0"); + newExpression.append(checkedExpression.getText()).append(".length()==0"); } } PsiReplacementUtil.replaceExpression(expressionToReplace, newExpression.toString()); } - private String getRemainingText(PsiExpression expression) { - if (useIsEmpty || - !(expression instanceof PsiMethodCallExpression)) { - return expression.getText(); + private static boolean isCheckedForNull(PsiExpression expression) { + final PsiPolyadicExpression polyadicExpression = + PsiTreeUtil.getParentOfType(expression, PsiPolyadicExpression.class, true, PsiStatement.class, PsiVariable.class); + if (polyadicExpression == null) { + return false; + } + final IElementType tokenType = polyadicExpression.getOperationTokenType(); + for (PsiExpression operand : polyadicExpression.getOperands()) { + if (PsiTreeUtil.isAncestor(operand, expression, true)) { + return false; + } + if (!(operand instanceof PsiBinaryExpression)) { + continue; + } + final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)operand; + final IElementType operationTokenType = binaryExpression.getOperationTokenType(); + if (JavaTokenType.ANDAND.equals(tokenType)) { + if (!JavaTokenType.NE.equals(operationTokenType)) { + continue; + } + } + else if (JavaTokenType.OROR.equals(tokenType)) { + if (!JavaTokenType.EQEQ.equals(operationTokenType)) { + continue; + } + } + else { + continue; + } + final PsiExpression lhs = binaryExpression.getLOperand(); + final PsiExpression rhs = binaryExpression.getROperand(); + if (rhs == null) { + continue; + } + if (PsiType.NULL.equals(lhs.getType()) && EquivalenceChecker.expressionsAreEquivalent(expression, rhs)) { + return true; + } + else if (PsiType.NULL.equals(rhs.getType()) && EquivalenceChecker.expressionsAreEquivalent(expression, lhs)) { + return true; + } + } + return false; + } + + private PsiExpression getCheckedExpression(PsiExpression expression) { + if (useIsEmpty || !(expression instanceof PsiMethodCallExpression)) { + return expression; } // to replace stringBuffer.toString().equals("") with // stringBuffer.length() == 0 @@ -161,15 +207,15 @@ public class StringEqualsEmptyStringInspection extends BaseInspection { final String referenceName = methodExpression.getReferenceName(); final PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); if (qualifierExpression == null) { - return expression.getText(); + return expression; } final PsiType type = qualifierExpression.getType(); if (HardcodedMethodConstants.TO_STRING.equals(referenceName) && type != null && (type.equalsToText( CommonClassNames.JAVA_LANG_STRING_BUFFER) || type.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUILDER))) { - return qualifierExpression.getText(); + return qualifierExpression; } else { - return expression.getText(); + return expression; } } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspection.java deleted file mode 100644 index 828b4c68d43f..000000000000 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspection.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.siyeh.ig.classlayout; - -import com.siyeh.ig.InspectionGadgetsFix; -import com.siyeh.ig.fixes.MoveClassFix; - -public class ClassInTopLevelPackageInspection extends ClassInTopLevelPackageInspectionBase { - - @Override - protected InspectionGadgetsFix buildFix(Object... infos) { - return new MoveClassFix(); - } -}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ProblematicWhitespaceInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ProblematicWhitespaceInspection.java index 8f823f019770..bbd0f1491925 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ProblematicWhitespaceInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ProblematicWhitespaceInspection.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. @@ -141,7 +141,7 @@ public class ProblematicWhitespaceInspection extends BaseInspection { registerError(file, file.getName(), Boolean.valueOf(isOnTheFly()), Boolean.TRUE); return; } - else { + else if (!spaceSeen) { final int currentIndent = Math.max(0, j); if (currentIndent != previousLineIndent) { registerError(file, file.getName(), Boolean.valueOf(isOnTheFly()), Boolean.TRUE); diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInTopLevelPackage.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInTopLevelPackage.html deleted file mode 100644 index c6263f25c4d5..000000000000 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInTopLevelPackage.html +++ /dev/null @@ -1,8 +0,0 @@ -<html> -<body> -Reports any classes which do not contain package declarations. -<!-- tooltip end --> -<p> - -</body> -</html>
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticIport.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticImport.after.java index f026afe3785e..f026afe3785e 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticIport.after.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticImport.after.java diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.after.java new file mode 100644 index 000000000000..7277bd021670 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.after.java @@ -0,0 +1,12 @@ +package com.siyeh.igfixes.performance.replace_with_isempty; + +public class NullCheckAlreadyPresent { + + String[] splitProperties = {"1","2"}; + + public void someAction() { + if (splitProperties[1] != null && splitProperties[1].isEmpty()) { + System.out.println(""); + } + } +}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.java new file mode 100644 index 000000000000..e91b650758e2 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.java @@ -0,0 +1,12 @@ +package com.siyeh.igfixes.performance.replace_with_isempty; + +public class NullCheckAlreadyPresent { + + String[] splitProperties = {"1","2"}; + + public void someAction() { + if (splitProperties[1] != null && "".<caret>equals(splitProperties[1])) { + System.out.println(""); + } + } +}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java index d7577b1c9c79..019805adcf17 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java @@ -123,4 +123,5 @@ class Expanded {{ System.out.println(u * 1); long g = 8L / 8L; long h = 9L * 0L; + int a = 8 * 0 * 8 * ; // don't warn }}
\ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml index 58e0898bdcdd..f6af12237ea0 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml @@ -38,90 +38,6 @@ <problem> <file>PointlessArithmeticExpression.java</file> - <line>30</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>k<=Integer.MAX_VALUE</code> can be replaced with 'true' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>34</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>k>=Integer.MIN_VALUE</code> can be replaced with 'true' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>38</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>k>Integer.MAX_VALUE</code> can be replaced with 'false' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>42</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>k<Integer.MIN_VALUE</code> can be replaced with 'false' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>46</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>Integer.MAX_VALUE >= k</code> can be replaced with 'true' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>50</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>Integer.MIN_VALUE <= k</code> can be replaced with 'true' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>54</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>Integer.MAX_VALUE < k</code> can be replaced with 'false' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>58</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>Integer.MIN_VALUE > k</code> can be replaced with 'false' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>70</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>i > Integer.MAX_VALUE</code> can be replaced with 'false' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>76</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>i <= Integer.MAX_VALUE</code> can be replaced with 'true' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>80</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>i >= Integer.MIN_VALUE</code> can be replaced with 'true' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> - <line>83</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> - <description><code>i < Integer.MIN_VALUE</code> can be replaced with 'false' #loc</description> - </problem> - - <problem> - <file>PointlessArithmeticExpression.java</file> <line>93</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class> <description><code>i / i</code> can be replaced with '1' #loc</description> diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java index 3168d9ec5b0b..92e72bb81a55 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java @@ -39,6 +39,32 @@ public class EqualsBetweenInconvertibleTypesInspectionTest extends LightInspecti "}"); } + public void testJavaUtilObjectsEquals() { + doStatementTest("java.util.Objects./*'equals()' between objects of inconvertible types 'Integer' and 'String'*/equals/**/(Integer.valueOf(1), \"string\");"); + } + + public void testComGoogleCommonBaseObjects() { + doStatementTest("com.google.common.base.Objects./*'equal()' between objects of inconvertible types 'Integer' and 'String'*/equal/**/(Integer.valueOf(1), \"string\");"); + } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] { + "package java.util;" + + "public final class Objects {" + + " public static boolean equals(Object a, Object b) {" + + " return (a == b) || (a != null && a.equals(b));" + + " }" + + "}", + "package com.google.common.base;" + + "public final class Objects {" + + " public static boolean equal(Object a, Object b) {" + + " return true;" + + " }" + + "}" + }; + } + @Override protected InspectionProfileEntry getInspection() { return new EqualsBetweenInconvertibleTypesInspection(); diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/StringEqualsEmptyStringFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/StringEqualsEmptyStringFixTest.java index a42fccbda5a6..6bd1cefe6320 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/StringEqualsEmptyStringFixTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/StringEqualsEmptyStringFixTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Bas Leijdekkers + * Copyright 2012-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. @@ -31,4 +31,5 @@ public class StringEqualsEmptyStringFixTest extends IGQuickFixesTestCase { public void testSimple() { doTest(); } public void testNullCheck() { doTest(); } + public void testNullCheckAlreadyPresent() { doTest(); } } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/ProblematicWhitespaceInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/ProblematicWhitespaceInspectionTest.java index c0e062c6d79b..3cfc26b152a2 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/ProblematicWhitespaceInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/ProblematicWhitespaceInspectionTest.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. @@ -69,6 +69,34 @@ public class ProblematicWhitespaceInspectionTest extends LightInspectionTestCase "}\n/**/"); } + public void testSmartTabsInFile2() { + final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()); + final CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptions(JavaFileType.INSTANCE); + options.USE_TAB_CHARACTER = true; + options.SMART_TABS = true; + doTest("class X {\n" + + "\tvoid aaa(boolean a, boolean b, boolean c) {\n" + + "\t\taaa(true,\n" + + "\t\t true,\n" + + "\t\t true);\n" + + "\t}\n" + + "}\n"); + } + + public void testSmartTabsInFile3() { + final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()); + final CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptions(JavaFileType.INSTANCE); + options.USE_TAB_CHARACTER = true; + options.SMART_TABS = true; + doTest("/*File 'X.java' uses spaces for indentation*/class X {\n" + + "\tvoid aaa(boolean a, boolean b, boolean c) {\n" + + "\t\taaa(true,\n" + + "\t \t true,\n" + + "\t\t true);\n" + + "\t}\n" + + "}\n/**/"); + } + @Override protected InspectionProfileEntry getInspection() { return new ProblematicWhitespaceInspection(); |