当前位置: 首页>>代码示例>>Java>>正文


Java XCastedExpression类代码示例

本文整理汇总了Java中org.eclipse.xtext.xbase.XCastedExpression的典型用法代码示例。如果您正苦于以下问题:Java XCastedExpression类的具体用法?Java XCastedExpression怎么用?Java XCastedExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XCastedExpression类属于org.eclipse.xtext.xbase包,在下文中一共展示了XCastedExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mustInsertTypeCast

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:21,代码来源:TypeConvertingCompiler.java

示例2: convertArrayToList

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
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(")");
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:25,代码来源:TypeConvertingCompiler.java

示例3: isConstant

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
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());
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:21,代码来源:ConstantExpressionValidator.java

示例4: internalEvaluate

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
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());
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:25,代码来源:AbstractConstantExpressionsInterpreter.java

示例5: testSerialize_01

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
@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));
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:25,代码来源:SerializerTest.java

示例6: testSerialize_02

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
@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));
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:24,代码来源:SerializerTest.java

示例7: checkCasts

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:8,代码来源:XbaseValidator.java

示例8: _computeTypes

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
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());
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:32,代码来源:XbaseTypeComputer.java

示例9: internalToConvertedExpression

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:35,代码来源:XbaseCompiler.java

示例10: _toJavaExpression

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
protected void _toJavaExpression(XCastedExpression expr, ITreeAppendable b) {
	b.append("((");
	serialize(expr.getType(), expr, b);
	b.append(") ");
	internalToConvertedExpression(expr.getTarget(), b, getLightweightType(expr));
	b.append(")");
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:8,代码来源:XbaseCompiler.java

示例11: _format

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
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());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:XbaseFormatter.java

示例12: internalEvaluate

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
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());
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:29,代码来源:ConstantConditionsInterpreter.java

示例13: internalEvaluate

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
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());
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:29,代码来源:SwitchConstantExpressionsInterpreter.java

示例14: testReferenceToString_2

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
@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"));
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:UIStringsTest.java

示例15: toResolvedOperations

import org.eclipse.xtext.xbase.XCastedExpression; //导入依赖的package包/类
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);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:ResolvedFeaturesTest.java


注:本文中的org.eclipse.xtext.xbase.XCastedExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。