Пример #1
0
  @Override
  public void handle(
      AnnotationValues<EqualsAndHashCode> annotation, JCAnnotation ast, JavacNode annotationNode) {
    deleteAnnotationIfNeccessary(annotationNode, EqualsAndHashCode.class);
    EqualsAndHashCode ann = annotation.getInstance();
    List<String> excludes = List.from(ann.exclude());
    List<String> includes = List.from(ann.of());
    JavacNode typeNode = annotationNode.up();

    checkForBogusFieldNames(typeNode, annotation);

    Boolean callSuper = ann.callSuper();
    if (!annotation.isExplicit("callSuper")) callSuper = null;
    if (!annotation.isExplicit("exclude")) excludes = null;
    if (!annotation.isExplicit("of")) includes = null;

    if (excludes != null && includes != null) {
      excludes = null;
      annotation.setWarning(
          "exclude",
          "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
    }

    FieldAccess fieldAccess = ann.doNotUseGetters() ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;

    generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true, fieldAccess);
  }
Пример #2
0
  public boolean handle(
      AnnotationValues<ToString> annotation, Annotation ast, EclipseNode annotationNode) {
    ToString ann = annotation.getInstance();
    List<String> excludes = Arrays.asList(ann.exclude());
    List<String> includes = Arrays.asList(ann.of());
    EclipseNode typeNode = annotationNode.up();
    Boolean callSuper = ann.callSuper();

    if (!annotation.isExplicit("callSuper")) callSuper = null;
    if (!annotation.isExplicit("exclude")) excludes = null;
    if (!annotation.isExplicit("of")) includes = null;

    if (excludes != null && includes != null) {
      excludes = null;
      annotation.setWarning(
          "exclude",
          "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
    }

    checkForBogusFieldNames(typeNode, annotation);

    FieldAccess fieldAccess = ann.doNotUseGetters() ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;

    return generateToString(
        typeNode,
        annotationNode,
        excludes,
        includes,
        ann.includeFieldNames(),
        callSuper,
        true,
        fieldAccess);
  }
Пример #3
0
 private void checkForBogusFieldNames(EclipseNode type, AnnotationValues<ToString> annotation) {
   if (annotation.isExplicit("exclude")) {
     for (int i :
         createListOfNonExistentFields(
             Arrays.asList(annotation.getInstance().exclude()), type, true, false)) {
       annotation.setWarning(
           "exclude", "This field does not exist, or would have been excluded anyway.", i);
     }
   }
   if (annotation.isExplicit("of")) {
     for (int i :
         createListOfNonExistentFields(
             Arrays.asList(annotation.getInstance().of()), type, false, false)) {
       annotation.setWarning("of", "This field does not exist.", i);
     }
   }
 }
Пример #4
0
 public void checkForBogusFieldNames(
     JavacNode type, AnnotationValues<EqualsAndHashCode> annotation) {
   if (annotation.isExplicit("exclude")) {
     for (int i :
         createListOfNonExistentFields(
             List.from(annotation.getInstance().exclude()), type, true, true)) {
       annotation.setWarning(
           "exclude", "This field does not exist, or would have been excluded anyway.", i);
     }
   }
   if (annotation.isExplicit("of")) {
     for (int i :
         createListOfNonExistentFields(
             List.from(annotation.getInstance().of()), type, false, false)) {
       annotation.setWarning("of", "This field does not exist.", i);
     }
   }
 }