diff options
author | Ayushman Jain | 2011-09-28 16:01:34 +0000 |
---|---|---|
committer | Ayushman Jain | 2011-09-28 16:01:34 +0000 |
commit | 9c0f466d3a1091abcce132530971b41684c74f20 (patch) | |
tree | 6959226d4d1a1693f48010b45156496aac46b110 | |
parent | a727125e8febab4dfedf84454a394010a0adb383 (diff) | |
download | eclipse.jdt.core-9c0f466d3a1091abcce132530971b41684c74f20.tar.gz eclipse.jdt.core-9c0f466d3a1091abcce132530971b41684c74f20.tar.xz eclipse.jdt.core-9c0f466d3a1091abcce132530971b41684c74f20.zip |
HEAD - Fixed bug
354502: Incorrect Compiler Warning: "Method can be declared as static"
3 files changed, 43 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java index a551aa001c..986755eacf 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java @@ -7076,4 +7076,39 @@ public void test124b() { compilerOptions /* custom options */ ); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=354502 +// Anonymous class instantiation of a non-static member type, method can't be static +public void test354502() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public abstract class Abstract{}\n" + + " public static abstract class Abstract2{}\n" + + " private void method1() {\n" + // don't warn + " new Abstract() {};\n" + + " }\n" + + " private void method2() {\n" + // warn + " new Abstract2() {};\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " private void method2() {\n" + + " ^^^^^^^^^\n" + + "The method method2() from the type X can be declared as static\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} } diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html index 2340dcabbb..7fbef5146e 100644 --- a/org.eclipse.jdt.core/buildnotes_jdt-core.html +++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html @@ -52,7 +52,9 @@ Eclipse SDK 3.8.0 - %date% - 3.8.0 M3 <h2>What's new in this drop</h2> <h3>Problem Reports Fixed</h3> -<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=241834">241834</a> +<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=354502">354502</a> +Incorrect Compiler Warning: "Method can be declared as static" +<br><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=241834">241834</a> [search] ClassCastException during move class refactoring <br><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=358827">358827</a> [1.7] exception analysis for t-w-r spoils null analysis diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java index 6818e1d2c5..c8f1c03829 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java @@ -59,6 +59,11 @@ public class QualifiedAllocationExpression extends AllocationExpression { // analyse the enclosing instance if (this.enclosingInstance != null) { flowInfo = this.enclosingInstance.analyseCode(currentScope, flowContext, flowInfo); + } else { + if (this.binding.declaringClass.superclass().isMemberType() && !this.binding.declaringClass.superclass().isStatic()) { + // creating an anonymous type of a non-static member type without an enclosing instance of parent type + currentScope.resetEnclosingMethodStaticFlag(); + } } // check captured variables are initialized in current context (26134) |