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

Skip to content

Commit 41f7ce4

Browse files
committed
Java2Script compiler for Eclipse 4.2
1 parent 5dcd269 commit 41f7ce4

File tree

5 files changed

+46
-60
lines changed

5 files changed

+46
-60
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/DependencyASTVisitor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Iterator;
1919
import java.util.List;
2020
import java.util.Set;
21-
2221
import org.eclipse.jdt.core.dom.ASTNode;
2322
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
2423
import org.eclipse.jdt.core.dom.Annotation;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 IBM Corporation and others.
2+
* Copyright (c) 2000, 2012 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
@@ -57,8 +57,7 @@ public abstract class AbstractImageBuilder implements ICompilerRequestor, ICompi
5757
protected boolean keepStoringProblemMarkers;
5858
protected SimpleSet filesWithAnnotations = null;
5959

60-
//2000 is best compromise between space used and speed
61-
public static int MAX_AT_ONCE = Integer.getInteger(JavaModelManager.MAX_COMPILED_UNITS_AT_ONCE, 2000).intValue();
60+
public static int MAX_AT_ONCE = 2000; // best compromise between space used and speed
6261
public final static String[] JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES = {
6362
IMarker.MESSAGE,
6463
IMarker.SEVERITY,
@@ -294,7 +293,7 @@ protected void compile(SourceFile[] units) {
294293
}
295294

296295
int unitsLength = units.length;
297-
this.compiledAllAtOnce = MAX_AT_ONCE == 0 || unitsLength <= MAX_AT_ONCE;
296+
this.compiledAllAtOnce = unitsLength <= MAX_AT_ONCE;
298297
if (this.compiledAllAtOnce) {
299298
// do them all now
300299
if (JavaBuilder.DEBUG)

sources/net.sf.j2s.core/src/net/sf/j2s/core/builder/IncrementalImageBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 IBM Corporation and others.
2+
* Copyright (c) 2000, 2012 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
@@ -799,7 +799,7 @@ protected void resetCollections() {
799799
protected void updateProblemsFor(SourceFile sourceFile, CompilationResult result) throws CoreException {
800800
if (CharOperation.equals(sourceFile.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME)) {
801801
IResource pkgResource = sourceFile.resource.getParent();
802-
pkgResource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
802+
pkgResource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
803803
}
804804
IMarker[] markers = JavaBuilder.getProblemsFor(sourceFile.resource);
805805
CategorizedProblem[] problems = result.getProblems();

sources/net.sf.j2s.core/src/net/sf/j2s/core/builder/JavaBuilder.java

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 IBM Corporation and others.
2+
* Copyright (c) 2000, 2011 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
@@ -12,6 +12,7 @@
1212

1313
import org.eclipse.core.resources.*;
1414
import org.eclipse.core.runtime.*;
15+
1516
import org.eclipse.jdt.core.*;
1617
import org.eclipse.jdt.core.compiler.*;
1718
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
@@ -20,8 +21,6 @@
2021
import org.eclipse.jdt.internal.core.util.Util;
2122

2223
import java.io.*;
23-
import java.lang.reflect.InvocationTargetException;
24-
import java.lang.reflect.Method;
2524
import java.util.*;
2625

2726
public class JavaBuilder extends IncrementalProjectBuilder {
@@ -158,7 +157,7 @@ protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) thro
158157
if (this.currentProject == null || !this.currentProject.isAccessible()) return new IProject[0];
159158

160159
if (DEBUG)
161-
System.out.println("\nJavaBuilder: Starting build of " + this.currentProject.getName() //$NON-NLS-1$
160+
System.out.println("\nStarting build of " + this.currentProject.getName() //$NON-NLS-1$
162161
+ " @ " + new Date(System.currentTimeMillis())); //$NON-NLS-1$
163162
this.notifier = new BuildNotifier(monitor, this.currentProject);
164163
this.notifier.begin();
@@ -170,39 +169,39 @@ protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) thro
170169
if (isWorthBuilding()) {
171170
if (kind == FULL_BUILD) {
172171
if (DEBUG)
173-
System.out.println("JavaBuilder: Performing full build as requested"); //$NON-NLS-1$
172+
System.out.println("Performing full build as requested by user"); //$NON-NLS-1$
174173
buildAll();
175174
} else {
176175
if ((this.lastState = getLastState(this.currentProject)) == null) {
177176
if (DEBUG)
178-
System.out.println("JavaBuilder: Performing full build since last saved state was not found"); //$NON-NLS-1$
177+
System.out.println("Performing full build since last saved state was not found"); //$NON-NLS-1$
179178
buildAll();
180179
} else if (hasClasspathChanged()) {
181180
// if the output location changes, do not delete the binary files from old location
182181
// the user may be trying something
183182
if (DEBUG)
184-
System.out.println("JavaBuilder: Performing full build since classpath has changed"); //$NON-NLS-1$
183+
System.out.println("Performing full build since classpath has changed"); //$NON-NLS-1$
185184
buildAll();
186185
} else if (this.nameEnvironment.sourceLocations.length > 0) {
187186
// if there is no source to compile & no classpath changes then we are done
188187
SimpleLookupTable deltas = findDeltas();
189188
if (deltas == null) {
190189
if (DEBUG)
191-
System.out.println("JavaBuilder: Performing full build since deltas are missing after incremental request"); //$NON-NLS-1$
190+
System.out.println("Performing full build since deltas are missing after incremental request"); //$NON-NLS-1$
192191
buildAll();
193192
} else if (deltas.elementSize > 0) {
194193
buildDeltas(deltas);
195194
} else if (DEBUG) {
196-
System.out.println("JavaBuilder: Nothing to build since deltas were empty"); //$NON-NLS-1$
195+
System.out.println("Nothing to build since deltas were empty"); //$NON-NLS-1$
197196
}
198197
} else {
199198
if (hasStructuralDelta()) { // double check that a jar file didn't get replaced in a binary project
200199
if (DEBUG)
201-
System.out.println("JavaBuilder: Performing full build since there are structural deltas"); //$NON-NLS-1$
200+
System.out.println("Performing full build since there are structural deltas"); //$NON-NLS-1$
202201
buildAll();
203202
} else {
204203
if (DEBUG)
205-
System.out.println("JavaBuilder: Nothing to build since there are no source folders and no deltas"); //$NON-NLS-1$
204+
System.out.println("Nothing to build since there are no source folders and no deltas"); //$NON-NLS-1$
206205
this.lastState.tagAsNoopBuild();
207206
}
208207
}
@@ -240,16 +239,16 @@ protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) thro
240239
}
241240
IProject[] requiredProjects = getRequiredProjects(true);
242241
if (DEBUG)
243-
System.out.println("JavaBuilder: Finished build of " + this.currentProject.getName() //$NON-NLS-1$
244-
+ " @ " + new Date(System.currentTimeMillis()) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
242+
System.out.println("Finished build of " + this.currentProject.getName() //$NON-NLS-1$
243+
+ " @ " + new Date(System.currentTimeMillis())); //$NON-NLS-1$
245244
return requiredProjects;
246245
}
247246

248247
private void buildAll() {
249248
this.notifier.checkCancel();
250249
this.notifier.subTask(Messages.bind(Messages.build_preparingBuild, this.currentProject.getName()));
251250
if (DEBUG && this.lastState != null)
252-
System.out.println("JavaBuilder: Clearing last state : " + this.lastState); //$NON-NLS-1$
251+
System.out.println("Clearing last state : " + this.lastState); //$NON-NLS-1$
253252
clearLastState();
254253
BatchImageBuilder imageBuilder = new Java2ScriptBatchImageBuilder(this, true);
255254
imageBuilder.build();
@@ -260,14 +259,14 @@ private void buildDeltas(SimpleLookupTable deltas) {
260259
this.notifier.checkCancel();
261260
this.notifier.subTask(Messages.bind(Messages.build_preparingBuild, this.currentProject.getName()));
262261
if (DEBUG && this.lastState != null)
263-
System.out.println("JavaBuilder: Clearing last state : " + this.lastState); //$NON-NLS-1$
262+
System.out.println("Clearing last state : " + this.lastState); //$NON-NLS-1$
264263
clearLastState(); // clear the previously built state so if the build fails, a full build will occur next time
265264
IncrementalImageBuilder imageBuilder = new Java2ScriptIncrementalImageBuilder(this);
266265
if (imageBuilder.build(deltas)) {
267266
recordNewState(imageBuilder.newState);
268267
} else {
269268
if (DEBUG)
270-
System.out.println("JavaBuilder: Performing full build since incremental build failed"); //$NON-NLS-1$
269+
System.out.println("Performing full build since incremental build failed"); //$NON-NLS-1$
271270
buildAll();
272271
}
273272
}
@@ -277,7 +276,7 @@ protected void clean(IProgressMonitor monitor) throws CoreException {
277276
if (this.currentProject == null || !this.currentProject.isAccessible()) return;
278277

279278
if (DEBUG)
280-
System.out.println("\nJavaBuilder: Cleaning " + this.currentProject.getName() //$NON-NLS-1$
279+
System.out.println("\nCleaning " + this.currentProject.getName() //$NON-NLS-1$
281280
+ " @ " + new Date(System.currentTimeMillis())); //$NON-NLS-1$
282281
this.notifier = new BuildNotifier(monitor, this.currentProject);
283282
this.notifier.begin();
@@ -286,7 +285,7 @@ protected void clean(IProgressMonitor monitor) throws CoreException {
286285

287286
initializeBuilder(CLEAN_BUILD, true);
288287
if (DEBUG)
289-
System.out.println("JavaBuilder: Clearing last state as part of clean : " + this.lastState); //$NON-NLS-1$
288+
System.out.println("Clearing last state as part of clean : " + this.lastState); //$NON-NLS-1$
290289
clearLastState();
291290
removeProblemsAndTasksFor(this.currentProject);
292291
new BatchImageBuilder(this, false).cleanOutputFolders(false);
@@ -298,7 +297,7 @@ protected void clean(IProgressMonitor monitor) throws CoreException {
298297
cleanup();
299298
}
300299
if (DEBUG)
301-
System.out.println("JavaBuilder: Finished cleaning " + this.currentProject.getName() //$NON-NLS-1$
300+
System.out.println("Finished cleaning " + this.currentProject.getName() //$NON-NLS-1$
302301
+ " @ " + new Date(System.currentTimeMillis())); //$NON-NLS-1$
303302
}
304303

@@ -367,12 +366,12 @@ private SimpleLookupTable findDeltas() {
367366
if (delta != null) {
368367
if (delta.getKind() != IResourceDelta.NO_CHANGE) {
369368
if (DEBUG)
370-
System.out.println("JavaBuilder: Found source delta for: " + this.currentProject.getName()); //$NON-NLS-1$
369+
System.out.println("Found source delta for: " + this.currentProject.getName()); //$NON-NLS-1$
371370
deltas.put(this.currentProject, delta);
372371
}
373372
} else {
374373
if (DEBUG)
375-
System.out.println("JavaBuilder: Missing delta for: " + this.currentProject.getName()); //$NON-NLS-1$
374+
System.out.println("Missing delta for: " + this.currentProject.getName()); //$NON-NLS-1$
376375
this.notifier.subTask(""); //$NON-NLS-1$
377376
return null;
378377
}
@@ -402,12 +401,12 @@ private SimpleLookupTable findDeltas() {
402401
if (delta != null) {
403402
if (delta.getKind() != IResourceDelta.NO_CHANGE) {
404403
if (DEBUG)
405-
System.out.println("JavaBuilder: Found binary delta for: " + p.getName()); //$NON-NLS-1$
404+
System.out.println("Found binary delta for: " + p.getName()); //$NON-NLS-1$
406405
deltas.put(p, delta);
407406
}
408407
} else {
409408
if (DEBUG)
410-
System.out.println("JavaBuilder: Missing delta for: " + p.getName()); //$NON-NLS-1$
409+
System.out.println("Missing delta for: " + p.getName()); //$NON-NLS-1$
411410
this.notifier.subTask(""); //$NON-NLS-1$
412411
return null;
413412
}
@@ -515,7 +514,7 @@ private boolean hasClasspathChanged() {
515514
} catch (CoreException ignore) { // skip it
516515
}
517516
if (DEBUG) {
518-
System.out.println("JavaBuilder: New location: " + newSourceLocations[n] + "\n!= old location: " + oldSourceLocations[o]); //$NON-NLS-1$ //$NON-NLS-2$
517+
System.out.println("New location: " + newSourceLocations[n] + "\n!= old location: " + oldSourceLocations[o]); //$NON-NLS-1$ //$NON-NLS-2$
519518
printLocations(newSourceLocations, oldSourceLocations);
520519
}
521520
return true;
@@ -529,7 +528,7 @@ private boolean hasClasspathChanged() {
529528
} catch (CoreException ignore) { // skip it
530529
}
531530
if (DEBUG) {
532-
System.out.println("JavaBuilder: Added non-empty source folder"); //$NON-NLS-1$
531+
System.out.println("Added non-empty source folder"); //$NON-NLS-1$
533532
printLocations(newSourceLocations, oldSourceLocations);
534533
}
535534
return true;
@@ -540,7 +539,7 @@ private boolean hasClasspathChanged() {
540539
continue;
541540
}
542541
if (DEBUG) {
543-
System.out.println("JavaBuilder: Removed non-empty source folder"); //$NON-NLS-1$
542+
System.out.println("Removed non-empty source folder"); //$NON-NLS-1$
544543
printLocations(newSourceLocations, oldSourceLocations);
545544
}
546545
return true;
@@ -553,14 +552,14 @@ private boolean hasClasspathChanged() {
553552
for (n = o = 0; n < newLength && o < oldLength; n++, o++) {
554553
if (newBinaryLocations[n].equals(oldBinaryLocations[o])) continue;
555554
if (DEBUG) {
556-
System.out.println("JavaBuilder: New location: " + newBinaryLocations[n] + "\n!= old location: " + oldBinaryLocations[o]); //$NON-NLS-1$ //$NON-NLS-2$
555+
System.out.println("New location: " + newBinaryLocations[n] + "\n!= old location: " + oldBinaryLocations[o]); //$NON-NLS-1$ //$NON-NLS-2$
557556
printLocations(newBinaryLocations, oldBinaryLocations);
558557
}
559558
return true;
560559
}
561560
if (n < newLength || o < oldLength) {
562561
if (DEBUG) {
563-
System.out.println("JavaBuilder: Number of binary folders/jar files has changed:"); //$NON-NLS-1$
562+
System.out.println("Number of binary folders/jar files has changed:"); //$NON-NLS-1$
564563
printLocations(newBinaryLocations, oldBinaryLocations);
565564
}
566565
return true;
@@ -614,15 +613,7 @@ private int initializeBuilder(int kind, boolean forBuild) throws CoreException {
614613
// Flush the existing external files cache if this is the beginning of a build cycle
615614
String projectName = this.currentProject.getName();
616615
if (builtProjects == null || builtProjects.contains(projectName)) {
617-
try {
618-
Method method = JavaModel.class.getMethod("flushExternalFileCache", new Class[] { Void.class });
619-
if (method != null) {
620-
method.invoke(JavaModel.class, new Object[0]);
621-
}
622-
} catch (Throwable e) {
623-
e.printStackTrace();
624-
}
625-
//JavaModel.flushExternalFileCache();
616+
JavaModel.flushExternalFileCache();
626617
builtProjects = new ArrayList();
627618
}
628619
builtProjects.add(projectName);
@@ -677,7 +668,7 @@ private boolean isWorthBuilding() throws CoreException {
677668
// Abort build only if there are classpath errors
678669
if (isClasspathBroken(this.javaProject.getRawClasspath(), this.currentProject)) {
679670
if (DEBUG)
680-
System.out.println("JavaBuilder: Aborted build because project has classpath errors (incomplete or involved in cycle)"); //$NON-NLS-1$
671+
System.out.println("Aborted build because project has classpath errors (incomplete or involved in cycle)"); //$NON-NLS-1$
681672

682673
removeProblemsAndTasksFor(this.currentProject); // remove all compilation problems
683674

@@ -707,18 +698,18 @@ private boolean isWorthBuilding() throws CoreException {
707698
JavaProject prereq = (JavaProject) JavaCore.create(p);
708699
if (prereq.hasCycleMarker() && JavaCore.WARNING.equals(this.javaProject.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true))) {
709700
if (DEBUG)
710-
System.out.println("JavaBuilder: Continued to build even though prereq project " + p.getName() //$NON-NLS-1$
701+
System.out.println("Continued to build even though prereq project " + p.getName() //$NON-NLS-1$
711702
+ " was not built since its part of a cycle"); //$NON-NLS-1$
712703
continue;
713704
}
714705
if (!hasJavaBuilder(p)) {
715706
if (DEBUG)
716-
System.out.println("JavaBuilder: Continued to build even though prereq project " + p.getName() //$NON-NLS-1$
707+
System.out.println("Continued to build even though prereq project " + p.getName() //$NON-NLS-1$
717708
+ " is not built by JavaBuilder"); //$NON-NLS-1$
718709
continue;
719710
}
720711
if (DEBUG)
721-
System.out.println("JavaBuilder: Aborted build because prereq project " + p.getName() //$NON-NLS-1$
712+
System.out.println("Aborted build because prereq project " + p.getName() //$NON-NLS-1$
722713
+ " was not built"); //$NON-NLS-1$
723714

724715
removeProblemsAndTasksFor(this.currentProject); // make this the only problem for this project
@@ -755,7 +746,7 @@ void mustPropagateStructuralChanges() {
755746
IProject project = this.workspaceRoot.getProject(participantPath.segment(0));
756747
if (hasBeenBuilt(project)) {
757748
if (DEBUG)
758-
System.out.println("JavaBuilder: Requesting another build iteration since cycle participant " + project.getName() //$NON-NLS-1$
749+
System.out.println("Requesting another build iteration since cycle participant " + project.getName() //$NON-NLS-1$
759750
+ " has not yet seen some structural changes"); //$NON-NLS-1$
760751
needRebuild();
761752
return;
@@ -765,10 +756,10 @@ void mustPropagateStructuralChanges() {
765756
}
766757

767758
private void printLocations(ClasspathLocation[] newLocations, ClasspathLocation[] oldLocations) {
768-
System.out.println("JavaBuilder: New locations:"); //$NON-NLS-1$
759+
System.out.println("New locations:"); //$NON-NLS-1$
769760
for (int i = 0, length = newLocations.length; i < length; i++)
770761
System.out.println(" " + newLocations[i].debugPathString()); //$NON-NLS-1$
771-
System.out.println("JavaBuilder: Old locations:"); //$NON-NLS-1$
762+
System.out.println("Old locations:"); //$NON-NLS-1$
772763
for (int i = 0, length = oldLocations.length; i < length; i++)
773764
System.out.println(" " + oldLocations[i].debugPathString()); //$NON-NLS-1$
774765
}
@@ -799,7 +790,7 @@ private void recordNewState(State state) {
799790
}
800791

801792
if (DEBUG)
802-
System.out.println("JavaBuilder: Recording new state : " + state); //$NON-NLS-1$
793+
System.out.println("Recording new state : " + state); //$NON-NLS-1$
803794
// state.dump();
804795
JavaModelManager.getJavaModelManager().setLastBuiltState(currentProject, newState);
805796
}

sources/net.sf.j2s.core/src/net/sf/j2s/core/builder/NameEnvironment.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
* Terry Parker <[email protected]>
1111
* - Contribution for https://bugs.eclipse.org/bugs/show_bug.cgi?id=372418
1212
* - Another problem with inner classes referenced from jars or class folders: "The type ... cannot be resolved"
13-
* Stephan Herrmann - Contribution for
14-
* Bug 392727 - Cannot compile project when a java file contains $ in its file name
1513
*******************************************************************************/
1614
package net.sf.j2s.core.builder;
1715

@@ -278,18 +276,17 @@ private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeNam
278276
// let the recompile loop fix up dependents when the secondary type Y has been deleted from X.java
279277
// Only enclosing type names are present in the additional units table, so strip off inner class specifications
280278
// when doing the lookup (https://bugs.eclipse.org/372418).
281-
// Also take care of $ in the name of the class (https://bugs.eclipse.org/377401)
282-
// and prefer name with '$' if unit exists rather than failing to search for nested class (https://bugs.eclipse.org/392727)
283-
SourceFile unit = (SourceFile) this.additionalUnits.get(qualifiedTypeName); // doesn't have file extension
284-
if (unit != null)
285-
return new NameEnvironmentAnswer(unit, null /*no access restriction*/);
279+
// Also take care of $ in the name of the class (https://bugs.eclipse.org/Bug 377401)
286280
int index = qualifiedTypeName.indexOf('$');
287281
if (index > 0) {
288282
String enclosingTypeName = qualifiedTypeName.substring(0, index);
289-
unit = (SourceFile) this.additionalUnits.get(enclosingTypeName); // doesn't have file extension
283+
SourceFile unit = (SourceFile) this.additionalUnits.get(enclosingTypeName); // doesn't have file extension
290284
if (unit != null)
291285
return new NameEnvironmentAnswer(unit, null /*no access restriction*/);
292286
}
287+
SourceFile unit = (SourceFile) this.additionalUnits.get(qualifiedTypeName); // doesn't have file extension
288+
if (unit != null)
289+
return new NameEnvironmentAnswer(unit, null /*no access restriction*/);
293290
}
294291

295292
String qBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class;

0 commit comments

Comments
 (0)