use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class OuterClassGenTest method getKotlinClassReader.
@NotNull
private ClassReader getKotlinClassReader(@Language("RegExp") @NotNull String internalNameRegexp, @NotNull String testDataFile) {
loadFile(getPrefix() + "/" + testDataFile + ".kt");
OutputFileCollection outputFiles = generateClassesInFile();
for (OutputFile file : outputFiles.asList()) {
if (file.getRelativePath().matches(internalNameRegexp + "\\.class")) {
return new ClassReader(file.asByteArray());
}
}
throw new AssertionError("Couldn't find class by regexp: " + internalNameRegexp + " in:\n" + StringsKt.join(outputFiles.asList(), "\n"));
}
use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class InnerClassInfoGenTest method extractInnerClasses.
@NotNull
private List<InnerClassAttribute> extractInnerClasses(@NotNull String className) {
OutputFile outputFile = generateClassesInFile().get(className + ".class");
assertNotNull(outputFile);
byte[] bytes = outputFile.asByteArray();
ClassReader reader = new ClassReader(bytes);
final List<InnerClassAttribute> result = new ArrayList<InnerClassAttribute>();
reader.accept(new ClassVisitor(ASM5) {
@Override
public void visitInnerClass(@NotNull String name, String outerName, String innerName, int access) {
result.add(new InnerClassAttribute(name, outerName, innerName, access));
}
}, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
return result;
}
use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class SourceInfoGenTest method getProducerInfo.
private String getProducerInfo(String name) {
OutputFile file = generateClassesInFile().get(name);
assertNotNull(file);
ClassReader classReader = new ClassReader(file.asByteArray());
final String[] producer = new String[1];
classReader.accept(new ClassVisitor(Opcodes.ASM5) {
@Override
public void visitSource(String source, String debug) {
producer[0] = source;
}
}, 0);
return producer[0];
}
use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class AbstractWriteFlagsTest method doMultiFileTest.
@Override
protected void doMultiFileTest(@NotNull File wholeFile, @NotNull List<TestFile> files, @Nullable File javaFilesDir) throws Exception {
compile(files, null, ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, Collections.<String>emptyList());
String fileText = FileUtil.loadFile(wholeFile, true);
List<TestedObject> testedObjects = parseExpectedTestedObject(fileText);
for (TestedObject testedObject : testedObjects) {
String className = null;
for (OutputFile outputFile : classFileFactory.asList()) {
String filePath = outputFile.getRelativePath();
if (testedObject.isFullContainingClassName && filePath.equals(testedObject.containingClass + ".class") || !testedObject.isFullContainingClassName && filePath.startsWith(testedObject.containingClass)) {
className = filePath;
}
}
assertNotNull("Couldn't find a class file with name " + testedObject.containingClass, className);
OutputFile outputFile = classFileFactory.get(className);
assertNotNull(outputFile);
ClassReader cr = new ClassReader(outputFile.asByteArray());
TestClassVisitor classVisitor = getClassVisitor(testedObject.kind, testedObject.name, false);
cr.accept(classVisitor, ClassReader.SKIP_CODE);
if (!classVisitor.isExists()) {
classVisitor = getClassVisitor(testedObject.kind, testedObject.name, true);
cr.accept(classVisitor, ClassReader.SKIP_CODE);
}
boolean isObjectExists = !Boolean.valueOf(findStringWithPrefixes(testedObject.textData, "// ABSENT: "));
assertEquals("Wrong object existence state: " + testedObject, isObjectExists, classVisitor.isExists());
if (isObjectExists) {
assertEquals("Wrong access flag for " + testedObject + " \n" + outputFile.asText(), getExpectedFlags(testedObject.textData), classVisitor.getAccess());
}
}
}
use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class AbstractPositionManagerTest method getReferenceMap.
private static Map<String, ReferenceType> getReferenceMap(OutputFileCollection outputFiles) {
Map<String, ReferenceType> referencesByName = Maps.newHashMap();
for (OutputFile outputFile : outputFiles.asList()) {
String classFileName = outputFile.getRelativePath();
String name = classFileName.substring(0, classFileName.lastIndexOf('.'));
referencesByName.put(name, new MockReferenceType(name));
}
return referencesByName;
}
Aggregations