public byte[] getBytes() throws JavaModelException { JavaElement pkg = (JavaElement) getParent(); if (pkg instanceof JarPackageFragment) { JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent(); ZipFile zip = null; try { zip = root.getJar(); String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/'); ZipEntry ze = zip.getEntry(entryName); if (ze != null) { return org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); } throw new JavaModelException( new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this)); } catch (IOException ioe) { throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION); } catch (CoreException e) { if (e instanceof JavaModelException) { throw (JavaModelException) e; } else { throw new JavaModelException(e); } } finally { JavaModelManager.getJavaModelManager().closeZipFile(zip); } } else { IFile file = (IFile) resource(); return Util.getResourceContentsAsByteArray(file); } }
/* This method replaces the version that used to sit in LE. The parameter `annotations' is a flattened sequence of annotations, where each dimension's annotations end with a sentinel null. Leaf type can be an already annotated type. See ArrayBinding.swapUnresolved for further special case handling if incoming leafType is a URB that would resolve to a raw type later. */ public ArrayBinding getArrayType( TypeBinding leafType, int dimensions, AnnotationBinding[] annotations) { ArrayBinding nakedType = null; TypeBinding[] derivedTypes = getDerivedTypes(leafType); for (int i = 0, length = derivedTypes.length; i < length; i++) { TypeBinding derivedType = derivedTypes[i]; if (derivedType == null) break; if (!derivedType.isArrayType() || derivedType.dimensions() != dimensions || derivedType.leafComponentType() != leafType) // $IDENTITY-COMPARISON$ continue; if (Util.effectivelyEqual(derivedType.getTypeAnnotations(), annotations)) return (ArrayBinding) derivedType; if (!derivedType.hasTypeAnnotations()) nakedType = (ArrayBinding) derivedType; } if (nakedType == null) nakedType = super.getArrayType(leafType, dimensions); if (!haveTypeAnnotations(leafType, annotations)) return nakedType; ArrayBinding arrayType = new ArrayBinding(leafType, dimensions, this.environment); arrayType.id = nakedType.id; arrayType.setTypeAnnotations(annotations, this.isAnnotationBasedNullAnalysisEnabled); return (ArrayBinding) cacheDerivedType(leafType, nakedType, arrayType); }
public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Util.hashCode(this.pairs); result = prime * result + CharOperation.hashCode(this.typename); return result; }
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; }
public RawTypeBinding getRawType( ReferenceBinding genericType, ReferenceBinding enclosingType, AnnotationBinding[] annotations) { if (genericType.hasTypeAnnotations()) throw new IllegalStateException(); RawTypeBinding nakedType = null; TypeBinding[] derivedTypes = getDerivedTypes(genericType); for (int i = 0, length = derivedTypes.length; i < length; i++) { TypeBinding derivedType = derivedTypes[i]; if (derivedType == null) break; if (!derivedType.isRawType() || derivedType.actualType() != genericType || derivedType.enclosingType() != enclosingType) // $IDENTITY-COMPARISON$ continue; if (Util.effectivelyEqual(derivedType.getTypeAnnotations(), annotations)) return (RawTypeBinding) derivedType; if (!derivedType.hasTypeAnnotations()) nakedType = (RawTypeBinding) derivedType; } if (nakedType == null) nakedType = super.getRawType(genericType, enclosingType); if (!haveTypeAnnotations(genericType, enclosingType, null, annotations)) return nakedType; RawTypeBinding rawType = new RawTypeBinding(genericType, enclosingType, this.environment); rawType.id = nakedType.id; rawType.setTypeAnnotations(annotations, this.isAnnotationBasedNullAnalysisEnabled); return (RawTypeBinding) cacheDerivedType(genericType, nakedType, rawType); }
public void resolveJavadoc() { if (this.binding == null) return; if (this.javadoc != null) { this.javadoc.resolve(this.scope); return; } if (this.binding.declaringClass != null && !this.binding.declaringClass.isLocalType()) { // Set javadoc visibility int javadocVisibility = this.binding.modifiers & ExtraCompilerModifiers.AccVisibilityMASK; ClassScope classScope = this.scope.classScope(); ProblemReporter reporter = this.scope.problemReporter(); int severity = reporter.computeSeverity(IProblem.JavadocMissing); if (severity != ProblemSeverities.Ignore) { if (classScope != null) { javadocVisibility = Util.computeOuterMostVisibility(classScope.referenceType(), javadocVisibility); } int javadocModifiers = (this.binding.modifiers & ~ExtraCompilerModifiers.AccVisibilityMASK) | javadocVisibility; reporter.javadocMissing(this.sourceStart, this.sourceEnd, severity, javadocModifiers); } } }
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=205046 public void test002() throws Exception { this.runConformTest( new String[] { "X.java", "public class X {\n" + " public static void main(String[] args) {\n" + " System.out.print(\"line 1\");\n" + " myBlock: {\n" + " System.out.print(\"line 2\");\n" + " if (false) {\n" + " break myBlock;\n" + " }\n" + " System.out.print(\"line 3\");\n" + " }\n" + " System.out.print(\"line 4\");\n" + " }" + "}", }, "line 1line 2line 3line 4"); String expectedOutput = " // Method descriptor #15 ([Ljava/lang/String;)V\n" + " // Stack: 2, Locals: 1\n" + " public static void main(java.lang.String[] args);\n" + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + " 3 ldc <String \"line 1\"> [22]\n" + " 5 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + " 11 ldc <String \"line 2\"> [30]\n" + " 13 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + " 16 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + " 19 ldc <String \"line 3\"> [32]\n" + " 21 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + " 24 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + " 27 ldc <String \"line 4\"> [34]\n" + " 29 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + " 32 return\n" + " Line numbers:\n" + " [pc: 0, line: 3]\n" + " [pc: 8, line: 5]\n" + " [pc: 16, line: 9]\n" + " [pc: 24, line: 11]\n" + " [pc: 32, line: 12]\n" + " Local variable table:\n" + " [pc: 0, pc: 33] local: args index: 0 type: java.lang.String[]\n"; File f = new File(OUTPUT_DIR + File.separator + "X.class"); byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); int index = result.indexOf(expectedOutput); if (index == -1 || expectedOutput.length() == 0) { System.out.println(Util.displayString(result, 3)); } if (index == -1) { assertEquals("Wrong contents", expectedOutput, result); } }
public WildcardBinding getWildcard( ReferenceBinding genericType, int rank, TypeBinding bound, TypeBinding[] otherBounds, int boundKind, AnnotationBinding[] annotations) { if (genericType == null) // pseudo wildcard denoting composite bounds for lub computation genericType = ReferenceBinding.LUB_GENERIC; if (genericType.hasTypeAnnotations()) throw new IllegalStateException(); WildcardBinding nakedType = null; TypeBinding[] derivedTypes = getDerivedTypes(genericType); for (int i = 0, length = derivedTypes.length; i < length; i++) { TypeBinding derivedType = derivedTypes[i]; if (derivedType == null) break; if (!derivedType.isWildcard() || derivedType.actualType() != genericType || derivedType.rank() != rank) // $IDENTITY-COMPARISON$ continue; if (derivedType.boundKind() != boundKind || derivedType.bound() != bound || !Util.effectivelyEqual( derivedType.additionalBounds(), otherBounds)) // $IDENTITY-COMPARISON$ continue; if (Util.effectivelyEqual(derivedType.getTypeAnnotations(), annotations)) return (WildcardBinding) derivedType; if (!derivedType.hasTypeAnnotations()) nakedType = (WildcardBinding) derivedType; } if (nakedType == null) nakedType = super.getWildcard(genericType, rank, bound, otherBounds, boundKind); if (!haveTypeAnnotations(genericType, bound, otherBounds, annotations)) return nakedType; WildcardBinding wildcard = new WildcardBinding(genericType, rank, bound, otherBounds, boundKind, this.environment); wildcard.id = nakedType.id; wildcard.setTypeAnnotations(annotations, this.isAnnotationBasedNullAnalysisEnabled); return (WildcardBinding) cacheDerivedType(genericType, nakedType, wildcard); }
/* * Compiler crash recovery in case of unexpected runtime exceptions */ protected void handleInternalException( Throwable internalException, CompilationUnitDeclaration unit, CompilationResult result) { if (result == null && unit != null) { result = unit.compilationResult; // current unit being processed ? } // Lookup environment may be in middle of connecting types if (result == null && this.lookupEnvironment.unitBeingCompleted != null) { result = this.lookupEnvironment.unitBeingCompleted.compilationResult; } if (result == null) { synchronized (this) { if (this.unitsToProcess != null && this.totalUnits > 0) result = this.unitsToProcess[this.totalUnits - 1].compilationResult; } } // last unit in beginToCompile ? boolean needToPrint = true; if (result != null) { /* create and record a compilation problem */ // only keep leading portion of the trace String[] pbArguments = new String[] { Messages.bind( Messages.compilation_internalError, Util.getExceptionSummary(internalException)), }; result.record( this.problemReporter.createProblem( result.getFileName(), IProblem.Unclassified, pbArguments, pbArguments, Error, // severity 0, // source start 0, // source end 0, // line number 0), // column number unit); /* hand back the compilation result */ if (!result.hasBeenAccepted) { this.requestor.acceptResult(result.tagAsAccepted()); needToPrint = false; } } if (needToPrint) { /* dump a stack trace to the console */ internalException.printStackTrace(); } }
void attach(TypeParameter[] parameters, int startPos) { if (methodDeclaration.modifiers != ClassFileConstants.AccDefault) return; int lastParameterEnd = parameters[parameters.length - 1].sourceEnd; Parser parser = this.parser(); Scanner scanner = parser.scanner; if (Util.getLineNumber( methodDeclaration.declarationSourceStart, scanner.lineEnds, 0, scanner.linePtr) != Util.getLineNumber(lastParameterEnd, scanner.lineEnds, 0, scanner.linePtr)) return; if (parser.modifiersSourceStart > lastParameterEnd && parser.modifiersSourceStart < methodDeclaration.declarationSourceStart) return; if (this.methodDeclaration instanceof MethodDeclaration) { ((MethodDeclaration) this.methodDeclaration).typeParameters = parameters; this.methodDeclaration.declarationSourceStart = startPos; } else if (this.methodDeclaration instanceof ConstructorDeclaration) { ((ConstructorDeclaration) this.methodDeclaration).typeParameters = parameters; this.methodDeclaration.declarationSourceStart = startPos; } }
Iterable<? extends File> getDefaultBootclasspath() { List<File> files = new ArrayList<>(); String javaversion = System.getProperty("java.version"); // $NON-NLS-1$ if (javaversion.length() > 3) javaversion = javaversion.substring(0, 3); long jdkLevel = CompilerOptions.versionToJdkLevel(javaversion); if (jdkLevel < ClassFileConstants.JDK1_6) { // wrong jdk - 1.6 or above is required return null; } for (String fileName : org.eclipse.jdt.internal.compiler.util.Util.collectFilesNames()) { files.add(new File(fileName)); } return files; }
protected void outputClassFiles(CompilationResult unitResult) { if ((unitResult != null) && (!unitResult.hasErrors() || this.forceOutputGeneration)) { ClassFile[] classFiles = unitResult.getClassFiles(); if (this.outputPath != null) { for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) { // retrieve the key and the corresponding classfile ClassFile classFile = classFiles[i]; String relativeName = new String(classFile.fileName()).replace('/', File.separatorChar) + ".class"; try { org.eclipse.jdt.internal.compiler.util.Util.writeToDisk( true, this.outputPath, relativeName, classFile); } catch (IOException e) { e.printStackTrace(); } } } } }
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException { JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent(); ZipFile zip = null; try { zip = root.getJar(); String entryName = Util.concatWith(pkg.names, getElementName(), '/'); ZipEntry ze = zip.getEntry(entryName); if (ze != null) { byte contents[] = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); String fileName = root.getHandleIdentifier() + IDependent.JAR_FILE_ENTRY_SEPARATOR + entryName; return new ClassFileReader(contents, fileName.toCharArray(), fullyInitialize); } } finally { JavaModelManager.getJavaModelManager().closeZipFile(zip); } return null; }
/** http://bugs.eclipse.org/bugs/show_bug.cgi?id=124212 */ public void test001() throws Exception { this.runConformTest( new String[] { "X.java", "public class X {\n" + " public static void main(String[] args) {\n" + " String s;\n" + " if(args.length == 0) {\n" + " s = \"SUCCESS\";\n" + " } else {\n" + " return;\n" + " }\n" + " System.out.println(s);\n" + " }\n" + "}", }, "SUCCESS"); ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent( new File(OUTPUT_DIR + File.separator + "X.class")); String actualOutput = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); String expectedOutput = " Local variable table:\n" + " [pc: 0, pc: 20] local: args index: 0 type: java.lang.String[]\n" + " [pc: 8, pc: 11] local: s index: 1 type: java.lang.String\n" + " [pc: 12, pc: 20] local: s index: 1 type: java.lang.String\n"; int index = actualOutput.indexOf(expectedOutput); if (index == -1 || expectedOutput.length() == 0) { System.out.println(Util.displayString(actualOutput, 3)); } if (index == -1) { assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); } }
protected boolean findSourceFiles( IResourceDelta sourceDelta, ClasspathMultiDirectory md, int segmentCount) throws CoreException { // When a package becomes a type or vice versa, expect 2 deltas, // one on the folder & one on the source file IResource resource = sourceDelta.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 switch (sourceDelta.getKind()) { case IResourceDelta.ADDED: if (!isExcluded) { IPath addedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount); createFolder( addedPackagePath, md.binaryFolder); // ensure package exists in the output folder // see if any known source file is from the same package... classpath already includes // new package 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$ } else { if (JavaBuilder.DEBUG) System.out.println("Found added package " + addedPackagePath); // $NON-NLS-1$ addDependentsOf(addedPackagePath, true); } } // $FALL-THROUGH$ collect all the source files case IResourceDelta.CHANGED: IResourceDelta[] children = sourceDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) if (!findSourceFiles(children[i], md, segmentCount)) return false; return true; case IResourceDelta.REMOVED: if (isExcluded) { // since this folder is excluded then there is nothing to delete (from this md), but // must walk any included subfolders children = sourceDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) if (!findSourceFiles(children[i], md, segmentCount)) return false; return true; } IPath removedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount); if (this.sourceLocations.length > 1) { for (int i = 0, l = this.sourceLocations.length; i < l; i++) { if (this.sourceLocations[i].sourceFolder.getFolder(removedPackagePath).exists()) { // only a package fragment was removed, same as removing multiple source files createFolder( removedPackagePath, md.binaryFolder); // ensure package exists in the output folder IResourceDelta[] removedChildren = sourceDelta.getAffectedChildren(); for (int j = 0, m = removedChildren.length; j < m; j++) if (!findSourceFiles(removedChildren[j], md, segmentCount)) return false; return true; } } } if ((sourceDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) { // same idea as moving a source file // see bug 163200 IResource movedFolder = this.javaBuilder.workspaceRoot.getFolder(sourceDelta.getMovedToPath()); JavaBuilder.removeProblemsAndTasksFor(movedFolder); } IFolder removedPackageFolder = md.binaryFolder.getFolder(removedPackagePath); if (removedPackageFolder.exists()) removedPackageFolder.delete(IResource.FORCE, null); // add dependents even when the package thinks it does not exist to be on the safe side if (JavaBuilder.DEBUG) System.out.println("Found removed package " + removedPackagePath); // $NON-NLS-1$ addDependentsOf(removedPackagePath, true); this.newState.removePackage(sourceDelta); } return true; case IResource.FILE: if (isExcluded) return true; String resourceName = resource.getName(); // GROOVY start // determine if this is a Groovy project final boolean isInterestingProject = LanguageSupportFactory.isInterestingProject(this.javaBuilder.getProject()); // GROOVY end // GROOVY start /* old { if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourceName)) { } new */ // GRECLIPSE-404 must call 'isJavaLikeFile' directly in order to make the Scala-Eclipse // plugin's weaving happy if ((!isInterestingProject && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourceName) && !LanguageSupportFactory.isInterestingSourceFile(resourceName)) || (isInterestingProject && LanguageSupportFactory.isSourceFile(resourceName, isInterestingProject))) { // GROOVY end IPath typePath = resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension(); String typeLocator = resource.getProjectRelativePath().toString(); switch (sourceDelta.getKind()) { case IResourceDelta.ADDED: if (JavaBuilder.DEBUG) System.out.println("Compile this added source file " + typeLocator); // $NON-NLS-1$ 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$ addDependentsOf(typePath, true); } return true; case IResourceDelta.REMOVED: char[][] definedTypeNames = this.newState.getDefinedTypeNamesFor(typeLocator); if (definedTypeNames == null) { // defined a single type matching typePath removeClassFile(typePath, md.binaryFolder); if ((sourceDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) { // remove problems and tasks for a compilation unit that is being moved (to // another package or renamed) // if the target file is a compilation unit, the new cu will be recompiled // if the target file is a non-java resource, then markers are removed // see bug 2857 IResource movedFile = this.javaBuilder.workspaceRoot.getFile(sourceDelta.getMovedToPath()); JavaBuilder.removeProblemsAndTasksFor(movedFile); } } else { if (JavaBuilder.DEBUG) System.out.println( "Found removed source file " + typePath.toString()); // $NON-NLS-1$ addDependentsOf( typePath, true); // add dependents of the source file since it may be involved in a name // collision if (definedTypeNames.length > 0) { // skip it if it failed to successfully define a type IPath packagePath = typePath.removeLastSegments(1); for (int i = 0, l = definedTypeNames.length; i < l; i++) removeClassFile( packagePath.append(new String(definedTypeNames[i])), md.binaryFolder); } } this.newState.removeLocator(typeLocator); return true; case IResourceDelta.CHANGED: if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0 && (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0) return true; // skip it since it really isn't changed if (JavaBuilder.DEBUG) System.out.println( "Compile this changed source file " + typeLocator); // $NON-NLS-1$ this.sourceFiles.add(new SourceFile((IFile) resource, md, true)); } return true; } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resourceName)) { // perform full build if a managed class file has been changed if (this.makeOutputFolderConsistent) { 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; } else if (md.hasIndependentOutputFolder) { if (this.javaBuilder.filterExtraResource(resource)) return true; // copy all other resource deltas to the output folder IPath resourcePath = resource.getFullPath().removeFirstSegments(segmentCount); IResource outputFile = md.binaryFolder.getFile(resourcePath); switch (sourceDelta.getKind()) { case IResourceDelta.ADDED: if (outputFile.exists()) { if (JavaBuilder.DEBUG) System.out.println("Deleting existing file " + resourcePath); // $NON-NLS-1$ outputFile.delete(IResource.FORCE, null); } if (JavaBuilder.DEBUG) System.out.println("Copying added file " + resourcePath); // $NON-NLS-1$ createFolder( resourcePath.removeLastSegments(1), md.binaryFolder); // ensure package exists in the output folder copyResource(resource, outputFile); return true; case IResourceDelta.REMOVED: if (outputFile.exists()) { if (JavaBuilder.DEBUG) System.out.println("Deleting removed file " + resourcePath); // $NON-NLS-1$ outputFile.delete(IResource.FORCE, null); } return true; case IResourceDelta.CHANGED: if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0 && (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0) return true; // skip it since it really isn't changed if (outputFile.exists()) { if (JavaBuilder.DEBUG) System.out.println("Deleting existing file " + resourcePath); // $NON-NLS-1$ outputFile.delete(IResource.FORCE, null); } if (JavaBuilder.DEBUG) System.out.println("Copying changed file " + resourcePath); // $NON-NLS-1$ createFolder( resourcePath.removeLastSegments(1), md.binaryFolder); // ensure package exists in the output folder copyResource(resource, outputFile); } return true; } } return true; }
protected void findAffectedSourceFiles( IResourceDelta binaryDelta, int segmentCount, StringSet structurallyChangedTypes) { // When a package becomes a type or vice versa, expect 2 deltas, // one on the folder & one on the class file IResource resource = binaryDelta.getResource(); switch (resource.getType()) { case IResource.FOLDER: switch (binaryDelta.getKind()) { case IResourceDelta.ADDED: case IResourceDelta.REMOVED: IPath packagePath = resource.getFullPath().removeFirstSegments(segmentCount); String packageName = packagePath.toString(); if (binaryDelta.getKind() == IResourceDelta.ADDED) { // see if any known source file is from the same package... classpath already includes // new package if (!this.newState.isKnownPackage(packageName)) { if (JavaBuilder.DEBUG) System.out.println("Found added package " + packageName); // $NON-NLS-1$ addDependentsOf(packagePath, false); return; } if (JavaBuilder.DEBUG) System.out.println( "Skipped dependents of added package " + packageName); // $NON-NLS-1$ } else { // see if the package still exists on the classpath if (!this.nameEnvironment.isPackage(packageName)) { if (JavaBuilder.DEBUG) System.out.println("Found removed package " + packageName); // $NON-NLS-1$ addDependentsOf(packagePath, false); return; } if (JavaBuilder.DEBUG) System.out.println( "Skipped dependents of removed package " + packageName); // $NON-NLS-1$ } // $FALL-THROUGH$ traverse the sub-packages and .class files case IResourceDelta.CHANGED: IResourceDelta[] children = binaryDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) findAffectedSourceFiles(children[i], segmentCount, structurallyChangedTypes); } return; case IResource.FILE: if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resource.getName())) { IPath typePath = resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension(); switch (binaryDelta.getKind()) { case IResourceDelta.ADDED: case IResourceDelta.REMOVED: if (JavaBuilder.DEBUG) System.out.println("Found added/removed class file " + typePath); // $NON-NLS-1$ addDependentsOf(typePath, false); return; case IResourceDelta.CHANGED: if ((binaryDelta.getFlags() & IResourceDelta.CONTENT) == 0) return; // skip it since it really isn't changed if (structurallyChangedTypes != null && !structurallyChangedTypes.includes(typePath.toString())) return; // skip since it wasn't a structural change if (JavaBuilder.DEBUG) System.out.println("Found changed class file " + typePath); // $NON-NLS-1$ addDependentsOf(typePath, false); } return; } } }
/* (non-Javadoc) * Save all source comments currently stored before flushing them. * @see org.eclipse.jdt.internal.compiler.parser.Parser#flushCommentsDefinedPriorTo(int) */ public int flushCommentsDefinedPriorTo(int position) { int lastCommentIndex = this.scanner.commentPtr; if (lastCommentIndex < 0) return position; // no comment // compute the index of the first obsolete comment int index = lastCommentIndex; int validCount = 0; while (index >= 0) { int commentEnd = this.scanner.commentStops[index]; if (commentEnd < 0) commentEnd = -commentEnd; // negative end position for non-javadoc comments if (commentEnd <= position) { break; } index--; validCount++; } // if the source at <position> is immediately followed by a line comment, then // flush this comment and shift <position> to the comment end. if (validCount > 0) { int immediateCommentEnd = 0; while (index < lastCommentIndex && (immediateCommentEnd = -this.scanner.commentStops[index + 1]) > 0) { // only tolerating non-javadoc comments (non-javadoc comment end positions are // negative) // is there any line break until the end of the immediate comment ? (thus only tolerating // line comment) immediateCommentEnd--; // comment end in one char too far if (org.eclipse.jdt.internal.compiler.util.Util.getLineNumber( position, this.scanner.lineEnds, 0, this.scanner.linePtr) != org.eclipse.jdt.internal.compiler.util.Util.getLineNumber( immediateCommentEnd, this.scanner.lineEnds, 0, this.scanner.linePtr)) break; position = immediateCommentEnd; validCount--; // flush this comment index++; } } if (index < 0) return position; // no obsolete comment pushOnCommentsStack(0, index); // store comment before flushing them switch (validCount) { case 0: // do nothing break; // move valid comment infos, overriding obsolete comment infos case 2: this.scanner.commentStarts[0] = this.scanner.commentStarts[index + 1]; this.scanner.commentStops[0] = this.scanner.commentStops[index + 1]; this.scanner.commentTagStarts[0] = this.scanner.commentTagStarts[index + 1]; this.scanner.commentStarts[1] = this.scanner.commentStarts[index + 2]; this.scanner.commentStops[1] = this.scanner.commentStops[index + 2]; this.scanner.commentTagStarts[1] = this.scanner.commentTagStarts[index + 2]; break; case 1: this.scanner.commentStarts[0] = this.scanner.commentStarts[index + 1]; this.scanner.commentStops[0] = this.scanner.commentStops[index + 1]; this.scanner.commentTagStarts[0] = this.scanner.commentTagStarts[index + 1]; break; default: System.arraycopy( this.scanner.commentStarts, index + 1, this.scanner.commentStarts, 0, validCount); System.arraycopy( this.scanner.commentStops, index + 1, this.scanner.commentStops, 0, validCount); System.arraycopy( this.scanner.commentTagStarts, index + 1, this.scanner.commentTagStarts, 0, validCount); } this.scanner.commentPtr = validCount - 1; return position; }
public void handle( int problemId, String[] problemArguments, int elaborationId, String[] messageArguments, int severity, int problemStartPosition, int problemEndPosition, ReferenceContext referenceContext, CompilationResult unitResult) { if (severity == ProblemSeverities.Ignore) return; // if no reference context, we need to abort from the current compilation process if (referenceContext == null) { if ((severity & ProblemSeverities.Error) != 0) { // non reportable error is fatal CategorizedProblem problem = this.createProblem( null, problemId, problemArguments, elaborationId, messageArguments, severity, 0, 0, 0, 0); throw new AbortCompilation(null, problem); } else { return; // ignore non reportable warning } } int[] lineEnds; int lineNumber = problemStartPosition >= 0 ? Util.getLineNumber( problemStartPosition, lineEnds = unitResult.getLineSeparatorPositions(), 0, lineEnds.length - 1) : 0; int columnNumber = problemStartPosition >= 0 ? Util.searchColumnNumber( unitResult.getLineSeparatorPositions(), lineNumber, problemStartPosition) : 0; CategorizedProblem problem = this.createProblem( unitResult.getFileName(), problemId, problemArguments, elaborationId, messageArguments, severity, problemStartPosition, problemEndPosition, lineNumber, columnNumber); if (problem == null) return; // problem couldn't be created, ignore switch (severity & ProblemSeverities.Error) { case ProblemSeverities.Error: record(problem, unitResult, referenceContext); if ((severity & ProblemSeverities.Fatal) != 0) { referenceContext.tagAsHavingErrors(); // should abort ? int abortLevel; if ((abortLevel = this.policy.stopOnFirstError() ? ProblemSeverities.AbortCompilation : severity & ProblemSeverities.Abort) != 0) { referenceContext.abort(abortLevel, problem); } } break; case ProblemSeverities.Warning: record(problem, unitResult, referenceContext); break; } }
public void resolve(MethodScope var1) { if ((this.field_446 & 16) == 0) { if (this.binding != null && this.binding.isValidBinding()) { this.field_446 |= 16; ClassScope var2 = var1.method_582(); if (var2 != null) { label338: { SourceTypeBinding var3 = var2.enclosingSourceType(); if (var3.superclass != null) { FieldBinding var4 = var2.findField(var3.superclass, this.name, this, false); if (var4 != null && var4.isValidBinding()) { label334: { if (var4 instanceof FieldBinding) { FieldBinding var5 = (FieldBinding) var4; if (var5.original() == this.binding || !var5.canBeSeenBy(var3, this, var1)) { break label334; } } var1.problemReporter().fieldHiding(this, var4); break label338; } } } Scope var13 = var2.parent; if (var13.kind != 4) { Binding var15 = var13.getBinding(this.name, 3, this, false); if (var15 != null && var15.isValidBinding() && var15 != this.binding) { label323: { if (var15 instanceof FieldBinding) { FieldBinding var6 = (FieldBinding) var15; if (var6.original() == this.binding || !var6.method_431() && var3.method_226()) { break label323; } } var1.problemReporter().fieldHiding(this, var15); } } } } } if (this.type != null) { this.type.resolvedType = this.binding.type; } FieldBinding var12 = var1.initializedField; int var14 = var1.field_407; try { var1.initializedField = this.binding; var1.field_407 = this.binding.field_304; method_761(var1, this.annotations, this.binding); if ((this.binding.getAnnotationTagBits() & 70368744177664L) == 0L && (this.binding.field_300 & 1048576) != 0 && var1.compilerOptions().field_1928 >= 3211264L) { var1.problemReporter().method_1675(this); } if (this.initialization == null) { this.binding.setConstant(Constant.NotAConstant); } else { this.binding.setConstant(Constant.NotAConstant); TypeBinding var17 = this.binding.type; this.initialization.setExpectedType(var17); TypeBinding var18; if (this.initialization instanceof ArrayInitializer) { if ((var18 = this.initialization.resolveTypeExpecting(var1, var17)) != null) { ((ArrayInitializer) this.initialization).binding = (ArrayBinding) var18; this.initialization.computeConversion(var1, var17, var18); } } else if ((var18 = this.initialization.resolveType(var1)) != null) { if (var17 != var18) { var1.compilationUnitScope().recordTypeConversion(var17, var18); } if (!this.initialization.isConstantValueOfTypeAssignableToType(var18, var17) && (!var17.method_148() || !BaseTypeBinding.method_185(var17.id, var18.id)) && !var18.isCompatibleWith(var17)) { if (!var1.isBoxingCompatibleWith(var18, var17) && (!var18.method_148() || var1.compilerOptions().field_1928 < 3211264L || var17.method_148() || !this.initialization.isConstantValueOfTypeAssignableToType( var18, var1.environment().method_486(var17)))) { if ((var17.tagBits & 128L) == 0L) { var1.problemReporter() .typeMismatchError(var18, var17, this.initialization, (ASTNode) null); } } else { this.initialization.computeConversion(var1, var17, var18); if (this.initialization instanceof CastExpression && (this.initialization.field_446 & 16384) == 0) { CastExpression.checkNeedForAssignedCast( var1, var17, (CastExpression) this.initialization); } } } else { this.initialization.computeConversion(var1, var17, var18); if (var18.method_174(var17)) { var1.problemReporter().method_1806(this.initialization, var18, var17); } if (this.initialization instanceof CastExpression && (this.initialization.field_446 & 16384) == 0) { CastExpression.checkNeedForAssignedCast( var1, var17, (CastExpression) this.initialization); } } if (this.binding.method_409()) { this.binding.setConstant( this.initialization.constant.castTo( (this.binding.type.id << 4) + this.initialization.constant.typeID())); } } else { this.binding.setConstant(Constant.NotAConstant); } if (this.binding == Assignment.method_944(this.initialization)) { var1.problemReporter().assignmentHasNoEffect(this, this.name); } } if (this.binding != null && this.binding.declaringClass != null && !this.binding.declaringClass.method_158()) { int var16 = this.binding.field_300 & 7; ProblemReporter var19 = var1.problemReporter(); int var7 = var19.computeSeverity(-1610612250); if (var7 != -1) { if (var2 != null) { var16 = Util.computeOuterMostVisibility(var2.referenceType(), var16); } int var8 = this.binding.field_300 & -8 | var16; } } } finally { var1.initializedField = var12; var1.field_407 = var14; if (this.binding.constant() == null) { this.binding.setConstant(Constant.NotAConstant); } } } } }
/* Private subroutine for public APIs. Create an annotated version of the type. To materialize the annotated version, we can't use new since this is a general purpose method designed to deal type bindings of all types. "Clone" the incoming type, specializing for any enclosing type that may itself be possibly be annotated. This is so the binding for @Outer Outer.Inner != Outer.@Inner Inner != @Outer Outer.@Inner Inner. Likewise so the bindings for @Readonly List<@NonNull String> != @Readonly List<@Nullable String> != @Readonly List<@Interned String> */ private TypeBinding getAnnotatedType( TypeBinding type, TypeBinding enclosingType, AnnotationBinding[] annotations) { if (type.kind() == Binding.PARAMETERIZED_TYPE) { return getParameterizedType( type.actualType(), type.typeArguments(), (ReferenceBinding) enclosingType, annotations); } TypeBinding nakedType = null; TypeBinding[] derivedTypes = getDerivedTypes(type); for (int i = 0, length = derivedTypes.length; i < length; i++) { TypeBinding derivedType = derivedTypes[i]; if (derivedType == null) break; if (derivedType.enclosingType() != enclosingType || !Util.effectivelyEqual( derivedType.typeArguments(), type.typeArguments())) // $IDENTITY-COMPARISON$ continue; switch (type.kind()) { case Binding.ARRAY_TYPE: if (!derivedType.isArrayType() || derivedType.dimensions() != type.dimensions() || derivedType.leafComponentType() != type.leafComponentType()) // $IDENTITY-COMPARISON$ continue; break; case Binding.RAW_TYPE: if (!derivedType.isRawType() || derivedType.actualType() != type.actualType()) // $IDENTITY-COMPARISON$ continue; break; case Binding.WILDCARD_TYPE: if (!derivedType.isWildcard() || derivedType.actualType() != type.actualType() || derivedType.rank() != type.rank() || derivedType.boundKind() != type.boundKind()) // $IDENTITY-COMPARISON$ continue; if (derivedType.bound() != type.bound() || !Util.effectivelyEqual( derivedType.additionalBounds(), type.additionalBounds())) // $IDENTITY-COMPARISON$ continue; break; default: switch (derivedType.kind()) { case Binding.ARRAY_TYPE: case Binding.RAW_TYPE: case Binding.WILDCARD_TYPE: case Binding.INTERSECTION_CAST_TYPE: case Binding.INTERSECTION_TYPE: continue; } break; } if (Util.effectivelyEqual(derivedType.getTypeAnnotations(), annotations)) { return derivedType; } if (!derivedType.hasTypeAnnotations()) nakedType = derivedType; } if (nakedType == null) nakedType = getUnannotatedType(type); if (!haveTypeAnnotations(type, enclosingType, null, annotations)) return nakedType; TypeBinding annotatedType = type.clone(enclosingType); annotatedType.id = nakedType.id; annotatedType.setTypeAnnotations(annotations, this.isAnnotationBasedNullAnalysisEnabled); TypeBinding keyType; switch (type.kind()) { case Binding.ARRAY_TYPE: keyType = type.leafComponentType(); break; case Binding.RAW_TYPE: case Binding.WILDCARD_TYPE: keyType = type.actualType(); break; default: keyType = nakedType; break; } return cacheDerivedType(keyType, nakedType, annotatedType); }
public final String getLocalizedMessage(int var1, int var2, String[] var3) { String var4 = (String) field_1056.get(keyFromID(var1 & 16777215)); if (var4 == null) { return "Unable to retrieve the error message for problem id: " + (var1 & 16777215) + ". Check compiler resources."; } else { char[] var5 = var4.toCharArray(); if (var2 != 0) { String var6 = (String) field_1056.get(keyFromID(var2)); if (var6 == null) { return "Unable to retrieve the error message elaboration for elaboration id: " + var2 + ". Check compiler resources."; } var5 = CharOperation.method_1383(var5, field_1059, var6.toCharArray()); } var5 = CharOperation.method_1383(var5, field_1057, field_1058); if (var3 == null) { return new String(var5); } else { int var13 = var5.length; int var7 = 0; StringBuffer var9 = null; if ((var1 & Integer.MIN_VALUE) != 0) { var9 = new StringBuffer(10 + var13 + var3.length * 20); var9.append((String) field_1056.get(keyFromID(514))); } while (true) { int var8; if ((var8 = CharOperation.method_1374('{', var5, var7)) > -1) { if (var9 == null) { var9 = new StringBuffer(var13 + var3.length * 20); } var9.append(var5, var7, var8 - var7); if ((var7 = CharOperation.method_1374('}', var5, var8 + 1)) > -1) { try { var9.append(var3[CharOperation.parseInt(var5, var8 + 1, var7 - var8 - 1)]); } catch (NumberFormatException var11) { var9.append(var5, var8 + 1, var7 - var8); } catch (ArrayIndexOutOfBoundsException var12) { return "Cannot bind message for problem (id: " + (var1 & 16777215) + ") \"" + new String(var5) + "\" with arguments: {" + Util.toString(var3) + "}"; } ++var7; continue; } var9.append(var5, var8, var13); break; } if (var9 == null) { return new String(var5); } var9.append(var5, var7, var13 - var7); break; } return new String(var9.toString()); } } }