当前位置: 首页>>代码示例>>Java>>正文


Java MethodSymbol.isStatic方法代码示例

本文整理汇总了Java中com.sun.tools.javac.code.Symbol.MethodSymbol.isStatic方法的典型用法代码示例。如果您正苦于以下问题:Java MethodSymbol.isStatic方法的具体用法?Java MethodSymbol.isStatic怎么用?Java MethodSymbol.isStatic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.code.Symbol.MethodSymbol的用法示例。


在下文中一共展示了MethodSymbol.isStatic方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: overrides

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
public boolean overrides(ExecutableElement e1, ExecutableElement e2, TypeElement cls) {
    MethodSymbol rider = (MethodSymbol)e1;
    MethodSymbol ridee = (MethodSymbol)e2;
    ClassSymbol origin = (ClassSymbol)cls;

    return rider.name == ridee.name &&

           // not reflexive as per JLS
           rider != ridee &&

           // we don't care if ridee is static, though that wouldn't
           // compile
           !rider.isStatic() &&

           // Symbol.overrides assumes the following
           ridee.isMemberOf(origin, toolEnv.getTypes()) &&

           // check access, signatures and check return types
           rider.overrides(ridee, origin, toolEnv.getTypes(), true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:WorkArounds.java

示例2: make

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
static ClassAndMethod make(MethodSymbol methodSymbol, @Nullable Types types) {
  List<? extends AnnotationMirror> annotationMirrors = methodSymbol.getAnnotationMirrors();
  List<String> annotations = new ArrayList<>(annotationMirrors.size());
  for (AnnotationMirror annotationMirror : annotationMirrors) {
    annotations.add(annotationMirror.getAnnotationType().toString());
  }

  ClassSymbol clazzSymbol = (ClassSymbol) methodSymbol.owner;

  return new ClassAndMethod(
      clazzSymbol.getQualifiedName().toString(),
      methodSymbol.getSimpleName().toString(),
      annotations,
      methodSymbol.isStatic(),
      methodSymbol.getReturnType().isPrimitive(),
      methodSymbol.getReturnType().getTag() == BOOLEAN,
      knownNonNullMethod(methodSymbol, clazzSymbol, types));
}
 
开发者ID:google,项目名称:error-prone,代码行数:19,代码来源:NullnessPropagationTransfer.java

示例3: knownNonNullMethod

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
private static boolean knownNonNullMethod(
    MethodSymbol methodSymbol, ClassSymbol clazzSymbol, @Nullable Types types) {
  if (types == null) {
    return false;
  }

  // Proto getters are not null
  if (methodSymbol.name.toString().startsWith("get")
      && methodSymbol.params().isEmpty()
      && !methodSymbol.isStatic()) {
    Type type = clazzSymbol.type;
    while (type != null) {
      TypeSymbol typeSymbol = type.asElement();
      if (typeSymbol == null) {
        break;
      }
      if (typeSymbol
          .getQualifiedName()
          .contentEquals("com.google.protobuf.AbstractMessageLite")) {
        return true;
      }
      type = types.supertype(type);
    }
  }
  return false;
}
 
开发者ID:google,项目名称:error-prone,代码行数:27,代码来源:NullnessPropagationTransfer.java

示例4: findSuperMethodInType

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
@Nullable
public static MethodSymbol findSuperMethodInType(
    MethodSymbol methodSymbol, Type superType, Types types) {
  if (methodSymbol.isStatic() || superType.equals(methodSymbol.owner.type)) {
    return null;
  }

  Scope scope = superType.tsym.members();
  for (Symbol sym : scope.getSymbolsByName(methodSymbol.name)) {
    if (sym != null
        && !sym.isStatic()
        && ((sym.flags() & Flags.SYNTHETIC) == 0)
        && sym.name.contentEquals(methodSymbol.name)
        && methodSymbol.overrides(
            sym, (TypeSymbol) methodSymbol.owner, types, /* checkResult= */ true)) {
      return (MethodSymbol) sym;
    }
  }
  return null;
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:ASTHelpers.java

示例5: inEqualsOrCompareTo

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
private boolean inEqualsOrCompareTo(Type classType, Type type, VisitorState state) {
  MethodTree methodTree = ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class);
  if (methodTree == null) {
    return false;
  }
  MethodSymbol sym = ASTHelpers.getSymbol(methodTree);
  if (sym == null || sym.isStatic()) {
    return false;
  }
  Symbol compareTo = getOnlyMember(state, state.getSymtab().comparableType, "compareTo");
  Symbol equals = getOnlyMember(state, state.getSymtab().objectType, "equals");
  if (!sym.overrides(compareTo, classType.tsym, state.getTypes(), /* checkResult= */ false)
      && !sym.overrides(equals, classType.tsym, state.getTypes(), /* checkResult= */ false)) {
    return false;
  }
  if (!ASTHelpers.isSameType(type, classType, state)) {
    return false;
  }
  return true;
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:ReferenceEquality.java

示例6: matchMethod

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
  MethodSymbol method = ASTHelpers.getSymbol(tree);

  if (method.isStatic() || method.isConstructor()) {
    return Description.NO_MATCH;
  }

  if (method.getModifiers().contains(Modifier.PUBLIC)
      || method.getModifiers().contains(Modifier.PRIVATE)) {
    List<MethodSymbol> overriddenMethods = getOverriddenMethods(state, method);

    if (!overriddenMethods.isEmpty()) {
      String customMessage = MESSAGE_BASE + "must have protected or package-private visibility";
      return buildDescription(tree).setMessage(customMessage).build();
    }
  }

  return Description.NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:ForOverrideChecker.java

示例7: getFirstOverride

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
/**
 * Returns the {@link MethodSymbol} of the first method that sym overrides in its supertype
 * closure, or {@code null} if no such method exists.
 */
private MethodSymbol getFirstOverride(Symbol sym, Types types) {
  ClassSymbol owner = sym.enclClass();
  for (Type s : types.closure(owner.type)) {
    if (s == owner.type) {
      continue;
    }
    for (Symbol m : s.tsym.members().getSymbolsByName(sym.name)) {
      if (!(m instanceof MethodSymbol)) {
        continue;
      }
      MethodSymbol msym = (MethodSymbol) m;
      if (msym.isStatic()) {
        continue;
      }
      if (sym.overrides(msym, owner, types, /* checkResult= */ false)) {
        return msym;
      }
    }
  }
  return null;
}
 
开发者ID:google,项目名称:error-prone,代码行数:26,代码来源:MissingOverride.java

示例8: findSuperMethods

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
public static Set<MethodSymbol> findSuperMethods(MethodSymbol methodSymbol, Types types) {
  Set<MethodSymbol> supers = new HashSet<MethodSymbol>();
  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
    }
    Scope scope = sup.tsym.members();
    for (Scope.Entry e = scope.lookup(methodSymbol.name); e.scope != null; e = e.next()) {
      if (e.sym != null
          && !e.sym.isStatic()
          && ((e.sym.flags() & Flags.SYNTHETIC) == 0)
          && e.sym.name.contentEquals(methodSymbol.name)
          && methodSymbol.overrides(e.sym, owner, types, true)) {
        supers.add((MethodSymbol) e.sym);
      }
    }
  }
  return supers;
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:26,代码来源:ASTHelpers.java

示例9: factoryMethod

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
MethodSymbol factoryMethod(ClassSymbol tsym) {
    for (Symbol sym : tsym.members().getSymbolsByName(names.provider, sym -> sym.kind == MTH)) {
        MethodSymbol mSym = (MethodSymbol)sym;
        if (mSym.isStatic() && (mSym.flags() & Flags.PUBLIC) != 0 && mSym.params().isEmpty()) {
            return mSym;
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:Modules.java

示例10: isMethodCanBeOverridden

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
private static boolean isMethodCanBeOverridden(MethodSymbol methodSymbol, VisitorState state) {
  if (methodSymbol.isStatic() || methodSymbol.isPrivate() || isFinalMethod(methodSymbol)) {
    return false;
  }

  ClassTree enclosingClassTree = ASTHelpers.findEnclosingNode(state.getPath(), ClassTree.class);
  boolean isEnclosingClassFinal = isFinalClass(enclosingClassTree);
  if (isEnclosingClassFinal) {
    return false;
  }

  return true;
}
 
开发者ID:google,项目名称:error-prone,代码行数:14,代码来源:MutableMethodReturnType.java

示例11: methodReferenceDescriptor

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
/** Returns a string descriptor of a method's reference type. */
private String methodReferenceDescriptor(Types types, MethodSymbol sym) {
  StringBuilder sb = new StringBuilder();
  sb.append(sym.getSimpleName()).append('(');
  if (!sym.isStatic()) {
    sb.append(Signatures.descriptor(sym.owner.type, types));
  }
  sym.params().stream().map(p -> Signatures.descriptor(p.type, types)).forEachOrdered(sb::append);
  sb.append(")");
  return sb.toString();
}
 
开发者ID:google,项目名称:error-prone,代码行数:12,代码来源:AmbiguousMethodReference.java

示例12: matchMethod

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
  MethodSymbol sym = ASTHelpers.getSymbol(tree);
  if (sym == null) {
    return NO_MATCH;
  }
  if (sym.isStatic() || sym.isConstructor() || sym.getModifiers().contains(Modifier.NATIVE)) {
    return NO_MATCH;
  }
  if (!sym.isPrivate()) {
    // Methods that override other methods, or that are overridden, can't be static.
    // We conservatively warn only for private methods.
    return NO_MATCH;
  }
  switch (sym.owner.enclClass().getNestingKind()) {
    case TOP_LEVEL:
      break;
    case MEMBER:
      if (sym.owner.enclClass().hasOuterInstance()) {
        return NO_MATCH;
      }
      break;
    case LOCAL:
    case ANONYMOUS:
      return NO_MATCH;
  }
  if (CanBeStaticAnalyzer.referencesOuter(tree, sym, state)) {
    return NO_MATCH;
  }
  if (isSubtype(sym.owner.enclClass().type, state.getSymtab().serializableType, state)) {
    switch (sym.getSimpleName().toString()) {
      case "readObject":
        if (sym.getParameters().size() == 1
            && isSameType(
                getOnlyElement(sym.getParameters()).type,
                state.getTypeFromString("java.io.ObjectInputStream"),
                state)) {
          return NO_MATCH;
        }
        break;
      case "writeObject":
        if (sym.getParameters().size() == 1
            && isSameType(
                getOnlyElement(sym.getParameters()).type,
                state.getTypeFromString("java.io.ObjectOutputStream"),
                state)) {
          return NO_MATCH;
        }
        break;
      case "readObjectNoData":
      case "readResolve":
      case "writeReplace":
        if (sym.getParameters().size() == 0) {
          return NO_MATCH;
        }
        break;
      default: // fall out
    }
  }
  return describeMatch(tree.getModifiers(), addModifiers(tree, state, Modifier.STATIC));
}
 
开发者ID:google,项目名称:error-prone,代码行数:62,代码来源:MethodCanBeStatic.java

示例13: matchMethodInvocation

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
  MethodSymbol method = ASTHelpers.getSymbol(tree);
  if (method == null) {
    return Description.NO_MATCH;
  }
  Type currentClass = getOutermostClass(state);

  if (method.isStatic() || method.isConstructor() || currentClass == null) {
    return Description.NO_MATCH;
  }
  // allow super.foo() calls to @ForOverride methods from overriding methods
  if (isSuperCall(currentClass, tree, state)) {
    MethodTree currentMethod = findDirectMethod(state.getPath());
    // currentMethod might be null if we are in a field initializer
    if (currentMethod != null) {
      // MethodSymbol.overrides doesn't check that names match, so we need to do that first.
      if (currentMethod.getName().equals(method.name)) {
        MethodSymbol currentMethodSymbol = ASTHelpers.getSymbol(currentMethod);
        if (currentMethodSymbol.overrides(
            method, (TypeSymbol) method.owner, state.getTypes(), /* checkResult= */ true)) {
          return Description.NO_MATCH;
        }
      }
    }
  }

  List<MethodSymbol> overriddenMethods = getOverriddenMethods(state, method);

  for (Symbol overriddenMethod : overriddenMethods) {
    Type declaringClass = overriddenMethod.outermostClass().asType();
    if (!declaringClass.equals(currentClass)) {
      String customMessage =
          MESSAGE_BASE
              + "must not be invoked directly "
              + "(except by the declaring class, "
              + declaringClass
              + ")";
      return buildDescription(tree).setMessage(customMessage).build();
    }
  }

  return Description.NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:45,代码来源:ForOverrideChecker.java

示例14: getOverriddenMethods

import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入方法依赖的package包/类
/**
 * Get overridden @ForOverride methods.
 *
 * @param state the VisitorState
 * @param method the method to find overrides for
 * @return a list of methods annotated @ForOverride that the method overrides, including the
 *     method itself if it has the annotation
 */
private List<MethodSymbol> getOverriddenMethods(VisitorState state, MethodSymbol method) {
  // Static methods cannot override, only overload.
  if (method.isStatic()) {
    throw new IllegalArgumentException(
        "getOverriddenMethods may not be called on a static method");
  }

  List<MethodSymbol> list = new LinkedList<>();
  list.add(method);

  // Iterate over supertypes of the type that owns this method, collecting a list of all method
  // symbols with the same name.  We intentionally exclude interface methods because interface
  // methods cannot be annotated @ForOverride.  @ForOverride methods must have protected or
  // package-private visibility, but interface methods have implicit public visibility.
  Type currType = state.getTypes().supertype(method.owner.type);
  while (currType != null
      && !currType.equals(state.getSymtab().objectType)
      && !currType.equals(Type.noType)) {
    Symbol sym = currType.tsym.members().findFirst(method.name);
    if (sym instanceof MethodSymbol) {
      list.add((MethodSymbol) sym);
    }
    currType = state.getTypes().supertype(currType);
  }

  // Remove methods that either don't have the @ForOverride annotation or don't override the
  // method in question.
  Iterator<MethodSymbol> iter = list.iterator();
  while (iter.hasNext()) {
    MethodSymbol member = iter.next();
    if (!hasAnnotation(FOR_OVERRIDE, member)
        // Note that MethodSymbol.overrides() ignores static-ness, but that's OK since we've
        // already checked that this method is not static.
        || !method.overrides(
            member, (TypeSymbol) member.owner, state.getTypes(), /* checkResult= */ true)) {
      iter.remove();
    }
  }

  return list;
}
 
开发者ID:google,项目名称:error-prone,代码行数:50,代码来源:ForOverrideChecker.java


注:本文中的com.sun.tools.javac.code.Symbol.MethodSymbol.isStatic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。