コード例 #1
0
 @Test
 public void testVisitFieldInsn() {
   AsmClass tagNameClass = asmClassProvider.getClass("tags/TagName");
   AsmField nameField = tagNameClass.getField("name");
   AsmMethod constructorWithString = tagNameClass.getMethod("<init>(Ljava/lang/String;)V");
   assertThat(constructorWithString.getCallsToField()).containsOnly(nameField);
 }
コード例 #2
0
 @Test
 public void testVisitTryCatchBlock() {
   AsmClass sourceFileClass = asmClassProvider.getClass("tags/SourceFile");
   AsmClass tagExceptionClass = asmClassProvider.getClass("tags/TagException");
   AsmMethod readSourceFileMethod = sourceFileClass.getMethod("readSourceFile()V");
   assertThat(readSourceFileMethod.getDistinctUsedAsmClasses()).contains(tagExceptionClass);
 }
コード例 #3
0
 @Test
 public void testVisitMethodInsn() {
   AsmClass sourceFileClass = asmClassProvider.getClass("tags/SourceFile");
   AsmMethod readMethod = sourceFileClass.getMethod("read()V");
   AsmMethod readSourceFileMethod = sourceFileClass.getMethod("readSourceFile()V");
   assertThat(readSourceFileMethod.getCallsToMethod()).contains(readMethod).hasSize(2);
   assertThat(readSourceFileMethod.getCallsToField()).hasSize(1);
 }
コード例 #4
0
 @Test
 public void testVisitTypeInsn() {
   AsmClass sourceFileClass = asmClassProvider.getClass("tags/SourceFile");
   AsmMethod constructor = sourceFileClass.getMethod("<init>()V");
   assertThat(
           constructor
               .getDistinctUsedAsmClasses()
               .contains(asmClassProvider.getClass("java/util/ArrayList")))
       .isNotNull();
 }
コード例 #5
0
 AsmMethod getMethodOrCreateIt(String key) {
   AsmMethod method = getMethod(key);
   if (method != null) {
     return method;
   }
   method = new AsmMethod(this, key);
   method.setBodyLoaded(false);
   addMethod(method);
   return method;
 }
コード例 #6
0
ファイル: AsmMethodVisitor.java プロジェクト: hpf911/sonar
 @Override
 public void visitFieldInsn(int opcode, String owner, String fieldName, String fieldDescription) {
   AsmClass targetClass = asmClassProvider.getClass(owner, DETAIL_LEVEL.NOTHING);
   AsmField targetField = targetClass.getFieldOrCreateIt(fieldName);
   method.addEdge(new AsmEdge(method, targetField, SourceCodeEdgeUsage.CALLS_FIELD, lineNumber));
   emptyMethod = false;
 }
コード例 #7
0
ファイル: AsmMethodVisitor.java プロジェクト: hpf911/sonar
 @Override
 public void visitTryCatchBlock(Label start, Label end, Label handler, String exception) {
   if (exception != null) {
     AsmClass exceptionClass = asmClassProvider.getClass(exception, DETAIL_LEVEL.NOTHING);
     method.addEdge(new AsmEdge(method, exceptionClass, SourceCodeEdgeUsage.USES, lineNumber));
   }
   emptyMethod = false;
 }
コード例 #8
0
ファイル: AsmMethodVisitor.java プロジェクト: hpf911/sonar
 @Override
 public void visitLdcInsn(Object cst) {
   if (cst instanceof Type) {
     Type type = (Type) cst;
     AsmClass usedClass = asmClassProvider.getClass(type.getInternalName(), DETAIL_LEVEL.NOTHING);
     method.addEdge(new AsmEdge(method, usedClass, SourceCodeEdgeUsage.USES, lineNumber));
   }
   emptyMethod = false;
 }
コード例 #9
0
ファイル: AsmMethod.java プロジェクト: h-t-ren/sonar
 private void computeAccessedField() {
   if (!isConstructor()) {
     for (AsmEdge edge : getOutgoingEdges()) {
       if (isCallToNonStaticInternalField(edge)) {
         if (isFieldAccesingDifferentField((AsmField) edge.getTo())) {
           accessedField = null;
           break;
         }
         accessedField = (AsmField) edge.getTo();
       } else if (isCallToNonStaticInternalMethod(edge)) {
         AsmMethod method = (AsmMethod) edge.getTo();
         if (isMethodNotAccessorOrAccessingDifferentField(method)) {
           accessedField = null;
           break;
         }
         accessedField = method.getAccessedField();
       }
     }
   }
 }
コード例 #10
0
ファイル: AsmMethodVisitor.java プロジェクト: hpf911/sonar
 @Override
 public void visitMethodInsn(
     int opcode, String owner, String methodName, String methodDescription) {
   if (isNotCallToJavaArrayMethod(owner)) {
     AsmClass targetClass = asmClassProvider.getClass(owner, DETAIL_LEVEL.STRUCTURE);
     AsmMethod targetMethod = targetClass.getMethodOrCreateIt(methodName + methodDescription);
     method.addEdge(
         new AsmEdge(method, targetMethod, SourceCodeEdgeUsage.CALLS_METHOD, lineNumber));
   }
   emptyMethod = false;
 }
コード例 #11
0
  @Test
  public void testVisitMethod() {
    AsmClass asmClass = asmClassProvider.getClass("java/lang/String");
    assertThat(asmClass.getMethod("charAt(I)C")).isNotNull();
    assertThat(asmClass.getMethod("charAt(I)C").isPublic()).isTrue();
    assertThat(asmClass.getMethod("charAt(I)C").isDeprecated()).isFalse();
    assertThat(asmClass.getMethod("charAt(I)C").isStatic()).isFalse();
    assertThat(asmClass.getMethod("valueOf(C)Ljava/lang/String;").isStatic()).isTrue();

    asmClass = asmClassProvider.getClass("tags/File");
    AsmMethod getLines =
        asmClass.getMethod("read(Ljava/util/Collection;Ljava/lang/String;)Ljava/lang/String;");
    assertThat(getLines.getDistinctUsedAsmClasses().contains(new AsmClass("java/util/Collection")))
        .isTrue();
    assertThat(getLines.getDistinctUsedAsmClasses().contains(new AsmClass("tags/File"))).isTrue();
    assertThat(getLines.getDistinctUsedAsmClasses().contains(new AsmClass("java/lang/String")))
        .isTrue();
    assertThat(
            getLines
                .getDistinctUsedAsmClasses()
                .contains(new AsmClass("java/lang/RuntimeException")))
        .isTrue();
  }
コード例 #12
0
ファイル: AsmMethod.java プロジェクト: h-t-ren/sonar
 private boolean isMethodNotAccessorOrAccessingDifferentField(AsmMethod method) {
   return !method.isAccessor()
       || (accessedField != null && !accessedField.equals(method.getAccessedField()));
 }
コード例 #13
0
ファイル: AsmMethodVisitor.java プロジェクト: hpf911/sonar
 @Override
 public void visitEnd() {
   method.setEmpty(emptyMethod);
 }
コード例 #14
0
ファイル: AsmMethodVisitor.java プロジェクト: hpf911/sonar
 @Override
 public void visitTypeInsn(int opcode, String internalName) {
   AsmClass usedClass = asmClassProvider.getClass(internalName, DETAIL_LEVEL.NOTHING);
   method.addEdge(new AsmEdge(method, usedClass, SourceCodeEdgeUsage.USES, lineNumber));
   emptyMethod = false;
 }
コード例 #15
0
 void addMethod(AsmMethod asmMethod) {
   methods.put(asmMethod.getKey(), asmMethod);
 }