List of usage examples for org.eclipse.jdt.internal.core.builder AbortIncrementalBuildException AbortIncrementalBuildException
public AbortIncrementalBuildException(String qualifiedTypeName)
From source file:org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.core.builder.AbstractImageBuilder#writeClassFileContents(org.eclipse.jdt.internal.compiler.ClassFile, org.eclipse.core.resources.IFile, java.lang.String, boolean, org.eclipse.jdt.internal.core.builder.SourceFile) *///from w w w . j a va 2 s. co m protected void writeClassFileContents(ClassFile classfile, IFile file, String qualifiedFileName, boolean isTopLevelType, SourceFile compilationUnit) throws CoreException { // Before writing out the class file, compare it to the previous file // If structural changes occurred then add dependent source files byte[] bytes = classfile.getBytes(); if (file.exists()) { if (writeClassFileCheck(file, qualifiedFileName, bytes) || compilationUnit.updateClassFile) { // see 46093 if (JavaBuilder.DEBUG) System.out.println("Writing changed class file " + file.getName());//$NON-NLS-1$ if (!file.isDerived()) file.setDerived(true, null); file.setContents(new ByteArrayInputStream(bytes), true, false, null); } else if (JavaBuilder.DEBUG) { System.out.println("Skipped over unchanged class file " + file.getName());//$NON-NLS-1$ } } else { if (isTopLevelType) addDependentsOf(new Path(qualifiedFileName), true); // new type if (JavaBuilder.DEBUG) System.out.println("Writing new class file " + file.getName());//$NON-NLS-1$ try { file.create(new ByteArrayInputStream(bytes), IResource.FORCE | IResource.DERIVED, null); } catch (CoreException e) { if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { IStatus status = e.getStatus(); if (status instanceof IResourceStatus) { IPath oldFilePath = ((IResourceStatus) status).getPath(); char[] oldTypeName = oldFilePath.removeFileExtension().lastSegment().toCharArray(); char[][] previousTypeNames = this.newState .getDefinedTypeNamesFor(compilationUnit.typeLocator()); boolean fromSameFile = false; if (previousTypeNames == null) { fromSameFile = CharOperation.equals(compilationUnit.getMainTypeName(), oldTypeName); } else { for (int i = 0, l = previousTypeNames.length; i < l; i++) { if (CharOperation.equals(previousTypeNames[i], oldTypeName)) { fromSameFile = true; break; } } } if (fromSameFile) { // file is defined by the same compilationUnit, but won't be deleted until later so do it now IFile collision = file.getParent().getFile(new Path(oldFilePath.lastSegment())); collision.delete(true, false, null); boolean success = false; try { file.create(new ByteArrayInputStream(bytes), IResource.FORCE | IResource.DERIVED, null); success = true; } catch (CoreException ignored) { // ignore the second exception } if (success) return; } } // catch the case that a type has been renamed and collides on disk with an as-yet-to-be-deleted type throw new AbortCompilation(true, new AbortIncrementalBuildException(qualifiedFileName)); } throw e; // rethrow } } }
From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianNameEnvironment.java
License:Open Source License
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName) { if (this.notifier != null) this.notifier.checkCancelWithinCompiler(); if (this.initialTypeNames != null && this.initialTypeNames.includes(qualifiedTypeName)) { if (this.isIncrementalBuild) // catch the case that a type inside a source file has been // renamed but other class files are looking for it throw new AbortCompilation(true, new AbortIncrementalBuildException(qualifiedTypeName)); return null; // looking for a file which we know was provided at the // beginning of the compilation }/*from w w w .j av a2s . c om*/ if (this.additionalUnits != null && this.sourceLocations.length > 0) { // if an additional source file is waiting to be compiled, answer it // BUT not if this is a secondary type search // if we answer X.java & it no longer defines Y then the binary type // looking for Y will think the class path is wrong // let the recompile loop fix up dependents when the secondary type // Y has been deleted from X.java SourceFile unit = (SourceFile) this.additionalUnits.get(qualifiedTypeName); // doesn't have file extension if (unit != null) return new NameEnvironmentAnswer(unit, null /* no access restriction*/); } String qBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class; String binaryFileName = qBinaryFileName; String qPackageName = ""; //$NON-NLS-1$ if (qualifiedTypeName.length() > typeName.length) { int typeNameStart = qBinaryFileName.length() - typeName.length - 6; // size of ".class" qPackageName = qBinaryFileName.substring(0, typeNameStart - 1); binaryFileName = qBinaryFileName.substring(typeNameStart); } NameEnvironmentAnswer suggestedAnswer = null; for (int i = 0, l = this.binaryLocations.length; i < l; i++) { NameEnvironmentAnswer answer = this.binaryLocations[i].findClass(binaryFileName, qPackageName, qBinaryFileName); if (answer != null) { if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer)) suggestedAnswer = answer; } } if (suggestedAnswer != null) return suggestedAnswer; return null; }