Lines 11-43
Link Here
|
11 |
package org.eclipse.jdt.core.tests.compiler.parser; |
11 |
package org.eclipse.jdt.core.tests.compiler.parser; |
12 |
|
12 |
|
13 |
import java.util.Locale; |
13 |
import java.util.Locale; |
|
|
14 |
import java.util.Map; |
14 |
|
15 |
|
|
|
16 |
import org.eclipse.jdt.core.compiler.CharOperation; |
17 |
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; |
18 |
import org.eclipse.jdt.core.tests.util.Util; |
19 |
import org.eclipse.jdt.internal.codeassist.select.SelectionJavadoc; |
15 |
import org.eclipse.jdt.internal.codeassist.select.SelectionParser; |
20 |
import org.eclipse.jdt.internal.codeassist.select.SelectionParser; |
16 |
import org.eclipse.jdt.internal.codeassist.select.SelectionScanner; |
21 |
import org.eclipse.jdt.internal.codeassist.select.SelectionScanner; |
|
|
22 |
import org.eclipse.jdt.internal.compiler.ASTVisitor; |
17 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
23 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
18 |
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; |
24 |
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; |
19 |
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; |
|
|
20 |
import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
25 |
import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
|
|
26 |
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; |
21 |
import org.eclipse.jdt.internal.compiler.ast.Block; |
27 |
import org.eclipse.jdt.internal.compiler.ast.Block; |
22 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
28 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
|
|
29 |
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; |
23 |
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; |
30 |
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; |
24 |
import org.eclipse.jdt.internal.compiler.ast.Initializer; |
31 |
import org.eclipse.jdt.internal.compiler.ast.Initializer; |
|
|
32 |
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; |
25 |
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; |
33 |
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; |
26 |
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; |
34 |
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; |
27 |
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; |
35 |
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; |
28 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
36 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
|
|
37 |
import org.eclipse.jdt.internal.compiler.lookup.BlockScope; |
38 |
import org.eclipse.jdt.internal.compiler.lookup.ClassScope; |
39 |
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; |
40 |
import org.eclipse.jdt.internal.compiler.lookup.MethodScope; |
29 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
41 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
30 |
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; |
42 |
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; |
31 |
import org.eclipse.jdt.core.compiler.CharOperation; |
|
|
32 |
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; |
33 |
import org.eclipse.jdt.core.tests.util.Util; |
34 |
|
43 |
|
35 |
public abstract class AbstractSelectionTest extends AbstractCompilerTest { |
44 |
public abstract class AbstractSelectionTest extends AbstractCompilerTest { |
36 |
|
45 |
|
37 |
public final static String NONE = "<NONE>"; |
46 |
public final static String NONE = "<NONE>"; |
|
|
47 |
protected StringBuffer result; |
48 |
|
38 |
public AbstractSelectionTest(String testName){ |
49 |
public AbstractSelectionTest(String testName){ |
39 |
super(testName); |
50 |
super(testName); |
40 |
} |
51 |
} |
|
|
52 |
|
53 |
class SelectionVisitor extends ASTVisitor { |
54 |
|
55 |
public boolean visit(ConstructorDeclaration constructor, ClassScope scope) { |
56 |
if (constructor.javadoc != null) { |
57 |
assertTrue("Invalid type for Javadoc on " + constructor, constructor.javadoc instanceof SelectionJavadoc); |
58 |
AbstractSelectionTest.this.result.append(constructor.javadoc.toString()); |
59 |
} |
60 |
return super.visit(constructor, scope); |
61 |
} |
62 |
|
63 |
public boolean visit(FieldDeclaration field, MethodScope scope) { |
64 |
if (field.javadoc != null) { |
65 |
assertTrue("Invalid type for Javadoc on " + field, field.javadoc instanceof SelectionJavadoc); |
66 |
AbstractSelectionTest.this.result.append(field.javadoc.toString()); |
67 |
} |
68 |
return super.visit(field, scope); |
69 |
} |
70 |
|
71 |
public boolean visit(MethodDeclaration method, ClassScope scope) { |
72 |
if (method.javadoc != null) { |
73 |
assertTrue("Invalid type for Javadoc on " + method, method.javadoc instanceof SelectionJavadoc); |
74 |
AbstractSelectionTest.this.result.append(method.javadoc.toString()); |
75 |
} |
76 |
return super.visit(method, scope); |
77 |
} |
78 |
|
79 |
public boolean visit(TypeDeclaration type, BlockScope scope) { |
80 |
if (type.javadoc != null) { |
81 |
assertTrue("Invalid type for Javadoc on " + type, type.javadoc instanceof SelectionJavadoc); |
82 |
AbstractSelectionTest.this.result.append(type.javadoc.toString()); |
83 |
} |
84 |
return super.visit(type, scope); |
85 |
} |
86 |
|
87 |
public boolean visit(TypeDeclaration type, ClassScope scope) { |
88 |
if (type.javadoc != null) { |
89 |
assertTrue("Invalid type for Javadoc on " + type, type.javadoc instanceof SelectionJavadoc); |
90 |
AbstractSelectionTest.this.result.append(type.javadoc.toString()); |
91 |
} |
92 |
return super.visit(type, scope); |
93 |
} |
94 |
|
95 |
public boolean visit(TypeDeclaration type, CompilationUnitScope scope) { |
96 |
if (type.javadoc != null) { |
97 |
assertTrue("Invalid type for Javadoc on " + type, type.javadoc instanceof SelectionJavadoc); |
98 |
AbstractSelectionTest.this.result.append(type.javadoc.toString()); |
99 |
} |
100 |
return super.visit(type, scope); |
101 |
} |
102 |
} |
41 |
/* |
103 |
/* |
42 |
* DietParse with selectionNode check |
104 |
* DietParse with selectionNode check |
43 |
*/ |
105 |
*/ |
Lines 327-330
Link Here
|
327 |
expectedReplacedSource, |
389 |
expectedReplacedSource, |
328 |
testName); |
390 |
testName); |
329 |
} |
391 |
} |
|
|
392 |
|
393 |
protected void runTestParseCompilationUnit(ICompilationUnit unit, String selection, Map customOptions, String expectedResult) { |
394 |
// Verify params |
395 |
assertNotNull("Missing source!", unit); |
396 |
assertNotNull("Missing selection!", selection); |
397 |
|
398 |
// enable custom options if any |
399 |
Map currentOptionsMap = getCompilerOptions(); |
400 |
if (customOptions != null) { |
401 |
currentOptionsMap.putAll(customOptions); |
402 |
} |
403 |
CompilerOptions options = new CompilerOptions(currentOptionsMap); |
404 |
|
405 |
// Get selection start and end |
406 |
int selectionStart = CharOperation.indexOf(selection.toCharArray(), unit.getContents(), true); |
407 |
int length = selection.length(); |
408 |
int selectionEnd = selectionStart + length - 1; |
409 |
|
410 |
// Parse unit |
411 |
SelectionParser parser = new SelectionParser(new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), |
412 |
options, |
413 |
new DefaultProblemFactory(Locale.getDefault()))); |
414 |
CompilationUnitDeclaration unitDecl = parser.dietParse(unit, new CompilationResult(unit, 0, 0, 0), selectionStart, selectionEnd); |
415 |
parser.getMethodBodies(unitDecl); |
416 |
|
417 |
// Visit compilation unit declaration to find javadoc |
418 |
unitDecl.traverse(new SelectionVisitor(), unitDecl.scope); |
419 |
|
420 |
// check results |
421 |
assertEquals(expectedResult, Util.getProblemLog(unitDecl.compilationResult, false, false)); |
422 |
} |
330 |
} |
423 |
} |