Skip to content

Commit 7d10e9b

Browse files
committed
Java2Script compiler for Eclipse 3.7
1 parent 2bc5bba commit 7d10e9b

File tree

9 files changed

+60
-133
lines changed

9 files changed

+60
-133
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: 8 additions & 43 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, 2009 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
@@ -25,7 +25,6 @@
2525
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
2626
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
2727
import org.eclipse.jdt.internal.core.JavaModelManager;
28-
import org.eclipse.jdt.internal.core.PackageFragment;
2928
import org.eclipse.jdt.internal.core.util.Messages;
3029
import org.eclipse.jdt.internal.core.util.Util;
3130

@@ -57,8 +56,7 @@ public abstract class AbstractImageBuilder implements ICompilerRequestor, ICompi
5756
protected boolean keepStoringProblemMarkers;
5857
protected SimpleSet filesWithAnnotations = null;
5958

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();
59+
public static int MAX_AT_ONCE = 2000; // best compromise between space used and speed
6260
public final static String[] JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES = {
6361
IMarker.MESSAGE,
6462
IMarker.SEVERITY,
@@ -294,7 +292,7 @@ protected void compile(SourceFile[] units) {
294292
}
295293

296294
int unitsLength = units.length;
297-
this.compiledAllAtOnce = MAX_AT_ONCE == 0 || unitsLength <= MAX_AT_ONCE;
295+
this.compiledAllAtOnce = unitsLength <= MAX_AT_ONCE;
298296
if (this.compiledAllAtOnce) {
299297
// do them all now
300298
if (JavaBuilder.DEBUG)
@@ -673,14 +671,12 @@ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] prob
673671
// but still try to compile as many source files as possible to help the case when the base libraries are in source
674672
if (!this.keepStoringProblemMarkers) return; // only want the one error recorded on this source file
675673

674+
IResource resource = sourceFile.resource;
676675
HashSet managedMarkerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes();
677-
problems: for (int i = 0, l = problems.length; i < l; i++) {
676+
for (int i = 0, l = problems.length; i < l; i++) {
678677
CategorizedProblem problem = problems[i];
679678
int id = problem.getID();
680-
// we may use a different resource for certain problems such as IProblem.MissingNonNullByDefaultAnnotationOnPackage
681-
// but at the start of the next problem we should reset it to the source file's resource
682-
IResource resource = sourceFile.resource;
683-
679+
684680
// handle missing classfile situation
685681
if (id == IProblem.IsClassPathCorrect) {
686682
String missingClassfileName = problem.getArguments()[0];
@@ -710,38 +706,6 @@ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] prob
710706
boolean managedProblem = false;
711707
if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType)
712708
|| (managedProblem = managedMarkerTypes.contains(markerType))) {
713-
if (id == IProblem.MissingNonNullByDefaultAnnotationOnPackage && !(CharOperation.equals(sourceFile.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME))) {
714-
// for this kind of problem, marker needs to be created on the package instead of on the source file
715-
// see bug 372012
716-
char[] fileName = sourceFile.getFileName();
717-
int pkgEnd = CharOperation.lastIndexOf('/', fileName);
718-
if (pkgEnd == -1)
719-
pkgEnd = CharOperation.lastIndexOf(File.separatorChar, fileName);
720-
PackageFragment pkg = null;
721-
if (pkgEnd != -1)
722-
pkg = (PackageFragment) Util.getPackageFragment(sourceFile.getFileName(), pkgEnd, -1 /*no jar separator for java files*/);
723-
724-
if (pkg != null) {
725-
try {
726-
IMarker[] existingMarkers = pkg.resource().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
727-
int len = existingMarkers.length;
728-
for (int j=0; j < len; j++) {
729-
if (((Integer)existingMarkers[j].getAttribute(IJavaModelMarker.ID)).intValue() == IProblem.MissingNonNullByDefaultAnnotationOnPackage) {
730-
continue problems; // marker already present
731-
}
732-
}
733-
} catch (CoreException e) {
734-
// marker retrieval failed, cannot do much
735-
if (JavaModelManager.VERBOSE) {
736-
e.printStackTrace();
737-
}
738-
}
739-
IResource tempRes = pkg.resource();
740-
if (tempRes != null) {
741-
resource = tempRes;
742-
}
743-
}
744-
}
745709
IMarker marker = resource.createMarker(markerType);
746710

747711
String[] attributeNames = JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES;
@@ -765,7 +729,8 @@ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] prob
765729
allValues[index++] = problem.isError() ? S_ERROR : S_WARNING; // severity
766730
allValues[index++] = new Integer(id); // ID
767731
allValues[index++] = new Integer(problem.getSourceStart()); // start
768-
allValues[index++] = new Integer(problem.getSourceEnd() + 1); // end
732+
int end = problem.getSourceEnd();
733+
allValues[index++] = new Integer(end > 0 ? end + 1 : end); // end
769734
allValues[index++] = new Integer(problem.getSourceLineNumber()); // line
770735
allValues[index++] = Util.getProblemArgumentsForMarker(problem.getArguments()); // arguments
771736
allValues[index++] = new Integer(problem.getCategoryID()); // category ID

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2012 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,8 @@
1818

1919
public abstract class ClasspathLocation {
2020

21-
static ClasspathLocation forSourceFolder(IContainer sourceFolder, IContainer outputFolder, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean ignoreOptionalProblems) {
22-
return new ClasspathMultiDirectory(sourceFolder, outputFolder, inclusionPatterns, exclusionPatterns, ignoreOptionalProblems);
21+
static ClasspathLocation forSourceFolder(IContainer sourceFolder, IContainer outputFolder, char[][] inclusionPatterns, char[][] exclusionPatterns) {
22+
return new ClasspathMultiDirectory(sourceFolder, outputFolder, inclusionPatterns, exclusionPatterns);
2323
}
2424

2525
public static ClasspathLocation forBinaryFolder(IContainer binaryFolder, boolean isOutputFolder, AccessRuleSet accessRuleSet) {

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2012 IBM Corporation and others.
2+
* Copyright (c) 2000, 2010 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
@@ -15,22 +15,20 @@
1515
import org.eclipse.jdt.core.compiler.CharOperation;
1616
import org.eclipse.jdt.internal.core.util.Util;
1717

18-
public class ClasspathMultiDirectory extends ClasspathDirectory {
18+
class ClasspathMultiDirectory extends ClasspathDirectory {
1919

2020
IContainer sourceFolder;
2121
char[][] inclusionPatterns; // used by builders when walking source folders
2222
char[][] exclusionPatterns; // used by builders when walking source folders
2323
boolean hasIndependentOutputFolder; // if output folder is not equal to any of the source folders
24-
public boolean ignoreOptionalProblems;
2524

26-
ClasspathMultiDirectory(IContainer sourceFolder, IContainer binaryFolder, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean ignoreOptionalProblems) {
25+
ClasspathMultiDirectory(IContainer sourceFolder, IContainer binaryFolder, char[][] inclusionPatterns, char[][] exclusionPatterns) {
2726
super(binaryFolder, true, null);
2827

2928
this.sourceFolder = sourceFolder;
3029
this.inclusionPatterns = inclusionPatterns;
3130
this.exclusionPatterns = exclusionPatterns;
3231
this.hasIndependentOutputFolder = false;
33-
this.ignoreOptionalProblems = ignoreOptionalProblems;
3432

3533
// handle the case when a state rebuilds a source folder
3634
if (this.inclusionPatterns != null && this.inclusionPatterns.length == 0)
@@ -44,8 +42,7 @@ public boolean equals(Object o) {
4442
if (!(o instanceof ClasspathMultiDirectory)) return false;
4543

4644
ClasspathMultiDirectory md = (ClasspathMultiDirectory) o;
47-
return this.ignoreOptionalProblems == md.ignoreOptionalProblems
48-
&& this.sourceFolder.equals(md.sourceFolder) && this.binaryFolder.equals(md.binaryFolder)
45+
return this.sourceFolder.equals(md.sourceFolder) && this.binaryFolder.equals(md.binaryFolder)
4946
&& CharOperation.equals(this.inclusionPatterns, md.inclusionPatterns)
5047
&& CharOperation.equals(this.exclusionPatterns, md.exclusionPatterns);
5148
}

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

Lines changed: 2 additions & 7 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, 2010 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
@@ -559,8 +559,7 @@ protected boolean findSourceFiles(IResourceDelta sourceDelta, ClasspathMultiDire
559559
for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
560560
if (this.sourceLocations[i].sourceFolder.getFolder(removedPackagePath).exists()) {
561561
// only a package fragment was removed, same as removing multiple source files
562-
if (md.hasIndependentOutputFolder)
563-
createFolder(removedPackagePath, md.binaryFolder); // ensure package exists in the output folder
562+
createFolder(removedPackagePath, md.binaryFolder); // ensure package exists in the output folder
564563
IResourceDelta[] removedChildren = sourceDelta.getAffectedChildren();
565564
for (int j = 0, m = removedChildren.length; j < m; j++)
566565
if (!findSourceFiles(removedChildren[j], md, segmentCount))
@@ -797,10 +796,6 @@ protected void resetCollections() {
797796
}
798797

799798
protected void updateProblemsFor(SourceFile sourceFile, CompilationResult result) throws CoreException {
800-
if (CharOperation.equals(sourceFile.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME)) {
801-
IResource pkgResource = sourceFile.resource.getParent();
802-
pkgResource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
803-
}
804799
IMarker[] markers = JavaBuilder.getProblemsFor(sourceFile.resource);
805800
CategorizedProblem[] problems = result.getProblems();
806801
if (problems == null && markers.length == 0) return;

0 commit comments

Comments
 (0)