use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class MethodLookup method lookup.
private static MethodLookup lookup(String className, String signature, SquidClassLoader classLoader, LookupMethodVisitor methodVisitor) {
byte[] bytes = classLoader.getBytesForClass(className);
if (bytes == null) {
return null;
}
ClassReader cr = new ClassReader(bytes);
LookupClassVisitor lookupVisitor = new LookupClassVisitor(methodVisitor, signature);
cr.accept(lookupVisitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
if (lookupVisitor.methodFound) {
return new MethodLookup(lookupVisitor.isStatic, lookupVisitor.isVarArgs, lookupVisitor.declaredExceptions);
}
// we didn't succeed to find the method in the class, try recursively on superclasses and interfaces
if (lookupVisitor.superClassName != null) {
MethodLookup result = lookup(lookupVisitor.superClassName, signature, classLoader, methodVisitor);
if (result != null) {
return result;
}
}
if (lookupVisitor.interfaces != null) {
return Arrays.stream(lookupVisitor.interfaces).map(iface -> lookup(iface, signature, classLoader, methodVisitor)).filter(Objects::nonNull).findAny().orElse(null);
}
return null;
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class ExportsDirectiveTreeImplTest method exportsDirective.
private ExportsDirectiveTree exportsDirective(String exportsDirective) {
CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n " + exportsDirective + "\n}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (ExportsDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class ExportsDirectiveTreeImplTest method createTree.
private CompilationUnitTree createTree(String... lines) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(Arrays.stream(lines).collect(Collectors.joining("\n")));
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return compilationUnitTree;
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class ProvidesDirectiveTreeImplTest method providesDirective.
private ProvidesDirectiveTree providesDirective(String exportsDirective) {
CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n " + exportsDirective + "\n}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (ProvidesDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class UsesDirectiveTreeImplTest method moduleDirective.
private UsesDirectiveTree moduleDirective(String exportsDirective) {
CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n " + exportsDirective + "\n}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (UsesDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
Aggregations