Пример #1
0
 @Override
 public void visit(Tree.BaseType that) {
   TypeDeclaration d = that.getDeclarationModel();
   if (d != null && d.equals(dec)) {
     detected = true;
   }
 }
Пример #2
0
 private static boolean isLegalAliasFreeImport(Declaration dec, Declaration importedDec) {
   if (importedDec instanceof Value) {
     Value value = (Value) importedDec;
     TypeDeclaration td = value.getTypeDeclaration();
     return td.isObjectClass() && td.equals(dec);
   } else {
     return false;
   }
 }
 static String defaultValue(Unit unit, Type t) {
   if (isTypeUnknown(t)) {
     return "nothing";
   }
   if (unit.isOptionalType(t)) {
     return "null";
   }
   if (t.isTypeAlias() || t.isClassOrInterface() && t.getDeclaration().isAlias()) {
     return defaultValue(unit, t.getExtendedType());
   }
   if (t.isClass()) {
     TypeDeclaration c = t.getDeclaration();
     if (c.equals(unit.getBooleanDeclaration())) {
       return "false";
     } else if (c.equals(unit.getIntegerDeclaration())) {
       return "0";
     } else if (c.equals(unit.getFloatDeclaration())) {
       return "0.0";
     } else if (c.equals(unit.getStringDeclaration())) {
       return "\"\"";
     } else if (c.equals(unit.getByteDeclaration())) {
       return "0.byte";
     } else if (c.equals(unit.getTupleDeclaration())) {
       final int minimumLength = unit.getTupleMinimumLength(t);
       final List<Type> tupleTypes = unit.getTupleElementTypes(t);
       final StringBuilder sb = new StringBuilder();
       for (int i = 0; i < minimumLength; i++) {
         sb.append(sb.length() == 0 ? "[" : ", ");
         Type currentType = tupleTypes.get(i);
         if (unit.isSequentialType(currentType)) {
           currentType = unit.getSequentialElementType(currentType);
         }
         sb.append(defaultValue(unit, currentType));
       }
       sb.append(']');
       return sb.toString();
     } else if (unit.isSequentialType(t)) {
       final StringBuilder sb = new StringBuilder();
       sb.append('[');
       if (!unit.getEmptyType().isSubtypeOf(t)) {
         sb.append(defaultValue(unit, unit.getSequentialElementType(t)));
       }
       sb.append(']');
       return sb.toString();
     } else if (unit.isIterableType(t)) {
       final StringBuilder sb = new StringBuilder();
       sb.append('{');
       if (!unit.getEmptyType().isSubtypeOf(t)) {
         sb.append(defaultValue(unit, unit.getIteratedType(t)));
       }
       sb.append('}');
       return sb.toString();
     } else {
       return "nothing";
     }
   } else {
     return "nothing";
   }
 }
 @Override
 public void visit(Tree.TypedDeclaration that) {
   super.visit(that);
   Tree.Identifier id = that.getIdentifier();
   if (id != null) {
     Type type = that.getType().getTypeModel();
     if (type != null) {
       TypeDeclaration td = type.getDeclaration();
       if ((td instanceof ClassOrInterface || td instanceof TypeParameter)
           && td.equals(declaration)) {
         String text = id.getText();
         String name = declaration.getName();
         if (text.equalsIgnoreCase(name) || text.endsWith(name)) {
           identifiers.add(id);
         }
       }
     }
   }
 }