diff options
| author | Jayaprakash Arthanareeswaran | 2014-02-14 12:49:53 +0000 |
|---|---|---|
| committer | Jayaprakash Arthanareeswaran | 2014-02-15 07:02:43 +0000 |
| commit | 8110fc486d3702b464fac7cbd52796cfda9c4f57 (patch) | |
| tree | 2997cd2ff082f2cf52f0ae2692c710729378cac7 | |
| parent | c7c1b7003223b2c8b40ad69d829cb8abad9348ab (diff) | |
| download | eclipse.jdt.core-8110fc486d3702b464fac7cbd52796cfda9c4f57.tar.gz eclipse.jdt.core-8110fc486d3702b464fac7cbd52796cfda9c4f57.tar.xz eclipse.jdt.core-8110fc486d3702b464fac7cbd52796cfda9c4f57.zip | |
Bug 428178 - [1.8] isMainMethod(IMethod) should consider the default
Public modifier for main method in interface
4 files changed, 109 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java index 4fcf2be816..fb6b63c1c1 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java @@ -38,6 +38,7 @@ import org.eclipse.jdt.core.tests.formatter.FormatterBugs18Tests; import org.eclipse.jdt.core.tests.formatter.FormatterJSR308Tests; import org.eclipse.jdt.core.tests.formatter.FormatterJSR335Tests; import org.eclipse.jdt.core.tests.model.CompletionTests18; +import org.eclipse.jdt.core.tests.model.JavaElement8Tests; import org.eclipse.jdt.core.tests.model.JavaSearchBugs8Tests; import org.eclipse.jdt.core.tests.model.ResolveTests18; import org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritingTest; @@ -59,6 +60,7 @@ public class RunAllJava8Tests extends TestCase { CompletionTests18.class, IncrementalTests18.class, org.eclipse.jdt.compiler.apt.tests.AllTests.class, + JavaElement8Tests.class, }; } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java index b309072d56..5523716d2f 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java @@ -1,10 +1,14 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -192,6 +196,8 @@ private static Class[] getAllTestClasses() { // Tests regarding null-annotations: NullAnnotationModelTests.class, + // Java model changes related to Java 8 + JavaElement8Tests.class, }; Class[] deprecatedClasses = getDeprecatedJDOMTestClasses(); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaElement8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaElement8Tests.java new file mode 100644 index 0000000000..65b5aaf50b --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaElement8Tests.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2014 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.model; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; + +public class JavaElement8Tests extends AbstractJavaModelTests { + + static { +// TESTS_NAMES = new String[] {"testBug428178"}; + } + + public JavaElement8Tests(String name) { + super(name); + this.endChar = ""; + } + public static Test suite() { + if (TESTS_PREFIX != null || TESTS_NAMES != null || TESTS_NUMBERS!=null || TESTS_RANGE !=null) { + return buildModelTestSuite(JavaElement8Tests.class); + } + TestSuite suite = new Suite(JavaElement8Tests.class.getName()); + suite.addTest(new JavaElement8Tests("testBug428178")); + suite.addTest(new JavaElement8Tests("testBug428178a")); + return suite; + } + public void testBug428178() throws Exception { + try { + IJavaProject project = createJavaProject("Bug428178", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8"); + project.open(null); + String fileContent = "package p;\n" + + "public interface Test {\n" + + " static void main(String[] args) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + "}"; + createFolder("/Bug428178/src/p"); + createFile( "/Bug428178/src/p/Test.java", fileContent); + + ICompilationUnit unit = getCompilationUnit("/Bug428178/src/p/Test.java"); + IMethod method = unit.getTypes()[0].getMethods()[0]; + assertNotNull("Method should not be null", method); + assertTrue("Should be a main method", method.isMainMethod()); + } + finally { + deleteProject("Bug428178"); + } + } + public void testBug428178a() throws Exception { + try { + IJavaProject project = createJavaProject("Bug428178", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8"); + project.open(null); + String fileContent = "package p;\n" + + "public interface Test {\n" + + " static void main(String[] args) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + "}"; + addLibrary(project, + "lib.jar", + "src.zip", new + String[] {"p/Test.java", fileContent}, + JavaCore.VERSION_1_8); + IType type = getPackageFragmentRoot("Bug428178", "lib.jar").getPackageFragment("p").getClassFile("Test.class").getType(); + IMethod method = type.getMethods()[0]; + assertNotNull("Method should not be null", method); + assertTrue("Should be a main method", method.isMainMethod()); + } + finally { + deleteProject("Bug428178"); + } + } +} diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java index 8cad15aece..ab86ad754e 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java @@ -1,10 +1,14 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -356,7 +360,10 @@ public boolean isBinary() { protected boolean isMainMethod(IMethod method) throws JavaModelException { if ("main".equals(method.getElementName()) && Signature.SIG_VOID.equals(method.getReturnType())) { //$NON-NLS-1$ int flags= method.getFlags(); - if (Flags.isStatic(flags) && Flags.isPublic(flags)) { + IType declaringType = null; + if (Flags.isStatic(flags) && + (Flags.isPublic(flags) || + ((declaringType = getDeclaringType()) != null && declaringType.isInterface()))) { String[] paramTypes= method.getParameterTypes(); if (paramTypes.length == 1) { String typeSignature= Signature.toString(paramTypes[0]); |
