本文整理汇总了Java中org.eclipse.jdt.internal.compiler.ast.ThrowStatement类的典型用法代码示例。如果您正苦于以下问题:Java ThrowStatement类的具体用法?Java ThrowStatement怎么用?Java ThrowStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThrowStatement类属于org.eclipse.jdt.internal.compiler.ast包,在下文中一共展示了ThrowStatement类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: returnVarNameIfNullCheck
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
public char[] returnVarNameIfNullCheck(Statement stat) {
if (!(stat instanceof IfStatement)) return null;
/* Check that the if's statement is a throw statement, possibly in a block. */ {
Statement then = ((IfStatement) stat).thenStatement;
if (then instanceof Block) {
Statement[] blockStatements = ((Block) then).statements;
if (blockStatements == null || blockStatements.length == 0) return null;
then = blockStatements[0];
}
if (!(then instanceof ThrowStatement)) return null;
}
/* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ {
Expression cond = ((IfStatement) stat).condition;
if (!(cond instanceof EqualExpression)) return null;
EqualExpression bin = (EqualExpression) cond;
int operatorId = ((bin.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT);
if (operatorId != OperatorIds.EQUAL_EQUAL) return null;
if (!(bin.left instanceof SingleNameReference)) return null;
if (!(bin.right instanceof NullLiteral)) return null;
return ((SingleNameReference) bin.left).token;
}
}
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:27,代码来源:HandleNonNull.java
示例2: visit
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
/**
* @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ThrowStatement, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
*/
public boolean visit(ThrowStatement throwStatement, BlockScope scope) {
this.scribe.printNextToken(TerminalTokens.TokenNamethrow);
Expression expression = throwStatement.exception;
final int numberOfParens = (expression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
if ((numberOfParens > 0 && this.preferences.insert_space_before_parenthesized_expression_in_throw)
|| numberOfParens == 0) {
this.scribe.space();
}
expression.traverse(this, scope);
/*
* Print the semi-colon
*/
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:CodeFormatterVisitor.java
示例3: generateNullCheck
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
/**
* Generates a new statement that checks if the given variable is null, and if so, throws a {@code NullPointerException} with the
* variable name as message.
*/
public static Statement generateNullCheck(AbstractVariableDeclaration variable, ASTNode source) {
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
if (isPrimitive(variable.type)) return null;
AllocationExpression exception = new AllocationExpression();
setGeneratedBy(exception, source);
exception.type = new QualifiedTypeReference(fromQualifiedName("java.lang.NullPointerException"), new long[]{p, p, p});
setGeneratedBy(exception.type, source);
exception.arguments = new Expression[] { new StringLiteral(variable.name, pS, pE, 0)};
setGeneratedBy(exception.arguments[0], source);
ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE);
setGeneratedBy(throwStatement, source);
SingleNameReference varName = new SingleNameReference(variable.name, p);
setGeneratedBy(varName, source);
NullLiteral nullLiteral = new NullLiteral(pS, pE);
setGeneratedBy(nullLiteral, source);
EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.EQUAL_EQUAL);
equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE;
setGeneratedBy(equalExpression, source);
IfStatement ifStatement = new IfStatement(equalExpression, throwStatement, 0, 0);
setGeneratedBy(ifStatement, source);
return ifStatement;
}
开发者ID:redundent,项目名称:lombok,代码行数:30,代码来源:EclipseHandlerUtil.java
示例4: createPrivateDefaultConstructor
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
private void createPrivateDefaultConstructor(EclipseNode typeNode, EclipseNode sourceNode) {
ASTNode source = sourceNode.get();
TypeDeclaration typeDeclaration = ((TypeDeclaration) typeNode.get());
long p = (long) source.sourceStart << 32 | source.sourceEnd;
ConstructorDeclaration constructor = new ConstructorDeclaration(((CompilationUnitDeclaration) typeNode.top().get()).compilationResult);
constructor.modifiers = ClassFileConstants.AccPrivate;
constructor.selector = typeDeclaration.name;
constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper);
constructor.constructorCall.sourceStart = source.sourceStart;
constructor.constructorCall.sourceEnd = source.sourceEnd;
constructor.thrownExceptions = null;
constructor.typeParameters = null;
constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;
constructor.arguments = null;
AllocationExpression exception = new AllocationExpression();
setGeneratedBy(exception, source);
long[] ps = new long[JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION.length];
Arrays.fill(ps, p);
exception.type = new QualifiedTypeReference(JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION, ps);
setGeneratedBy(exception.type, source);
exception.arguments = new Expression[] {
new StringLiteral(UNSUPPORTED_MESSAGE, source.sourceStart, source.sourceEnd, 0)
};
setGeneratedBy(exception.arguments[0], source);
ThrowStatement throwStatement = new ThrowStatement(exception, source.sourceStart, source.sourceEnd);
setGeneratedBy(throwStatement, source);
constructor.statements = new Statement[] {throwStatement};
injectMethod(typeNode, constructor);
}
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:38,代码来源:HandleUtilityClass.java
示例5: endVisit
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
@Override
public void endVisit(ThrowStatement x, BlockScope scope) {
try {
SourceInfo info = makeSourceInfo(x);
JExpression exception = pop(x.exception);
push(new JThrowStatement(info, exception));
} catch (Throwable e) {
throw translateException(x, e);
}
}
开发者ID:WeTheInternet,项目名称:xapi,代码行数:11,代码来源:GwtAstBuilder.java
示例6: generateNullCheck
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
/**
* Generates a new statement that checks if the given variable is null, and if so, throws a specified exception with the
* variable name as message.
*
* @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}.
*/
public static Statement generateNullCheck(AbstractVariableDeclaration variable, EclipseNode sourceNode) {
NullCheckExceptionType exceptionType = sourceNode.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE);
if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION;
ASTNode source = sourceNode.get();
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
if (isPrimitive(variable.type)) return null;
AllocationExpression exception = new AllocationExpression();
setGeneratedBy(exception, source);
int partCount = 1;
String exceptionTypeStr = exceptionType.getExceptionType();
for (int i = 0; i < exceptionTypeStr.length(); i++) if (exceptionTypeStr.charAt(i) == '.') partCount++;
long[] ps = new long[partCount];
Arrays.fill(ps, 0L);
exception.type = new QualifiedTypeReference(fromQualifiedName(exceptionTypeStr), ps);
setGeneratedBy(exception.type, source);
exception.arguments = new Expression[] {
new StringLiteral(exceptionType.toExceptionMessage(new String(variable.name)).toCharArray(), pS, pE, 0)
};
setGeneratedBy(exception.arguments[0], source);
ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE);
setGeneratedBy(throwStatement, source);
SingleNameReference varName = new SingleNameReference(variable.name, p);
setGeneratedBy(varName, source);
NullLiteral nullLiteral = new NullLiteral(pS, pE);
setGeneratedBy(nullLiteral, source);
EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.EQUAL_EQUAL);
equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE;
setGeneratedBy(equalExpression, source);
Block throwBlock = new Block(0);
throwBlock.statements = new Statement[] {throwStatement};
throwBlock.sourceStart = pS; throwBlock.sourceEnd = pE;
setGeneratedBy(throwBlock, source);
IfStatement ifStatement = new IfStatement(equalExpression, throwBlock, 0, 0);
setGeneratedBy(ifStatement, source);
return ifStatement;
}
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:48,代码来源:EclipseHandlerUtil.java
示例7: visit
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
@Override public boolean visit(ThrowStatement node, BlockScope scope) {
fixPositions(setGeneratedBy(node, source));
return super.visit(node, scope);
}
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:5,代码来源:SetGeneratedByVisitor.java
示例8: endVisit
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
public void endVisit(ThrowStatement throwStatement, BlockScope scope) {
acceptException((ReferenceBinding)throwStatement.exception.resolvedType);
super.endVisit(throwStatement, scope);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:5,代码来源:ThrownExceptionFinder.java
示例9: isGuardClause
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
private boolean isGuardClause(Block block) {
return !commentStartsBlock(block.sourceStart, block.sourceEnd)
&& block.statements != null
&& block.statements.length == 1
&& (block.statements[0] instanceof ReturnStatement || block.statements[0] instanceof ThrowStatement);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:7,代码来源:CodeFormatterVisitor.java
示例10: consumeStatementThrow
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
protected void consumeStatementThrow() {
// ThrowStatement ::= 'throw' Expression ';'
this.expressionLengthPtr--;
pushOnAstStack(new ThrowStatement(this.expressionStack[this.expressionPtr--], this.intStack[this.intPtr--], this.endStatementPosition));
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:6,代码来源:Parser.java
示例11: visit
import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; //导入依赖的package包/类
@Override public boolean visit(ThrowStatement node, BlockScope scope) {
setGeneratedBy(node, source);
applyOffsetASTNode(node);
return super.visit(node, scope);
}
开发者ID:redundent,项目名称:lombok,代码行数:6,代码来源:SetGeneratedByVisitor.java
注:本文中的org.eclipse.jdt.internal.compiler.ast.ThrowStatement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论