Refine search
private NameEnvironmentAnswer createNameEnvironmentAnswer(final String pClazzName, final byte[] clazzBytes) throws ClassFormatException { final char[] fileName = pClazzName.toCharArray(); final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true); return new NameEnvironmentAnswer(classFileReader, null); }
private NameEnvironmentAnswer findType(String packageName, String typeName) { NameEnvironmentAnswer suggestedAnswer = null; Collection<ClasspathEntry> entries = !packageName.isEmpty() ? packages.get(packageName) : this.entries; if (entries != null) { for (ClasspathEntry entry : entries) { NameEnvironmentAnswer answer = entry.findType(packageName, typeName); if (answer != null) { if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) { return answer; } } else if (answer.isBetter(suggestedAnswer)) { // remember suggestion and keep looking suggestedAnswer = answer; } } } } return suggestedAnswer; }
ReferenceBinding askForType(PackageBinding packageBinding, char[] name) { if (packageBinding == null) { if (this.defaultPackage == null) return null; packageBinding = this.defaultPackage; } NameEnvironmentAnswer answer = this.nameEnvironment.findType(name, packageBinding.compoundName); if (answer == null) return null; if (answer.isBinaryType()) { // the type was found as a .class file this.typeRequestor.accept(answer.getBinaryType(), packageBinding, answer.getAccessRestriction()); } else if (answer.isCompilationUnit()) { // the type was found as a .java file, try to build it then search the cache this.typeRequestor.accept(answer.getCompilationUnit(), answer.getAccessRestriction()); } else if (answer.isSourceType()) { // the type was found as a source model this.typeRequestor.accept(answer.getSourceTypes(), packageBinding, answer.getAccessRestriction()); } return packageBinding.getType0(name); }
@Override public NameEnvironmentAnswer findType(String packageName, String typeName, AccessRestriction accessRestriction) { try { String qualifiedFileName = packageName + "/" + typeName + SUFFIX_STRING_class; ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedFileName); if (reader != null) { return new NameEnvironmentAnswer(reader, accessRestriction); } } catch (ClassFormatException | IOException e) { // treat as if class file is missing } return null; }
answer = new NameEnvironmentAnswer(workingCopy, null /*no access restriction*/); } else { answer = location.findClass( if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer))
private NameEnvironmentAnswer findSourceSecondaryType(String typeName, String qualifiedPackageName, String qualifiedBinaryFileName) { if (this.packageSecondaryTypes == null) this.packageSecondaryTypes = new Hashtable<>(); Hashtable<String, String> packageEntry = this.packageSecondaryTypes.get(qualifiedPackageName); if (packageEntry == null) { packageEntry = getSecondaryTypes(qualifiedPackageName); this.packageSecondaryTypes.put(qualifiedPackageName, packageEntry); } String fileName = packageEntry.get(typeName); return fileName != null ? new NameEnvironmentAnswer(new CompilationUnit(null, fileName, this.encoding, this.destinationPath), fetchAccessRestriction(qualifiedBinaryFileName)) : null; }
public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName) { if (!isPackage(qualifiedPackageName)) return null; // most common case try { ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName); if (reader != null) { String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length); if (this.externalAnnotationPath != null) { try { this.annotationZipFile = reader.setExternalAnnotationProvider(this.externalAnnotationPath, fileNameWithoutExtension, this.annotationZipFile, null); } catch (IOException e) { // don't let error on annotations fail class reading } } if (this.accessRuleSet == null) return new NameEnvironmentAnswer(reader, null); return new NameEnvironmentAnswer(reader, this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray())); } } catch (IOException e) { // treat as if class file is missing } catch (ClassFormatException e) { // treat as if class file is missing } return null; }
return new NameEnvironmentAnswer(unit, null /*no access restriction*/); int index = qualifiedTypeName.indexOf('$'); if (index > 0) { unit = (SourceFile) this.additionalUnits.get(enclosingTypeName); // doesn't have file extension if (unit != null) return new NameEnvironmentAnswer(unit, null /*no access restriction*/); this.modulePathEntries != null ? this.modulePathEntries::containsKey : null); if (answer != null) { char[] answerMod = answer.moduleName(); if (answerMod != null && this.modulePathEntries != null) { if (!this.modulePathEntries.containsKey(String.valueOf(answerMod))) continue; // assumed to be filtered out by --limit-modules if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer))
NameEnvironmentAnswer answer = this.classpaths[i].findClass(typeName, qualifiedPackageName, null, qualifiedBinaryFileName, asBinaryOnly); if (answer != null) { if (answer.moduleName() != null && !this.moduleLocations.containsKey(String.valueOf(answer.moduleName()))) continue; // type belongs to an unobservable module if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer)) : p.findClass(typeName, qp2, null, qb2, asBinaryOnly); if (answer != null) { if (answer.moduleName() != null && !this.moduleLocations.containsKey(String.valueOf(answer.moduleName()))) continue; // type belongs to an unobservable module if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer))
NameEnvironmentAnswer answer = nameEnvironment.findType(TypeConstants.PACKAGE_INFO_NAME, this.binding.compoundName); if (answer != null && answer.isBinaryType()) { IBinaryType type = answer.getBinaryType(); char[][][] missingTypeNames = type.getMissingTypeNames(); IBinaryAnnotation[] binaryAnnotations = type.getAnnotations();
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName, boolean asBinaryOnly){ NameEnvironmentAnswer answer = internalFindClass(qualifiedTypeName, typeName, asBinaryOnly); if (this.annotationsFromClasspath && answer != null && answer.getBinaryType() instanceof ClassFileReader) { for (int i = 0, length = this.classpaths.length; i < length; i++) { Classpath classpathEntry = this.classpaths[i]; if (classpathEntry.hasAnnotationFileFor(qualifiedTypeName)) { ZipFile zip = classpathEntry instanceof ClasspathJar ? ((ClasspathJar) classpathEntry).zipFile : null; try { ((ClassFileReader) answer.getBinaryType()).setExternalAnnotationProvider(classpathEntry.getPath(), qualifiedTypeName, zip, null); break; } catch (IOException e) { // ignore broken entry, keep searching } } } } return answer; } private NameEnvironmentAnswer internalFindClass(String qualifiedTypeName, char[] typeName, boolean asBinaryOnly){
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName, boolean asBinaryOnly, /*NonNull*/char[] moduleName) { NameEnvironmentAnswer answer = internalFindClass(qualifiedTypeName, typeName, asBinaryOnly, moduleName); if (this.annotationsFromClasspath && answer != null && answer.getBinaryType() instanceof ClassFileReader) { for (int i = 0, length = this.classpaths.length; i < length; i++) { Classpath classpathEntry = this.classpaths[i]; shouldClose = true; answer.setBinaryType(ExternalAnnotationDecorator.create(answer.getBinaryType(), classpathEntry.getPath(), qualifiedTypeName, zip)); return answer; answer.setBinaryType(new ExternalAnnotationDecorator(answer.getBinaryType(), null));
public boolean isBetter(NameEnvironmentAnswer currentBest, int currentBestClasspathPosition, NameEnvironmentAnswer toTest, int toTestClasspathPosition) { boolean useNewAnswer = false; if (currentBest == null) { useNewAnswer = true; } else { if (toTest.isBetter(currentBest)) { useNewAnswer = true; } else { // If neither one is better, use the one with the earlier classpath position if (!currentBest.isBetter(toTest)) { useNewAnswer = (toTestClasspathPosition < currentBestClasspathPosition); } } } return useNewAnswer; }
@Override public NameEnvironmentAnswer findType(String packageName, String typeName, AccessRestriction accessRestriction) { try { String qualifiedFileName = packageName + "/" + typeName + SUFFIX_STRING_class; ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedFileName); if (reader != null) { return new NameEnvironmentAnswer(reader, accessRestriction); } } catch (ClassFormatException | IOException e) { // treat as if class file is missing } return null; }
answer = new NameEnvironmentAnswer(workingCopy, null /*no access restriction*/); } else { answer = location.findClass( if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer))
private NameEnvironmentAnswer findSourceSecondaryType(String typeName, String qualifiedPackageName, String qualifiedBinaryFileName) { if (this.packageSecondaryTypes == null) this.packageSecondaryTypes = new Hashtable<>(); Hashtable<String, String> packageEntry = this.packageSecondaryTypes.get(qualifiedPackageName); if (packageEntry == null) { packageEntry = getPackageTypes(qualifiedPackageName); this.packageSecondaryTypes.put(qualifiedPackageName, packageEntry); } String fileName = packageEntry.get(typeName); return fileName != null ? new NameEnvironmentAnswer(new CompilationUnit(null, fileName, this.encoding, this.destinationPath), fetchAccessRestriction(qualifiedBinaryFileName)) : null; }
NameEnvironmentAnswer answer = nameEnvironment.findType(TypeConstants.PACKAGE_INFO_NAME, this.binding.compoundName); if (answer != null && answer.isBinaryType()) { IBinaryType type = answer.getBinaryType(); char[][][] missingTypeNames = type.getMissingTypeNames(); IBinaryAnnotation[] binaryAnnotations = type.getAnnotations();
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName, boolean asBinaryOnly){ NameEnvironmentAnswer answer = internalFindClass(qualifiedTypeName, typeName, asBinaryOnly); if (this.annotationsFromClasspath && answer != null && answer.getBinaryType() instanceof ClassFileReader) { for (int i = 0, length = this.classpaths.length; i < length; i++) { Classpath classpathEntry = this.classpaths[i]; if (classpathEntry.hasAnnotationFileFor(qualifiedTypeName)) { ZipFile zip = classpathEntry instanceof ClasspathJar ? ((ClasspathJar) classpathEntry).zipFile : null; try { ((ClassFileReader) answer.getBinaryType()).setExternalAnnotationProvider(classpathEntry.getPath(), qualifiedTypeName, zip, null); break; } catch (IOException e) { // ignore broken entry, keep searching } } } } return answer; } private NameEnvironmentAnswer internalFindClass(String qualifiedTypeName, char[] typeName, boolean asBinaryOnly){
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName, boolean asBinaryOnly, /*NonNull*/char[] moduleName) { NameEnvironmentAnswer answer = internalFindClass(qualifiedTypeName, typeName, asBinaryOnly, moduleName); if (this.annotationsFromClasspath && answer != null && answer.getBinaryType() instanceof ClassFileReader) { for (int i = 0, length = this.classpaths.length; i < length; i++) { Classpath classpathEntry = this.classpaths[i]; shouldClose = true; answer.setBinaryType(ExternalAnnotationDecorator.create(answer.getBinaryType(), classpathEntry.getPath(), qualifiedTypeName, zip)); return answer; answer.setBinaryType(new ExternalAnnotationDecorator(answer.getBinaryType(), null));
public boolean isBetter(NameEnvironmentAnswer currentBest, int currentBestClasspathPosition, NameEnvironmentAnswer toTest, int toTestClasspathPosition) { boolean useNewAnswer = false; if (currentBest == null) { useNewAnswer = true; } else { if (toTest.isBetter(currentBest)) { useNewAnswer = true; } else { // If neither one is better, use the one with the earlier classpath position if (!currentBest.isBetter(toTest)) { useNewAnswer = (toTestClasspathPosition < currentBestClasspathPosition); } } } return useNewAnswer; }