Skip to content

Commit abe3d79

Browse files
committed
Doc: javadoc package 'net.sf.j2s.core.builder'; comment changes in JavaBuilder
also: - extract conversion code between "Eclipse" and "Java2Script" builder States into separate methods 'toEclipseState' and 'toJava2ScriptState'.
1 parent 089ad28 commit abe3d79

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ private void buildAll() {
252252
if (DEBUG && this.lastState != null)
253253
System.out.println("JavaBuilder: Clearing last state : " + this.lastState); //$NON-NLS-1$
254254
clearLastState();
255+
// j2sChange: Instead of BatchImageBuilder use Java2ScriptBatchImageBuilder
255256
BatchImageBuilder imageBuilder = new Java2ScriptBatchImageBuilder(this, true);
256257
imageBuilder.build();
257258
recordNewState(imageBuilder.newState);
@@ -263,6 +264,7 @@ private void buildDeltas(SimpleLookupTable deltas) {
263264
if (DEBUG && this.lastState != null)
264265
System.out.println("JavaBuilder: Clearing last state : " + this.lastState); //$NON-NLS-1$
265266
clearLastState(); // clear the previously built state so if the build fails, a full build will occur next time
267+
// j2sChange: Instead of IncrementalImageBuilder use Java2ScriptIncrementalImageBuilder.
266268
IncrementalImageBuilder imageBuilder = new Java2ScriptIncrementalImageBuilder(this);
267269
if (imageBuilder.build(deltas)) {
268270
recordNewState(imageBuilder.newState);
@@ -419,7 +421,18 @@ private SimpleLookupTable findDeltas() {
419421
}
420422

421423
public State getLastState(IProject project) {
424+
// j2sChange: We need to convert the "Eclipse" State to the "Java2Script" State.
422425
org.eclipse.jdt.internal.core.builder.State lastBuiltState = (org.eclipse.jdt.internal.core.builder.State) JavaModelManager.getJavaModelManager().getLastBuiltState(project, this.notifier.monitor);
426+
return toJava2ScriptState(project, lastBuiltState);
427+
}
428+
429+
// j2sChange: convert an "Eclipse" State to a "Java2Script" State.
430+
private State toJava2ScriptState(IProject project, org.eclipse.jdt.internal.core.builder.State lastBuiltState) {
431+
// We use 'instance to bytes' serialization and 'bytes to instance' deserialization
432+
// to do the conversions.
433+
//
434+
// (Note: casting is not an option here, as both State classes are independent.).
435+
423436
if (lastBuiltState == null) {
424437
return null;
425438
}
@@ -785,6 +798,20 @@ private void recordNewState(State state) {
785798
if (prereqProject != null && prereqProject != this.currentProject)
786799
state.recordStructuralDependency(prereqProject, getLastState(prereqProject));
787800
}
801+
if (DEBUG)
802+
System.out.println("JavaBuilder: Recording new state : " + state); //$NON-NLS-1$
803+
// state.dump();
804+
805+
// j2sChange: We need to convert the "Java2Script" State to the "Eclipse" State.
806+
JavaModelManager.getJavaModelManager().setLastBuiltState(this.currentProject, toEclipseState(state));
807+
}
808+
809+
// j2sChange: convert a "Java2Script" State to an "Eclipse" State.
810+
private org.eclipse.jdt.internal.core.builder.State toEclipseState(State state) {
811+
// We use 'instance to bytes' serialization and 'bytes to instance' deserialization
812+
// to do the conversions.
813+
//
814+
// (Note: casting is not an option here, as both State classes are independent.).
788815

789816
ByteArrayOutputStream baos = new ByteArrayOutputStream();
790817
DataOutputStream out = new DataOutputStream(baos);
@@ -802,11 +829,7 @@ private void recordNewState(State state) {
802829
} catch (IOException e) {
803830
e.printStackTrace();
804831
}
805-
806-
if (DEBUG)
807-
System.out.println("JavaBuilder: Recording new state : " + state); //$NON-NLS-1$
808-
// state.dump();
809-
JavaModelManager.getJavaModelManager().setLastBuiltState(this.currentProject, newState);
832+
return newState;
810833
}
811834

812835
/**
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 java2script.org 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+
* Udo Borkowski - initial version, based on an email memo by Zhou Renjian
10+
*
11+
******************************************************************************/
12+
13+
14+
/**
15+
Generate *.js files while compiling Java sources to *.class files.
16+
17+
<p>This package is a modified copy of the Eclipse package
18+
'<code>org.eclipse.jdt.internal.core.builder</code>' from
19+
'<code>org.eclipse.jdt.core/model</code>'
20+
(<a href="git://git.eclipse.org/gitroot/jdt/eclipse.jdt.core.git">Git</a>).
21+
22+
<p>The major changes (beside the new package name
23+
<code>net.sf.j2s.core.builder</code>) are in the class {@link JavaBuilder}.
24+
The changes mainly reference several new, Java2Script-specific classes, like
25+
{@link Java2ScriptBatchImageBuilder}, or {@link Java2ScriptIncrementalImageBuilder}.
26+
The changes in JavaBuilder are marked with '<code>// j2sChange: ...</code>' comments.
27+
28+
<p>Also notice the new <code>*Proxy</code> classes, like
29+
{@link ClasspathDirectoryProxy} or {@link CompilationParticipantResultProxy}.
30+
These <code>*Proxy</code> classes keep the original JDT classes unchanged as
31+
much as possible and expose necessary inner accesses to the Java2Script builder.
32+
33+
<p><b>Historical Note</b>
34+
35+
<p>In earlier versions of Java2Script the original JDT Core plugin was modified
36+
to add the extension point. Therefore it was necessary to re-deploy the Eclipse
37+
JDT Core plugin jars and restart Eclipse after installation. That approach
38+
caused a lot of inconveniences and was drop.
39+
*/
40+
package net.sf.j2s.core.builder;
41+

0 commit comments

Comments
 (0)