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

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


    Set<MethodSymbol> supers = new HashSet<>();
    if (methodSymbol.isStatic()) {
      return supers;
    }

    TypeSymbol owner = (TypeSymbol) methodSymbol.owner;
    // Iterates over an ordered list of all super classes and interfaces.
    for (Type sup : types.closure(owner.type)) {
      if (sup == owner.type) {
        continue; // Skip the owner of the method
      }
View Full Code Here


   * Find a method in the enclosing class's superclass that this method overrides.
   *
   * @return A superclass method that is overridden by {@code method}
   */
  public static MethodSymbol findSuperMethod(MethodSymbol method, Types types) {
    TypeSymbol superClass = method.enclClass().getSuperclass().tsym;
    if (superClass == null) {
      return null;
    }
    for (Symbol sym : superClass.members().getElements()) {
      if (sym.name.contentEquals(method.name)
          && method.overrides(sym, superClass, types, true)) {
        return (MethodSymbol) sym;
      }
    }
View Full Code Here

        instanceMethod(Matchers.<ExpressionTree>isSubtypeOf("java.lang.Class"), "getAnnotation"))
        .matches(tree, state)) {
      return Description.NO_MATCH;
    }
    MemberSelectTree memTree = (MemberSelectTree) tree.getArguments().get(0);
    TypeSymbol annotation = ASTHelpers.getSymbol(memTree.getExpression()).type.tsym;

    Retention retention = ASTHelpers.getAnnotation(annotation, Retention.class);
    if (retention != null && retention.value().equals(RUNTIME)) {
      return Description.NO_MATCH;
    }
View Full Code Here

        members = ((JCBlock) path.getLeaf()).getStatements();
      }
      for (JCTree jcTree : members) {
        if (jcTree.getKind() == Kind.VARIABLE) {
          JCVariableDecl declaration = (JCVariableDecl) jcTree;
          TypeSymbol variableTypeSymbol = declaration.getType().type.tsym;

          if (ASTHelpers.getSymbol(toReplace).isMemberOf(variableTypeSymbol, state.getTypes())) {
            if (toReplace.getKind() == Kind.IDENTIFIER) {
              fix = SuggestedFix.prefixWith(toReplace, declaration.getName() + ".");
            } else {
View Full Code Here

  @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)) {
View Full Code Here

    }
    return Description.NO_MATCH;
  }

  private MethodSymbol findSuperMethod(MethodSymbol method, VisitorState state) {
    TypeSymbol superClass = method.enclClass().getSuperclass().tsym;
    for (Symbol s : superClass.members().getElements()) {
      if (s.name.contentEquals(method.name)
          && method.overrides(s, superClass, state.getTypes(), true)) {
        return (MethodSymbol) s;
      }
    }
View Full Code Here

      }
      JCBlock block = (JCBlock)path.getLeaf();
      for (JCStatement jcStatement : block.getStatements()) {
        if (jcStatement.getKind() == Kind.VARIABLE) {
          JCVariableDecl declaration = (JCVariableDecl) jcStatement;
          TypeSymbol variableTypeSymbol = declaration.getType().type.tsym;

          if (ASTHelpers.getSymbol(toReplace).isMemberOf(variableTypeSymbol, state.getTypes())) {
            if (toReplace.getKind() == Kind.IDENTIFIER) {
              fix = SuggestedFix.prefixWith(toReplace, declaration.getName() + ".");
            } else {
View Full Code Here

public class MissingCasesInEnumSwitch extends BugChecker
    implements SwitchTreeMatcher {

  @Override
  public Description matchSwitch(SwitchTree tree, VisitorState state) {
    TypeSymbol switchType = ((JCSwitch) tree).getExpression().type.tsym;

    if (switchType.getKind() != ElementKind.ENUM) {
      return Description.NO_MATCH;
    }

    if (hasDefaultCase(tree)) {
      return Description.NO_MATCH;
View Full Code Here

        return (JCMethodDecl) getTree((Element) method);
    }

    public JCTree getTree(Element element) {
        Symbol symbol = (Symbol) element;
        TypeSymbol enclosing = symbol.enclClass();
        Env<AttrContext> env = enter.getEnv(enclosing);
        if (env == null)
            return null;
        JCClassDecl classNode = env.enclClass;
        if (classNode != null) {
View Full Code Here

        Env<AttrContext> env = getAttrContext(path);

        Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
                new Log.DeferredDiagnosticHandler(log);
        try {
            final TypeSymbol tsym;
            final Name memberName;
            if (ref.qualifierExpression == null) {
                tsym = env.enclClass.sym;
                memberName = ref.memberName;
            } else {
View Full Code Here

TOP

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

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.