View | Details | Raw Unified | Return to bug 192449 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-2 / +5 lines)
Lines 1111-1119 Link Here
1111
		// check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored)	
1111
		// check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored)	
1112
		while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions
1112
		while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions
1113
		if (lastComment >= 0 && this.javadocParser != null) {
1113
		if (lastComment >= 0 && this.javadocParser != null) {
1114
			int commentEnd = this.scanner.commentStops[lastComment] - 1; //stop is one over,
1114
			int commentEnd = this.scanner.commentStops[lastComment] - 1; //stop is one over
1115
			// do not report problem before last parsed comment while recovering code...
1115
			// do not report problem before last parsed comment while recovering code...
1116
			this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd;
1116
			if (this.javadocParser.shouldReportProblems) {
1117
				this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd;
1118
			}
1117
			if (this.javadocParser.checkDeprecation(lastComment)) {
1119
			if (this.javadocParser.checkDeprecation(lastComment)) {
1118
				checkAndSetModifiers(ClassFileConstants.AccDeprecated);
1120
				checkAndSetModifiers(ClassFileConstants.AccDeprecated);
1119
			}
1121
			}
Lines 10387-10390 Link Here
10387
	exp.sourceEnd = this.intStack[this.intPtr--];
10389
	exp.sourceEnd = this.intStack[this.intPtr--];
10388
	exp.sourceStart = this.intStack[this.intPtr--];
10390
	exp.sourceStart = this.intStack[this.intPtr--];
10389
}
10391
}
10392
10390
}
10393
}
(-)compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java (+4 lines)
Lines 34-39 Link Here
34
	// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=153399
34
	// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=153399
35
	// Store value tag positions
35
	// Store value tag positions
36
	private long validValuePositions, invalidValuePositions;
36
	private long validValuePositions, invalidValuePositions;
37
	
38
	// returns whether this JavadocParser shuold report errors or not (overrides reportProblems)
39
	// see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=192449"
40
	public boolean shouldReportProblems = true;
37
41
38
	public JavadocParser(Parser sourceParser) {
42
	public JavadocParser(Parser sourceParser) {
39
		super(sourceParser);
43
		super(sourceParser);
(-)model/org/eclipse/jdt/internal/core/util/CommentRecorderParser.java (-2 / +4 lines)
Lines 63-73 Link Here
63
			}
63
			}
64
			checkDeprecated = true;
64
			checkDeprecated = true;
65
			int commentSourceEnd = this.scanner.commentStops[lastCommentIndex] - 1; //stop is one over
65
			int commentSourceEnd = this.scanner.commentStops[lastCommentIndex] - 1; //stop is one over
66
			
67
			// do not report problem before last parsed comment while recovering code...
66
			// do not report problem before last parsed comment while recovering code...
68
			this.javadocParser.reportProblems = this.currentElement == null || commentSourceEnd > this.lastJavadocEnd;
67
			if (this.javadocParser.shouldReportProblems) {
68
				this.javadocParser.reportProblems = this.currentElement == null || commentSourceEnd > this.lastJavadocEnd;
69
			}
69
			deprecated = this.javadocParser.checkDeprecation(lastCommentIndex);
70
			deprecated = this.javadocParser.checkDeprecation(lastCommentIndex);
70
			this.javadoc = this.javadocParser.docComment;
71
			this.javadoc = this.javadocParser.docComment;
72
			if (currentElement == null) this.lastJavadocEnd = commentSourceEnd;
71
			break nextComment;
73
			break nextComment;
72
		}
74
		}
73
		if (deprecated) {
75
		if (deprecated) {
(-)model/org/eclipse/jdt/internal/compiler/SourceElementParser.java (-2 / +4 lines)
Lines 176-184 Link Here
176
		// check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored)	
176
		// check deprecation in last comment if javadoc (can be followed by non-javadoc comments which are simply ignored)	
177
		while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions
177
		while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--; // non javadoc comment have negative end positions
178
		if (lastComment >= 0 && this.javadocParser != null) {
178
		if (lastComment >= 0 && this.javadocParser != null) {
179
			int commentEnd = this.scanner.commentStops[lastComment] - 1; //stop is one over,
179
			int commentEnd = this.scanner.commentStops[lastComment] - 1; //stop is one over
180
			// do not report problem before last parsed comment while recovering code...
180
			// do not report problem before last parsed comment while recovering code...
181
			this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd;
181
			if (this.javadocParser.shouldReportProblems) {
182
				this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd;
183
			}
182
			if (this.javadocParser.checkDeprecation(lastComment)) {
184
			if (this.javadocParser.checkDeprecation(lastComment)) {
183
				checkAndSetModifiers(ClassFileConstants.AccDeprecated);
185
				checkAndSetModifiers(ClassFileConstants.AccDeprecated);
184
			}
186
			}
(-)codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionJavadocParser.java (+1 lines)
Lines 28-33 Link Here
28
28
29
	public SelectionJavadocParser(SelectionParser sourceParser) {
29
	public SelectionJavadocParser(SelectionParser sourceParser) {
30
		super(sourceParser);
30
		super(sourceParser);
31
		this.shouldReportProblems = false;
31
		this.kind = SELECTION_PARSER | TEXT_PARSE;
32
		this.kind = SELECTION_PARSER | TEXT_PARSE;
32
	}
33
	}
33
34
(-)src/org/eclipse/jdt/core/tests/compiler/parser/SelectionJavadocTest.java (-65 / +31 lines)
Lines 11-40 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;
15
16
import junit.framework.Test;
14
17
15
import org.eclipse.jdt.core.tests.util.Util;
18
import org.eclipse.jdt.core.tests.util.Util;
16
import org.eclipse.jdt.internal.codeassist.select.SelectionJavadoc;
17
import org.eclipse.jdt.internal.codeassist.select.SelectionParser;
19
import org.eclipse.jdt.internal.codeassist.select.SelectionParser;
18
import org.eclipse.jdt.internal.compiler.ASTVisitor;
19
import org.eclipse.jdt.internal.compiler.CompilationResult;
20
import org.eclipse.jdt.internal.compiler.CompilationResult;
20
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
21
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
21
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
22
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
22
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
23
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
24
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
25
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
26
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
23
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
27
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
24
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
28
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
25
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
29
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
30
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
31
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
32
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
33
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
26
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
34
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
27
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
35
28
36
import junit.framework.Test;
37
38
/**
29
/**
39
 * Class to test selection in Javadoc comments.
30
 * Class to test selection in Javadoc comments.
40
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=54968"
31
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=54968"
Lines 42-48 Link Here
42
public class SelectionJavadocTest extends AbstractSelectionTest {
33
public class SelectionJavadocTest extends AbstractSelectionTest {
43
	
34
	
44
	String source;
35
	String source;
45
	StringBuffer result;
46
	ICompilationUnit unit;
36
	ICompilationUnit unit;
47
37
48
	public SelectionJavadocTest(String testName) {
38
	public SelectionJavadocTest(String testName) {
Lines 58-114 Link Here
58
		return buildAllCompliancesTestSuite(SelectionJavadocTest.class);
48
		return buildAllCompliancesTestSuite(SelectionJavadocTest.class);
59
	}
49
	}
60
50
61
	class SelectionVisitor extends ASTVisitor {
62
63
		public boolean visit(ConstructorDeclaration constructor, ClassScope scope) {
64
			if (constructor.javadoc != null) {
65
				assertTrue("Invalid type for Javadoc on " + constructor, constructor.javadoc instanceof SelectionJavadoc);
66
				SelectionJavadocTest.this.result.append(constructor.javadoc.toString());
67
			}
68
			return super.visit(constructor, scope);
69
		}
70
71
		public boolean visit(FieldDeclaration field, MethodScope scope) {
72
			if (field.javadoc != null) {
73
				assertTrue("Invalid type for Javadoc on " + field, field.javadoc instanceof SelectionJavadoc);
74
				SelectionJavadocTest.this.result.append(field.javadoc.toString());
75
			}
76
			return super.visit(field, scope);
77
		}
78
79
		public boolean visit(MethodDeclaration method, ClassScope scope) {
80
			if (method.javadoc != null) {
81
				assertTrue("Invalid type for Javadoc on " + method, method.javadoc instanceof SelectionJavadoc);
82
				SelectionJavadocTest.this.result.append(method.javadoc.toString());
83
			}
84
			return super.visit(method, scope);
85
		}
86
87
		public boolean visit(TypeDeclaration type, BlockScope scope) {
88
			if (type.javadoc != null) {
89
				assertTrue("Invalid type for Javadoc on " + type, type.javadoc instanceof SelectionJavadoc);
90
				SelectionJavadocTest.this.result.append(type.javadoc.toString());
91
			}
92
			return super.visit(type, scope);
93
		}
94
95
		public boolean visit(TypeDeclaration type, ClassScope scope) {
96
			if (type.javadoc != null) {
97
				assertTrue("Invalid type for Javadoc on " + type, type.javadoc instanceof SelectionJavadoc);
98
				SelectionJavadocTest.this.result.append(type.javadoc.toString());
99
			}
100
			return super.visit(type, scope);
101
		}
102
103
		public boolean visit(TypeDeclaration type, CompilationUnitScope scope) {
104
			if (type.javadoc != null) {
105
				assertTrue("Invalid type for Javadoc on " + type, type.javadoc instanceof SelectionJavadoc);
106
				SelectionJavadocTest.this.result.append(type.javadoc.toString());
107
			}
108
			return super.visit(type, scope);
109
		}
110
	}
111
112
	protected void assertValid(String expected) {
51
	protected void assertValid(String expected) {
113
		String actual = this.result.toString();
52
		String actual = this.result.toString();
114
		if (!actual.equals(expected)) {
53
		if (!actual.equals(expected)) {
Lines 163-169 Link Here
163
		// Visit compilation unit declaration to find javadoc
102
		// Visit compilation unit declaration to find javadoc
164
		unitDecl.traverse(new SelectionVisitor(), unitDecl.scope);
103
		unitDecl.traverse(new SelectionVisitor(), unitDecl.scope);
165
	}
104
	}
166
105
	
167
	public void test01() {
106
	public void test01() {
168
		setUnit("Test.java",
107
		setUnit("Test.java",
169
			"public class Test {\n" + 
108
			"public class Test {\n" + 
Lines 861-864 Link Here
861
			"/**<SelectOnType:Other>*/\n"
800
			"/**<SelectOnType:Other>*/\n"
862
		);
801
		);
863
	}
802
	}
803
	
804
	/**
805
	 * @bug 192449: [javadoc][assist] SelectionJavadocParser should not report problems
806
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=192449"
807
	 */
808
	public void test26() {
809
		setUnit("Test.java",
810
			"public class Test {\n" + 
811
			"	public void bar() {\n" + 
812
			"		new Object() {\n" + 
813
			"			/**\n" + 
814
			"			 * @see \n" +
815
			"			 * @see Test\n" +
816
			"			 * @see Other\n" + 
817
			"			 */\n" + 
818
			"			public class Other {}\n" + 
819
			"		};\n" + 
820
			"	}\n" + 
821
			"}"
822
		);
823
		Map optionsMap = getCompilerOptions();
824
		optionsMap.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED);
825
		optionsMap.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.WARNING);
826
		optionsMap.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, CompilerOptions.ENABLED);
827
		optionsMap.put(CompilerOptions.OPTION_ReportMissingJavadoc, CompilerOptions.WARNING);
828
		runTestParseCompilationUnit(this.unit, "NoReference", optionsMap, ""); // SelectionJavadocParser should not report errors
829
	}
864
}
830
}
(-)src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSelectionTest.java (-4 / +97 lines)
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
}
(-)src/org/eclipse/jdt/core/tests/util/Util.java (+54 lines)
Lines 20-27 Link Here
20
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IContainer;
21
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.jdt.core.compiler.CategorizedProblem;
23
import org.eclipse.jdt.core.compiler.IProblem;
24
import org.eclipse.jdt.core.compiler.IProblem;
24
import org.eclipse.jdt.core.tests.compiler.regression.Requestor;
25
import org.eclipse.jdt.core.tests.compiler.regression.Requestor;
26
import org.eclipse.jdt.internal.compiler.CompilationResult;
25
import org.eclipse.jdt.internal.compiler.Compiler;
27
import org.eclipse.jdt.internal.compiler.Compiler;
26
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
28
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
27
import org.eclipse.jdt.internal.compiler.IProblemFactory;
29
import org.eclipse.jdt.internal.compiler.IProblemFactory;
Lines 31-36 Link Here
31
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
33
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
32
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
34
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
33
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
35
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
36
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
34
public class Util {
37
public class Util {
35
    // Trace for delete operation
38
    // Trace for delete operation
36
    /*
39
    /*
Lines 1230-1233 Link Here
1230
        }
1233
        }
1231
    }
1234
    }
1232
}
1235
}
1236
/**
1237
 * Returns the compilation errors / warnings for the given CompilationResult.
1238
 *
1239
 * @param compilationResult the compilation result
1240
 * @param showCategory
1241
 * @param showWarningToken
1242
 * @return String the problem log
1243
 */
1244
public static String getProblemLog(CompilationResult compilationResult, boolean showCategory, boolean showWarningToken) {
1245
	StringBuffer buffer = new StringBuffer(100);
1246
	if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
1247
		CategorizedProblem[] problems = compilationResult.getAllProblems();
1248
		int count = problems.length;
1249
		int problemCount = 0;
1250
		char[] unitSource = compilationResult.compilationUnit.getContents();
1251
		for (int i = 0; i < count; i++) { 
1252
			DefaultProblem problem = (DefaultProblem) problems[i];
1253
			if (problem != null) {
1254
				if (problemCount == 0)
1255
					buffer.append("----------\n");
1256
				problemCount++;
1257
				buffer.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
1258
				buffer.append(" in " + new String(problem.getOriginatingFileName()).replace('/', '\\'));
1259
				try {
1260
					buffer.append(problem.errorReportSource(unitSource));
1261
					buffer.append("\n");
1262
					if (showCategory) {
1263
						String category = problem.getInternalCategoryMessage();
1264
						if (category != null) {
1265
							buffer.append("[@cat:").append(category).append("] ");
1266
						}
1267
					}
1268
					if (showWarningToken) {
1269
						long irritant = ProblemReporter.getIrritant(problem.getID());
1270
						if (irritant != 0) {
1271
							String warningToken = CompilerOptions.warningTokenFromIrritant(irritant);
1272
							if (warningToken != null) {
1273
								buffer.append("[@sup:").append(warningToken).append("] ");
1274
							}
1275
						}
1276
					}
1277
					buffer.append(problem.getMessage());
1278
					buffer.append("\n");
1279
				} catch (Exception e) {
1280
				}
1281
				buffer.append("----------\n");
1282
			}
1283
		}
1284
	}
1285
	return buffer.toString();
1286
}
1233
}
1287
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java (-46 / +3 lines)
Lines 16-29 Link Here
16
16
17
import junit.framework.Assert;
17
import junit.framework.Assert;
18
18
19
import org.eclipse.jdt.core.compiler.CategorizedProblem;
19
import org.eclipse.jdt.core.tests.util.Util;
20
import org.eclipse.jdt.internal.compiler.ClassFile;
20
import org.eclipse.jdt.internal.compiler.ClassFile;
21
import org.eclipse.jdt.internal.compiler.CompilationResult;
21
import org.eclipse.jdt.internal.compiler.CompilationResult;
22
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
22
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
23
import org.eclipse.jdt.internal.compiler.IProblemFactory;
23
import org.eclipse.jdt.internal.compiler.IProblemFactory;
24
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
25
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
26
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
27
24
28
public class Requestor extends Assert implements ICompilerRequestor {
25
public class Requestor extends Assert implements ICompilerRequestor {
29
	public boolean hasErrors = false;
26
	public boolean hasErrors = false;
Lines 45-92 Link Here
45
	this.showWarningToken = showWarningToken;
42
	this.showWarningToken = showWarningToken;
46
}
43
}
47
public void acceptResult(CompilationResult compilationResult) {
44
public void acceptResult(CompilationResult compilationResult) {
48
	StringBuffer buffer = new StringBuffer(100);
45
	this.hasErrors |= compilationResult.hasErrors();
49
	hasErrors |= compilationResult.hasErrors();
46
	this.problemLog += Util.getProblemLog(compilationResult, this.showCategory, this.showWarningToken);
50
	if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
51
		CategorizedProblem[] problems = compilationResult.getAllProblems();
52
		int count = problems.length;
53
		int problemCount = 0;
54
		char[] unitSource = compilationResult.compilationUnit.getContents();
55
		for (int i = 0; i < count; i++) { 
56
			DefaultProblem problem = (DefaultProblem) problems[i];
57
			if (problem != null) {
58
				if (problemCount == 0)
59
					buffer.append("----------\n");
60
				problemCount++;
61
				buffer.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
62
				buffer.append(" in " + new String(problem.getOriginatingFileName()).replace('/', '\\'));
63
				try {
64
					buffer.append(problem.errorReportSource(unitSource));
65
					buffer.append("\n");
66
					if (showCategory) {
67
						String category = problem.getInternalCategoryMessage();
68
						if (category != null) {
69
							buffer.append("[@cat:").append(category).append("] ");
70
						}
71
					}
72
					if (showWarningToken) {
73
						long irritant = ProblemReporter.getIrritant(problem.getID());
74
						if (irritant != 0) {
75
							String warningToken = CompilerOptions.warningTokenFromIrritant(irritant);
76
							if (warningToken != null) {
77
								buffer.append("[@sup:").append(warningToken).append("] ");
78
							}
79
						}
80
					}
81
					buffer.append(problem.getMessage());
82
					buffer.append("\n");
83
				} catch (Exception e) {
84
				}
85
				buffer.append("----------\n");
86
			}
87
		}
88
		problemLog += buffer.toString();
89
	}
90
	outputClassFiles(compilationResult);
47
	outputClassFiles(compilationResult);
91
	if (this.clientRequestor != null) {
48
	if (this.clientRequestor != null) {
92
		this.clientRequestor.acceptResult(compilationResult);
49
		this.clientRequestor.acceptResult(compilationResult);

Return to bug 192449