コード例 #1
0
 // handles assignment to subscription expression
 @Override
 public RType afterSubscriptionType(
     List<RExpression> indices, RType valueType, boolean isSingleBracket) {
   if (indices.isEmpty()) {
     return this;
   }
   if (indices.size() > 1) {
     return RUnknownType.INSTANCE;
   }
   if (isSingleBracket && valueType instanceof RListType) {
     RListType list = (RListType) valueType;
     if (!list.myPrecise) {
       return RUnknownType.INSTANCE;
     }
     if (list.myPositionalTypes.isEmpty()) {
       return RUnknownType.INSTANCE;
     }
     valueType = list.myPositionalTypes.get(0).myType;
   }
   RExpression index = indices.get(0);
   RListType resultType = new RListType(this);
   if (index instanceof RStringLiteralExpression) {
     String quoted = index.getText();
     String indexName = quoted.substring(1, quoted.length() - 1);
     if (valueType instanceof RNullType) {
       resultType.removeField(indexName);
     } else {
       resultType.addField(indexName, valueType);
     }
   }
   if (index instanceof RNumericLiteralExpression) {
     try {
       int i = Integer.parseInt(index.getText());
       if (valueType instanceof RNullType) {
         resultType.removeField(i - 1);
       } else {
         resultType.addField(i - 1, valueType);
       }
     } catch (NumberFormatException e) {
       // do nothing
     }
   }
   return resultType;
 }
コード例 #2
0
 @Override
 public RType afterMemberType(String tag, RType valueType) {
   RListType clone = clone();
   if (valueType instanceof RNullType) {
     clone.removeField(tag);
   } else {
     clone.addField(tag, valueType);
   }
   return clone;
 }