View | Details | Raw Unified | Return to bug 245860
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/builder/CompilationParticipantResult.java (-1 / +100 lines)
Lines 15-21 Link Here
15
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.jdt.core.compiler.*;
16
import org.eclipse.jdt.core.compiler.*;
17
17
18
public class CompilationParticipantResult {
18
public class CompilationParticipantResult extends BuildContext {
19
	protected SourceFile sourceFile;
19
	protected SourceFile sourceFile;
20
	protected boolean hasAnnotations; // only set during processAnnotations
20
	protected boolean hasAnnotations; // only set during processAnnotations
21
	protected IFile[] addedFiles; // added/changed generated source files that need to be compiled
21
	protected IFile[] addedFiles; // added/changed generated source files that need to be compiled
Lines 32-37 Link Here
32
	this.dependencies = null;
32
	this.dependencies = null;
33
}
33
}
34
34
35
/**
36
 * Returns the contents of the compilation unit.
37
 *
38
 * @return the contents of the compilation unit
39
 */
40
public char[] getContents() {
41
	return this.sourceFile.getContents();
42
}
43
44
/**
45
 * Returns the <code>IFile</code> representing the compilation unit.
46
 *
47
 * @return the <code>IFile</code> representing the compilation unit
48
 */
49
public IFile getFile() {
50
	return this.sourceFile.resource;
51
}
52
53
/**
54
 * Returns whether the compilation unit contained any annotations when it was compiled.
55
 *
56
 * NOTE: This is only valid during {@link CompilationParticipant#processAnnotations(BuildContext[])}.
57
 *
58
 * @return whether the compilation unit contained any annotations when it was compiled
59
 */
60
public boolean hasAnnotations() {
61
	return this.hasAnnotations; // only set during processAnnotations
62
}
63
64
/**
65
 * Record the added/changed generated files that need to be compiled.
66
 *
67
 * @param addedGeneratedFiles the added/changed files
68
 */
69
public void recordAddedGeneratedFiles(IFile[] addedGeneratedFiles) {
70
	int length2 = addedGeneratedFiles.length;
71
	if (length2 == 0) return;
72
73
	int length1 = this.addedFiles == null ? 0 : this.addedFiles.length;
74
	IFile[] merged = new IFile[length1 + length2];
75
	if (length1 > 0) // always make a copy even if currently empty
76
		System.arraycopy(this.addedFiles, 0, merged, 0, length1);
77
	System.arraycopy(addedGeneratedFiles, 0, merged, length1, length2);
78
	this.addedFiles = merged;
79
}
80
81
/**
82
 * Record the generated files that need to be deleted.
83
 *
84
 * @param deletedGeneratedFiles the files that need to be deleted
85
 */
86
public void recordDeletedGeneratedFiles(IFile[] deletedGeneratedFiles) {
87
	int length2 = deletedGeneratedFiles.length;
88
	if (length2 == 0) return;
89
90
	int length1 = this.deletedFiles == null ? 0 : this.deletedFiles.length;
91
	IFile[] merged = new IFile[length1 + length2];
92
	if (length1 > 0) // always make a copy even if currently empty
93
		System.arraycopy(this.deletedFiles, 0, merged, 0, length1);
94
	System.arraycopy(deletedGeneratedFiles, 0, merged, length1, length2);
95
	this.deletedFiles = merged;
96
}
97
98
/**
99
 * Record the fully-qualified type names of any new dependencies, each name is of the form "p1.p2.A.B".
100
 *
101
 * @param typeNameDependencies the fully-qualified type names of new dependencies
102
 */
103
public void recordDependencies(String[] typeNameDependencies) {
104
	int length2 = typeNameDependencies.length;
105
	if (length2 == 0) return;
106
107
	int length1 = this.dependencies == null ? 0 : this.dependencies.length;
108
	String[] merged = new String[length1 + length2];
109
	if (length1 > 0) // always make a copy even if currently empty
110
		System.arraycopy(this.dependencies, 0, merged, 0, length1);
111
	System.arraycopy(typeNameDependencies, 0, merged, length1, length2);
112
	this.dependencies = merged;
113
}
114
115
/**
116
 * Record new problems to report against this compilationUnit.
117
 * Markers are persisted for these problems only for the declared managed marker type
118
 * (see the 'compilationParticipant' extension point).
119
 *
120
 * @param newProblems the problems to report
121
 */
122
public void recordNewProblems(CategorizedProblem[] newProblems) {
123
	int length2 = newProblems.length;
124
	if (length2 == 0) return;
125
126
	int length1 = this.problems == null ? 0 : this.problems.length;
127
	CategorizedProblem[] merged = new CategorizedProblem[length1 + length2];
128
	if (length1 > 0) // always make a copy even if currently empty
129
		System.arraycopy(this.problems, 0, merged, 0, length1);
130
	System.arraycopy(newProblems, 0, merged, length1, length2);
131
	this.problems = merged;
132
}
133
35
void reset(boolean detectedAnnotations) {
134
void reset(boolean detectedAnnotations) {
36
	// called prior to processAnnotations
135
	// called prior to processAnnotations
37
	this.hasAnnotations = detectedAnnotations;
136
	this.hasAnnotations = detectedAnnotations;
(-)model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java (-8 / +8 lines)
Lines 283-289 Link Here
283
		this.filesWithAnnotations.clear();
283
		this.filesWithAnnotations.clear();
284
284
285
	// notify CompilationParticipants which source files are about to be compiled
285
	// notify CompilationParticipants which source files are about to be compiled
286
	BuildContext[] participantResults = this.javaBuilder.participants == null ? null : notifyParticipants(units);
286
	CompilationParticipantResult[] participantResults = this.javaBuilder.participants == null ? null : notifyParticipants(units);
287
	if (participantResults != null && participantResults.length > units.length) {
287
	if (participantResults != null && participantResults.length > units.length) {
288
		units = new SourceFile[participantResults.length];
288
		units = new SourceFile[participantResults.length];
289
		for (int i = participantResults.length; --i >= 0;)
289
		for (int i = participantResults.length; --i >= 0;)
Lines 539-548 Link Here
539
	return newCompiler;
539
	return newCompiler;
540
}
540
}
541
541
542
protected BuildContext[] notifyParticipants(SourceFile[] unitsAboutToCompile) {
542
protected CompilationParticipantResult[] notifyParticipants(SourceFile[] unitsAboutToCompile) {
543
	BuildContext[] results = new BuildContext[unitsAboutToCompile.length];
543
	CompilationParticipantResult[] results = new CompilationParticipantResult[unitsAboutToCompile.length];
544
	for (int i = unitsAboutToCompile.length; --i >= 0;)
544
	for (int i = unitsAboutToCompile.length; --i >= 0;)
545
		results[i] = new BuildContext(unitsAboutToCompile[i]);
545
		results[i] = new CompilationParticipantResult(unitsAboutToCompile[i]);
546
546
547
	// TODO (kent) do we expect to have more than one participant?
547
	// TODO (kent) do we expect to have more than one participant?
548
	// and if so should we pass the generated files from the each processor to the others to process?
548
	// and if so should we pass the generated files from the each processor to the others to process?
Lines 572-578 Link Here
572
						uniqueFiles.add(unitsAboutToCompile[f]);
572
						uniqueFiles.add(unitsAboutToCompile[f]);
573
				}
573
				}
574
				if (uniqueFiles.addIfNotIncluded(sourceFile) == sourceFile) {
574
				if (uniqueFiles.addIfNotIncluded(sourceFile) == sourceFile) {
575
					CompilationParticipantResult newResult = new BuildContext(sourceFile);
575
					CompilationParticipantResult newResult = new CompilationParticipantResult(sourceFile);
576
					// is there enough room to add all the addedGeneratedFiles.length ?
576
					// is there enough room to add all the addedGeneratedFiles.length ?
577
					if (toAdd == null) {
577
					if (toAdd == null) {
578
						toAdd = new CompilationParticipantResult[addedGeneratedFiles.length];
578
						toAdd = new CompilationParticipantResult[addedGeneratedFiles.length];
Lines 589-595 Link Here
589
589
590
	if (added >0 ) {
590
	if (added >0 ) {
591
		int length = results.length;
591
		int length = results.length;
592
		System.arraycopy(results, 0, results = new BuildContext[length + added], 0 , length);
592
		System.arraycopy(results, 0, results = new CompilationParticipantResult[length + added], 0 , length);
593
		System.arraycopy(toAdd, 0, results, length, added);
593
		System.arraycopy(toAdd, 0, results, length, added);
594
	}
594
	}
595
	return results;
595
	return results;
Lines 597-603 Link Here
597
597
598
protected abstract void processAnnotationResults(CompilationParticipantResult[] results);
598
protected abstract void processAnnotationResults(CompilationParticipantResult[] results);
599
599
600
protected void processAnnotations(BuildContext[] results) {
600
protected void processAnnotations(CompilationParticipantResult[] results) {
601
	boolean hasAnnotationProcessor = false;
601
	boolean hasAnnotationProcessor = false;
602
	for (int i = 0, l = this.javaBuilder.participants.length; !hasAnnotationProcessor && i < l; i++)
602
	for (int i = 0, l = this.javaBuilder.participants.length; !hasAnnotationProcessor && i < l; i++)
603
		hasAnnotationProcessor = this.javaBuilder.participants[i].isAnnotationProcessor();
603
		hasAnnotationProcessor = this.javaBuilder.participants[i].isAnnotationProcessor();
Lines 605-611 Link Here
605
605
606
	boolean foundAnnotations = this.filesWithAnnotations != null && this.filesWithAnnotations.elementSize > 0;
606
	boolean foundAnnotations = this.filesWithAnnotations != null && this.filesWithAnnotations.elementSize > 0;
607
	for (int i = results.length; --i >= 0;)
607
	for (int i = results.length; --i >= 0;)
608
		((CompilationParticipantResult) results[i]).reset(foundAnnotations && this.filesWithAnnotations.includes(results[i].sourceFile));
608
		results[i].reset(foundAnnotations && this.filesWithAnnotations.includes(results[i].sourceFile));
609
609
610
	// even if no files have annotations, must still tell every annotation processor in case the file used to have them
610
	// even if no files have annotations, must still tell every annotation processor in case the file used to have them
611
	for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
611
	for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
(-)model/org/eclipse/jdt/core/compiler/BuildContext.java (-52 / +8 lines)
Lines 13-20 Link Here
13
package org.eclipse.jdt.core.compiler;
13
package org.eclipse.jdt.core.compiler;
14
14
15
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.jdt.internal.core.builder.CompilationParticipantResult;
17
import org.eclipse.jdt.internal.core.builder.SourceFile;
18
16
19
/**
17
/**
20
 * The context of a build event that is notified to interested compilation
18
 * The context of a build event that is notified to interested compilation
Lines 25-41 Link Here
25
 * @noinstantiate This class is not intended to be instantiated by clients.
23
 * @noinstantiate This class is not intended to be instantiated by clients.
26
 * @noextend This class is not intended to be subclassed by clients.
24
 * @noextend This class is not intended to be subclassed by clients.
27
 */
25
 */
28
public class BuildContext extends CompilationParticipantResult {
26
public class BuildContext {
29
30
/**
31
 * Creates a build context for the given source file.
32
 *
33
 * @param sourceFile the source file being built
34
 * @noreference This constructor is not intended to be called by clients.
35
 */
36
public BuildContext(SourceFile sourceFile) {
37
	super(sourceFile);
38
}
39
27
40
/**
28
/**
41
 * Returns the contents of the compilation unit.
29
 * Returns the contents of the compilation unit.
Lines 43-49 Link Here
43
 * @return the contents of the compilation unit
31
 * @return the contents of the compilation unit
44
 */
32
 */
45
public char[] getContents() {
33
public char[] getContents() {
46
	return this.sourceFile.getContents();
34
	return null; // default overridden by concrete implementation
47
}
35
}
48
36
49
/**
37
/**
Lines 52-58 Link Here
52
 * @return the <code>IFile</code> representing the compilation unit
40
 * @return the <code>IFile</code> representing the compilation unit
53
 */
41
 */
54
public IFile getFile() {
42
public IFile getFile() {
55
	return this.sourceFile.resource;
43
	return null; // default overridden by concrete implementation
56
}
44
}
57
45
58
/**
46
/**
Lines 63-69 Link Here
63
 * @return whether the compilation unit contained any annotations when it was compiled
51
 * @return whether the compilation unit contained any annotations when it was compiled
64
 */
52
 */
65
public boolean hasAnnotations() {
53
public boolean hasAnnotations() {
66
	return this.hasAnnotations; // only set during processAnnotations
54
	return false; // default overridden by concrete implementation
67
}
55
}
68
56
69
/**
57
/**
Lines 72-86 Link Here
72
 * @param addedGeneratedFiles the added/changed files
60
 * @param addedGeneratedFiles the added/changed files
73
 */
61
 */
74
public void recordAddedGeneratedFiles(IFile[] addedGeneratedFiles) {
62
public void recordAddedGeneratedFiles(IFile[] addedGeneratedFiles) {
75
	int length2 = addedGeneratedFiles.length;
63
	// default overridden by concrete implementation
76
	if (length2 == 0) return;
77
78
	int length1 = this.addedFiles == null ? 0 : this.addedFiles.length;
79
	IFile[] merged = new IFile[length1 + length2];
80
	if (length1 > 0) // always make a copy even if currently empty
81
		System.arraycopy(this.addedFiles, 0, merged, 0, length1);
82
	System.arraycopy(addedGeneratedFiles, 0, merged, length1, length2);
83
	this.addedFiles = merged;
84
}
64
}
85
65
86
/**
66
/**
Lines 89-103 Link Here
89
 * @param deletedGeneratedFiles the files that need to be deleted
69
 * @param deletedGeneratedFiles the files that need to be deleted
90
 */
70
 */
91
public void recordDeletedGeneratedFiles(IFile[] deletedGeneratedFiles) {
71
public void recordDeletedGeneratedFiles(IFile[] deletedGeneratedFiles) {
92
	int length2 = deletedGeneratedFiles.length;
72
	// default overridden by concrete implementation
93
	if (length2 == 0) return;
94
95
	int length1 = this.deletedFiles == null ? 0 : this.deletedFiles.length;
96
	IFile[] merged = new IFile[length1 + length2];
97
	if (length1 > 0) // always make a copy even if currently empty
98
		System.arraycopy(this.deletedFiles, 0, merged, 0, length1);
99
	System.arraycopy(deletedGeneratedFiles, 0, merged, length1, length2);
100
	this.deletedFiles = merged;
101
}
73
}
102
74
103
/**
75
/**
Lines 106-120 Link Here
106
 * @param typeNameDependencies the fully-qualified type names of new dependencies
78
 * @param typeNameDependencies the fully-qualified type names of new dependencies
107
 */
79
 */
108
public void recordDependencies(String[] typeNameDependencies) {
80
public void recordDependencies(String[] typeNameDependencies) {
109
	int length2 = typeNameDependencies.length;
81
	// default overridden by concrete implementation
110
	if (length2 == 0) return;
111
112
	int length1 = this.dependencies == null ? 0 : this.dependencies.length;
113
	String[] merged = new String[length1 + length2];
114
	if (length1 > 0) // always make a copy even if currently empty
115
		System.arraycopy(this.dependencies, 0, merged, 0, length1);
116
	System.arraycopy(typeNameDependencies, 0, merged, length1, length2);
117
	this.dependencies = merged;
118
}
82
}
119
83
120
/**
84
/**
Lines 125-139 Link Here
125
 * @param newProblems the problems to report
89
 * @param newProblems the problems to report
126
 */
90
 */
127
public void recordNewProblems(CategorizedProblem[] newProblems) {
91
public void recordNewProblems(CategorizedProblem[] newProblems) {
128
	int length2 = newProblems.length;
92
	// default overridden by concrete implementation
129
	if (length2 == 0) return;
130
131
	int length1 = this.problems == null ? 0 : this.problems.length;
132
	CategorizedProblem[] merged = new CategorizedProblem[length1 + length2];
133
	if (length1 > 0) // always make a copy even if currently empty
134
		System.arraycopy(this.problems, 0, merged, 0, length1);
135
	System.arraycopy(newProblems, 0, merged, length1, length2);
136
	this.problems = merged;
137
}
93
}
138
94
139
}
95
}

Return to bug 245860