Examples of UnexpectedType


Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

      if (replType.isString()) {
        newStringValue = ((IString)replValue).getValue();
      }
      if (name.equals("uri")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        URI uri = URIUtil.createFromEncoded(newStringValue);
        // now destruct it again
        scheme = uri.getScheme();
        authority = uri.getAuthority();
        path = uri.getPath();
        query = uri.getQuery();
        fragment = uri.getFragment();
        uriPartChanged = true;
      }
      else if (name.equals("scheme")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        scheme = newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("authority")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        authority = newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("host")) {
        URI uri = value.getURI();
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        if (!ctx.getResolverRegistry().supportsHost(uri)) {
          throw new UndeclaredField(name, "The scheme " + uri.getScheme() + " does not support the host field, use authority instead.", getTypeFactory().sourceLocationType(), ctx.getCurrentAST());
        }
        uri = URIUtil.changeHost(uri, newStringValue);
        authority = uri.getAuthority();
        uriPartChanged = true;
      }
      else if (name.equals("path")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        path = newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("file")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        int i = path.lastIndexOf("/");
       
        if (i != -1) {
          path = path.substring(0, i) + "/" + newStringValue;
        }
        else {
          path = path + "/" + newStringValue; 
        }
        uriPartChanged = true;
      }
      else if (name.equals("parent")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
       
        int i = path.lastIndexOf("/");
        String parent = newStringValue;
       
        if (!parent.startsWith("/")) {
          parent = "/" + parent;
        }
        if (i != -1) {
          path =parent + path.substring(i);
        }
        else {
          path = parent;
        }
        uriPartChanged = true;
      }
      else if (name.equals("ls")) {
        throw new UnsupportedOperation("can not update the children of a location", ctx.getCurrentAST());
      }
      else if (name.equals("extension")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        String ext = newStringValue;
       
        if (path.length() > 1) {
          int index = path.lastIndexOf('.');

          if (index == -1 && !ext.isEmpty()) {
            path = path + (!ext.startsWith(".") ? "." : "") + ext;
          }
          else if (!ext.isEmpty()) {
            path = path.substring(0, index) + (!ext.startsWith(".") ? "." : "") + ext;
          }
          else {
            path = path.substring(0, index);
          }
        }
        uriPartChanged = true;
      }
      else if (name.equals("top")) {
        if (replType.isString()) {
          URI uri = URIUtil.assumeCorrect(newStringValue);
          scheme = uri.getScheme();
          authority = uri.getAuthority();
          path = uri.getPath();
          query = uri.getQuery();
          fragment = uri.getFragment();
        }
        else if (replType.isSourceLocation()) {
          ISourceLocation rep = ((ISourceLocation) repl.getValue());
          scheme = rep.getScheme();
          authority = rep.hasAuthority() ? rep.getAuthority() : null;
          path = rep.hasPath() ? rep.getPath() : null;
          query = rep.hasQuery() ? rep.getQuery() : null;
          fragment = rep.hasFragment() ? rep.getFragment() : null;
        }
        else {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        uriPartChanged = true;
      }
      else if (name.equals("fragment")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        fragment = newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("query")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        query= newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("user")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        URI uri = loc.getURI();
        if (!ctx.getResolverRegistry().supportsHost(uri)) {
          throw new UndeclaredField(name, "The scheme " + uri.getScheme() + " does not support the user field, use authority instead.", getTypeFactory().sourceLocationType(), ctx.getCurrentAST());
        }
        if (uri.getHost() != null) {
          uri = URIUtil.changeUserInformation(uri, newStringValue);
        }
        authority = uri.getAuthority();
        uriPartChanged = true;
      }
      else if (name.equals("port")) {
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
       
        URI uri = loc.getURI();
        if (!ctx.getResolverRegistry().supportsHost(uri)) {
          throw new UndeclaredField(name, "The scheme " + uri.getScheme() + " does not support the port field, use authority instead.", getTypeFactory().sourceLocationType(), ctx.getCurrentAST());
        }
        if (uri.getHost() != null) {
          int port = Integer.parseInt(((IInteger) repl.getValue()).getStringRepresentation());
          uri = URIUtil.changePort(uri, port);
        }
        authority = uri.getAuthority();
        uriPartChanged = true;
      }
      else if (name.equals("length")){
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        iLength = ((IInteger) replValue).intValue();
       
        if (iLength < 0) {
          throw RuntimeExceptionFactory.illegalArgument(replValue, ctx.getCurrentAST(), ctx.getStackTrace());
        }
      }
      else if (name.equals("offset")){
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        iOffset = ((IInteger) replValue).intValue();
       
        if (iOffset < 0) {
          RuntimeExceptionFactory.illegalArgument(replValue, ctx.getCurrentAST(), ctx.getStackTrace());
        }
      }
      else if (name.equals("begin")) {
        if (!replType.isSubtypeOf(intTuple)) {
          throw new UnexpectedType(intTuple, replType, ctx.getCurrentAST());
        }
        iBeginLine = ((IInteger) ((ITuple) replValue).get(0)).intValue();
        iBeginColumn = ((IInteger) ((ITuple) replValue).get(1)).intValue();
       
        if (iBeginColumn < 0 || iBeginLine < 0) {
          throw RuntimeExceptionFactory.illegalArgument(replValue, ctx.getCurrentAST(), ctx.getStackTrace());
        }
      }
      else if (name.equals("end")) {
        if (!replType.isSubtypeOf(intTuple)) {
          throw new UnexpectedType(intTuple, replType, ctx.getCurrentAST());
        }
        iEndLine = ((IInteger) ((ITuple) replValue).get(0)).intValue();
        iEndColumn = ((IInteger) ((ITuple) replValue).get(1)).intValue();
       
        if (iEndLine < 0 || iEndColumn < 0) {
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

    }

    @Override
    public IBooleanResult buildBacktracker(IEvaluatorContext __eval) {

      throw new UnexpectedType(TF.boolType(), this
          .interpret(__eval.getEvaluator()).getType(),
          this);

    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

    }

    @Override
    public IBooleanResult buildBacktracker(IEvaluatorContext __eval) {

      throw new UnexpectedType(TF.boolType(), this
          .interpret(__eval.getEvaluator()).getType(),
          this);

    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

    }

    @Override
    public IBooleanResult buildBacktracker(IEvaluatorContext __eval) {

      throw new UnexpectedType(TF.boolType(), this
          .interpret(__eval.getEvaluator()).getType(),
          this);

    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

    }

    @Override
    public IBooleanResult buildBacktracker(IEvaluatorContext __eval) {

      throw new UnexpectedType(TF.boolType(), this
          .interpret(__eval.getEvaluator()).getType(),
          this);

    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

    }

    @Override
    public IBooleanResult buildBacktracker(IEvaluatorContext __eval) {

      throw new UnexpectedType(TF.boolType(), this
          .interpret(__eval.getEvaluator()).getType(),
          this);
    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

    }

    @Override
    public IBooleanResult buildBacktracker(IEvaluatorContext __eval) {

      throw new UnexpectedType(TF.boolType(), this
          .interpret(__eval.getEvaluator()).getType(),
          this);

    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

    Type returnType = getReturnType();
    Type instantiatedReturnType = returnType.instantiate(ctx.getCurrentEnvt().getTypeBindings());

    if(!result.getType().isSubtypeOf(instantiatedReturnType)){
      throw new UnexpectedType(instantiatedReturnType, result.getType(), e.getLocation());
    }

    if (!returnType.isBottom() && result.getType().isBottom()) {
      throw new UnexpectedType(returnType, result.getType(), e.getLocation());
    }

    return makeResult(instantiatedReturnType, result.getValue(), eval);
  }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

      super(__param1, __param2);
    }

    @Override
    public IBooleanResult buildBacktracker(IEvaluatorContext __eval) {
      throw new UnexpectedType(TF.boolType(), this
          .interpret(__eval.getEvaluator()).getType(),
          this);
    }
View Full Code Here

Examples of org.rascalmpl.interpreter.staticErrors.UnexpectedType

    INumber iFrom = from.getValue();
    INumber iTo = to.getValue();
   
    // I still think it is ugly to do it here...
    if (!second.getType().isSubtypeOf(tf.numberType())) {
      throw new UnexpectedType(tf.numberType(), second.getType(), ctx.getCurrentAST());
    }
   
    INumber iSecond = (INumber) second.getValue();
    INumber diff = iSecond.subtract(iFrom);
   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.