Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2b1b60b

Browse files
committed
Make net.sf.j2s.core compatiable with latest Eclipse (4.4/4.5)
1 parente5b535e commit2b1b60b

13 files changed

+176
-87
lines changed

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

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000,2008 IBM Corporation and others.
2+
* Copyright (c) 2000,2013 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,6 +25,7 @@
2525
importorg.eclipse.jdt.internal.compiler.util.SimpleSet;
2626
importorg.eclipse.jdt.internal.compiler.util.SuffixConstants;
2727
importorg.eclipse.jdt.internal.core.JavaModelManager;
28+
importorg.eclipse.jdt.internal.core.PackageFragment;
2829
importorg.eclipse.jdt.internal.core.util.Messages;
2930
importorg.eclipse.jdt.internal.core.util.Util;
3031

@@ -56,7 +57,8 @@ public abstract class AbstractImageBuilder implements ICompilerRequestor, ICompi
5657
protectedbooleankeepStoringProblemMarkers;
5758
protectedSimpleSetfilesWithAnnotations =null;
5859

59-
publicstaticintMAX_AT_ONCE =2000;// best compromise between space used and speed
60+
//2000 is best compromise between space used and speed
61+
publicstaticintMAX_AT_ONCE =Integer.getInteger(JavaModelManager.MAX_COMPILED_UNITS_AT_ONCE,2000).intValue();
6062
publicfinalstaticString[]JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES = {
6163
IMarker.MESSAGE,
6264
IMarker.SEVERITY,
@@ -292,7 +294,7 @@ protected void compile(SourceFile[] units) {
292294
}
293295

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

674-
IResourceresource =sourceFile.resource;
675676
HashSetmanagedMarkerTypes =JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes();
676-
for (inti =0,l =problems.length;i <l;i++) {
677+
problems:for (inti =0,l =problems.length;i <l;i++) {
677678
CategorizedProblemproblem =problems[i];
678679
intid =problem.getID();
679-
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+
IResourceresource =sourceFile.resource;
683+
680684
// handle missing classfile situation
681685
if (id ==IProblem.IsClassPathCorrect) {
682686
StringmissingClassfileName =problem.getArguments()[0];
@@ -706,6 +710,38 @@ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] prob
706710
booleanmanagedProblem =false;
707711
if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType)
708712
|| (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+
intpkgEnd =CharOperation.lastIndexOf('/',fileName);
718+
if (pkgEnd == -1)
719+
pkgEnd =CharOperation.lastIndexOf(File.separatorChar,fileName);
720+
PackageFragmentpkg =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+
intlen =existingMarkers.length;
728+
for (intj=0;j <len;j++) {
729+
if (((Integer)existingMarkers[j].getAttribute(IJavaModelMarker.ID)).intValue() ==IProblem.MissingNonNullByDefaultAnnotationOnPackage) {
730+
continueproblems;// marker already present
731+
}
732+
}
733+
}catch (CoreExceptione) {
734+
// marker retrieval failed, cannot do much
735+
if (JavaModelManager.VERBOSE) {
736+
e.printStackTrace();
737+
}
738+
}
739+
IResourcetempRes =pkg.resource();
740+
if (tempRes !=null) {
741+
resource =tempRes;
742+
}
743+
}
744+
}
709745
IMarkermarker =resource.createMarker(markerType);
710746

711747
String[]attributeNames =JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES;
@@ -729,8 +765,7 @@ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] prob
729765
allValues[index++] =problem.isError() ?S_ERROR :S_WARNING;// severity
730766
allValues[index++] =newInteger(id);// ID
731767
allValues[index++] =newInteger(problem.getSourceStart());// start
732-
intend =problem.getSourceEnd();
733-
allValues[index++] =newInteger(end >0 ?end +1 :end);// end
768+
allValues[index++] =newInteger(problem.getSourceEnd() +1);// end
734769
allValues[index++] =newInteger(problem.getSourceLineNumber());// line
735770
allValues[index++] =Util.getProblemArgumentsForMarker(problem.getArguments());// arguments
736771
allValues[index++] =newInteger(problem.getCategoryID());// category ID
@@ -835,7 +870,7 @@ protected void writeClassFileContents(ClassFile classFile, IFile file, String qu
835870
if (JavaBuilder.DEBUG)
836871
System.out.println("Writing changed class file " +file.getName());//$NON-NLS-1$
837872
if (!file.isDerived())
838-
file.setDerived(true);
873+
file.setDerived(true,null);
839874
file.setContents(input,true,false,null);
840875
}else {
841876
// Default implementation just writes out the bytes for the new class file...

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000,2009 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
@@ -16,7 +16,7 @@ public class AdditionalTypeCollection extends ReferenceCollection {
1616

1717
protectedAdditionalTypeCollection(char[][]definedTypeNames,char[][][]qualifiedReferences,char[][]simpleNameReferences,char[][]rootReferences) {
1818
super(qualifiedReferences,simpleNameReferences,rootReferences);
19-
this.definedTypeNames =definedTypeNames;// do not bother interning member type names (ie. 'A$M')
19+
this.definedTypeNames =definedTypeNames;// do not bother interning member type names (i.e. 'A$M')
2020
}
2121
}
2222

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000,2008 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
@@ -105,7 +105,7 @@ protected void cleanOutputFolders(boolean copyBack) throws CoreException {
105105
member.accept(
106106
newIResourceVisitor() {
107107
publicbooleanvisit(IResourceresource)throwsCoreException {
108-
resource.setDerived(true);
108+
resource.setDerived(true,null);
109109
returnresource.getType() !=IResource.FILE;
110110
}
111111
}
@@ -137,7 +137,7 @@ public boolean visit(IResourceProxy proxy) throws CoreException {
137137
if (Util.isExcluded(resource.getFullPath(),inclusionPatterns,exclusionPatterns,false))
138138
returnfalse;
139139
if (!resource.isDerived())
140-
resource.setDerived(true);
140+
resource.setDerived(true,null);
141141
resource.delete(IResource.FORCE,null);
142142
}
143143
returnfalse;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000,2009 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,6 +15,7 @@
1515
importorg.eclipse.core.runtime.*;
1616

1717
importorg.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
18+
importorg.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
1819
importorg.eclipse.jdt.internal.compiler.env.AccessRuleSet;
1920
importorg.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
2021
importorg.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
@@ -151,7 +152,8 @@ public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPa
151152
StringfileNameWithoutExtension =qualifiedBinaryFileName.substring(0,qualifiedBinaryFileName.length() -SuffixConstants.SUFFIX_CLASS.length);
152153
returnnewNameEnvironmentAnswer(reader,this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()));
153154
}
154-
}catch (Exceptione) {// treat as if class file is missing
155+
}catch (IOExceptione) {// treat as if class file is missing
156+
}catch (ClassFormatExceptione) {// treat as if class file is missing
155157
}
156158
returnnull;
157159
}

‎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,2006 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
@@ -18,8 +18,8 @@
1818

1919
publicabstractclassClasspathLocation {
2020

21-
staticClasspathLocationforSourceFolder(IContainersourceFolder,IContaineroutputFolder,char[][]inclusionPatterns,char[][]exclusionPatterns) {
22-
returnnewClasspathMultiDirectory(sourceFolder,outputFolder,inclusionPatterns,exclusionPatterns);
21+
staticClasspathLocationforSourceFolder(IContainersourceFolder,IContaineroutputFolder,char[][]inclusionPatterns,char[][]exclusionPatterns,booleanignoreOptionalProblems) {
22+
returnnewClasspathMultiDirectory(sourceFolder,outputFolder,inclusionPatterns,exclusionPatterns,ignoreOptionalProblems);
2323
}
2424

2525
publicstaticClasspathLocationforBinaryFolder(IContainerbinaryFolder,booleanisOutputFolder,AccessRuleSetaccessRuleSet) {

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

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

18-
classClasspathMultiDirectoryextendsClasspathDirectory {
18+
publicclassClasspathMultiDirectoryextendsClasspathDirectory {
1919

2020
IContainersourceFolder;
2121
char[][]inclusionPatterns;// used by builders when walking source folders
2222
char[][]exclusionPatterns;// used by builders when walking source folders
2323
booleanhasIndependentOutputFolder;// if output folder is not equal to any of the source folders
24+
publicbooleanignoreOptionalProblems;
2425

25-
ClasspathMultiDirectory(IContainersourceFolder,IContainerbinaryFolder,char[][]inclusionPatterns,char[][]exclusionPatterns) {
26+
ClasspathMultiDirectory(IContainersourceFolder,IContainerbinaryFolder,char[][]inclusionPatterns,char[][]exclusionPatterns,booleanignoreOptionalProblems) {
2627
super(binaryFolder,true,null);
2728

2829
this.sourceFolder =sourceFolder;
2930
this.inclusionPatterns =inclusionPatterns;
3031
this.exclusionPatterns =exclusionPatterns;
3132
this.hasIndependentOutputFolder =false;
33+
this.ignoreOptionalProblems =ignoreOptionalProblems;
3234

3335
// handle the case when a state rebuilds a source folder
3436
if (this.inclusionPatterns !=null &&this.inclusionPatterns.length ==0)
@@ -42,7 +44,8 @@ public boolean equals(Object o) {
4244
if (!(oinstanceofClasspathMultiDirectory))returnfalse;
4345

4446
ClasspathMultiDirectorymd = (ClasspathMultiDirectory)o;
45-
returnthis.sourceFolder.equals(md.sourceFolder) &&this.binaryFolder.equals(md.binaryFolder)
47+
returnthis.ignoreOptionalProblems ==md.ignoreOptionalProblems
48+
&&this.sourceFolder.equals(md.sourceFolder) &&this.binaryFolder.equals(md.binaryFolder)
4649
&&CharOperation.equals(this.inclusionPatterns,md.inclusionPatterns)
4750
&&CharOperation.equals(this.exclusionPatterns,md.exclusionPatterns);
4851
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000,2009 IBM Corporation and others.
2+
* Copyright (c) 2000,2013 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
@@ -229,8 +229,16 @@ protected void addDependentsOf(IPath path, boolean isStructuralChange, StringSet
229229
if (isStructuralChange) {
230230
Stringlast =path.lastSegment();
231231
if (last.length() ==TypeConstants.PACKAGE_INFO_NAME.length)
232-
if (CharOperation.equals(last.toCharArray(),TypeConstants.PACKAGE_INFO_NAME))
232+
if (CharOperation.equals(last.toCharArray(),TypeConstants.PACKAGE_INFO_NAME)) {
233233
path =path.removeLastSegments(1);// the package-info file has changed so blame the package itself
234+
/* https://bugs.eclipse.org/bugs/show_bug.cgi?id=323785, in the case of default package,
235+
there is no need to blame the package itself as there can be no annotations or documentation
236+
comment tags in the package-info file that can influence the rest of the package. Just bail out
237+
so we don't touch null objects below.
238+
*/
239+
if (path.isEmpty())
240+
return;
241+
}
234242
}
235243

236244
if (isStructuralChange && !this.hasStructuralChanges) {
@@ -551,7 +559,8 @@ protected boolean findSourceFiles(IResourceDelta sourceDelta, ClasspathMultiDire
551559
for (inti =0,l =this.sourceLocations.length;i <l;i++) {
552560
if (this.sourceLocations[i].sourceFolder.getFolder(removedPackagePath).exists()) {
553561
// only a package fragment was removed, same as removing multiple source files
554-
createFolder(removedPackagePath,md.binaryFolder);// ensure package exists in the output folder
562+
if (md.hasIndependentOutputFolder)
563+
createFolder(removedPackagePath,md.binaryFolder);// ensure package exists in the output folder
555564
IResourceDelta[]removedChildren =sourceDelta.getAffectedChildren();
556565
for (intj =0,m =removedChildren.length;j <m;j++)
557566
if (!findSourceFiles(removedChildren[j],md,segmentCount))
@@ -788,6 +797,10 @@ protected void resetCollections() {
788797
}
789798

790799
protectedvoidupdateProblemsFor(SourceFilesourceFile,CompilationResultresult)throwsCoreException {
800+
if (CharOperation.equals(sourceFile.getMainTypeName(),TypeConstants.PACKAGE_INFO_NAME)) {
801+
IResourcepkgResource =sourceFile.resource.getParent();
802+
pkgResource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER,false,IResource.DEPTH_ZERO);
803+
}
791804
IMarker[]markers =JavaBuilder.getProblemsFor(sourceFile.resource);
792805
CategorizedProblem[]problems =result.getProblems();
793806
if (problems ==null &&markers.length ==0)return;
@@ -818,7 +831,7 @@ protected void writeClassFileContents(ClassFile classfile, IFile file, String qu
818831
if (JavaBuilder.DEBUG)
819832
System.out.println("Writing changed class file " +file.getName());//$NON-NLS-1$
820833
if (!file.isDerived())
821-
file.setDerived(true);
834+
file.setDerived(true,null);
822835
file.setContents(newByteArrayInputStream(bytes),true,false,null);
823836
}elseif (JavaBuilder.DEBUG) {
824837
System.out.println("Skipped over unchanged class file " +file.getName());//$NON-NLS-1$

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp