Lines 7-13
Link Here
|
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
10 |
* Stephan Herrmann - Contribution for Bug 342671 - ClassCastException: org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.ArrayBinding |
10 |
* Stephan Herrmann - Contributions for |
|
|
11 |
* Bug 342671 - ClassCastException: org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.ArrayBinding |
12 |
* Bug 353474 - type converters should include more annotations |
11 |
*******************************************************************************/ |
13 |
*******************************************************************************/ |
12 |
package org.eclipse.jdt.core.tests.dom; |
14 |
package org.eclipse.jdt.core.tests.dom; |
13 |
|
15 |
|
Lines 50-56
Link Here
|
50 |
static { |
52 |
static { |
51 |
// TESTS_NUMBERS = new int[] { 353 }; |
53 |
// TESTS_NUMBERS = new int[] { 353 }; |
52 |
// TESTS_RANGE = new int[] { 325, -1 }; |
54 |
// TESTS_RANGE = new int[] { 325, -1 }; |
53 |
// TESTS_NAMES = new String[] {"test0204"}; |
55 |
// TESTS_NAMES = new String[] {"testBug353474"}; |
54 |
} |
56 |
} |
55 |
public static Test suite() { |
57 |
public static Test suite() { |
56 |
return buildModelTestSuite(ASTConverter15Test.class); |
58 |
return buildModelTestSuite(ASTConverter15Test.class); |
Lines 11348-11352
Link Here
|
11348 |
rhsType = ((Assignment)((ExpressionStatement)((Statement) statements.get(1))).getExpression()).getRightHandSide().resolveTypeBinding(); |
11350 |
rhsType = ((Assignment)((ExpressionStatement)((Statement) statements.get(1))).getExpression()).getRightHandSide().resolveTypeBinding(); |
11349 |
assertFalse("Assignement compatible", rhsType.isAssignmentCompatible(assignmentType)); |
11351 |
assertFalse("Assignement compatible", rhsType.isAssignmentCompatible(assignmentType)); |
11350 |
} |
11352 |
} |
|
|
11353 |
// Bug 353474 - type converters should include more annotations |
11354 |
public void testBug353474() throws CoreException { |
11355 |
|
11356 |
this.createFolder("/Converter15/src/testBug353474/annot"); |
11357 |
String contents = |
11358 |
"package testBug353474.annot;\n" + |
11359 |
"import static java.lang.annotation.ElementType.*;\n" + |
11360 |
"import java.lang.annotation.*;\n" + |
11361 |
"@Retention(RetentionPolicy.CLASS)\n" + |
11362 |
"@Target({METHOD,PARAMETER,LOCAL_VARIABLE})\n" + |
11363 |
"public @interface Nullable {\n" + |
11364 |
"}\n"; |
11365 |
getWorkingCopy("/Converter15/src/testBug353474/annot/Nullable.java", contents, true/*resolve*/); |
11366 |
|
11367 |
this.createFolder("/Converter15/src/testBug353474/p1"); |
11368 |
contents = |
11369 |
"package testBug353474.p1;\n" + |
11370 |
"import testBug353474.annot.*;\n" + |
11371 |
"public class C1 {\n" + |
11372 |
" public @Nullable String foo(@Nullable Object arg) {\n" + |
11373 |
" return \"\";\n" + |
11374 |
" }\n" + |
11375 |
"}\n"; |
11376 |
getWorkingCopy("/Converter15/src/testBug353474/p1/C1.java", contents, true/*resolve*/); |
11377 |
|
11378 |
this.workingCopy = getWorkingCopy("/Converter15/src/testBug353474/p1/C2.java", true/*resolve*/); |
11379 |
contents = |
11380 |
"package testBug353474.p1;\n" + |
11381 |
"public class C2 {\n" + |
11382 |
" public String bar(C1 c1) {\n" + |
11383 |
" return c1.foo(null);\n" + |
11384 |
" }\n" + |
11385 |
"}\n"; |
11386 |
ASTNode node = buildAST( |
11387 |
contents, |
11388 |
this.workingCopy, |
11389 |
true); |
11390 |
assertNotNull("No node", node); |
11391 |
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); |
11392 |
CompilationUnit compilationUnit = (CompilationUnit) node; |
11393 |
TypeDeclaration c2 = (TypeDeclaration) compilationUnit.types().get(0); |
11394 |
MethodDeclaration bar = (MethodDeclaration) c2.bodyDeclarations().get(0); |
11395 |
ReturnStatement returnStat = (ReturnStatement) bar.getBody().statements().get(0); |
11396 |
MethodInvocation fooCall = (MethodInvocation) returnStat.getExpression(); |
11397 |
IMethodBinding resolvedFoo = fooCall.resolveMethodBinding(); |
11398 |
IAnnotationBinding[] parameterAnnotations0 = resolvedFoo.getParameterAnnotations(0); |
11399 |
assertNotNull("Parameter annotation should not be null", parameterAnnotations0); |
11400 |
assertEquals("Should have exactly one annotation", 1, parameterAnnotations0.length); |
11401 |
assertEquals("Unexpected annotation name", "Nullable", parameterAnnotations0[0].getName()); |
11402 |
|
11403 |
IAnnotationBinding[] returnAnnotations = resolvedFoo.getAnnotations(); |
11404 |
assertNotNull("Return annotation should not be null", returnAnnotations); |
11405 |
assertEquals("Should have exactly one return annotation", 1, returnAnnotations.length); |
11406 |
assertEquals("Unexpected annotation name", "Nullable", returnAnnotations[0].getName()); |
11407 |
deleteFolder("/Converter15/src/testBug353474"); |
11408 |
} |
11409 |
// Bug 353474 - type converters should include more annotations |
11410 |
// secondary type comes from binary |
11411 |
public void testBug353474a() throws CoreException { |
11412 |
String jarLocation = getWorkspacePath()+"Converter15/bins/bug353474.jar"; |
11413 |
IJavaProject jp = createJavaProject("Bug353464a", new String[]{"src"}, new String[]{"CONVERTER_JCL15_LIB", jarLocation}, "bin", "1.5"); |
11414 |
try { |
11415 |
this.workingCopy = getWorkingCopy("/Bug353464a/src/testBug353474/p1/C2.java", true/*resolve*/); |
11416 |
String contents = |
11417 |
"package testBug353474.p1;\n" + |
11418 |
"public class C2 {\n" + |
11419 |
" public String bar(C1a c1) {\n" + |
11420 |
" return c1.foo(null);\n" + |
11421 |
" }\n" + |
11422 |
"}\n"; |
11423 |
ASTNode node = buildAST( |
11424 |
contents, |
11425 |
this.workingCopy, |
11426 |
true); |
11427 |
assertNotNull("No node", node); |
11428 |
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); |
11429 |
CompilationUnit compilationUnit = (CompilationUnit) node; |
11430 |
TypeDeclaration c2 = (TypeDeclaration) compilationUnit.types().get(0); |
11431 |
MethodDeclaration bar = (MethodDeclaration) c2.bodyDeclarations().get(0); |
11432 |
ReturnStatement returnStat = (ReturnStatement) bar.getBody().statements().get(0); |
11433 |
MethodInvocation fooCall = (MethodInvocation) returnStat.getExpression(); |
11434 |
IMethodBinding resolvedFoo = fooCall.resolveMethodBinding(); |
11435 |
IAnnotationBinding[] parameterAnnotations0 = resolvedFoo.getParameterAnnotations(0); |
11436 |
assertNotNull("Parameter annotation should not be null", parameterAnnotations0); |
11437 |
assertEquals("Should have exactly one annotation", 1, parameterAnnotations0.length); |
11438 |
assertEquals("Unexpected annotation name", "Nullable", parameterAnnotations0[0].getName()); |
11439 |
|
11440 |
IAnnotationBinding[] returnAnnotations = resolvedFoo.getAnnotations(); |
11441 |
assertNotNull("Return annotation should not be null", returnAnnotations); |
11442 |
assertEquals("Should have exactly one return annotation", 1, returnAnnotations.length); |
11443 |
assertEquals("Unexpected annotation name", "Nullable", returnAnnotations[0].getName()); |
11444 |
} finally { |
11445 |
deleteProject(jp); |
11446 |
} |
11447 |
} |
11351 |
|
11448 |
|
11352 |
} |
11449 |
} |