本文整理汇总了Java中org.eclipse.xtext.xbase.XReturnExpression类的典型用法代码示例。如果您正苦于以下问题:Java XReturnExpression类的具体用法?Java XReturnExpression怎么用?Java XReturnExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XReturnExpression类属于org.eclipse.xtext.xbase包,在下文中一共展示了XReturnExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: checkInvalidReturnExpression
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
@Check
public void checkInvalidReturnExpression(XExpression expression) {
final EReference contFeature = (EReference) expression.eContainingFeature();
final Map<EReference, EarlyExitKind> map = getDisallowedEarlyExitReferences();
if (map.containsKey(contFeature)) {
EarlyExitKind exitKind = map.get(contFeature);
List<XExpression> returns = newArrayList();
collectExits(expression, returns);
for (XExpression expr : returns) {
if (expr instanceof XReturnExpression && (exitKind == EarlyExitKind.RETURN || exitKind == EarlyExitKind.BOTH)) {
error("A return expression is not allowed in this context.", expr, null, IssueCodes.INVALID_EARLY_EXIT);
}
if (expr instanceof XThrowExpression && (exitKind == EarlyExitKind.THROW || exitKind == EarlyExitKind.BOTH)) {
error("A throw expression is not allowed in this context.", expr, null, IssueCodes.INVALID_EARLY_EXIT);
}
}
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:EarlyExitValidator.java
示例2: checkValidReturn
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
protected void checkValidReturn(XReturnExpression object, ITypeComputationState state) {
// if the expectation comes from a method's return type
// then it is legal, thus we must check if the return is
// contained in a throw expression
if (hasThrowableExpectation(state) &&
EcoreUtil2.getContainerOfType(object, XThrowExpression.class) != null) {
state.addDiagnostic(new EObjectDiagnosticImpl(
Severity.ERROR,
IssueCodes.INVALID_RETURN,
"Invalid return inside throw.",
object,
null,
-1,
new String[] {
}));
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:18,代码来源:XbaseTypeComputer.java
示例3: checkValidReturnExpression
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
protected void checkValidReturnExpression(XExpression returnValue, ITypeComputationState expressionState) {
ITypeComputationResult result = expressionState.computeTypes(returnValue);
LightweightTypeReference actualType = result.getActualExpressionType();
int conformanceFlags = result.getConformanceFlags();
if (actualType.isPrimitiveVoid() && (conformanceFlags & ConformanceFlags.NO_IMPLICIT_RETURN) != 0) {
String message = "Invalid return's expression.";
if (returnValue instanceof XReturnExpression) {
// when the return's expression is directory a return
// we provide a more detailed error
message = "Return cannot be nested.";
}
expressionState.addDiagnostic(new EObjectDiagnosticImpl(
Severity.ERROR,
IssueCodes.INVALID_RETURN,
message,
returnValue,
null,
-1,
new String[] {
}));
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:23,代码来源:XbaseTypeComputer.java
示例4: checkReturn
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
@Check
public void checkReturn(XReturnExpression expr) {
XExpression returnedExpression = expr.getExpression();
IResolvedTypes resolvedTypes = typeResolver.resolveTypes(expr);
LightweightTypeReference expectedReturnType = resolvedTypes.getExpectedReturnType(expr);
if (expectedReturnType == null) {
return;
}
if (expectedReturnType.isPrimitiveVoid()) {
if (returnedExpression != null)
error("Void functions cannot return a value.", expr, null,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN);
} else {
if (returnedExpression == null)
error("The function must return a result of type " + expectedReturnType.getHumanReadableName() + ".", expr, null,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN);
else {
LightweightTypeReference expressionType = getActualType(returnedExpression);
if (expressionType.isPrimitiveVoid()) {
error("Incompatible types. Expected " + getNameOfTypes(expectedReturnType) + " but was "
+ canonicalName(expressionType), returnedExpression, null,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES);
}
}
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:28,代码来源:XbaseValidator.java
示例5: collectExits
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
protected void collectExits(EObject expr, List<XExpression> found) {
if (expr instanceof XReturnExpression) {
found.add((XExpression) expr);
} else if (expr instanceof XThrowExpression) {
found.add((XExpression) expr);
} else if (expr instanceof XClosure) {
return;
}
for (EObject child : expr.eContents()) {
collectExits(child, found);
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:13,代码来源:EarlyExitValidator.java
示例6: _computeTypes
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
protected void _computeTypes(XReturnExpression object, ITypeComputationState state) {
XExpression returnValue = object.getExpression();
ITypeComputationState expressionState = state.withReturnExpectation();
checkValidReturn(object, state);
LightweightTypeReference primitiveVoid = getPrimitiveVoid(state);
if (returnValue != null) {
checkValidReturnExpression(returnValue, expressionState);
state.acceptActualType(primitiveVoid, ConformanceFlags.NO_IMPLICIT_RETURN);
} else {
state.acceptActualType(primitiveVoid, ConformanceFlags.EXPLICIT_VOID_RETURN);
state.acceptActualType(primitiveVoid, ConformanceFlags.NO_IMPLICIT_RETURN);
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:16,代码来源:XbaseTypeComputer.java
示例7: internalToConvertedExpression
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的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
示例8: _toJavaStatement
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
/**
* @param isReferenced unused in this context but necessary for dispatch signature
*/
protected void _toJavaStatement(XReturnExpression expr, ITreeAppendable b, boolean isReferenced) {
if (expr.getExpression()!=null) {
internalToJavaStatement(expr.getExpression(), b, true);
b.newLine().append("return ");
LightweightTypeReference returnTypeToCompile = findRealReturnType(expr);
internalToConvertedExpression(expr.getExpression(), b, returnTypeToCompile);
b.append(";");
} else {
b.newLine().append("return;");
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:15,代码来源:XbaseCompiler.java
示例9: _format
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
protected void _format(final XReturnExpression expr, @Extension final IFormattableDocument format) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.<XExpression>prepend(expr.getExpression(), _function);
format.<XExpression>format(expr.getExpression());
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:8,代码来源:XbaseFormatter.java
示例10: exitPoints
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
protected Collection<IEarlyExitComputer.ExitPoint> exitPoints(final XExpression expression) {
if (expression instanceof XDoWhileExpression) {
return _exitPoints((XDoWhileExpression)expression);
} else if (expression instanceof XWhileExpression) {
return _exitPoints((XWhileExpression)expression);
} else if (expression instanceof XAbstractFeatureCall) {
return _exitPoints((XAbstractFeatureCall)expression);
} else if (expression instanceof XBasicForLoopExpression) {
return _exitPoints((XBasicForLoopExpression)expression);
} else if (expression instanceof XBlockExpression) {
return _exitPoints((XBlockExpression)expression);
} else if (expression instanceof XConstructorCall) {
return _exitPoints((XConstructorCall)expression);
} else if (expression instanceof XForLoopExpression) {
return _exitPoints((XForLoopExpression)expression);
} else if (expression instanceof XIfExpression) {
return _exitPoints((XIfExpression)expression);
} else if (expression instanceof XReturnExpression) {
return _exitPoints((XReturnExpression)expression);
} else if (expression instanceof XSwitchExpression) {
return _exitPoints((XSwitchExpression)expression);
} else if (expression instanceof XSynchronizedExpression) {
return _exitPoints((XSynchronizedExpression)expression);
} else if (expression instanceof XThrowExpression) {
return _exitPoints((XThrowExpression)expression);
} else if (expression instanceof XTryCatchFinallyExpression) {
return _exitPoints((XTryCatchFinallyExpression)expression);
} else if (expression instanceof XVariableDeclaration) {
return _exitPoints((XVariableDeclaration)expression);
} else if (expression != null) {
return _exitPoints(expression);
} else {
throw new IllegalArgumentException("Unhandled parameter types: " +
Arrays.<Object>asList(expression).toString());
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:37,代码来源:DefaultEarlyExitComputer.java
示例11: _format
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
protected void _format(final XReturnExpression expr, final FormattableDocument format) {
final Procedure1<FormattingDataInit> _function = (FormattingDataInit it) -> {
it.oneSpace();
};
Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _prepend = this._formattingDataFactory.prepend(this._nodeModelAccess.nodeForEObject(expr.getExpression()), _function);
format.operator_add(_prepend);
this.format(expr.getExpression(), format);
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:XbaseFormatter2.java
示例12: hasReturnExpression
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
public boolean hasReturnExpression(final XExpression expression) {
boolean _switchResult = false;
boolean _matched = false;
if (expression instanceof XReturnExpression) {
_matched=true;
_switchResult = true;
}
if (!_matched) {
if (expression instanceof XThrowExpression) {
_matched=true;
_switchResult = true;
}
}
if (!_matched) {
if (expression instanceof XClosure) {
_matched=true;
_switchResult = false;
}
}
if (!_matched) {
final Function1<EObject, Boolean> _function = (EObject content) -> {
boolean _switchResult_1 = false;
boolean _matched_1 = false;
if (content instanceof XExpression) {
_matched_1=true;
_switchResult_1 = this.hasReturnExpression(((XExpression)content));
}
if (!_matched_1) {
_switchResult_1 = false;
}
return Boolean.valueOf(_switchResult_1);
};
_switchResult = IterableExtensions.<EObject>exists(expression.eContents(), _function);
}
return _switchResult;
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:37,代码来源:AbstractBatchReturnTypeTest.java
示例13: testReturnExpressionInBlock_1
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
@Test public void testReturnExpressionInBlock_1() throws Exception {
XBlockExpression block = (XBlockExpression) expression(
"{ return 1 2 }");
assertEquals(2, block.getExpressions().size());
assertTrue(block.getExpressions().get(0) instanceof XReturnExpression);
XReturnExpression returnExpression = (XReturnExpression) block.getExpressions().get(0);
assertTrue(returnExpression.getExpression() instanceof XNumberLiteral);
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:XbaseParserTest.java
示例14: testReturnExpressionInBlock_2
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
@Test public void testReturnExpressionInBlock_2() throws Exception {
XBlockExpression block = (XBlockExpression) expression(
"{ return }");
assertEquals(1, block.getExpressions().size());
assertTrue(block.getExpressions().get(0) instanceof XReturnExpression);
XReturnExpression returnExpression = (XReturnExpression) block.getExpressions().get(0);
assertNull(returnExpression.getExpression());
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:XbaseParserTest.java
示例15: testReturnExpressionInBlock_3
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
@Test public void testReturnExpressionInBlock_3() throws Exception {
XBlockExpression block = (XBlockExpression) expression(
"{ return; 1 2 }");
assertEquals(3, block.getExpressions().size());
assertTrue(block.getExpressions().get(0) instanceof XReturnExpression);
XReturnExpression returnExpression = (XReturnExpression) block.getExpressions().get(0);
assertNull(returnExpression.getExpression());
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:XbaseParserTest.java
示例16: testFeatureCallVarArgument_04
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
@Test
public void testFeatureCallVarArgument_04() {
ExpectationTestingTypeComputer _typeComputer = this.getTypeComputer();
final Function1<XExpression, Boolean> _function = (XExpression it) -> {
return Boolean.valueOf((it instanceof XReturnExpression));
};
_typeComputer.setPredicate(_function);
this.expects("new foo.ClassWithGenericMethod().genericMethod(return null)").types("Unbound[T]").finalizedAs("Object");
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:10,代码来源:AbstractExpectationTest.java
示例17: checkReturnExpressions
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
/**
* Checks that return expressions do not occur in check implementations.
*
* @param expression
* the expression
*/
@Check
public void checkReturnExpressions(final XReturnExpression expression) {
if (expression.getExpression() != null) {
error(Messages.CheckJavaValidator_NO_RETURN_IN_CHECK_IMPL, XbasePackage.Literals.XRETURN_EXPRESSION__EXPRESSION, IssueCodes.RETURN_IN_IMPL);
}
}
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:13,代码来源:CheckJavaValidator.java
示例18: sequence_XReturnExpression
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
@Deprecated
protected void sequence_XReturnExpression(EObject context, XReturnExpression semanticObject) {
sequence_XReturnExpression(createContext(context, semanticObject), semanticObject);
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:5,代码来源:AbstractXbaseSemanticSequencer.java
示例19: isValueExpectedRecursive
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
protected boolean isValueExpectedRecursive(XExpression expr) {
EStructuralFeature feature = expr.eContainingFeature();
EObject container = expr.eContainer();
// is part of block
if (container instanceof XBlockExpression) {
XBlockExpression blockExpression = (XBlockExpression) container;
final List<XExpression> expressions = blockExpression.getExpressions();
if (expressions.get(expressions.size()-1) != expr) {
return false;
}
}
// no expectation cases
if (feature == XbasePackage.Literals.XTRY_CATCH_FINALLY_EXPRESSION__FINALLY_EXPRESSION
|| feature == XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__BODY
|| feature == XbasePackage.Literals.XFOR_LOOP_EXPRESSION__EACH_EXPRESSION) {
return false;
}
// is value expected
if (container instanceof XAbstractFeatureCall
|| container instanceof XConstructorCall
|| container instanceof XAssignment
|| container instanceof XVariableDeclaration
|| container instanceof XReturnExpression
|| container instanceof XThrowExpression
|| feature == XbasePackage.Literals.XFOR_LOOP_EXPRESSION__FOR_EXPRESSION
|| feature == XbasePackage.Literals.XSWITCH_EXPRESSION__SWITCH
|| feature == XbasePackage.Literals.XCASE_PART__CASE
|| feature == XbasePackage.Literals.XIF_EXPRESSION__IF
|| feature == XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__PREDICATE
|| feature == XbasePackage.Literals.XBASIC_FOR_LOOP_EXPRESSION__EXPRESSION
|| feature == XbasePackage.Literals.XSYNCHRONIZED_EXPRESSION__PARAM) {
return true;
}
if (isLocalClassSemantics(container) || logicalContainerProvider.getLogicalContainer(expr) != null) {
LightweightTypeReference expectedReturnType = typeResolver.resolveTypes(expr).getExpectedReturnType(expr);
return expectedReturnType == null || !expectedReturnType.isPrimitiveVoid();
}
if (container instanceof XCasePart || container instanceof XCatchClause) {
container = container.eContainer();
}
if (container instanceof XExpression) {
return isValueExpectedRecursive((XExpression) container);
}
return true;
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:47,代码来源:XbaseValidator.java
示例20: computeTypes
import org.eclipse.xtext.xbase.XReturnExpression; //导入依赖的package包/类
@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);
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:57,代码来源:XbaseTypeComputer.java
注:本文中的org.eclipse.xtext.xbase.XReturnExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论