Lines 53-65
Link Here
|
53 |
"}" |
53 |
"}" |
54 |
); |
54 |
); |
55 |
this.cu = getCompilationUnit("/P/p/X.java"); |
55 |
this.cu = getCompilationUnit("/P/p/X.java"); |
|
|
56 |
String cuSource = |
57 |
"package p;\n" + |
58 |
"public class Constants {\n" + |
59 |
" static final long field1 = 938245798324893L;\n" + |
60 |
" static final long field2 = 938245798324893l;\n" + |
61 |
" static final long field3 = 938245798324893;\n" + |
62 |
" static final char field4 = ' ';\n" + |
63 |
" static final double field5 = 938245798324893D;\n" + |
64 |
" static final float field6 = 123456f;\n" + |
65 |
" static final int field7 = 1<<0;\n" + |
66 |
"}"; |
67 |
createFile("/P/p/Constants.java", cuSource); |
56 |
} |
68 |
} |
57 |
|
69 |
|
58 |
// Use this static initializer to specify subset for tests |
70 |
// Use this static initializer to specify subset for tests |
59 |
// All specified tests which do not belong to the class are skipped... |
71 |
// All specified tests which do not belong to the class are skipped... |
60 |
static { |
72 |
static { |
61 |
// Names of tests to run: can be "testBugXXXX" or "BugXXXX") |
73 |
// Names of tests to run: can be "testBugXXXX" or "BugXXXX") |
62 |
// TESTS_NAMES = new String[] { "TypeParameterBug73884" }; |
74 |
// TESTS_NAMES = new String[] { "testFieldConstant" }; |
63 |
// Numbers of tests to run: "test<number>" will be run for each number of this array |
75 |
// Numbers of tests to run: "test<number>" will be run for each number of this array |
64 |
// TESTS_NUMBERS = new int[] { 13 }; |
76 |
// TESTS_NUMBERS = new int[] { 13 }; |
65 |
// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last } |
77 |
// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last } |
Lines 336-422
Link Here
|
336 |
/** |
348 |
/** |
337 |
* Test the field constant |
349 |
* Test the field constant |
338 |
*/ |
350 |
*/ |
339 |
public void testFieldConstant() throws CoreException { |
351 |
private IField getConstantField(String fieldName) { |
340 |
try { |
352 |
IType type = getCompilationUnit("/P/p/Constants.java").getType("Constants"); |
341 |
String cuSource = |
353 |
IField field = type.getField(fieldName); |
342 |
"package p;\n" + |
354 |
return field; |
343 |
"public class Y {\n" + |
355 |
} |
344 |
" static final long field1 = 938245798324893L;\n" + |
356 |
|
345 |
" static final long field2 = 938245798324893l;\n" + |
357 |
public void testFieldConstant01() throws CoreException { |
346 |
" static final long field3 = 938245798324893;\n" + |
358 |
IField field = getConstantField("field1"); |
347 |
" static final char field4 = ' ';\n" + |
359 |
|
348 |
" static final double field5 = 938245798324893D;\n" + |
360 |
Object constant = field.getConstant(); |
349 |
" static final float field6 = 123456f;\n" + |
361 |
Long value = (Long) constant; |
350 |
"}"; |
362 |
assertEquals("Wrong value", 938245798324893l, value.longValue()); |
351 |
createFile("/P/p/Y.java", cuSource); |
363 |
} |
352 |
IType type = getCompilationUnit("/P/p/Y.java").getType("Y"); |
364 |
|
353 |
IField field = type.getField("field1"); |
365 |
public void testFieldConstant02() throws CoreException { |
354 |
|
366 |
IField field = getConstantField("field2"); |
355 |
String actualSource = field.getSource(); |
367 |
|
356 |
String expectedSource = "static final long field1 = 938245798324893L;"; |
368 |
Object constant = field.getConstant(); |
357 |
assertSourceEquals("Unexpected source'", expectedSource, actualSource); |
369 |
Long value = (Long) constant; |
358 |
Object constant = field.getConstant(); |
370 |
assertEquals("Wrong value", 938245798324893l, value.longValue()); |
359 |
assertNotNull("No constant", constant); |
371 |
} |
360 |
assertTrue("Not a Long", constant instanceof Long); |
|
|
361 |
Long value = (Long) constant; |
362 |
assertEquals("Wrong value", 938245798324893l, value.longValue()); |
363 |
|
364 |
field = type.getField("field2"); |
365 |
|
372 |
|
366 |
actualSource = field.getSource(); |
373 |
public void testFieldConstant03() throws CoreException { |
367 |
expectedSource = "static final long field2 = 938245798324893l;"; |
374 |
IField field = getConstantField("field3"); |
368 |
assertSourceEquals("Unexpected source'", expectedSource, actualSource); |
375 |
|
369 |
constant = field.getConstant(); |
376 |
Object constant = field.getConstant(); |
370 |
assertNotNull("No constant", constant); |
377 |
Long value = (Long) constant; |
371 |
assertTrue("Not a Long", constant instanceof Long); |
378 |
assertEquals("Wrong value", 938245798324893l, value.longValue()); |
372 |
value = (Long) constant; |
379 |
} |
373 |
assertEquals("Wrong value", 938245798324893l, value.longValue()); |
380 |
|
374 |
|
381 |
public void testFieldConstant04() throws CoreException { |
375 |
field = type.getField("field3"); |
382 |
IField field = getConstantField("field4"); |
|
|
383 |
|
384 |
Object constant = field.getConstant(); |
385 |
Character character = (Character) constant; |
386 |
assertEquals("Wrong value", ' ', character.charValue()); |
387 |
} |
376 |
|
388 |
|
377 |
actualSource = field.getSource(); |
389 |
public void testFieldConstant05() throws CoreException { |
378 |
expectedSource = "static final long field3 = 938245798324893;"; |
390 |
IField field = getConstantField("field5"); |
379 |
assertSourceEquals("Unexpected source'", expectedSource, actualSource); |
391 |
|
380 |
constant = field.getConstant(); |
392 |
Object constant = field.getConstant(); |
381 |
assertNotNull("No constant", constant); |
393 |
Double double1 = (Double) constant; |
382 |
assertTrue("Not a Long", constant instanceof Long); |
394 |
assertEquals("Wrong value", 938245798324893l, double1.doubleValue(), 0.01); |
383 |
value = (Long) constant; |
395 |
} |
384 |
assertEquals("Wrong value", 938245798324893l, value.longValue()); |
|
|
385 |
|
396 |
|
386 |
field = type.getField("field4"); |
397 |
public void testFieldConstant06() throws CoreException { |
387 |
|
398 |
IField field = getConstantField("field6"); |
388 |
actualSource = field.getSource(); |
399 |
|
389 |
expectedSource = "static final char field4 = ' ';"; |
400 |
Object constant = field.getConstant(); |
390 |
assertSourceEquals("Unexpected source'", expectedSource, actualSource); |
401 |
Float float1 = (Float) constant; |
391 |
constant = field.getConstant(); |
402 |
assertEquals("Wrong value", 123456, float1.floatValue(), 0.01f); |
392 |
assertNotNull("No constant", constant); |
403 |
} |
393 |
assertTrue("Not a Character", constant instanceof Character); |
|
|
394 |
Character character = (Character) constant; |
395 |
assertEquals("Wrong value", ' ', character.charValue()); |
396 |
|
397 |
field = type.getField("field5"); |
398 |
|
399 |
actualSource = field.getSource(); |
400 |
expectedSource = "static final double field5 = 938245798324893D;"; |
401 |
assertSourceEquals("Unexpected source'", expectedSource, actualSource); |
402 |
constant = field.getConstant(); |
403 |
assertNotNull("No constant", constant); |
404 |
assertTrue("Not a Double", constant instanceof Double); |
405 |
Double double1 = (Double) constant; |
406 |
assertEquals("Wrong value", 938245798324893l, double1.doubleValue(), 0.01); |
407 |
|
404 |
|
408 |
field = type.getField("field6"); |
405 |
public void testFieldConstant07() throws CoreException { |
409 |
|
406 |
IField field = getConstantField("field7"); |
410 |
actualSource = field.getSource(); |
407 |
|
411 |
expectedSource = "static final float field6 = 123456f;"; |
408 |
Object constant = field.getConstant(); |
412 |
assertSourceEquals("Unexpected source'", expectedSource, actualSource); |
409 |
assertNull("Should not be a constant", constant); |
413 |
constant = field.getConstant(); |
|
|
414 |
assertNotNull("No constant", constant); |
415 |
assertTrue("Not a Float", constant instanceof Float); |
416 |
Float float1 = (Float) constant; |
417 |
assertEquals("Wrong value", 123456, float1.floatValue(), 0.01f); |
418 |
} finally { |
419 |
deleteFile("/P/p/Y.java"); |
420 |
} |
421 |
} |
410 |
} |
422 |
} |
411 |
} |