Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9555b23

Browse files
author
jossonsmith
committed
Migrate Java2Script compiler to Eclipse 3.2
1 parent b04128e commit 9555b23

22 files changed

+891
-387
lines changed

src/net/sf/j2s/core/builder/AbortIncrementalBuildException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2004 IBM Corporation and others.
2+
* Copyright (c) 2000, 2006 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

src/net/sf/j2s/core/builder/AbstractImageBuilder.java

Lines changed: 274 additions & 109 deletions
Large diffs are not rendered by default.

src/net/sf/j2s/core/builder/AdditionalTypeCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2004 IBM Corporation and others.
2+
* Copyright (c) 2000, 2006 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

src/net/sf/j2s/core/builder/BatchImageBuilder.java

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2004 IBM Corporation and others.
2+
* Copyright (c) 2000, 2006 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -14,32 +14,38 @@
1414
import org.eclipse.core.runtime.*;
1515

1616
import org.eclipse.jdt.core.JavaCore;
17+
import org.eclipse.jdt.internal.compiler.ClassFile;
1718
import org.eclipse.jdt.internal.core.util.Messages;
1819
import org.eclipse.jdt.internal.core.util.Util;
1920

2021
import java.util.*;
2122

2223
public class BatchImageBuilder extends AbstractImageBuilder {
2324

24-
protected BatchImageBuilder(JavaBuilder javaBuilder) {
25-
super(javaBuilder);
25+
IncrementalImageBuilder incrementalBuilder; // if annotations or secondary types have to be processed after the compile loop
26+
ArrayList missingSecondaryTypes; // qualified names for any secondary types found after the first compile loop
27+
28+
protected BatchImageBuilder(JavaBuilder javaBuilder, boolean buildStarting) {
29+
super(javaBuilder, buildStarting, null);
2630
this.nameEnvironment.isIncrementalBuild = false;
31+
this.incrementalBuilder = null;
32+
this.missingSecondaryTypes = null;
2733
}
2834

2935
public void build() {
3036
if (JavaBuilder.DEBUG)
3137
System.out.println("FULL build"); //$NON-NLS-1$
3238

3339
try {
34-
notifier.subTask(Messages.build_cleaningOutput);
40+
notifier.subTask(Messages.bind(Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
3541
JavaBuilder.removeProblemsAndTasksFor(javaBuilder.currentProject);
3642
cleanOutputFolders(true);
37-
notifier.updateProgressDelta(0.1f);
43+
notifier.updateProgressDelta(0.05f);
3844

3945
notifier.subTask(Messages.build_analyzingSources);
4046
ArrayList sourceFiles = new ArrayList(33);
4147
addAllSourceFiles(sourceFiles);
42-
notifier.updateProgressDelta(0.15f);
48+
notifier.updateProgressDelta(0.10f);
4349

4450
if (sourceFiles.size() > 0) {
4551
SourceFile[] allSourceFiles = new SourceFile[sourceFiles.size()];
@@ -48,6 +54,11 @@ public void build() {
4854
notifier.setProgressPerCompilationUnit(0.75f / allSourceFiles.length);
4955
workQueue.addAll(allSourceFiles);
5056
compile(allSourceFiles);
57+
58+
if (this.missingSecondaryTypes != null && !this.missingSecondaryTypes.isEmpty())
59+
rebuildTypesAffectedByMissingSecondaryTypes();
60+
if (this.incrementalBuilder != null)
61+
this.incrementalBuilder.buildAfterBatchBuild();
5162
}
5263

5364
if (javaBuilder.javaProject.hasCycleMarker())
@@ -59,6 +70,11 @@ public void build() {
5970
}
6071
}
6172

73+
protected void acceptSecondaryType(ClassFile classFile) {
74+
if (this.missingSecondaryTypes != null)
75+
this.missingSecondaryTypes.add(classFile.fileName());
76+
}
77+
6278
protected void addAllSourceFiles(final ArrayList sourceFiles) throws CoreException {
6379
for (int i = 0, l = sourceLocations.length; i < l; i++) {
6480
final ClasspathMultiDirectory sourceLocation = sourceLocations[i];
@@ -102,9 +118,13 @@ protected void cleanOutputFolders(boolean copyBack) throws CoreException {
102118
boolean deleteAll = JavaCore.CLEAN.equals(
103119
javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
104120
if (deleteAll) {
121+
if (this.javaBuilder.participants != null)
122+
for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
123+
this.javaBuilder.participants[i].cleanStarting(this.javaBuilder.javaProject);
124+
105125
ArrayList visited = new ArrayList(sourceLocations.length);
106126
for (int i = 0, l = sourceLocations.length; i < l; i++) {
107-
notifier.subTask(Messages.build_cleaningOutput);
127+
notifier.subTask(Messages.bind(Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
108128
ClasspathMultiDirectory sourceLocation = sourceLocations[i];
109129
if (sourceLocation.hasIndependentOutputFolder) {
110130
IContainer outputFolder = sourceLocation.binaryFolder;
@@ -185,6 +205,18 @@ else if (!sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder))
185205
}
186206
}
187207

208+
protected void cleanUp() {
209+
this.incrementalBuilder = null;
210+
this.missingSecondaryTypes = null;
211+
super.cleanUp();
212+
}
213+
214+
protected void compile(SourceFile[] units, SourceFile[] additionalUnits, boolean compilingFirstGroup) {
215+
if (!compilingFirstGroup && this.missingSecondaryTypes == null)
216+
this.missingSecondaryTypes = new ArrayList(7);
217+
super.compile(units, additionalUnits, compilingFirstGroup);
218+
}
219+
188220
protected void copyExtraResourcesBack(ClasspathMultiDirectory sourceLocation, final boolean deletedAll) throws CoreException {
189221
// When, if ever, does a builder need to copy resources files (not .java or .class) into the output folder?
190222
// If we wipe the output folder at the beginning of the build then all 'extra' resources must be copied to the output folder.
@@ -225,8 +257,7 @@ public boolean visit(IResourceProxy proxy) throws CoreException {
225257
}
226258
copiedResource.delete(IResource.FORCE, null); // last one wins
227259
}
228-
resource.copy(copiedResource.getFullPath(), IResource.FORCE, null);
229-
copiedResource.setDerived(true);
260+
resource.copy(copiedResource.getFullPath(), IResource.FORCE | IResource.DERIVED, null);
230261
Util.setReadOnly(copiedResource, false); // just in case the original was read only
231262
return false;
232263
case IResource.FOLDER :
@@ -284,6 +315,24 @@ protected IResource findOriginalResource(IPath partialPath) {
284315
return null;
285316
}
286317

318+
protected void processAnnotationResults(CompilationParticipantResult[] results) {
319+
// to compile the compilation participant results, we need to incrementally recompile all affected types
320+
// whenever the generated types are initially added or structurally changed
321+
if (this.incrementalBuilder == null)
322+
this.incrementalBuilder = new IncrementalImageBuilder(this);
323+
this.incrementalBuilder.processAnnotationResults(results);
324+
}
325+
326+
protected void rebuildTypesAffectedByMissingSecondaryTypes() {
327+
// to compile types that could not find 'missing' secondary types because of multiple
328+
// compile groups, we need to incrementally recompile all affected types as if the missing
329+
// secondary types have just been added
330+
if (this.incrementalBuilder == null)
331+
this.incrementalBuilder = new IncrementalImageBuilder(this);
332+
for (int i = this.missingSecondaryTypes.size(); --i >=0; )
333+
this.incrementalBuilder.addAffectedSourceFiles((char[]) this.missingSecondaryTypes.get(i));
334+
}
335+
287336
public String toString() {
288337
return "batch image builder for:\n\tnew state: " + newState; //$NON-NLS-1$
289338
}

src/net/sf/j2s/core/builder/BuildNotifier.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2004 IBM Corporation and others.
2+
* Copyright (c) 2000, 2006 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -13,6 +13,7 @@
1313
import org.eclipse.core.resources.*;
1414
import org.eclipse.core.runtime.*;
1515

16+
import org.eclipse.jdt.core.compiler.CategorizedProblem;
1617
import org.eclipse.jdt.core.compiler.IProblem;
1718
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
1819
import org.eclipse.jdt.internal.core.util.Messages;
@@ -203,7 +204,7 @@ public void subTask(String message) {
203204
this.previousSubtask = msg;
204205
}
205206

206-
protected void updateProblemCounts(IProblem[] newProblems) {
207+
protected void updateProblemCounts(CategorizedProblem[] newProblems) {
207208
for (int i = 0, l = newProblems.length; i < l; i++)
208209
if (newProblems[i].isError()) newErrorCount++; else newWarningCount++;
209210
}
@@ -212,10 +213,10 @@ protected void updateProblemCounts(IProblem[] newProblems) {
212213
* Update the problem counts from one compilation result given the old and new problems,
213214
* either of which may be null.
214215
*/
215-
protected void updateProblemCounts(IMarker[] oldProblems, IProblem[] newProblems) {
216+
protected void updateProblemCounts(IMarker[] oldProblems, CategorizedProblem[] newProblems) {
216217
if (newProblems != null) {
217218
next : for (int i = 0, l = newProblems.length; i < l; i++) {
218-
IProblem newProblem = newProblems[i];
219+
CategorizedProblem newProblem = newProblems[i];
219220
if (newProblem.getID() == IProblem.Task) continue; // skip task
220221
boolean isError = newProblem.isError();
221222
String message = newProblem.getMessage();
@@ -245,7 +246,7 @@ protected void updateProblemCounts(IMarker[] oldProblems, IProblem[] newProblems
245246

246247
if (newProblems != null) {
247248
for (int j = 0, m = newProblems.length; j < m; j++) {
248-
IProblem pb = newProblems[j];
249+
CategorizedProblem pb = newProblems[j];
249250
if (pb.getID() == IProblem.Task) continue; // skip task
250251
if (wasError == pb.isError() && message.equals(pb.getMessage()))
251252
continue next;

src/net/sf/j2s/core/builder/ClasspathDirectory.java

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2005 IBM Corporation and others.
2+
* Copyright (c) 2000, 2006 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -10,29 +10,30 @@
1010
*******************************************************************************/
1111
package net.sf.j2s.core.builder;
1212

13+
import java.io.IOException;
14+
1315
import org.eclipse.core.resources.*;
1416
import org.eclipse.core.runtime.*;
1517

1618
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
19+
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
1720
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
1821
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
1922
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
2023
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
24+
import org.eclipse.jdt.internal.core.util.Util;
2125

2226
public class ClasspathDirectory extends ClasspathLocation {
2327

2428
IContainer binaryFolder; // includes .class files for a single directory
2529
boolean isOutputFolder;
26-
String binaryLocation;
2730
SimpleLookupTable directoryCache;
2831
String[] missingPackageHolder = new String[1];
2932
AccessRuleSet accessRuleSet;
3033

3134
ClasspathDirectory(IContainer binaryFolder, boolean isOutputFolder, AccessRuleSet accessRuleSet) {
3235
this.binaryFolder = binaryFolder;
3336
this.isOutputFolder = isOutputFolder;
34-
IPath location = binaryFolder.getLocation();
35-
this.binaryLocation = location != null ? location.addTrailingSeparator().toString() : ""; //$NON-NLS-1$
3637
this.directoryCache = new SimpleLookupTable(5);
3738
this.accessRuleSet = accessRuleSet;
3839
}
@@ -48,7 +49,7 @@ String[] directoryList(String qualifiedPackageName) {
4849

4950
try {
5051
IResource container = binaryFolder.findMember(qualifiedPackageName); // this is a case-sensitive check
51-
if (container instanceof IContainer && !isExcluded(container)) {
52+
if (container instanceof IContainer) {
5253
IResource[] members = ((IContainer) container).members();
5354
dirList = new String[members.length];
5455
int index = 0;
@@ -94,34 +95,21 @@ public boolean equals(Object o) {
9495
public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName) {
9596
if (!doesFileExist(binaryFileName, qualifiedPackageName, qualifiedBinaryFileName)) return null; // most common case
9697

98+
ClassFileReader reader = null;
9799
try {
98-
ClassFileReader reader = ClassFileReader.read(binaryLocation + qualifiedBinaryFileName);
99-
if (reader != null) {
100-
if (this.accessRuleSet == null)
101-
return new NameEnvironmentAnswer(reader, null);
102-
String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length);
103-
return new NameEnvironmentAnswer(reader, this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()));
104-
}
105-
} catch (Exception e) {
106-
// handle the case when the project is the output folder and the top-level package is a linked folder
107-
if (binaryFolder instanceof IProject) {
108-
IResource file = binaryFolder.findMember(qualifiedBinaryFileName);
109-
if (file instanceof IFile) {
110-
IPath location = file.getLocation();
111-
if (location != null) {
112-
try {
113-
ClassFileReader reader = ClassFileReader.read(location.toString());
114-
if (reader != null) {
115-
if (this.accessRuleSet == null)
116-
return new NameEnvironmentAnswer(reader, null);
117-
String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length);
118-
return new NameEnvironmentAnswer(reader, this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()));
119-
}
120-
} catch (Exception ignored) { // treat as if class file is missing
121-
}
122-
}
123-
}
124-
}
100+
reader = Util.newClassFileReader(this.binaryFolder.getFile(new Path(qualifiedBinaryFileName)));
101+
} catch (CoreException e) {
102+
return null;
103+
} catch (ClassFormatException e) {
104+
return null;
105+
} catch (IOException e) {
106+
return null;
107+
}
108+
if (reader != null) {
109+
if (this.accessRuleSet == null)
110+
return new NameEnvironmentAnswer(reader, null);
111+
String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length);
112+
return new NameEnvironmentAnswer(reader, this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()));
125113
}
126114
return null;
127115
}
@@ -154,7 +142,7 @@ public String toString() {
154142
}
155143

156144
public String debugPathString() {
157-
return this.binaryLocation;
145+
return this.binaryFolder.getFullPath().toString();
158146
}
159147

160148

src/net/sf/j2s/core/builder/ClasspathJar.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2005 IBM Corporation and others.
2+
* Copyright (c) 2000, 2006 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -18,8 +18,9 @@
1818
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
1919
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
2020
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
21+
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
2122
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
22-
import org.eclipse.jdt.internal.core.util.SimpleSet;
23+
import org.eclipse.jdt.internal.core.util.Util;
2324

2425
import java.io.*;
2526
import java.util.*;
@@ -86,8 +87,17 @@ static SimpleSet findPackageSet(ClasspathJar jar) {
8687

8788
ClasspathJar(IFile resource, AccessRuleSet accessRuleSet) {
8889
this.resource = resource;
89-
IPath location = resource.getLocation();
90-
this.zipFilename = location != null ? location.toString() : ""; //$NON-NLS-1$
90+
try {
91+
java.net.URI location = resource.getLocationURI();
92+
if (location == null) {
93+
this.zipFilename = ""; //$NON-NLS-1$
94+
} else {
95+
File localFile = Util.toLocalFile(location, null);
96+
this.zipFilename = localFile.getPath();
97+
}
98+
} catch (CoreException e) {
99+
// ignore
100+
}
91101
this.zipFile = null;
92102
this.knownPackageNames = null;
93103
this.accessRuleSet = accessRuleSet;

src/net/sf/j2s/core/builder/ClasspathLocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2004 IBM Corporation and others.
2+
* Copyright (c) 2000, 2006 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

src/net/sf/j2s/core/builder/ImageBuilderInternalException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2004 IBM Corporation and others.
2+
* Copyright (c) 2000, 2006 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at

0 commit comments

Comments
 (0)