Java 类org.eclipse.xtext.xbase.XCastedExpression 实例源码

项目:xtext-extras    文件:TypeConvertingCompiler.java   
private boolean mustInsertTypeCast(XExpression expression, LightweightTypeReference actualType) {
    IResolvedTypes resolvedTypes = getResolvedTypes(expression);
    if (mustCheckForMandatoryTypeCast(resolvedTypes, expression)) {
        if (expression instanceof XAbstractFeatureCall) {
            LightweightTypeReference featureType = resolvedTypes.getActualType(((XAbstractFeatureCall) expression).getFeature());
            if (featureType != null && !featureType.isMultiType() && actualType.isAssignableFrom(featureType)) {
                return false;
            }
        }
        if (expression.eContainer() instanceof XCastedExpression) {
            XCastedExpression castedExpression = (XCastedExpression) expression.eContainer();
            LightweightTypeReference castedExpressionType = getResolvedTypes(castedExpression).getActualType(castedExpression);
            if (castedExpressionType != null) {
                return actualType.getType() != castedExpressionType.getType();  
            }
        }
        return true;
    }
    return false;
}
项目:xtext-extras    文件:TypeConvertingCompiler.java   
private void convertArrayToList(final LightweightTypeReference left, final ITreeAppendable appendable, XExpression context,
        final Later expression) {
    if (!(context.eContainer() instanceof XCastedExpression)) {
        if (context.eContainer() instanceof XAbstractFeatureCall) {
            appendable.append("((");
        } else {
            appendable.append("(");
        }
        appendable.append(left);
        appendable.append(")");
    }
    appendable.append(Conversions.class);
    appendable.append(".doWrapArray(");
    expression.exec(appendable);
    if (!(context.eContainer() instanceof XCastedExpression)) {
        if (context.eContainer() instanceof XAbstractFeatureCall) {
            appendable.append("))");
        } else {
            appendable.append(")");
        }
    } else {
        appendable.append(")");
    }
}
项目:xtext-extras    文件:ConstantExpressionValidator.java   
public boolean isConstant(final XExpression expression) {
  if (expression instanceof XAbstractFeatureCall) {
    return _isConstant((XAbstractFeatureCall)expression);
  } else if (expression instanceof XBooleanLiteral) {
    return _isConstant((XBooleanLiteral)expression);
  } else if (expression instanceof XCastedExpression) {
    return _isConstant((XCastedExpression)expression);
  } else if (expression instanceof XNumberLiteral) {
    return _isConstant((XNumberLiteral)expression);
  } else if (expression instanceof XStringLiteral) {
    return _isConstant((XStringLiteral)expression);
  } else if (expression instanceof XTypeLiteral) {
    return _isConstant((XTypeLiteral)expression);
  } else if (expression != null) {
    return _isConstant(expression);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(expression).toString());
  }
}
项目:xtext-extras    文件:AbstractConstantExpressionsInterpreter.java   
public Object internalEvaluate(final XExpression it, final Context ctx) {
  if (it instanceof XBinaryOperation) {
    return _internalEvaluate((XBinaryOperation)it, ctx);
  } else if (it instanceof XUnaryOperation) {
    return _internalEvaluate((XUnaryOperation)it, ctx);
  } else if (it instanceof XBooleanLiteral) {
    return _internalEvaluate((XBooleanLiteral)it, ctx);
  } else if (it instanceof XCastedExpression) {
    return _internalEvaluate((XCastedExpression)it, ctx);
  } else if (it instanceof XStringLiteral) {
    return _internalEvaluate((XStringLiteral)it, ctx);
  } else if (it instanceof XTypeLiteral) {
    return _internalEvaluate((XTypeLiteral)it, ctx);
  } else if (it instanceof XAnnotation) {
    return _internalEvaluate((XAnnotation)it, ctx);
  } else if (it != null) {
    return _internalEvaluate(it, ctx);
  } else if (it == null) {
    return _internalEvaluate((Void)null, ctx);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, ctx).toString());
  }
}
项目:xtext-extras    文件:SerializerTest.java   
@Test public void testSerialize_01() throws Exception {
    Resource resource = newResource("'foo' as String");
    XCastedExpression casted = (XCastedExpression) resource.getContents().get(0);

    XbaseFactory factory = XbaseFactory.eINSTANCE;
    XClosure closure = factory.createXClosure();
    XStringLiteral stringLiteral = factory.createXStringLiteral();
    stringLiteral.setValue("value");
    XBlockExpression blockExpression = factory.createXBlockExpression();
    blockExpression.getExpressions().add(stringLiteral);
    closure.setExpression(blockExpression);
    closure.setExplicitSyntax(true);
    XInstanceOfExpression instanceOfExpression = factory.createXInstanceOfExpression();
    instanceOfExpression.setExpression(closure);
    instanceOfExpression.setType(EcoreUtil.copy(casted.getType()));
    resource.getContents().clear();
    resource.getContents().add(instanceOfExpression);
    ISerializer serializer = get(ISerializer.class);
    String string = serializer.serialize(instanceOfExpression);
    assertEquals("[|\"value\"] instanceof String", string);

    XInstanceOfExpression parsedExpression = parseHelper.parse(string);
    assertTrue(EcoreUtil.equals(instanceOfExpression, parsedExpression));
}
项目:xtext-extras    文件:SerializerTest.java   
@Test public void testSerialize_02() throws Exception {
    Resource resource = newResource("'foo' as String");
    XCastedExpression casted = (XCastedExpression) resource.getContents().get(0);

    XbaseFactory factory = XbaseFactory.eINSTANCE;
    XIfExpression ifExpression = factory.createXIfExpression();
    ifExpression.setIf(factory.createXBooleanLiteral());
    XStringLiteral stringLiteral = factory.createXStringLiteral();
    stringLiteral.setValue("value");
    ifExpression.setThen(stringLiteral);
    XInstanceOfExpression instanceOfExpression = factory.createXInstanceOfExpression();
    instanceOfExpression.setExpression(ifExpression);
    instanceOfExpression.setType(EcoreUtil.copy(casted.getType()));
    resource.getContents().clear();
    resource.getContents().add(instanceOfExpression);
    ISerializer serializer = get(ISerializer.class);
    String string = serializer.serialize(instanceOfExpression);
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=464846
    assertEquals("( if(false) \"value\" ) instanceof String", string);

    XInstanceOfExpression parsedExpression = parseHelper.parse(string);
    assertTrue(EcoreUtil.equals(instanceOfExpression, parsedExpression));
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkCasts(XCastedExpression cast) {
    if (cast.getType() == null) return;
    LightweightTypeReference toType = toLightweightTypeReference(cast.getType());
    LightweightTypeReference fromType = getActualType(cast.getTarget());
    checkCast(cast.getType(), toType, fromType);
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
protected void _computeTypes(XCastedExpression object, ITypeComputationState state) {
    // TODO: should we hold on the previously known expression?
    /* 
     * ('foo' as CharSequence) as NullPointerException
     * In this case, we know - even though it's CharSequence on the Java side - 
     * that the type of ('foo' as CharSequence) is still a String
     * which is not conformant to NPE. The subsequent cast will always fail at
     * runtime. This could be detected.
     * 
     * It could be interesting to have a subtype of MultiTypeReference, e.g. CastedTypeReference
     * that still knows about the original type. This would be similar to a nested switch
     * with the difference, that we want to know which type to use on the Java side in order
     * to disambiguate overloaded methods:
     * 
     * m(Object o) {} // 1
     * m(String s) {}
     * 
     * {
     *   val o = '' as Object
     *   m(o) // calls 1
     *   o.substring(1) // valid, too - compiler could insert the cast back to String
     * }
     */
    JvmTypeReference type = object.getType();
    if (type != null) {
        state.withNonVoidExpectation().computeTypes(object.getTarget());
        state.acceptActualType(state.getReferenceOwner().toLightweightTypeReference(type));
    } else {
        state.computeTypes(object.getTarget());
    }
}
项目:xtext-extras    文件:XbaseCompiler.java   
@Override
protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) {
    if (obj instanceof XBlockExpression) {
        _toJavaExpression((XBlockExpression) obj, appendable);
    } else if (obj instanceof XCastedExpression) {
        _toJavaExpression((XCastedExpression) obj, appendable);
    } else if (obj instanceof XClosure) {
        _toJavaExpression((XClosure) obj, appendable);
    } else if (obj instanceof XAnnotation) {
        _toJavaExpression((XAnnotation) obj, appendable);
    } else if (obj instanceof XConstructorCall) {
        _toJavaExpression((XConstructorCall) obj, appendable);
    } else if (obj instanceof XIfExpression) {
        _toJavaExpression((XIfExpression) obj, appendable);
    } else if (obj instanceof XInstanceOfExpression) {
        _toJavaExpression((XInstanceOfExpression) obj, appendable);
    } else if (obj instanceof XSwitchExpression) {
        _toJavaExpression((XSwitchExpression) obj, appendable);
    } else if (obj instanceof XTryCatchFinallyExpression) {
        _toJavaExpression((XTryCatchFinallyExpression) obj, appendable);
    } else if (obj instanceof XListLiteral) {
        _toJavaExpression((XListLiteral) obj, appendable);
    } else if (obj instanceof XSetLiteral) {
        _toJavaExpression((XSetLiteral) obj, appendable);
    } else if (obj instanceof XSynchronizedExpression) {
        _toJavaExpression((XSynchronizedExpression) obj, appendable);
    } else if (obj instanceof XReturnExpression) {
        _toJavaExpression((XReturnExpression) obj, appendable);
    } else if (obj instanceof XThrowExpression) {
        _toJavaExpression((XThrowExpression) obj, appendable);
    } else {
        super.internalToConvertedExpression(obj, appendable);
    }
}
项目:xtext-extras    文件:XbaseCompiler.java   
protected void _toJavaExpression(XCastedExpression expr, ITreeAppendable b) {
    b.append("((");
    serialize(expr.getType(), expr, b);
    b.append(") ");
    internalToConvertedExpression(expr.getTarget(), b, getLightweightType(expr));
    b.append(")");
}
项目:xtext-extras    文件:XbaseFormatter.java   
protected void _format(final XCastedExpression expr, @Extension final IFormattableDocument doc) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  doc.surround(this.textRegionExtensions.regionFor(expr).keyword("as"), _function);
  doc.<XExpression>format(expr.getTarget());
  doc.<JvmTypeReference>format(expr.getType());
}
项目:xtext-extras    文件:ConstantConditionsInterpreter.java   
public EvaluationResult internalEvaluate(final XExpression it, final EvaluationContext context) {
  if (it instanceof XBinaryOperation) {
    return _internalEvaluate((XBinaryOperation)it, context);
  } else if (it instanceof XUnaryOperation) {
    return _internalEvaluate((XUnaryOperation)it, context);
  } else if (it instanceof XAbstractFeatureCall) {
    return _internalEvaluate((XAbstractFeatureCall)it, context);
  } else if (it instanceof XBooleanLiteral) {
    return _internalEvaluate((XBooleanLiteral)it, context);
  } else if (it instanceof XCastedExpression) {
    return _internalEvaluate((XCastedExpression)it, context);
  } else if (it instanceof XNullLiteral) {
    return _internalEvaluate((XNullLiteral)it, context);
  } else if (it instanceof XNumberLiteral) {
    return _internalEvaluate((XNumberLiteral)it, context);
  } else if (it instanceof XStringLiteral) {
    return _internalEvaluate((XStringLiteral)it, context);
  } else if (it instanceof XTypeLiteral) {
    return _internalEvaluate((XTypeLiteral)it, context);
  } else if (it != null) {
    return _internalEvaluate(it, context);
  } else if (it == null) {
    return _internalEvaluate((Void)null, context);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, context).toString());
  }
}
项目:xtext-extras    文件:SwitchConstantExpressionsInterpreter.java   
public Object internalEvaluate(final XExpression it, final Context ctx) {
  if (it instanceof XBinaryOperation) {
    return _internalEvaluate((XBinaryOperation)it, ctx);
  } else if (it instanceof XUnaryOperation) {
    return _internalEvaluate((XUnaryOperation)it, ctx);
  } else if (it instanceof XAbstractFeatureCall) {
    return _internalEvaluate((XAbstractFeatureCall)it, ctx);
  } else if (it instanceof XBooleanLiteral) {
    return _internalEvaluate((XBooleanLiteral)it, ctx);
  } else if (it instanceof XCastedExpression) {
    return _internalEvaluate((XCastedExpression)it, ctx);
  } else if (it instanceof XNumberLiteral) {
    return _internalEvaluate((XNumberLiteral)it, ctx);
  } else if (it instanceof XStringLiteral) {
    return _internalEvaluate((XStringLiteral)it, ctx);
  } else if (it instanceof XTypeLiteral) {
    return _internalEvaluate((XTypeLiteral)it, ctx);
  } else if (it instanceof XAnnotation) {
    return _internalEvaluate((XAnnotation)it, ctx);
  } else if (it != null) {
    return _internalEvaluate(it, ctx);
  } else if (it == null) {
    return _internalEvaluate((Void)null, ctx);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, ctx).toString());
  }
}
项目:xtext-extras    文件:UIStringsTest.java   
@Test
public void testReferenceToString_2() throws Exception {
    XExpression expr = expression("null as foo.String", true);
    assertTrue(expr instanceof XCastedExpression);
    XCastedExpression operator = (XCastedExpression) expr;
    JvmTypeReference reference = operator.getType();
    assertEquals("String", this.uiStrings.referenceToString(reference, "the-default-value"));
}
项目:xtext-extras    文件:ResolvedFeaturesTest.java   
public ResolvedFeatures toResolvedOperations(final String castExpression) {
  try {
    XExpression _expression = this.expression(castExpression);
    final XCastedExpression cast = ((XCastedExpression) _expression);
    final ResolvedFeatures result = this.overrideHelper.getResolvedFeatures(cast.getType());
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:StandardTypeParameterSubstitutorTest.java   
protected LightweightTypeReference toTypeReference(final CharSequence reference) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("null as ");
    _builder.append(reference);
    final String expression = _builder.toString();
    XExpression _expression = this.expression(expression);
    final XCastedExpression castExpression = ((XCastedExpression) _expression);
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(castExpression);
    return resolvedTypes.getActualType(castExpression);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:AbstractExpectationTest.java   
@Test
public void testExtension() {
  ExpectationTestingTypeComputer _typeComputer = this.getTypeComputer();
  final Function1<XExpression, Boolean> _function = (XExpression it) -> {
    return Boolean.valueOf((it instanceof XCastedExpression));
  };
  _typeComputer.setPredicate(_function);
  this.expects("(null as String[]).size").types(((String) null)).finalizedAs(((String) null)).queriedAs("List<String>");
}
项目:xtext-extras    文件:AbstractExpectationTest.java   
@Test
public void testBug379531_01() {
  ExpectationTestingTypeComputer _typeComputer = this.getTypeComputer();
  final Function1<XExpression, Boolean> _function = (XExpression it) -> {
    return Boolean.valueOf((it instanceof XCastedExpression));
  };
  _typeComputer.setPredicate(_function);
  this.expects("newArrayList(\'\', \'\', null as String)").types("Unbound[T]").finalizedAs("String");
}
项目:xtext-extras    文件:AbstractExpectationTest.java   
@Test
public void testBug379531_02() {
  ExpectationTestingTypeComputer _typeComputer = this.getTypeComputer();
  final Function1<XExpression, Boolean> _function = (XExpression it) -> {
    return Boolean.valueOf((it instanceof XCastedExpression));
  };
  _typeComputer.setPredicate(_function);
  this.expects("newArrayList(\'\', \'\', null as CharSequence)").types("Unbound[T]").finalizedAs("CharSequence");
}
项目:xtext-extras    文件:ArrayTypesTest.java   
protected LightweightTypeReference toTypeReference(final String reference) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("null as ");
    _builder.append(reference);
    final String expression = _builder.toString();
    XExpression _expression = this.expression(expression);
    final XCastedExpression castExpression = ((XCastedExpression) _expression);
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(castExpression);
    return resolvedTypes.getActualType(castExpression);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:ErrorSafeExtensionsTest.java   
@Test
public void testSerializeSafely() {
  XExpression _validatedExpression = this.validatedExpression("null as Unresolved");
  final XCastedExpression e = ((XCastedExpression) _validatedExpression);
  final TreeAppendable app = this.createTreeAppendable(e);
  Assert.assertTrue(this._errorSafeExtensions.hasErrors(e));
  this._errorSafeExtensions.serializeSafely(e.getType(), app);
  Assert.assertEquals("/* Unresolved */", app.getContent());
}
项目:xtext-extras    文件:ErrorSafeExtensionsTest.java   
@Test
public void testSerializeSafely_1() {
  XExpression _validatedExpression = this.validatedExpression("null as Unresolved");
  final XCastedExpression e = ((XCastedExpression) _validatedExpression);
  final TreeAppendable app = this.createTreeAppendable(e);
  Assert.assertTrue(this._errorSafeExtensions.hasErrors(e));
  this._errorSafeExtensions.serializeSafely(e.getType(), "Object", app);
  Assert.assertEquals("/* Unresolved */Object", app.getContent());
}
项目:xtext-extras    文件:ErrorSafeExtensionsTest.java   
@Test
public void testSerializeSafely_2() {
  XExpression _validatedExpression = this.validatedExpression("null as String");
  final XCastedExpression e = ((XCastedExpression) _validatedExpression);
  final TreeAppendable app = this.createTreeAppendable(e);
  Assert.assertFalse(this._errorSafeExtensions.hasErrors(e));
  this._errorSafeExtensions.serializeSafely(e.getType(), app);
  Assert.assertEquals("String", app.getContent());
}
项目:dsl-devkit    文件:AbstractCheckSemanticSequencer.java   
/**
 * Constraint:
 *     (target=XCastedExpression_XCastedExpression_1_0_0_0 type=JvmTypeReference)
 */
protected void sequence_XCastedExpression(EObject context, XCastedExpression semanticObject) {
    if(errorAcceptor != null) {
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XCASTED_EXPRESSION__TYPE) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XCASTED_EXPRESSION__TYPE));
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XCASTED_EXPRESSION__TARGET) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XCASTED_EXPRESSION__TARGET));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getXCastedExpressionAccess().getXCastedExpressionTargetAction_1_0_0_0(), semanticObject.getTarget());
    feeder.accept(grammarAccess.getXCastedExpressionAccess().getTypeJvmTypeReferenceParserRuleCall_1_1_0(), semanticObject.getType());
    feeder.finish();
}
项目:dsl-devkit    文件:AbstractCheckCfgSemanticSequencer.java   
/**
 * Constraint:
 *     (target=XCastedExpression_XCastedExpression_1_0_0_0 type=JvmTypeReference)
 */
protected void sequence_XCastedExpression(EObject context, XCastedExpression semanticObject) {
    if(errorAcceptor != null) {
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XCASTED_EXPRESSION__TYPE) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XCASTED_EXPRESSION__TYPE));
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XCASTED_EXPRESSION__TARGET) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XCASTED_EXPRESSION__TARGET));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getXCastedExpressionAccess().getXCastedExpressionTargetAction_1_0_0_0(), semanticObject.getTarget());
    feeder.accept(grammarAccess.getXCastedExpressionAccess().getTypeJvmTypeReferenceParserRuleCall_1_1_0(), semanticObject.getType());
    feeder.finish();
}
项目:xtext-extras    文件:AbstractXbaseSemanticSequencer.java   
@Deprecated
protected void sequence_XCastedExpression(EObject context, XCastedExpression semanticObject) {
    sequence_XCastedExpression(createContext(context, semanticObject), semanticObject);
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
@Override
public void computeTypes(XExpression expression, ITypeComputationState state) {
    if (expression instanceof XAssignment) {
        _computeTypes((XAssignment)expression, state);
    } else if (expression instanceof XAbstractFeatureCall) {
        _computeTypes((XAbstractFeatureCall)expression, state);
    } else if (expression instanceof XDoWhileExpression) {
        _computeTypes((XDoWhileExpression)expression, state);
    } else if (expression instanceof XWhileExpression) {
        _computeTypes((XWhileExpression)expression, state);
    } else if (expression instanceof XBlockExpression) {
        _computeTypes((XBlockExpression)expression, state);
    } else if (expression instanceof XBooleanLiteral) {
        _computeTypes((XBooleanLiteral)expression, state);
    } else if (expression instanceof XCastedExpression) {
        _computeTypes((XCastedExpression)expression, state);
    } else if (expression instanceof XClosure) {
        _computeTypes((XClosure)expression, state);
    } else if (expression instanceof XConstructorCall) {
        _computeTypes((XConstructorCall)expression, state);
    } else if (expression instanceof XForLoopExpression) {
        _computeTypes((XForLoopExpression)expression, state);
    } else if (expression instanceof XBasicForLoopExpression) {
        _computeTypes((XBasicForLoopExpression)expression, state);
    } else if (expression instanceof XIfExpression) {
        _computeTypes((XIfExpression)expression, state);
    } else if (expression instanceof XInstanceOfExpression) {
        _computeTypes((XInstanceOfExpression)expression, state);
    } else if (expression instanceof XNumberLiteral) {
        _computeTypes((XNumberLiteral)expression, state);
    } else if (expression instanceof XNullLiteral) {
        _computeTypes((XNullLiteral)expression, state);
    } else if (expression instanceof XReturnExpression) {
        _computeTypes((XReturnExpression)expression, state);
    } else if (expression instanceof XStringLiteral) {
        _computeTypes((XStringLiteral)expression, state);
    } else if (expression instanceof XSwitchExpression) {
        _computeTypes((XSwitchExpression)expression, state);
    } else if (expression instanceof XThrowExpression) {
        _computeTypes((XThrowExpression)expression, state);
    } else if (expression instanceof XTryCatchFinallyExpression) {
        _computeTypes((XTryCatchFinallyExpression)expression, state);
    } else if (expression instanceof XTypeLiteral) {
        _computeTypes((XTypeLiteral)expression, state);
    } else if (expression instanceof XVariableDeclaration) {
        _computeTypes((XVariableDeclaration)expression, state);
    } else if (expression instanceof XListLiteral) {
        _computeTypes((XListLiteral)expression, state);
    } else if (expression instanceof XSetLiteral) {
        _computeTypes((XSetLiteral)expression, state);
    } else if (expression instanceof XSynchronizedExpression) {
        _computeTypes((XSynchronizedExpression)expression, state);
    } else {
        throw new UnsupportedOperationException("Missing type computation for expression type: " + expression.eClass().getName() + " / " + state);
    }
}
项目:xtext-extras    文件:XbaseCompiler.java   
@Override
protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable appendable, boolean isReferenced) {
    if (obj instanceof XBlockExpression) {
        _toJavaStatement((XBlockExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XCastedExpression) {
        _toJavaStatement((XCastedExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XClosure) {
        _toJavaStatement((XClosure) obj, appendable, isReferenced);
    } else if (obj instanceof XConstructorCall) {
        _toJavaStatement((XConstructorCall) obj, appendable, isReferenced);
    } else if (obj instanceof XDoWhileExpression) {
        _toJavaStatement((XDoWhileExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XForLoopExpression) {
        _toJavaStatement((XForLoopExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XBasicForLoopExpression) {
        _toJavaStatement((XBasicForLoopExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XIfExpression) {
        _toJavaStatement((XIfExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XInstanceOfExpression) {
        _toJavaStatement((XInstanceOfExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XReturnExpression) {
        _toJavaStatement((XReturnExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XSwitchExpression) {
        _toJavaStatement((XSwitchExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XThrowExpression) {
        _toJavaStatement((XThrowExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XTryCatchFinallyExpression) {
        _toJavaStatement((XTryCatchFinallyExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XVariableDeclaration) {
        _toJavaStatement((XVariableDeclaration) obj, appendable, isReferenced);
    } else if (obj instanceof XWhileExpression) {
        _toJavaStatement((XWhileExpression) obj, appendable, isReferenced);
    } else if (obj instanceof XListLiteral) {
        _toJavaStatement((XListLiteral) obj, appendable, isReferenced);
    } else if (obj instanceof XSetLiteral) {
        _toJavaStatement((XSetLiteral) obj, appendable, isReferenced);
    } else if (obj instanceof XSynchronizedExpression) {
        _toJavaStatement((XSynchronizedExpression) obj, appendable, isReferenced);
    } else {
        super.doInternalToJavaStatement(obj, appendable, isReferenced);
    }
}
项目:xtext-extras    文件:XbaseCompiler.java   
protected void _toJavaStatement(XCastedExpression expr, ITreeAppendable b, boolean isReferenced) {
    internalToJavaStatement(expr.getTarget(), b, isReferenced);
}
项目:xtext-extras    文件:XbaseCompiler.java   
@Override
protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) {
    if (expr instanceof XAnnotation) {
        return false;
    }
    if (expr instanceof XListLiteral) {
        return false;
    }
    if (expr instanceof XSetLiteral) {
        return false;
    }
    if (expr instanceof XCastedExpression) {
        return false;
    }
    if (expr instanceof XInstanceOfExpression) {
        return false;
    }
    if (expr instanceof XMemberFeatureCall && isVariableDeclarationRequired((XMemberFeatureCall) expr, b))
        return true;
    EObject container = expr.eContainer();
    if ((container instanceof XVariableDeclaration)
        || (container instanceof XReturnExpression) 
        || (container instanceof XThrowExpression)) {
        return false;
    }
    if (container instanceof XIfExpression) {
        XIfExpression ifExpression = (XIfExpression) container;
        if (ifExpression.getThen() == expr || ifExpression.getElse() == expr) {
            return false;
        }
    }
    if (container instanceof XCasePart) {
        XCasePart casePart = (XCasePart) container;
        if (casePart.getThen() == expr) {
            return false;
        }
    }
    if (container instanceof XSwitchExpression) {
        XSwitchExpression switchExpression = (XSwitchExpression) container;
        if (switchExpression.getDefault() == expr) {
            return false;
        }
    }
    if (container instanceof XBlockExpression) {
        List<XExpression> siblings = ((XBlockExpression) container).getExpressions();
        if (siblings.get(siblings.size() - 1) == expr) {
            return isVariableDeclarationRequired(getFeatureCall(expr), expr, b);
        }
    }
    if (container instanceof XClosure) {
        if (((XClosure) container).getExpression() == expr) {
            return false;
        }
    }
    if (expr instanceof XAssignment) {
        XAssignment a = (XAssignment) expr;
        for (XExpression arg : getActualArguments(a)) {
            if (isVariableDeclarationRequired(arg, b, recursive)) {
                return true;
            }
        }
    }
    return super.isVariableDeclarationRequired(expr, b, recursive);
}
项目:xtext-extras    文件:XbaseInterpreter.java   
/**
 * don't call this directly. Always call evaluate() internalEvaluate()
 */
protected Object doEvaluate(XExpression expression, IEvaluationContext context, CancelIndicator indicator) {
    if (expression instanceof XAssignment) {
      return _doEvaluate((XAssignment)expression, context, indicator);
    } else if (expression instanceof XDoWhileExpression) {
      return _doEvaluate((XDoWhileExpression)expression, context, indicator);
    } else if (expression instanceof XMemberFeatureCall) {
      return _doEvaluate((XMemberFeatureCall)expression, context, indicator);
    } else if (expression instanceof XWhileExpression) {
      return _doEvaluate((XWhileExpression)expression, context, indicator);
    } else if (expression instanceof XFeatureCall) {
        return _doEvaluate((XFeatureCall)expression, context, indicator);
    } else if (expression instanceof XAbstractFeatureCall) {
        return _doEvaluate((XAbstractFeatureCall)expression, context, indicator);
    } else if (expression instanceof XBlockExpression) {
      return _doEvaluate((XBlockExpression)expression, context, indicator);
    } else if (expression instanceof XSynchronizedExpression) {
      return _doEvaluate((XSynchronizedExpression)expression, context, indicator);
    } else if (expression instanceof XBooleanLiteral) {
      return _doEvaluate((XBooleanLiteral)expression, context, indicator);
    } else if (expression instanceof XCastedExpression) {
      return _doEvaluate((XCastedExpression)expression, context, indicator);
    } else if (expression instanceof XClosure) {
      return _doEvaluate((XClosure)expression, context, indicator);
    } else if (expression instanceof XConstructorCall) {
      return _doEvaluate((XConstructorCall)expression, context, indicator);
    } else if (expression instanceof XForLoopExpression) {
      return _doEvaluate((XForLoopExpression)expression, context, indicator);
    } else if (expression instanceof XBasicForLoopExpression) {
      return _doEvaluate((XBasicForLoopExpression)expression, context, indicator);
    } else if (expression instanceof XIfExpression) {
      return _doEvaluate((XIfExpression)expression, context, indicator);
    } else if (expression instanceof XInstanceOfExpression) {
      return _doEvaluate((XInstanceOfExpression)expression, context, indicator);
    } else if (expression instanceof XNullLiteral) {
      return _doEvaluate((XNullLiteral)expression, context, indicator);
    } else if (expression instanceof XNumberLiteral) {
      return _doEvaluate((XNumberLiteral)expression, context, indicator);
    } else if (expression instanceof XReturnExpression) {
      return _doEvaluate((XReturnExpression)expression, context, indicator);
    } else if (expression instanceof XStringLiteral) {
      return _doEvaluate((XStringLiteral)expression, context, indicator);
    } else if (expression instanceof XSwitchExpression) {
      return _doEvaluate((XSwitchExpression)expression, context, indicator);
    } else if (expression instanceof XThrowExpression) {
      return _doEvaluate((XThrowExpression)expression, context, indicator);
    } else if (expression instanceof XTryCatchFinallyExpression) {
      return _doEvaluate((XTryCatchFinallyExpression)expression, context, indicator);
    } else if (expression instanceof XTypeLiteral) {
      return _doEvaluate((XTypeLiteral)expression, context, indicator);
    } else if (expression instanceof XVariableDeclaration) {
          return _doEvaluate((XVariableDeclaration)expression, context, indicator);
    } else if (expression instanceof XListLiteral) {
          return _doEvaluate((XListLiteral)expression, context, indicator);
    } else if (expression instanceof XSetLiteral) {
          return _doEvaluate((XSetLiteral)expression, context, indicator);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(expression, context, indicator).toString());
    }
}
项目:xtext-extras    文件:ConstantExpressionValidator.java   
protected boolean _isConstant(final XCastedExpression expression) {
  return (this._primitives.isPrimitive(expression.getType()) || this._typeReferences.is(expression.getType(), String.class));
}
项目:xtext-extras    文件:XbaseImplicitReturnFinder.java   
protected void _findImplicitReturns(final XCastedExpression expression, final ImplicitReturnFinder.Acceptor acceptor) {
  acceptor.accept(expression);
}
项目:xtext-extras    文件:XbaseImplicitReturnFinder.java   
public void findImplicitReturns(final XExpression expression, final ImplicitReturnFinder.Acceptor acceptor) {
  if (expression instanceof XAbstractFeatureCall) {
    _findImplicitReturns((XAbstractFeatureCall)expression, acceptor);
    return;
  } else if (expression instanceof XBlockExpression) {
    _findImplicitReturns((XBlockExpression)expression, acceptor);
    return;
  } else if (expression instanceof XBooleanLiteral) {
    _findImplicitReturns((XBooleanLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XCastedExpression) {
    _findImplicitReturns((XCastedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XClosure) {
    _findImplicitReturns((XClosure)expression, acceptor);
    return;
  } else if (expression instanceof XCollectionLiteral) {
    _findImplicitReturns((XCollectionLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XConstructorCall) {
    _findImplicitReturns((XConstructorCall)expression, acceptor);
    return;
  } else if (expression instanceof XIfExpression) {
    _findImplicitReturns((XIfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XInstanceOfExpression) {
    _findImplicitReturns((XInstanceOfExpression)expression, acceptor);
    return;
  } else if (expression instanceof XNullLiteral) {
    _findImplicitReturns((XNullLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XNumberLiteral) {
    _findImplicitReturns((XNumberLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XStringLiteral) {
    _findImplicitReturns((XStringLiteral)expression, acceptor);
    return;
  } else if (expression instanceof XSwitchExpression) {
    _findImplicitReturns((XSwitchExpression)expression, acceptor);
    return;
  } else if (expression instanceof XSynchronizedExpression) {
    _findImplicitReturns((XSynchronizedExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTryCatchFinallyExpression) {
    _findImplicitReturns((XTryCatchFinallyExpression)expression, acceptor);
    return;
  } else if (expression instanceof XTypeLiteral) {
    _findImplicitReturns((XTypeLiteral)expression, acceptor);
    return;
  } else if (expression != null) {
    _findImplicitReturns(expression, acceptor);
    return;
  } else if (expression == null) {
    _findImplicitReturns((Void)null, acceptor);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(expression, acceptor).toString());
  }
}
项目:xtext-extras    文件:ConstantConditionsInterpreter.java   
protected EvaluationResult _internalEvaluate(final XCastedExpression expression, final EvaluationContext context) {
  return this.doEvaluate(expression.getTarget(), context);
}
项目:xtext-extras    文件:AbstractConstantExpressionsInterpreter.java   
protected Object _internalEvaluate(final XCastedExpression expression, final Context ctx) {
  return this.evaluate(expression.getTarget(), ctx);
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testCastedExpression() throws Exception {
    XCastedExpression cast = (XCastedExpression) expression("bar as Foo");
    assertTrue(cast.getTarget() instanceof XFeatureCall);
    assertNotNull(cast.getType());
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testCastedExpression_2() throws Exception {
    XBinaryOperation binary = (XBinaryOperation) expression("bar.baz as Foo + zonk");
    assertTrue(binary.getExplicitArguments().get(0) instanceof XCastedExpression);
    assertTrue(binary.getExplicitArguments().get(1) instanceof XFeatureCall);
}
项目:xtext-extras    文件:XbaseExpectedTypeProviderTest.java   
@Test public void testCastedExpression() throws Exception {
    XCastedExpression expression = (XCastedExpression) expression("null as String");
    assertExpected(null, expression.getTarget());
}
项目:xtext-extras    文件:AbstractXbaseLinkingTest.java   
@Test public void testEscapedQualifiedName() throws Exception {
    XCastedExpression expression = (XCastedExpression) expression("null as ^testdata/* foobar */.^FieldAccessSub");
    assertFalse(expression.getType().getType().eIsProxy());
}