KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > compiler > BuildContext


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *
11  *******************************************************************************/

12
13 package org.eclipse.jdt.core.compiler;
14
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
19 /**
20  * The context of a build event that is notified to interested compilation
21  * participants when {@link CompilationParticipant#buildStarting(BuildContext[], boolean) a build is starting},
22  * or to annotations processors when {@link CompilationParticipant#processAnnotations(BuildContext[]) a source file has annotations}.
23  * <p>
24  * This class is not intended to be instanciated or subclassed by clients.
25  * </p>
26  * @since 3.2
27  */

28 public class BuildContext extends CompilationParticipantResult {
29
30 /**
31  * Creates a build context for the given source file.
32  * <p>
33  * This constructor is not intended to be called by clients.
34  * </p>
35  *
36  * @param sourceFile the source file being built
37  */

38 public BuildContext(SourceFile sourceFile) {
39     super(sourceFile);
40 }
41
42 /**
43  * Returns the contents of the compilation unit.
44  *
45  * @return the contents of the compilation unit
46  */

47 public char[] getContents() {
48     return this.sourceFile.getContents();
49 }
50
51 /**
52  * Returns the <code>IFile</code> representing the compilation unit.
53  *
54  * @return the <code>IFile</code> representing the compilation unit
55  */

56 public IFile getFile() {
57     return this.sourceFile.resource;
58 }
59
60 /**
61  * Returns whether the compilation unit contained any annotations when it was compiled.
62  *
63  * NOTE: This is only valid during {@link CompilationParticipant#processAnnotations(BuildContext[])}.
64  *
65  * @return whether the compilation unit contained any annotations when it was compiled
66  */

67 public boolean hasAnnotations() {
68     return this.hasAnnotations; // only set during processAnnotations
69
}
70
71 /**
72  * Record the added/changed generated files that need to be compiled.
73  *
74  * @param addedGeneratedFiles the added/changed files
75  */

76 public void recordAddedGeneratedFiles(IFile[] addedGeneratedFiles) {
77     int length2 = addedGeneratedFiles.length;
78     if (length2 == 0) return;
79
80     int length1 = this.addedFiles == null ? 0 : this.addedFiles.length;
81     IFile[] merged = new IFile[length1 + length2];
82     if (length1 > 0) // always make a copy even if currently empty
83
System.arraycopy(this.addedFiles, 0, merged, 0, length1);
84     System.arraycopy(addedGeneratedFiles, 0, merged, length1, length2);
85     this.addedFiles = merged;
86 }
87
88 /**
89  * Record the generated files that need to be deleted.
90  *
91  * @param deletedGeneratedFiles the files that need to be deleted
92  */

93 public void recordDeletedGeneratedFiles(IFile[] deletedGeneratedFiles) {
94     int length2 = deletedGeneratedFiles.length;
95     if (length2 == 0) return;
96
97     int length1 = this.deletedFiles == null ? 0 : this.deletedFiles.length;
98     IFile[] merged = new IFile[length1 + length2];
99     if (length1 > 0) // always make a copy even if currently empty
100
System.arraycopy(this.deletedFiles, 0, merged, 0, length1);
101     System.arraycopy(deletedGeneratedFiles, 0, merged, length1, length2);
102     this.deletedFiles = merged;
103 }
104
105 /**
106  * Record the fully-qualified type names of any new dependencies, each name is of the form "p1.p2.A.B".
107  *
108  * @param typeNameDependencies the fully-qualified type names of new dependencies
109  */

110 public void recordDependencies(String JavaDoc[] typeNameDependencies) {
111     int length2 = typeNameDependencies.length;
112     if (length2 == 0) return;
113
114     int length1 = this.dependencies == null ? 0 : this.dependencies.length;
115     String JavaDoc[] merged = new String JavaDoc[length1 + length2];
116     if (length1 > 0) // always make a copy even if currently empty
117
System.arraycopy(this.dependencies, 0, merged, 0, length1);
118     System.arraycopy(typeNameDependencies, 0, merged, length1, length2);
119     this.dependencies = merged;
120 }
121
122 /**
123  * Record new problems to report against this compilationUnit.
124  * Markers are persisted for these problems only for the declared managed marker type
125  * (see the 'compilationParticipant' extension point).
126  *
127  * @param newProblems the problems to report
128  */

129 public void recordNewProblems(CategorizedProblem[] newProblems) {
130     int length2 = newProblems.length;
131     if (length2 == 0) return;
132
133     int length1 = this.problems == null ? 0 : this.problems.length;
134     CategorizedProblem[] merged = new CategorizedProblem[length1 + length2];
135     if (length1 > 0) // always make a copy even if currently empty
136
System.arraycopy(this.problems, 0, merged, 0, length1);
137     System.arraycopy(newProblems, 0, merged, length1, length2);
138     this.problems = merged;
139 }
140
141 }
142
Popular Tags