コード例 #1
0
 private CollectionLiteralAnnotationTerm startCollection(Tree.Term t) {
   Unit unit = t.getUnit();
   // Continue the visit to collect the elements
   ProducedType iteratedType = unit.getIteratedType(parameter().getType());
   TypeDeclaration declaration = iteratedType.getDeclaration();
   LiteralAnnotationTerm factory;
   if (unit.getStringDeclaration().equals(declaration)) {
     factory = StringLiteralAnnotationTerm.FACTORY;
   } else if (unit.getIntegerDeclaration().equals(declaration)) {
     factory = IntegerLiteralAnnotationTerm.FACTORY;
   } else if (unit.getCharacterDeclaration().equals(declaration)) {
     factory = CharacterLiteralAnnotationTerm.FACTORY;
   } else if (unit.getBooleanDeclaration().equals(declaration)) {
     factory = BooleanLiteralAnnotationTerm.FACTORY;
   } else if (unit.getFloatDeclaration().equals(declaration)) {
     factory = FloatLiteralAnnotationTerm.FACTORY;
   } else if (Decl.isEnumeratedTypeWithAnonCases(iteratedType)) {
     factory = ObjectLiteralAnnotationTerm.FACTORY;
   } else if (Decl.isAnnotationClass(declaration)) {
     t.addError(
         "compiler bug: iterables of annotation classes or annotation constructors not supported as literal "
             + (checkingDefaults ? "defaulted parameters" : "arguments"));
     return null;
   } else if (iteratedType.isSubtypeOf(
       ((TypeDeclaration) unit.getLanguageModuleDeclarationDeclaration("Declaration"))
           .getType())) {
     factory = DeclarationLiteralAnnotationTerm.FACTORY;
   } else {
     throw new RuntimeException();
   }
   CollectionLiteralAnnotationTerm result = this.elements;
   this.elements = new CollectionLiteralAnnotationTerm(factory);
   return result;
 }
コード例 #2
0
  private boolean isConstantValue(Declaration d) {
    if (d instanceof Value) {
      Value value = (Value) d;
      if (value.isShared() && !value.isVariable()) {
        Unit unit = value.getUnit();
        TypeDeclaration type = value.getTypeDeclaration();

        if (type == unit.getSequentialDeclaration()) {
          ProducedType elementType = unit.getIteratedType(value.getType());
          type = elementType.getDeclaration();
        }

        if (unit.getStringDeclaration().equals(type)
            || unit.getIntegerDeclaration().equals(type)
            || unit.getFloatDeclaration().equals(type)
            || unit.getCharacterDeclaration().equals(type)) {
          return true;
        }
      }
    }
    return false;
  }