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


Java XTryCatchFinallyExpression类代码示例

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


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

示例1: checkCatchClausesOrder

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
@Check
public void checkCatchClausesOrder(XTryCatchFinallyExpression expression) {
	ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
	List<LightweightTypeReference> previousTypeReferences = new ArrayList<LightweightTypeReference>();
	for (XCatchClause catchClause : expression.getCatchClauses()) {
		LightweightTypeReference actualTypeReference = owner.toLightweightTypeReference(catchClause.getDeclaredParam().getParameterType());
		if (actualTypeReference == null) {
			continue;
		}
		if (isHandled(actualTypeReference, previousTypeReferences)) {
			error("Unreachable code: The catch block can never match. It is already handled by a previous condition.", catchClause.getDeclaredParam().getParameterType(), null, IssueCodes.UNREACHABLE_CATCH_BLOCK);
			continue;
		}
		previousTypeReferences.add(actualTypeReference);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:XbaseValidator.java

示例2: caseXTryCatchFinallyExpression

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
@Override
public Boolean caseXTryCatchFinallyExpression(XTryCatchFinallyExpression object) {
	List<XCatchClause> clauses = object.getCatchClauses();
	if (clauses.isEmpty()) {
		return Boolean.TRUE;
	}
	final List<LightweightTypeReference> caughtExceptions = Lists.newArrayList();
	boolean wasThrowable = false;
	for(XCatchClause clause: clauses) {
		JvmTypeReference caught = clause.getDeclaredParam().getParameterType();
		if (caught != null) {
			LightweightTypeReference caughtException = delegate.toLightweightReference(caught).getRawTypeReference();
			if (caughtException.isType(Throwable.class)) {
				wasThrowable = true;
			}
			caughtExceptions.add(caughtException);
		}
		delegate.collectThrownExceptions(clause.getExpression());
	}
	delegate.collectThrownExceptions(object.getFinallyExpression());
	if (wasThrowable) {
		return Boolean.FALSE;
	}
	delegate.catchExceptions(caughtExceptions).collectThrownExceptions(object.getExpression());
	return Boolean.FALSE;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:27,代码来源:ThrownExceptionSwitch.java

示例3: emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
/**
 * Syntax: '('*
 */
@Override
protected void emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a(EObject semanticObject,
		ISynNavigable transition, List<INode> nodes) {

	Keyword kw = grammarAccess.getXParenthesizedExpressionAccess().getLeftParenthesisKeyword_0();

	if (nodes == null) {
		if (semanticObject instanceof XIfExpression || semanticObject instanceof XTryCatchFinallyExpression) {
			EObject cnt = semanticObject.eContainer();
			if (cnt instanceof XExpression && !(cnt instanceof XBlockExpression)
					&& !(cnt instanceof XForLoopExpression))
				acceptUnassignedKeyword(kw, kw.getValue(), null);
		}
		if (semanticObject instanceof XConstructorCall) {
			XConstructorCall call = (XConstructorCall) semanticObject;
			if (!call.isExplicitConstructorCall() && call.getArguments().isEmpty()) {
				acceptUnassignedKeyword(kw, kw.getValue(), null);
			}
		}
	}
	acceptNodes(transition, nodes);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:26,代码来源:XbaseSyntacticSequencer.java

示例4: bracesAreAddedByOuterStructure

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
protected boolean bracesAreAddedByOuterStructure(XExpression expression) {
	EObject container = expression.eContainer();
	if (container instanceof XTryCatchFinallyExpression 
			|| container instanceof XIfExpression
			|| container instanceof XClosure
			|| container instanceof XSynchronizedExpression) {
		return true;
	}
	if (container instanceof XBlockExpression) {
		XBlockExpression blockExpression = (XBlockExpression) container;
		EList<XExpression> expressions = blockExpression.getExpressions();
		if (expressions.size() == 1 && expressions.get(0) == expression) {
			return bracesAreAddedByOuterStructure(blockExpression);
		}
	}
	if (!(container instanceof XExpression)) {
		return true;
	}
	return false;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:21,代码来源:XbaseCompiler.java

示例5: _toJavaStatement

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
protected void _toJavaStatement(XTryCatchFinallyExpression expr, ITreeAppendable outerAppendable, boolean isReferenced) {
	ITreeAppendable b = outerAppendable.trace(expr, false);
	if (isReferenced && !isPrimitiveVoid(expr)) {
		declareSyntheticVariable(expr, b);
	}
	b.newLine().append("try {").increaseIndentation();
	final boolean canBeReferenced = isReferenced && !isPrimitiveVoid(expr.getExpression());
	internalToJavaStatement(expr.getExpression(), b, canBeReferenced);
	if (canBeReferenced) {
		b.newLine().append(getVarName(expr, b)).append(" = ");
		internalToConvertedExpression(expr.getExpression(), b, getLightweightType(expr));
		b.append(";");
	}
	b.decreaseIndentation().newLine().append("}");
	appendCatchAndFinally(expr, b, isReferenced);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:XbaseCompiler.java

示例6: _exitPoints

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XTryCatchFinallyExpression expression) {
  Collection<IEarlyExitComputer.ExitPoint> tryExitPoints = this.getExitPoints(expression.getExpression());
  boolean _isNotEmpty = this.isNotEmpty(tryExitPoints);
  if (_isNotEmpty) {
    Collection<IEarlyExitComputer.ExitPoint> result = Lists.<IEarlyExitComputer.ExitPoint>newArrayList(tryExitPoints);
    EList<XCatchClause> _catchClauses = expression.getCatchClauses();
    for (final XCatchClause catchClause : _catchClauses) {
      {
        Collection<IEarlyExitComputer.ExitPoint> catchExitPoints = this.getExitPoints(catchClause.getExpression());
        boolean _isNotEmpty_1 = this.isNotEmpty(catchExitPoints);
        if (_isNotEmpty_1) {
          result.addAll(catchExitPoints);
        } else {
          return this.getExitPoints(expression.getFinallyExpression());
        }
      }
    }
    return result;
  }
  return this.getExitPoints(expression.getFinallyExpression());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:22,代码来源:DefaultEarlyExitComputer.java

示例7: internalToConvertedExpression

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的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: appendCatchAndFinally

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
protected void appendCatchAndFinally(XTryCatchFinallyExpression expr, ITreeAppendable b, boolean isReferenced) {
	final EList<XCatchClause> catchClauses = expr.getCatchClauses();
	if (!catchClauses.isEmpty()) {
		String variable = b.declareSyntheticVariable(Tuples.pair(expr, "_catchedThrowable"), "_t");
		b.append(" catch (final Throwable ").append(variable).append(") ");
		b.append("{").increaseIndentation();
		b.newLine();
		Iterator<XCatchClause> iterator = catchClauses.iterator();
		while (iterator.hasNext()) {
			XCatchClause catchClause = iterator.next();
			ITreeAppendable catchClauseAppendable = b.trace(catchClause);
			appendCatchClause(catchClause, isReferenced, variable, catchClauseAppendable);
			if (iterator.hasNext()) {
				b.append(" else ");
			}
		}
		b.append(" else {");
		b.increaseIndentation();
		final JvmType sneakyThrowType = findKnownTopLevelType(Exceptions.class, expr);
		if (sneakyThrowType == null) {
			b.append("COMPILE ERROR : '"+Exceptions.class.getCanonicalName()+"' could not be found on the classpath!");
		} else {
			b.newLine().append("throw ");
			b.append(sneakyThrowType);
			b.append(".sneakyThrow(");
			b.append(variable);
			b.append(");");
		}
		closeBlock(b);
		closeBlock(b);
	}
	final XExpression finallyExp = expr.getFinallyExpression();
	if (finallyExp != null) {
		b.append(" finally {").increaseIndentation();
		internalToJavaStatement(finallyExp, b, false);
		b.decreaseIndentation().newLine().append("}");
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:39,代码来源:XbaseCompiler.java

示例9: _findImplicitReturns

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
protected void _findImplicitReturns(final XTryCatchFinallyExpression expression, final ImplicitReturnFinder.Acceptor acceptor) {
  this.findImplicitReturns(expression.getExpression(), acceptor);
  final Consumer<XCatchClause> _function = (XCatchClause it) -> {
    this.findImplicitReturns(it.getExpression(), acceptor);
  };
  expression.getCatchClauses().forEach(_function);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:8,代码来源:XbaseImplicitReturnFinder.java

示例10: exitPoints

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的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: doTestTryCatchExpression

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
protected void doTestTryCatchExpression(XTryCatchFinallyExpression tryEx) {
	assertFeatureCall("foo", ((XThrowExpression)tryEx.getExpression()).getExpression());
	assertFeatureCall("baz", tryEx.getFinallyExpression());
	
	assertEquals(1,tryEx.getCatchClauses().size());
	XCatchClause clause = tryEx.getCatchClauses().get(0);
	assertFeatureCall("bar", clause.getExpression());
	assertEquals("java.lang.Exception", clause.getDeclaredParam().getParameterType().getIdentifier());
	assertEquals("e", clause.getDeclaredParam().getName());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:XbaseParserTest.java

示例12: doTestTryCatchExpression_2

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
protected void doTestTryCatchExpression_2(XTryCatchFinallyExpression tryEx) {
	assertFeatureCall("foo", tryEx.getExpression());
	assertNull(tryEx.getFinallyExpression());
	
	assertEquals(1,tryEx.getCatchClauses().size());
	XCatchClause clause = tryEx.getCatchClauses().get(0);
	assertFeatureCall("bar", clause.getExpression());
	assertEquals("java.lang.Exception", clause.getDeclaredParam().getParameterType().getIdentifier());
	assertEquals("e", clause.getDeclaredParam().getName());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:XbaseParserTest.java

示例13: testTryCatchExpression_3

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
/**
 * see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=356722
 */
@Test public void testTryCatchExpression_3() throws Exception {
	XTryCatchFinallyExpression tryEx = (XTryCatchFinallyExpression) expression(
			"try foo catch (java.lang.Exception) {}");
	Iterator<INode> iterator = ((XtextResource)tryEx.eResource()).getParseResult().getSyntaxErrors().iterator();
	final INode errorNode = iterator.next();
	assertEquals(")",errorNode.getText());
	assertEquals("missing RULE_ID at ')'",errorNode.getSyntaxErrorMessage().getMessage());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:12,代码来源:XbaseParserTest.java

示例14: testTryCatchExpression

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
@Test public void testTryCatchExpression() throws Exception {
	XTryCatchFinallyExpression exp = (XTryCatchFinallyExpression)  
			expressionWithExpectedType("try null catch (java.lang.Throwable t) null finally null", "String");

	assertExpected("java.lang.String", exp.getExpression());
	for (XCatchClause cc : exp.getCatchClauses()) {
		assertExpected("java.lang.String", cc.getExpression());
	}
	assertExpected(null, exp.getFinallyExpression());
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:XbaseExpectedTypeProviderTest.java

示例15: testTryCatch

import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; //导入依赖的package包/类
@Test
public void testTryCatch() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("try 1 catch(Exception e) 2");
    XExpression _expression = this.expression(_builder);
    final XTryCatchFinallyExpression expr = ((XTryCatchFinallyExpression) _expression);
    this.hasImplicitReturns(expr, expr.getExpression(), IterableExtensions.<XCatchClause>head(expr.getCatchClauses()).getExpression());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:13,代码来源:ImplicitReturnFinderTest.java


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