State newState = new State(); newState.javaProjectName = in.readUTF(); if (!project.getName().equals(newState.javaProjectName)) { if ((folderName = in.readUTF()).length() > 0) outputFolder = project.getFolder(folderName); ClasspathMultiDirectory md = (ClasspathMultiDirectory) ClasspathLocation.forSourceFolder(sourceFolder, outputFolder, readNames(in), readNames(in), in.readBoolean()); if (in.readBoolean()) md.hasIndependentOutputFolder = true; : (IContainer) root.getFolder(path); newState.binaryLocations[i] = ClasspathLocation.forBinaryFolder(outputFolder, in.readBoolean(), readRestriction(in), new Path(in.readUTF()), in.readBoolean()); break; case EXTERNAL_JAR : String jarPath = in.readUTF(); newState.binaryLocations[i] = ClasspathLocation.forLibrary(jarPath, in.readLong(), readRestriction(in), new Path(in.readUTF()), Util.isJrt(jarPath) ? false : in.readBoolean()); break; case INTERNAL_JAR : newState.binaryLocations[i] = ClasspathLocation.forLibrary(root.getFile(new Path(in.readUTF())), readRestriction(in), new Path(in.readUTF()), in.readBoolean()); newState.recordLocatorForType(in.readUTF(), internedTypeLocators[in.readInt()]); char[][] internedRootNames = ReferenceCollection.internSimpleNames(readNames(in), false); char[][] internedSimpleNames = ReferenceCollection.internSimpleNames(readNames(in), false); char[][][] internedQualifiedNames = new char[length = in.readInt()][][]; for (int i = 0; i < length; i++) {
void tagAsStructurallyChanged() { this.previousStructuralBuildTime = this.lastStructuralBuildTime; this.structurallyChangedTypes = new StringSet(7); this.lastStructuralBuildTime = computeStructuralBuildTime(this.previousStructuralBuildTime); }
protected IncrementalImageBuilder(JavaBuilder javaBuilder) { this(javaBuilder, null); this.newState.copyFrom(javaBuilder.lastState); }
if (this.sourceLocations.length > 1 && this.newState.isKnownPackage(addedPackagePath.toString())) { if (JavaBuilder.DEBUG) System.out.println("Skipped dependents of added package " + addedPackagePath); //$NON-NLS-1$ System.out.println("Found removed package " + removedPackagePath); //$NON-NLS-1$ addDependentsOf(removedPackagePath, true); this.newState.removePackage(sourceDelta); this.sourceFiles.add(new SourceFile((IFile) resource, md, true)); String typeName = typePath.toString(); if (!this.newState.isDuplicateLocator(typeName, typeLocator)) { // adding dependents results in 2 duplicate errors if (JavaBuilder.DEBUG) System.out.println("Found added source file " + typeName); //$NON-NLS-1$ char[][] definedTypeNames = this.newState.getDefinedTypeNamesFor(typeLocator); if (definedTypeNames == null) { // defined a single type matching typePath removeClassFile(typePath, md.binaryFolder); this.newState.removeLocator(typeLocator); return true; case IResourceDelta.CHANGED : if (this.newState.isKnownType(typePath.toString())) { if (JavaBuilder.DEBUG) System.out.println("MUST DO FULL BUILD. Found change to class file " + typePath); //$NON-NLS-1$
addDependentsOf(typePath, true); // add dependents of the source file since its now deleted this.previousSourceFiles = null; // existing source files did not see it as deleted since they were compiled before it was char[][] definedTypeNames = this.newState.getDefinedTypeNamesFor(typeLocator); if (definedTypeNames == null) { // defined a single type matching typePath removeClassFile(typePath, sourceFile.sourceLocation.binaryFolder); this.newState.removeLocator(typeLocator);
if (this.newState.isDuplicateLocator(qualifiedTypeName, typeLocator)) continue; } else { String qualifiedTypeName = new String(classFile.fileName()); // the qualified type name "p1/p2/A" if (this.newState.isDuplicateLocator(qualifiedTypeName, typeLocator)) { if (duplicateTypeNames == null) duplicateTypeNames = new ArrayList(); continue; this.newState.recordLocatorForType(qualifiedTypeName, typeLocator); if (result.checkSecondaryTypes && !qualifiedTypeName.equals(compilationUnit.initialTypeName)) acceptSecondaryType(classFile);
protected void compile(SourceFile[] units, SourceFile[] additionalUnits, boolean compilingFirstGroup) { if (compilingFirstGroup && additionalUnits != null) { // add any source file from additionalUnits to units if it defines secondary types // otherwise its possible during testing with MAX_AT_ONCE == 1 that a secondary type // can cause an infinite loop as it alternates between not found and defined, see bug 146324 ArrayList extras = null; for (int i = 0, l = additionalUnits.length; i < l; i++) { SourceFile unit = additionalUnits[i]; if (unit != null && this.newState.getDefinedTypeNamesFor(unit.typeLocator()) != null) { if (JavaBuilder.DEBUG) System.out.println("About to compile file with secondary types "+ unit.typeLocator()); //$NON-NLS-1$ if (extras == null) extras = new ArrayList(3); extras.add(unit); } } if (extras != null) { int oldLength = units.length; int toAdd = extras.size(); System.arraycopy(units, 0, units = new SourceFile[oldLength + toAdd], 0, oldLength); for (int i = 0; i < toAdd; i++) units[oldLength++] = (SourceFile) extras.get(i); } } super.compile(units, additionalUnits, compilingFirstGroup); }
internedSimpleNames = null; Object[] keyTable = state.getReferences().keyTable; Object[] valueTable = state.getReferences().valueTable; IFile file = null; String typeLocator = null;
protected AbstractImageBuilder(JavaBuilder javaBuilder, boolean buildStarting, State newState, CompilationGroup compilationGroup) { // local copies this.javaBuilder = javaBuilder; this.compilationGroup = compilationGroup; this.nameEnvironment = compilationGroup == CompilationGroup.TEST ? javaBuilder.testNameEnvironment : javaBuilder.nameEnvironment; this.sourceLocations = this.nameEnvironment.sourceLocations; this.notifier = javaBuilder.notifier; this.keepStoringProblemMarkers = true; // may get disabled when missing classfiles are encountered if (buildStarting) { this.newState = newState == null ? new State(javaBuilder) : newState; this.compiler = newCompiler(); this.workQueue = new WorkQueue(); this.problemSourceFiles = new LinkedHashSet(3); if (this.javaBuilder.participants != null) { for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++) { if (this.javaBuilder.participants[i].isAnnotationProcessor()) { // initialize this set so the builder knows to gather CUs that define Annotation types // each Annotation processor participant is then asked to process these files AFTER // the compile loop. The normal dependency loop will then recompile all affected types this.filesWithAnnotations = new HashSet<>(1); break; } } } } }
protected boolean checkForClassFileChanges(IResourceDelta binaryDelta, ClasspathMultiDirectory md, int segmentCount) throws CoreException { IResource resource = binaryDelta.getResource(); // remember that if inclusion & exclusion patterns change then a full build is done boolean isExcluded = (md.exclusionPatterns != null || md.inclusionPatterns != null) && Util.isExcluded(resource, md.inclusionPatterns, md.exclusionPatterns); switch(resource.getType()) { case IResource.FOLDER : if (isExcluded && md.inclusionPatterns == null) return true; // no need to go further with this delta since its children cannot be included IResourceDelta[] children = binaryDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) if (!checkForClassFileChanges(children[i], md, segmentCount)) return false; return true; case IResource.FILE : if (!isExcluded && org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resource.getName())) { // perform full build if a managed class file has been changed IPath typePath = resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension(); if (this.newState.isKnownType(typePath.toString())) { if (JavaBuilder.DEBUG) System.out.println("MUST DO FULL BUILD. Found change to class file " + typePath); //$NON-NLS-1$ return false; } return true; } } return true; }
structurallyChangedTypes = this.newState.getStructurallyChangedTypes(this.javaBuilder.getLastState(prereqProject)); for (int j = 0, m = children.length; j < m; j++) findAffectedSourceFiles(children[j], segmentCount, structurallyChangedTypes);
if (binaryDelta.getKind() == IResourceDelta.ADDED) { if (!this.newState.isKnownPackage(packageName)) { if (JavaBuilder.DEBUG) System.out.println("Found added package " + packageName); //$NON-NLS-1$
o--; continue; } else if (this.lastState.isSourceFolderEmpty(oldSourceLocations[o].sourceFolder)) { n--; continue; if (this.lastState.isSourceFolderEmpty(oldSourceLocations[o].sourceFolder)) { o++; continue;
if (this.sourceLocations.length > 1 && this.newState.isKnownPackage(addedPackagePath.toString())) { if (JavaBuilder.DEBUG) System.out.println("Skipped dependents of added package " + addedPackagePath); //$NON-NLS-1$ System.out.println("Found removed package " + removedPackagePath); //$NON-NLS-1$ addDependentsOf(removedPackagePath, true); this.newState.removePackage(sourceDelta); this.sourceFiles.add(new SourceFile((IFile) resource, md, true)); String typeName = typePath.toString(); if (!this.newState.isDuplicateLocator(typeName, typeLocator)) { // adding dependents results in 2 duplicate errors if (JavaBuilder.DEBUG) System.out.println("Found added source file " + typeName); //$NON-NLS-1$ char[][] definedTypeNames = this.newState.getDefinedTypeNamesFor(typeLocator); if (definedTypeNames == null) { // defined a single type matching typePath removeClassFile(typePath, md.binaryFolder); this.newState.removeLocator(typeLocator); return true; case IResourceDelta.CHANGED : if (this.newState.isKnownType(typePath.toString())) { if (JavaBuilder.DEBUG) System.out.println("MUST DO FULL BUILD. Found change to class file " + typePath); //$NON-NLS-1$
addDependentsOf(typePath, true); // add dependents of the source file since its now deleted this.previousSourceFiles = null; // existing source files did not see it as deleted since they were compiled before it was char[][] definedTypeNames = this.newState.getDefinedTypeNamesFor(typeLocator); if (definedTypeNames == null) { // defined a single type matching typePath removeClassFile(typePath, sourceFile.sourceLocation.binaryFolder); this.newState.removeLocator(typeLocator);
if (this.newState.isDuplicateLocator(qualifiedTypeName, typeLocator)) continue; } else { String qualifiedTypeName = new String(classFile.fileName()); // the qualified type name "p1/p2/A" if (this.newState.isDuplicateLocator(qualifiedTypeName, typeLocator)) { if (duplicateTypeNames == null) duplicateTypeNames = new ArrayList(); continue; this.newState.recordLocatorForType(qualifiedTypeName, typeLocator); if (result.checkSecondaryTypes && !qualifiedTypeName.equals(compilationUnit.initialTypeName)) acceptSecondaryType(classFile);
protected void compile(SourceFile[] units, SourceFile[] additionalUnits, boolean compilingFirstGroup) { if (compilingFirstGroup && additionalUnits != null) { // add any source file from additionalUnits to units if it defines secondary types // otherwise its possible during testing with MAX_AT_ONCE == 1 that a secondary type // can cause an infinite loop as it alternates between not found and defined, see bug 146324 ArrayList extras = null; for (int i = 0, l = additionalUnits.length; i < l; i++) { SourceFile unit = additionalUnits[i]; if (unit != null && this.newState.getDefinedTypeNamesFor(unit.typeLocator()) != null) { if (JavaBuilder.DEBUG) System.out.println("About to compile file with secondary types "+ unit.typeLocator()); //$NON-NLS-1$ if (extras == null) extras = new ArrayList(3); extras.add(unit); } } if (extras != null) { int oldLength = units.length; int toAdd = extras.size(); System.arraycopy(units, 0, units = new SourceFile[oldLength + toAdd], 0, oldLength); for (int i = 0; i < toAdd; i++) units[oldLength++] = (SourceFile) extras.get(i); } } super.compile(units, additionalUnits, compilingFirstGroup); }
State projectState = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(javaProject.getProject(), null); if (projectState != null) { Object[] values = projectState.getReferences().valueTable; int vLength = values.length; for (int j=0; j<vLength; j++) {
protected AbstractImageBuilder(JavaBuilder javaBuilder, boolean buildStarting, State newState) { // local copies this.javaBuilder = javaBuilder; this.nameEnvironment = javaBuilder.nameEnvironment; this.sourceLocations = this.nameEnvironment.sourceLocations; this.notifier = javaBuilder.notifier; this.keepStoringProblemMarkers = true; // may get disabled when missing classfiles are encountered if (buildStarting) { this.newState = newState == null ? new State(javaBuilder) : newState; this.compiler = newCompiler(); this.workQueue = new WorkQueue(); this.problemSourceFiles = new ArrayList(3); if (this.javaBuilder.participants != null) { for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++) { if (this.javaBuilder.participants[i].isAnnotationProcessor()) { // initialize this set so the builder knows to gather CUs that define Annotation types // each Annotation processor participant is then asked to process these files AFTER // the compile loop. The normal dependency loop will then recompile all affected types this.filesWithAnnotations = new SimpleSet(1); break; } } } } }
protected boolean checkForClassFileChanges(IResourceDelta binaryDelta, ClasspathMultiDirectory md, int segmentCount) throws CoreException { IResource resource = binaryDelta.getResource(); // remember that if inclusion & exclusion patterns change then a full build is done boolean isExcluded = (md.exclusionPatterns != null || md.inclusionPatterns != null) && Util.isExcluded(resource, md.inclusionPatterns, md.exclusionPatterns); switch(resource.getType()) { case IResource.FOLDER : if (isExcluded && md.inclusionPatterns == null) return true; // no need to go further with this delta since its children cannot be included IResourceDelta[] children = binaryDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) if (!checkForClassFileChanges(children[i], md, segmentCount)) return false; return true; case IResource.FILE : if (!isExcluded && org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resource.getName())) { // perform full build if a managed class file has been changed IPath typePath = resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension(); if (this.newState.isKnownType(typePath.toString())) { if (JavaBuilder.DEBUG) System.out.println("MUST DO FULL BUILD. Found change to class file " + typePath); //$NON-NLS-1$ return false; } return true; } } return true; }