Skip to content

Commit

Permalink
SONARJAVA-3317 To improve performance precompute JMethodSymbol.signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Apr 8, 2020
1 parent 11cd5a5 commit 50c8c6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.sonar.java.model;

import org.eclipse.jdt.core.dom.ASTUtils;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.sonar.java.resolve.Symbols;
Expand Down Expand Up @@ -53,8 +54,13 @@ final class JMethodSymbol extends JSymbol implements Symbol.MethodSymbol {
*/
private MethodSymbol overriddenSymbol = Symbols.unknownMethodSymbol;

private final String signature;

JMethodSymbol(JSema sema, IMethodBinding methodBinding) {
super(sema, methodBinding);
this.signature = methodBinding().getDeclaringClass().getBinaryName()
+ "#" + name()
+ ASTUtils.signature(methodBinding().getMethodDeclaration());
}

IMethodBinding methodBinding() {
Expand Down Expand Up @@ -134,9 +140,7 @@ private IMethodBinding find(Predicate<IMethodBinding> predicate, ITypeBinding t)

@Override
public String signature() {
return methodBinding().getDeclaringClass().getBinaryName()
+ "#" + name()
+ JSema.signature(methodBinding().getMethodDeclaration());
return signature;
}

@Nullable
Expand Down
4 changes: 0 additions & 4 deletions java-frontend/src/main/java/org/sonar/java/model/JSema.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,4 @@ IAnnotationBinding[] resolvePackageAnnotations(String packageName) {
return ASTUtils.resolvePackageAnnotations(ast, packageName);
}

static String signature(IMethodBinding methodBinding) {
return ASTUtils.signature(methodBinding);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ void symbol_type() {
@Test
void symbol_method() {
assertAll(
() -> assertThat(instanceSize(JMethodSymbol.class, X86_64)).isEqualTo(88),
() -> assertThat(instanceSize(JMethodSymbol.class, X86_64_COOPS)).isEqualTo(48)
() -> assertThat(instanceSize(JMethodSymbol.class, X86_64)).isEqualTo(96),
() -> assertThat(instanceSize(JMethodSymbol.class, X86_64_COOPS)).isEqualTo(56)
);
}

Expand Down

0 comments on commit 50c8c6e

Please sign in to comment.