Lines 10-15
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.tests.compiler.regression; |
11 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
|
12 |
|
|
|
13 |
import java.io.File; |
14 |
import java.util.Map; |
15 |
|
16 |
import org.eclipse.jdt.core.ToolFactory; |
17 |
import org.eclipse.jdt.core.compiler.CharOperation; |
18 |
import org.eclipse.jdt.core.util.IClassFileAttribute; |
19 |
import org.eclipse.jdt.core.util.IClassFileReader; |
20 |
import org.eclipse.jdt.core.util.IMethodInfo; |
21 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
22 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
23 |
|
13 |
import junit.framework.Test; |
24 |
import junit.framework.Test; |
14 |
|
25 |
|
15 |
public class VarargsTest extends AbstractComparableTest { |
26 |
public class VarargsTest extends AbstractComparableTest { |
Lines 22-28
Link Here
|
22 |
// All specified tests which does not belong to the class are skipped... |
33 |
// All specified tests which does not belong to the class are skipped... |
23 |
static { |
34 |
static { |
24 |
// TESTS_NAMES = new String[] { "test000" }; |
35 |
// TESTS_NAMES = new String[] { "test000" }; |
25 |
// TESTS_NUMBERS = new int[] { 30 }; |
36 |
// TESTS_NUMBERS = new int[] { 60 }; |
26 |
// TESTS_RANGE = new int[] { 11, -1 }; |
37 |
// TESTS_RANGE = new int[] { 11, -1 }; |
27 |
} |
38 |
} |
28 |
public static Test suite() { |
39 |
public static Test suite() { |
Lines 2063-2067
Link Here
|
2063 |
" ^^^^\n" + |
2074 |
" ^^^^\n" + |
2064 |
"Zork cannot be resolved to a type\n" + |
2075 |
"Zork cannot be resolved to a type\n" + |
2065 |
"----------\n"); |
2076 |
"----------\n"); |
2066 |
} |
2077 |
} |
|
|
2078 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186181 |
2079 |
public void test060() { |
2080 |
Map options = this.getCompilerOptions(); |
2081 |
options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); |
2082 |
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); |
2083 |
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); |
2084 |
this.runConformTest( |
2085 |
new String[] { |
2086 |
"X.java", |
2087 |
"public class X {\n" + |
2088 |
" public static String varargMethod( Object... objects ) {\r\n" + |
2089 |
" String s = \"\";\n" + |
2090 |
" for (Object object : objects)\n" + |
2091 |
" s += \",\" + object.toString();\n" + |
2092 |
" return s;\n" + |
2093 |
" }\n" + |
2094 |
"}", |
2095 |
}, |
2096 |
"", |
2097 |
null, |
2098 |
true, |
2099 |
null, |
2100 |
options, |
2101 |
null); |
2102 |
|
2103 |
// make sure that this file contains the varargs attribute |
2104 |
IClassFileReader reader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); |
2105 |
IMethodInfo[] methodInfos = reader.getMethodInfos(); |
2106 |
assertEquals("Wrong size", 2, methodInfos.length); |
2107 |
IMethodInfo methodInfo = null; |
2108 |
if (CharOperation.equals(methodInfos[0].getName(), "varargMethod".toCharArray())) { |
2109 |
methodInfo = methodInfos[0]; |
2110 |
} else if (CharOperation.equals(methodInfos[1].getName(), "varargMethod".toCharArray())) { |
2111 |
methodInfo = methodInfos[1]; |
2112 |
} |
2113 |
assertTrue("ACC_VARARGS is not set", (methodInfo.getAccessFlags() & ClassFileConstants.AccVarargs) == 0); |
2114 |
assertNotNull("Method varargMethodshould be there", methodInfo); |
2115 |
assertEquals("2", 2, methodInfo.getAttributeCount()); |
2116 |
IClassFileAttribute[] attributes = methodInfo.getAttributes(); |
2117 |
assertTrue("varargs attribute not found", CharOperation.equals(attributes[0].getAttributeName(), "Varargs".toCharArray()) |
2118 |
|| CharOperation.equals(attributes[1].getAttributeName(), "Varargs".toCharArray())); |
2119 |
|
2120 |
options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); |
2121 |
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); |
2122 |
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); |
2123 |
this.runConformTest( |
2124 |
new String[] { |
2125 |
"UseVararg.java", |
2126 |
"public class UseVararg {\r\n" + |
2127 |
" public static void main( String[] args ) {\n" + |
2128 |
" String arg = \"SUCCESS\";\n" + |
2129 |
" String results = X.varargMethod(arg);\n" + |
2130 |
" System.out.println( results );\n" + |
2131 |
" }\r\n" + |
2132 |
"}", |
2133 |
}, |
2134 |
",SUCCESS", |
2135 |
null, |
2136 |
false, |
2137 |
null, |
2138 |
options, |
2139 |
null); |
2140 |
} |
2067 |
} |
2141 |
} |