コード例 #1
0
ファイル: AliasHasNoSetter.java プロジェクト: nest/nestml
  @Override
  public void check(final ASTAliasDecl alias) {
    final ASTDeclaration decl = alias.getDeclaration();
    checkState(decl.getEnclosingScope().isPresent(), "No scope assigned to the node: " + decl);
    final Scope scope = decl.getEnclosingScope().get();

    if (alias.isAlias()) {
      // per default aliases have only a single variable. it is checked by the AliasHasOneVar coco.
      final String aliasVar = decl.getVars().get(0);
      final String varTypeName = AstUtils.computeTypeName(decl.getDatatype());
      if (isSetterPresent(aliasVar, varTypeName, scope)
          || AliasInverter.isRelativeExpression(decl.getExpr().get())) {
        Log.trace(
            "The setter will be generated or used for the alias  at "
                + alias.get_SourcePositionStart().toString(),
            ERROR_CODE);
      }
    }
  }
コード例 #2
0
ファイル: VarHasTypeName.java プロジェクト: rcfduarte/nestml
  @Override
  public void check(final ASTDeclaration astDeclaration) {
    checkArgument(
        astDeclaration.getEnclosingScope().isPresent(),
        "Declaration hast no scope. Run symboltable creator.");
    final Scope scope = astDeclaration.getEnclosingScope().get();

    for (String var : astDeclaration.getVars()) {
      // tries to resolve the variable name as type. if it is possible, then the variable name
      // clashes with type name is reported as an error
      final Optional<NESTMLTypeSymbol> res = scope.resolve(var, NESTMLTypeSymbol.KIND);

      // could resolve type as variable, report an error
      if (res.isPresent()) {
        Log.error(
            ERROR_CODE + ":" + String.format(ERROR_MSG_FORMAT, var),
            astDeclaration.get_SourcePositionEnd());
      }
    }
  }