Package com.sun.tools.javac.code.Symbol

Examples of com.sun.tools.javac.code.Symbol.MethodSymbol


    category = JDK, severity = ERROR, maturity = MATURE)
public class Overrides extends BugChecker implements MethodTreeMatcher {

  @Override
  public Description matchMethod(MethodTree methodTree, VisitorState state) {
    MethodSymbol methodSymbol = (MethodSymbol) ASTHelpers.getSymbol(methodTree);
    boolean isVarargs = (methodSymbol.flags() & Flags.VARARGS) != 0;

    Set<MethodSymbol> superMethods = ASTHelpers.findSuperMethods(methodSymbol, state.getTypes());

    // If there are no super methods, we're fine:
    if (superMethods.isEmpty()) {
View Full Code Here


  public static Matcher<MethodTree> hasAnnotationOnAnyOverriddenMethod(
      final String annotationType) {
    return new Matcher<MethodTree>() {
      @Override
      public boolean matches(MethodTree tree, VisitorState state) {
        MethodSymbol methodSym = ASTHelpers.getSymbol(tree);
        Symbol annotationSym = state.getSymbolFromString(annotationType);
        if ((methodSym == null) || (annotationSym == null)) {
          return false;
        }
View Full Code Here

  private MethodSymbol supermethod;

  @Override
  public Description matchMethod(MethodTree tree, VisitorState state) {
    MethodSymbol method = (MethodSymbol) ASTHelpers.getSymbol(tree);
    ClassSymbol classSym = method.enclClass();
    TypeSymbol superClass = classSym.getSuperclass().tsym;

    for (Symbol s : superClass.members().getElements()) {
      if (s.name.contentEquals(method.name) && s.getKind() == ElementKind.METHOD) {
        MethodSymbol supermethod = (MethodSymbol) s;

        // if this method actually overrides the supermethod, then it's correct and not a match.
        if (method.overrides(supermethod, superClass, state.getTypes(), true)) {
          return Description.NO_MATCH;
        }
View Full Code Here

  }

  public Description describe(MethodTree tree, VisitorState state) {
    SuggestedFix.Builder builder = null;

    MethodSymbol method = (MethodSymbol) ASTHelpers.getSymbol(tree);

    if (supermethod == null){
      throw new IllegalStateException("Matching supermethod was not found");
    }
View Full Code Here

    return NO_MATCH;
  }

  @Override
  public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
    MethodSymbol symbol = getSymbol(tree);
    // TODO(cpovirk): determine whether anyone might be calling Foo.this()
    if (!isIdentifierWithName(tree.getMethodSelect(), "this")) {
      return NO_MATCH;
    }
    callersToEvaluate.put(symbol, new Caller(tree, state));
View Full Code Here

    return evaluateCallers(symbol);
  }

  @Override
  public Description matchMethod(MethodTree tree, VisitorState state) {
    MethodSymbol symbol = getSymbol(tree);
    if (!symbol.isConstructor()) {
      return NO_MATCH;
    }
    paramTypesForMethod.put(symbol, unmodifiableList(tree.getParameters()));
    return evaluateCallers(symbol);
  }
View Full Code Here

    if (INJECTABLE_METHOD_MATCHER.matches(methodTree, state)
        || !OVERRIDE_METHOD_MATCHER.matches(methodTree, state)) {
      return Description.NO_MATCH;
    }
    boolean foundJavaxInject = false;
    MethodSymbol method = (MethodSymbol) ASTHelpers.getSymbol(methodTree);
    MethodSymbol superMethod = null;
    for (boolean checkSuperClass = true; checkSuperClass; method = superMethod) {
      superMethod = findSuperMethod(method, state);
      if (isAnnotatedWith(superMethod, GUICE_INJECT_ANNOTATION)) {
        return Description.NO_MATCH;
      }
View Full Code Here

  @Override
  public Description matchMethod(MethodTree methodTree, VisitorState state) {
    // if method is itself annotated with @Inject or it has no ancestor methods, return No_MATCH;
    if (!INJECTABLE_METHOD_MATCHER.matches(methodTree, state)
        && OVERRIDE_METHOD_MATCHER.matches(methodTree, state)) {
      MethodSymbol method = (MethodSymbol) ASTHelpers.getSymbol(methodTree);
      MethodSymbol superMethod = null;
      for (boolean checkSuperClass = true; checkSuperClass; method = superMethod) {
        superMethod = ASTHelpers.findSuperMethod(method, state.getTypes());
        if (isAnnotatedWith(superMethod, GUICE_INJECT_ANNOTATION)) {
          return describeMatch(methodTree, SuggestedFix.builder()
              .addImport("javax.inject.Inject")
View Full Code Here

        java.util.List<Symbol> enclosedElements = getEnclosedElements(invTarget);
        Symbol s = contains(enclosedElements, typeParams, mName, args);
        if (s != null) {
            return (MethodSymbol) s;
        }
        MethodSymbol ms = (MethodSymbol) contains(elementUtils.getAllMembers((TypeElement) invTarget), typeParams, mName, args);
        if (ms == null) {
            throw new NoSuchElementException(mi.toString());
        }
        return ms;
    }
View Full Code Here

            }
            accessor = getAccessor((JCFieldAccess) fa.selected, cut, n);
            return getSymbol(((JCFieldAccess) fa.selected).name, accessor, cut, n);
        }
        if (fa.selected instanceof JCMethodInvocation) {
            MethodSymbol s = (MethodSymbol) getSymbol(fa.selected, cut, n);
            Type returnType = s.getReturnType();
            return returnType.asElement();
        } else if (fa.selected instanceof JCArrayTypeTree) {
            JCArrayTypeTree arr = (JCArrayTypeTree) fa.selected;
            return getSymbol(arr.elemtype, cut, n);
        } else if (fa.selected instanceof JCArrayAccess) {
View Full Code Here

TOP

Related Classes of com.sun.tools.javac.code.Symbol.MethodSymbol

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.