Search in sources :

Example 31 with SquidClassLoader

use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.

the class VariableReadExtractorTest method buildMethodTree.

private static MethodTree buildMethodTree(String methodCode) {
    CompilationUnitTree cut = (CompilationUnitTree) PARSER.parse("class A { int field1; int field2; " + methodCode + " }");
    SemanticModel.createFor(cut, new SquidClassLoader(Collections.emptyList()));
    return (MethodTree) ((ClassTree) cut.types().get(0)).members().get(2);
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader)

Example 32 with SquidClassLoader

use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.

the class MethodTreeImplTest method createTree.

private CompilationUnitTree createTree(String code) {
    CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(code);
    SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
    return compilationUnitTree;
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader)

Example 33 with SquidClassLoader

use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.

the class OpensDirectiveTreeImplTest 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;
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader)

Example 34 with SquidClassLoader

use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.

the class ReassignmentFinderTest method classTree.

private ClassTree classTree(String classBody) {
    CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(classBody);
    SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
    return (ClassTree) compilationUnitTree.types().get(0);
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader)

Example 35 with SquidClassLoader

use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.

the class ValueBasedUtilsTest method testIsValueBased.

@Test
public void testIsValueBased() throws Exception {
    File file = new File("src/test/files/checks/helpers/ValueBasedUtilsTest.java");
    CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
    SemanticModel.createFor(tree, new SquidClassLoader(Collections.emptyList()));
    List<Tree> members = ((ClassTree) tree.types().get(0)).members();
    members.stream().forEach(member -> checkMember((VariableTree) member));
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) Tree(org.sonar.plugins.java.api.tree.Tree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) File(java.io.File) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader) Test(org.junit.Test)

Aggregations

SquidClassLoader (org.sonar.java.bytecode.loader.SquidClassLoader)53 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)37 File (java.io.File)24 Test (org.junit.Test)18 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)12 ArrayList (java.util.ArrayList)11 ClassTree (org.sonar.plugins.java.api.tree.ClassTree)10 SemanticModel (org.sonar.java.resolve.SemanticModel)9 Tree (org.sonar.plugins.java.api.tree.Tree)9 List (java.util.List)7 Collectors (java.util.stream.Collectors)6 BeforeClass (org.junit.BeforeClass)6 BehaviorCache (org.sonar.java.se.xproc.BehaviorCache)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Opcodes (org.objectweb.asm.Opcodes)5 JavaParser (org.sonar.java.ast.parser.JavaParser)5 IOException (java.io.IOException)4 Collections (java.util.Collections)4 Before (org.junit.Before)4 Label (org.objectweb.asm.Label)4