Search in sources :

Example 6 with OutputFile

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"));
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) OutputFileCollection(org.jetbrains.kotlin.backend.common.output.OutputFileCollection) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with OutputFile

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;
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) ArrayList(java.util.ArrayList) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) ClassVisitor(org.jetbrains.org.objectweb.asm.ClassVisitor) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with OutputFile

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];
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) ClassVisitor(org.jetbrains.org.objectweb.asm.ClassVisitor)

Example 9 with OutputFile

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());
        }
    }
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile)

Example 10 with OutputFile

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;
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) ReferenceType(com.sun.jdi.ReferenceType)

Aggregations

OutputFile (org.jetbrains.kotlin.backend.common.output.OutputFile)14 NotNull (org.jetbrains.annotations.NotNull)7 OutputFileCollection (org.jetbrains.kotlin.backend.common.output.OutputFileCollection)4 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)4 ClassVisitor (org.jetbrains.org.objectweb.asm.ClassVisitor)3 Main (com.android.dx.command.dexer.Main)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ReferenceType (com.sun.jdi.ReferenceType)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Manifest (java.util.jar.Manifest)1 TestOnly (org.jetbrains.annotations.TestOnly)1 GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)1 Diagnostic (org.jetbrains.kotlin.diagnostics.Diagnostic)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)1