use of org.jetbrains.org.objectweb.asm.ClassReader in project intellij-community by JetBrains.
the class Mappings method getCallback.
public Callbacks.Backend getCallback() {
return new Callbacks.Backend() {
public void associate(String classFileName, Collection<String> sources, ClassReader cr) {
synchronized (myLock) {
final int classFileNameS = myContext.get(classFileName);
final Pair<ClassRepr, Set<UsageRepr.Usage>> result = new ClassfileAnalyzer(myContext).analyze(classFileNameS, cr);
final ClassRepr repr = result.first;
if (repr != null) {
final Set<UsageRepr.Usage> localUsages = result.second;
final int className = repr.name;
for (String sourceFileName : sources) {
final File sourceFile = new File(sourceFileName);
myClassToSourceFile.put(className, sourceFile);
mySourceFileToClasses.put(sourceFile, repr);
}
for (final int s : repr.getSupers()) {
myClassToSubclasses.put(s, className);
}
for (final UsageRepr.Usage u : localUsages) {
final int owner = u.getOwner();
if (owner != className) {
myClassToClassDependency.put(owner, className);
}
}
}
}
}
public void associate(final String classFileName, final String sourceFileName, final ClassReader cr) {
associate(classFileName, Collections.singleton(sourceFileName), cr);
}
@Override
public void registerImports(final String className, final Collection<String> imports, Collection<String> staticImports) {
final List<String> allImports = new ArrayList<>();
for (String anImport : imports) {
if (!anImport.endsWith("*")) {
// filter out wildcard imports
allImports.add(anImport);
}
}
for (final String s : staticImports) {
int i = s.length() - 1;
while (s.charAt(i) != '.') {
i--;
}
final String anImport = s.substring(0, i);
if (!anImport.endsWith("*")) {
// filter out wildcard imports
allImports.add(anImport);
}
}
if (!allImports.isEmpty()) {
myPostPasses.offer(() -> {
final int rootClassName = myContext.get(className.replace(".", "/"));
final Collection<File> fileNames = myClassToSourceFile.get(rootClassName);
final ClassRepr repr = fileNames != null && !fileNames.isEmpty() ? getReprByName(fileNames.iterator().next(), rootClassName) : null;
for (final String i : allImports) {
final int iname = myContext.get(i.replace('.', '/'));
myClassToClassDependency.put(iname, rootClassName);
if (repr != null && repr.addUsage(UsageRepr.createClassUsage(myContext, iname))) {
for (File fileName : fileNames) {
mySourceFileToClasses.put(fileName, repr);
}
}
}
});
}
}
};
}
use of org.jetbrains.org.objectweb.asm.ClassReader in project intellij-community by JetBrains.
the class SourceLineCounterUtil method collectSrcLinesForUntouchedFiles.
public static void collectSrcLinesForUntouchedFiles(final List<Integer> uncoveredLines, byte[] content, final boolean excludeLines) {
final ClassReader reader = new ClassReader(content);
final SourceLineCounter collector = new SourceLineCounter(null, excludeLines, null);
reader.accept(collector, 0);
final TIntObjectHashMap lines = collector.getSourceLines();
lines.forEachKey(new TIntProcedure() {
public boolean execute(int line) {
line--;
uncoveredLines.add(line);
return true;
}
});
}
use of org.jetbrains.org.objectweb.asm.ClassReader in project intellij-community by JetBrains.
the class ByteCodeViewerManager method processClassFile.
private static String processClassFile(byte[] bytes) {
final ClassReader classReader = new ClassReader(bytes);
final StringWriter writer = new StringWriter();
final PrintWriter printWriter = new PrintWriter(writer);
try {
classReader.accept(new TraceClassVisitor(null, new Textifier(), printWriter), 0);
} finally {
printWriter.close();
}
return writer.toString();
}
use of org.jetbrains.org.objectweb.asm.ClassReader 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.org.objectweb.asm.ClassReader in project kotlin by JetBrains.
the class OuterClassGenTest method doCustomTest.
private void doCustomTest(@Language("RegExp") @NotNull String internalNameRegexp, @NotNull OuterClassInfo expectedInfo, @NotNull String testDataFile) {
ClassReader kotlinReader = getKotlinClassReader(internalNameRegexp, testDataFile);
OuterClassInfo kotlinInfo = readOuterClassInfo(kotlinReader);
String message = "Error in enclosingMethodInfo info for class: " + kotlinReader.getClassName();
if (kotlinInfo == null) {
assertNull(expectedInfo.getOwner());
} else {
assertTrue(message + "\n" + kotlinInfo.getOwner() + " doesn't start with " + expectedInfo.getOwner(), kotlinInfo.getOwner().startsWith(expectedInfo.getOwner()));
}
assertEquals(message, expectedInfo.getMethodName(), kotlinInfo.getMethodName());
assertEquals(message, expectedInfo.getMethodDesc(), kotlinInfo.getMethodDesc());
}
Aggregations