Пример #1
0
 @Override
 public IType getType() {
   // Adapter ca pour prendre ne ocmpte les ITypeProvider
   IType tt = facets.getTypeDenotedBy(TYPE, this);
   IType kt = facets.getTypeDenotedBy(INDEX, this, tt.getKeyType());
   IType ct = facets.getTypeDenotedBy(OF, this, tt.getContentType());
   final boolean isContainerWithNoContentsType = tt.isContainer() && ct == Types.NO_TYPE;
   final boolean isContainerWithNoKeyType = tt.isContainer() && kt == Types.NO_TYPE;
   final boolean isSpeciesWithAgentType = tt.id() == IType.SPECIES && ct.id() == IType.AGENT;
   if (isContainerWithNoContentsType || isContainerWithNoKeyType || isSpeciesWithAgentType) {
     compileTypeProviderFacets();
     final IExpression expr = facets.getExpr(INIT, VALUE, UPDATE, FUNCTION, DEFAULT);
     if (expr != null) {
       final IType exprType = expr.getType();
       if (tt.isAssignableFrom(exprType)) {
         tt = exprType;
       } else {
         if (isContainerWithNoKeyType) {
           kt = exprType.getKeyType();
         }
         if (isContainerWithNoContentsType || isSpeciesWithAgentType) {
           ct = exprType.getContentType();
         }
       }
     }
   }
   return GamaType.from(tt, kt, ct);
 }
Пример #2
0
  @Override
  public EObject getUnderlyingElement(final Object facet) {
    if (facet == null) {
      return element;
    }
    if (facet instanceof EObject) {
      return (EObject) facet;
    }

    final IExpressionDescription f =
        facet instanceof IExpressionDescription
            ? (IExpressionDescription) facet
            : facets.get(facet);
    if (f == null) {
      return element;
    }
    final EObject target = f.getTarget();
    if (target == null) {
      return element;
    }
    return getExpressionFactory().getFacetExpression(this, target);
    // if ( target.eContainer() == null ) { return target; }
    // return target.eContainer(); // Should be a Facet

    // if ( f != null && f.getTarget() != null && f.getTarget().eContainer()
    // != null ) { return f.getTarget(); }
    // return element;

  }
Пример #3
0
 protected void compileTypeProviderFacets() {
   for (final String s : typeProviderFacets) {
     final IExpressionDescription expr = facets.get(s);
     if (expr != null) {
       expr.compile(this);
     }
   }
 }
Пример #4
0
 /**
  * Method validate()
  *
  * @see msi.gaml.compilation.IDescriptionValidator#validate(msi.gaml.descriptions.IDescription)
  */
 @Override
 public void validate(final IDescription description) {
   // Verify that the state is inside a species with fsm control
   SpeciesDescription species = description.getSpeciesContext();
   String keyword = description.getKeyword();
   IArchitecture control = species.getControl();
   // String control = species.getControlName();
   if (!(control instanceof FsmArchitecture)) {
     if (keyword.equals(STATE)) {
       description.error(
           "A state can only be defined in an fsm-controlled or user-controlled species",
           IGamlIssue.WRONG_CONTEXT);
       return;
     } else if (control.getClass() == FsmArchitecture.class) {
       description.error(
           "A "
               + description.getKeyword()
               + " can only be defined in a user-controlled species (one of"
               + AllowedArchitectures
               + ")",
           IGamlIssue.WRONG_CONTEXT);
       return;
     }
   }
   if (!Assert.nameIsValid(description)) {
     return;
   }
   Facets ff = description.getFacets();
   IExpression expr = ff.getExpr(INITIAL);
   if (IExpressionFactory.TRUE_EXPR.equals(expr)) {
     assertNoOther(description, INITIAL);
   } else {
     expr = ff.getExpr(FINAL);
     if (IExpressionFactory.TRUE_EXPR.equals(expr)) {
       assertNoOther(description, FINAL);
     } else {
       assertAtLeastOne(description, INITIAL);
     }
   }
 }
Пример #5
0
 @Override
 public void dispose() {
   if (isBuiltIn()) {
     return;
   }
   facets.dispose();
   // if ( children != null ) {
   // for ( IDescription c : children ) {
   // c.dispose();
   // }
   // children.clear();
   // }
   enclosing = null;
 }
Пример #6
0
 public SymbolDescription(
     final String keyword,
     final IDescription superDesc,
     final ChildrenProvider cp,
     final EObject source,
     final Facets facets) {
   this.facets = facets;
   facets.putAsLabel(KEYWORD, keyword);
   this.keyword = keyword;
   element = source;
   if (superDesc != null) {
     // setOriginName(superDesc.getName());
     originName = superDesc.getName();
   }
   setEnclosingDescription(superDesc);
   if (getMeta().hasSequence()) {
     // this.children = new ArrayList();
     addChildren(cp.getChildren());
   } else {
     // this.children = null;
   }
 }
Пример #7
0
  private final boolean validateFacets(final boolean document) {

    // final Facets facets = getFacets();
    // Special case for "do", which can accept (at parsing time) any facet
    final boolean isDo = keyword.equals(DO);
    final boolean isBuiltIn = isBuiltIn();
    final SymbolProto proto = getMeta();
    final Set<String> missingFacets = proto.getMissingMandatoryFacets(facets);
    if (missingFacets != null) {
      error("Missing facets " + missingFacets, IGamlIssue.MISSING_FACET);
      return false;
    }
    // final Set<String> mandatories = new THashSet(proto.mandatoryFacets);
    final boolean ok =
        facets.forEachEntry(
            new TObjectObjectProcedure<String, IExpressionDescription>() {

              @Override
              public boolean execute(final String facet, final IExpressionDescription expr) {
                // mandatories.remove(facet);
                final FacetProto fp = proto.getFacet(facet);
                if (fp == null) {
                  if (!isDo) {
                    error("Unknown facet " + facet, IGamlIssue.UNKNOWN_FACET, facet);
                    return false;
                  }
                  return true;
                } else if (fp.deprecated != null) {
                  warning(
                      "Facet '" + facet + "' is deprecated: " + fp.deprecated,
                      IGamlIssue.DEPRECATED,
                      facet);
                }
                if (fp.values.size() > 0) {
                  final String val = expr.getExpression().literalValue();
                  // We have a multi-valued facet
                  if (!fp.values.contains(val)) {
                    error(
                        "Facet '"
                            + facet
                            + "' is expecting a value among "
                            + fp.values
                            + " instead of "
                            + val,
                        facet);
                    return false;
                  }
                } else {
                  IExpression exp;
                  if (fp.types[0] == IType.NEW_TEMP_ID) {
                    exp = createVarWithTypes(facet);
                    expr.setExpression(exp);
                  } else if (!fp.isLabel() && !facet.equals(WITH) && !facet.equals(DEPENDS_ON)) {
                    exp = expr.compile(SymbolDescription.this);
                  } else {
                    exp = expr.getExpression();
                  }

                  if (exp != null && !isBuiltIn) {

                    // Some expresssions might not be compiled (like
                    // "depends_on", for instance)
                    boolean compatible = false;
                    final IType actualType = exp.getType();
                    final TypesManager tm = getModelDescription().getTypesManager();
                    final IType contentType = tm.get(fp.contentType);
                    final IType keyType = tm.get(fp.keyType);
                    for (final int type : fp.types) {
                      IType requestedType = tm.get(type);
                      if (requestedType.isContainer()) {
                        requestedType = GamaType.from(requestedType, keyType, contentType);
                      }
                      compatible = compatible || actualType.isTranslatableInto(requestedType);
                      if (compatible) {
                        break;
                      }
                    }
                    if (!compatible) {
                      final String[] strings = new String[fp.types.length];
                      for (int i = 0; i < fp.types.length; i++) {
                        IType requestedType = tm.get(fp.types[i]);
                        if (requestedType.isContainer()) {
                          requestedType = GamaType.from(requestedType, keyType, contentType);
                        }
                        strings[i] = requestedType.toString();
                      }

                      warning(
                          "Facet '"
                              + facet
                              + "' is expecting "
                              + Arrays.toString(strings)
                              + " instead of "
                              + actualType,
                          IGamlIssue.SHOULD_CAST,
                          facet,
                          tm.get(fp.types[0]).toString());
                    }
                  }
                }
                return true;
              }
            });
    // if ( ok && !mandatories.isEmpty() ) {
    // error("Missing facets " + mandatories, IGamlIssue.MISSING_FACET);
    // return false;
    // }
    return ok;
  }
Пример #8
0
 @Override
 public String getName() {
   return facets.getLabel(NAME);
 }