|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2014 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* This is an implementation of an early-draft specification developed under the Java |
| 9 |
* Community Process (JCP) and is made available for testing and evaluation purposes |
| 10 |
* only. The code is not compatible with any specification of the JCP. |
| 11 |
* |
| 12 |
* Contributors: |
| 13 |
* IBM Corporation - initial API and implementation |
| 14 |
*******************************************************************************/ |
| 15 |
package org.eclipse.jdt.core.tests.model; |
| 16 |
|
| 17 |
import junit.framework.Test; |
| 18 |
import junit.framework.TestSuite; |
| 19 |
|
| 20 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 21 |
import org.eclipse.jdt.core.IJavaProject; |
| 22 |
import org.eclipse.jdt.core.IMethod; |
| 23 |
import org.eclipse.jdt.core.IType; |
| 24 |
import org.eclipse.jdt.core.JavaCore; |
| 25 |
|
| 26 |
public class JavaElement8Tests extends AbstractJavaModelTests { |
| 27 |
|
| 28 |
static { |
| 29 |
// TESTS_NAMES = new String[] {"testBug428178"}; |
| 30 |
} |
| 31 |
|
| 32 |
public JavaElement8Tests(String name) { |
| 33 |
super(name); |
| 34 |
this.endChar = ""; |
| 35 |
} |
| 36 |
public static Test suite() { |
| 37 |
if (TESTS_PREFIX != null || TESTS_NAMES != null || TESTS_NUMBERS!=null || TESTS_RANGE !=null) { |
| 38 |
return buildModelTestSuite(JavaElement8Tests.class); |
| 39 |
} |
| 40 |
TestSuite suite = new Suite(JavaElement8Tests.class.getName()); |
| 41 |
suite.addTest(new JavaElement8Tests("testBug428178")); |
| 42 |
suite.addTest(new JavaElement8Tests("testBug428178a")); |
| 43 |
return suite; |
| 44 |
} |
| 45 |
public void testBug428178() throws Exception { |
| 46 |
try { |
| 47 |
IJavaProject project = createJavaProject("Bug428178", new String[] {"src"}, new String[] {"JCL18_FULL"}, "bin", "1.8"); |
| 48 |
project.open(null); |
| 49 |
String fileContent = "package p;\n" + |
| 50 |
"public interface Test {\n" + |
| 51 |
" static void main(String[] args) {\n" + |
| 52 |
" System.out.println(\"Hello\");\n" + |
| 53 |
" }\n" + |
| 54 |
"}"; |
| 55 |
createFolder("/Bug428178/src/p"); |
| 56 |
createFile( "/Bug428178/src/p/Test.java", fileContent); |
| 57 |
|
| 58 |
ICompilationUnit unit = getCompilationUnit("/Bug428178/src/p/Test.java"); |
| 59 |
IMethod method = unit.getTypes()[0].getMethods()[0]; |
| 60 |
assertNotNull("Method should not be null", method); |
| 61 |
assertTrue("Should be a main method", method.isMainMethod()); |
| 62 |
} |
| 63 |
finally { |
| 64 |
deleteProject("Bug428178"); |
| 65 |
} |
| 66 |
} |
| 67 |
public void testBug428178a() throws Exception { |
| 68 |
try { |
| 69 |
IJavaProject project = createJavaProject("Bug428178", new String[] {"src"}, new String[] {"JCL18_FULL"}, "bin", "1.8"); |
| 70 |
project.open(null); |
| 71 |
String fileContent = "package p;\n" + |
| 72 |
"public interface Test {\n" + |
| 73 |
" static void main(String[] args) {\n" + |
| 74 |
" System.out.println(\"Hello\");\n" + |
| 75 |
" }\n" + |
| 76 |
"}"; |
| 77 |
addLibrary(project, |
| 78 |
"lib.jar", |
| 79 |
"src.zip", new |
| 80 |
String[] {"p/Test.java", fileContent}, |
| 81 |
JavaCore.VERSION_1_8); |
| 82 |
IType type = getPackageFragmentRoot("Bug428178", "lib.jar").getPackageFragment("p").getClassFile("Test.class").getType(); |
| 83 |
IMethod method = type.getMethods()[0]; |
| 84 |
assertNotNull("Method should not be null", method); |
| 85 |
assertTrue("Should be a main method", method.isMainMethod()); |
| 86 |
} |
| 87 |
finally { |
| 88 |
deleteProject("Bug428178"); |
| 89 |
} |
| 90 |
} |
| 91 |
} |