@CheckForNull
  @Override
  public NullnessAnnotation getResolvedAnnotation(final Object o, boolean getMinimal) {

    Profiler profiler = Global.getAnalysisCache().getProfiler();
    profiler.start(this.getClass());
    try {
      if (o instanceof XMethodParameter) {
        XMethodParameter mp = (XMethodParameter) o;
        XMethod m = mp.getMethod();
        // TODO: Handle argument to equals specially: generate special
        // bug code for it
        int parameterNumber = mp.getParameterNumber();
        if (parameterNumber == 0) {
          if (m.getName().equals("equals")
              && m.getSignature().equals("(Ljava/lang/Object;)Z")
              && !m.isStatic()) return NullnessAnnotation.CHECK_FOR_NULL;
          else if (m.getName().equals("main")
              && m.getSignature().equals("([Ljava/lang/String;)V")
              && m.isStatic()
              && m.isPublic()) return NullnessAnnotation.NONNULL;
          else if (assertsFirstParameterIsNonnull(m)) return NullnessAnnotation.NONNULL;
          else if (m.getName().equals("compareTo")
              && m.getSignature().endsWith(";)Z")
              && !m.isStatic()) return NullnessAnnotation.NONNULL;
        }
      } else if (o instanceof XMethod) {
        XMethod m = (XMethod) o;
        String name = m.getName();
        String signature = m.getSignature();
        if (!m.isStatic()
            && (name.equals("clone") && signature.equals("()Ljava/lang/Object;")
                || name.equals("toString") && signature.equals("()Ljava/lang/String;")
                || m.isPrivate()
                    && name.equals("readResolve")
                    && signature.equals("()Ljava/lang/Object;"))) {
          NullnessAnnotation result = super.getDirectAnnotation(m);
          if (result != null) return result;
          return NullnessAnnotation.NONNULL;
        }

      } else if (o instanceof XField) {
        XField f = (XField) o;
        if (f.getName().startsWith("this$")) return NullnessAnnotation.NONNULL;
      }
      NullnessAnnotation result = super.getResolvedAnnotation(o, getMinimal);
      return result;
    } finally {
      profiler.end(this.getClass());
    }
  }
Пример #2
0
 @Override
 public String getHeading() {
   StringBuilder singleLineHeading = new StringBuilder();
   if (isNotBlank(field.getDisplayString())) {
     singleLineHeading
         .append(field.getDisplayString())
         .append("(")
         .append(field.getName())
         .append(")");
   } else {
     singleLineHeading.append(field.getName());
   }
   if (isNotBlank(field.getDescription())) {
     singleLineHeading.append(" [").append(field.getDescription()).append("]");
   }
   this.name = field.getName();
   this.description = field.getDescription();
   this.displayString = field.getDisplayString();
   field.setName(null);
   field.setDescription(null);
   field.setDisplayString(null);
   this.heading = singleLineHeading.toString();
   return singleLineHeading.toString() + ":";
 }