• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TryStmt类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public Boolean visit(final TryStmt n1, final Node arg) {
	final TryStmt n2 = (TryStmt) arg;

	if (!nodeEquals(n1.getTryBlock(), n2.getTryBlock())) {
		return Boolean.FALSE;
	}

	if (!nodesEquals(n1.getCatchs(), n2.getCatchs())) {
		return Boolean.FALSE;
	}

	if (!nodeEquals(n1.getFinallyBlock(), n2.getFinallyBlock())) {
		return Boolean.FALSE;
	}

	return Boolean.TRUE;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:18,代码来源:EqualsVisitor.java


示例2: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public void visit(final TryStmt n, final A arg) {
	visitComment(n.getComment(), arg);
	if (n.getResources() != null) {
		for (final VariableDeclarationExpr v : n.getResources()) {
			v.accept(this, arg);
		}
	}
	n.getTryBlock().accept(this, arg);
	if (n.getCatchs() != null) {
		for (final CatchClause c : n.getCatchs()) {
			c.accept(this, arg);
		}
	}
	if (n.getFinallyBlock() != null) {
		n.getFinallyBlock().accept(this, arg);
	}
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:18,代码来源:VoidVisitorAdapter.java


示例3: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public void visit(final TryStmt n, final A arg) {
    jw.write(n); 
    visitComment(n.getComment(), arg);
    if (n.getResources() != null) {
        for (final VariableDeclarationExpr v : n.getResources()) {
            v.accept(this, arg);
        }
    }
    n.getTryBlock().accept(this, arg);
    if (n.getCatchs() != null) {
        for (final CatchClause c : n.getCatchs()) {
            c.accept(this, arg);
        }
    }
    if (n.getFinallyBlock() != null) {
        n.getFinallyBlock().accept(this, arg);
    }
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:19,代码来源:JsonVisitorAdapter.java


示例4: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public Boolean visit(final TryStmt n1, final Node arg) {
	final TryStmt n2 = (TryStmt) arg;

	if (!nodeEquals(n1.getTryBlock(), n2.getTryBlock())) {
		return false;
	}

	if (!nodesEquals(n1.getCatchs(), n2.getCatchs())) {
		return false;
	}
	
	if(!nodesEquals(n1.getResources(), n2.getResources())) {
		return false;
	}

	if (!nodeEquals(n1.getFinallyBlock(), n2.getFinallyBlock())) {
		return false;
	}

	return true;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:22,代码来源:EqualsVisitor.java


示例5: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public Node visit(final TryStmt n, final A arg) {
	visitComment(n, arg);
	final List<VariableDeclarationExpr> types = n.getResources();
	for (int i = 0; i < types.size(); i++) {
		n.getResources().set(i,
				(VariableDeclarationExpr) n.getResources().get(i).accept(this, arg));
	}
	n.setTryBlock((BlockStmt) n.getTryBlock().accept(this, arg));
	final List<CatchClause> catchs = n.getCatchs();
	if (catchs != null) {
		for (int i = 0; i < catchs.size(); i++) {
			catchs.set(i, (CatchClause) catchs.get(i).accept(this, arg));
		}
		removeNulls(catchs);
	}
	if (n.getFinallyBlock() != null) {
		n.setFinallyBlock((BlockStmt) n.getFinallyBlock().accept(this, arg));
	}
	return n;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:21,代码来源:ModifierVisitorAdapter.java


示例6: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override
public void visit(final TryStmt n, final Void arg) {
	if (canAddNewLine(n)) printer.println();

	printJavaComment(n.getComment(), arg);
	printer.print("try ");
	if (!n.getResources().isEmpty()) {
		printer.print("(");
		Iterator<Expression> resources = n.getResources().iterator();
		boolean first = true;
		while (resources.hasNext()) {
			resources.next().accept(this, arg);
			if (resources.hasNext()) {
				printer.print(";");
				printer.println();
				if (first) {
					printer.indent();
				}
			}
			first = false;
		}
		if (n.getResources().size() > 1) {
			printer.unindent();
		}
		printer.print(") ");
	}
	n.getTryBlock().accept(this, arg);
	for (final CatchClause c : n.getCatchClauses()) {
		c.accept(this, arg);
	}
	if (n.getFinallyBlock().isPresent()) {
		printer.print(" finally ");
		n.getFinallyBlock().get().accept(this, arg);
	}

	if (getNext(n) != null) printer.println();
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:38,代码来源:SrcRemapper.java


示例7: isBlockStmt

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
private static boolean isBlockStmt(Node n) {
	return n instanceof BlockStmt
			|| n instanceof DoStmt
			|| n instanceof ForStmt
			|| n instanceof ForeachStmt
			|| n instanceof IfStmt
			|| n instanceof SwitchStmt
			|| n instanceof TryStmt
			|| n instanceof WhileStmt;
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:11,代码来源:SrcRemapper.java


示例8: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override
public void visit(final TryStmt n, final Object arg) {
    printer.printLn("TryStmt");
    printJavaComment(n.getComment(), arg);
    printer.print("try ");
    if (!n.getResources().isEmpty()) {
        printer.print("(");
        Iterator<VariableDeclarationExpr> resources = n.getResources().iterator();
        boolean first = true;
        while (resources.hasNext()) {
            visit(resources.next(), arg);
            if (resources.hasNext()) {
                printer.print(";");
                printer.printLn();
                if (first) {
                    printer.indent();
                }
            }
            first = false;
        }
        if (n.getResources().size() > 1) {
            printer.unindent();
        }
        printer.print(") ");
    }
    n.getTryBlock().accept(this, arg);
    if (n.getCatchs() != null) {
        for (final CatchClause c : n.getCatchs()) {
            c.accept(this, arg);
        }
    }
    if (n.getFinallyBlock() != null) {
        printer.print(" finally ");
        n.getFinallyBlock().accept(this, arg);
    }
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:37,代码来源:ASTDumpVisitor.java


示例9: parseTryStatement

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
/**
 *
 * @param ts
 *      a github javaparser TryStatement
 * @param attributes
 *      the list of attributes of the class,
 *      to potentially get a type from the name
 * @param bd
 *      a body declaration
 * @return
 *      a TryStatement structure
 */
private TryStatement parseTryStatement(TryStmt ts, List<Attribute> attributes, BodyDeclaration bd) {
    TryStatement tryStatement = new TryStatement();
    tryStatement.setBody(parseStatement(ts.getTryBlock(), attributes, bd));
    if (ts.getCatchs() != null) {
        List<CatchClause> catchClauses = new ArrayList<>();
        List<com.github.javaparser.ast.stmt.CatchClause> japaCatchClauses = ts.getCatchs();
        for (com.github.javaparser.ast.stmt.CatchClause japaCatchClause : japaCatchClauses) {
            CatchClause catchClause = new CatchClause();
            List<Field> params = new ArrayList<>();
            if (japaCatchClause.getExcept().getTypes() != null) {
                for (Type t : japaCatchClause.getExcept().getTypes()) {
                    String type = ParserUtils.parseException(t.toString()).get("type");
                    String name = ParserUtils.parseException(t.toString()).get("name");
                    List<String> doc = null;
                    if (t.getComment() != null) {
                        doc = ParserUtils.prepareComments(t.getComment().getContent());
                    }
                    Field f = new Field(doc, name, type);
                    params.add(f);
                }
            }
            catchClause.setParameters(params);
            List<Stmt> body = new ArrayList<>();
            body.addAll(parseStatement(japaCatchClause.getCatchBlock(), attributes, bd));
            catchClause.setBody(body);
            catchClauses.add(catchClause);
            this.loc++;
        }
        tryStatement.setCatchClauses(catchClauses);
    }
    if (ts.getFinallyBlock() != null) {
        tryStatement.setFinallyStmts(parseStatement(ts.getFinallyBlock(), attributes, bd));
    }

    return tryStatement;
}
 
开发者ID:DevMine,项目名称:parsers,代码行数:49,代码来源:Parser.java


示例10: doMerge

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public TryStmt doMerge(TryStmt first, TryStmt second) {
  TryStmt ts = new TryStmt();
  ts.setResources(mergeCollectionsInOrder(first.getResources(),second.getResources()));
  ts.setCatchs(mergeCollectionsInOrder(first.getCatchs(),second.getCatchs()));
  ts.setTryBlock(mergeSingle(first.getTryBlock(),second.getTryBlock()));
  ts.setFinallyBlock(mergeSingle(first.getFinallyBlock(),second.getFinallyBlock()));
  return ts;
}
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:9,代码来源:TryStmtMerger.java


示例11: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public void visit(final TryStmt n, final Object arg) {
printJavaComment(n.getComment(), arg);
printer.print("try ");
if (!n.getResources().isEmpty()) {
    printer.print("(");
    Iterator<VariableDeclarationExpr> resources = n.getResources().iterator();
    boolean first = true;
    while (resources.hasNext()) {
	visit(resources.next(), arg);
	if (resources.hasNext()) {
	    printer.print(";");
	    printer.printLn();
	    if (first) {
		printer.indent();
	    }
	}
	first = false;
    }
    if (n.getResources().size() > 1) {
	printer.unindent();
    }
    printer.print(") ");
}
n.getTryBlock().accept(this, arg);
if (n.getCatchs() != null) {
    for (final CatchClause c : n.getCatchs()) {
	c.accept(this, arg);
    }
}
if (n.getFinallyBlock() != null) {
    printer.print(" finally ");
    n.getFinallyBlock().accept(this, arg);
}
   }
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:35,代码来源:DumpVisitor.java


示例12: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public Node visit(final TryStmt n, final A arg) {
	n.setTryBlock((BlockStmt) n.getTryBlock().accept(this, arg));
	final List<CatchClause> catchs = n.getCatchs();
	if (catchs != null) {
		for (int i = 0; i < catchs.size(); i++) {
			catchs.set(i, (CatchClause) catchs.get(i).accept(this, arg));
		}
		removeNulls(catchs);
	}
	if (n.getFinallyBlock() != null) {
		n.setFinallyBlock((BlockStmt) n.getFinallyBlock().accept(this, arg));
	}
	return n;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:15,代码来源:ModifierVisitorAdapter.java


示例13: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override
public Node visit(TryStmt _n, Object _arg) {
	List<VariableDeclarationExpr> resources = visit(_n.getResources(),_arg);
	BlockStmt tryBlock = cloneNodes(_n.getTryBlock(), _arg);
	List<CatchClause> catchs = visit(_n.getCatchs(), _arg);
	BlockStmt finallyBlock = cloneNodes(_n.getFinallyBlock(), _arg);
	Comment comment = cloneNodes(_n.getComment(), _arg);

	TryStmt r = new TryStmt(
			_n.getRange(),
			resources, tryBlock, catchs, finallyBlock
	);
	r.setComment(comment);
	return r;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:16,代码来源:CloneVisitor.java


示例14: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public void visit(final TryStmt n, final Object arg) {
	printJavaComment(n.getComment(), arg);
	printer.print("try ");
	if (!n.getResources().isEmpty()) {
		printer.print("(");
		Iterator<VariableDeclarationExpr> resources = n.getResources().iterator();
		boolean first = true;
		while (resources.hasNext()) {
			visit(resources.next(), arg);
			if (resources.hasNext()) {
				printer.print(";");
				printer.printLn();
				if (first) {
					printer.indent();
				}
			}
			first = false;
		}
		if (n.getResources().size() > 1) {
			printer.unindent();
		}
		printer.print(") ");
	}
	n.getTryBlock().accept(this, arg);
	if (n.getCatchs() != null) {
		for (final CatchClause c : n.getCatchs()) {
			c.accept(this, arg);
		}
	}
	if (n.getFinallyBlock() != null) {
		printer.print(" finally ");
		n.getFinallyBlock().accept(this, arg);
	}
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:35,代码来源:DumpVisitor.java


示例15: addAssert

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
private void addAssert(Snippet snippet, List<Statement> statements) throws Exception {
    if (snippet.getMethod().getReturnType() == Void.class
            || snippet.getMethod().getReturnType() == void.class) {
        // no asserts for void return values
        return;
    }

    otherExprStatements = new ArrayList<>();
    List<Statement> originalStatements = new ArrayList<>(statements);

    // interate on originalStatements, edit statements
    for (int idx = 0; idx < originalStatements.size(); idx++) {
        Statement stmt = originalStatements.get(idx);
        if (stmt instanceof ExpressionStmt) {
            addAssertForExpressionLine(snippet, statements, idx);
        } else if (stmt instanceof TryStmt) {
            // skip
        } else {
            System.out.println("Not expression statement: " + snippet.getId());
            System.out.println("Statement class: " + stmt.getClass());
            throw new RuntimeException("What to do?");
        }
    }
    //
    // if (statements.size() == 1) {
    // if (statements.get(0) instanceof ExpressionStmt) {
    // } else {
    // // FIXME
    // // throw new RuntimeException("Not expression statement: " + snippet.getId());
    // }
    // } else {
    // throw new RuntimeException("More than one statement: " + snippet.getId());
    // }

}
 
开发者ID:SETTE-Testing,项目名称:sette-tool,代码行数:36,代码来源:EvoSuiteParserMutation.java


示例16: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override
public Node visit(
    TryStmt n, Map<Node, Node> arg
) {
  if (arg.containsKey(n)) {
    return arg.get(n);
  }
  return super.visit(n, arg);
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:10,代码来源:ConcreteModifierVisitor.java


示例17: execute

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override
public void execute(PathResolver pathResolver) throws Exception {
    CompilationUnit cu = new CompilationUnit();
    cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("db.migration")));
    List<ImportDeclaration> imports = new ArrayList<>();
    imports.add(new ImportDeclaration(ASTHelper.createNameExpr("org.flywaydb.core.api.migration.jdbc.JdbcMigration"), false, false));
    imports.add(new ImportDeclaration(ASTHelper.createNameExpr("java.sql.Connection"), false, false));
    imports.add(new ImportDeclaration(ASTHelper.createNameExpr("java.sql.Statement"), false, false));
    cu.setImports(imports);

    String version = LocalDateTime.now().format(VERSION_FMT);
    ClassOrInterfaceDeclaration migrationClass = new ClassOrInterfaceDeclaration(
            ModifierSet.PUBLIC, false, "V" + version + "__Create"
            + CaseConverter.pascalCase(tableName));
    ASTHelper.addTypeDeclaration(cu, migrationClass);

    List<ClassOrInterfaceType> implementList = new ArrayList<>();
    implementList.add(new ClassOrInterfaceType("JdbcMigration"));
    migrationClass.setImplements(implementList);
    MethodDeclaration migrateMethod = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "migrate");
    ASTHelper.addMember(migrationClass, migrateMethod);
    ASTHelper.addParameter(migrateMethod, ASTHelper.createParameter(
            ASTHelper.createReferenceType("Connection", 0), "connection"
    ));
    migrateMethod.setThrows(Collections.singletonList(ASTHelper.createNameExpr("Exception")));

    List<AnnotationExpr> annotations = new ArrayList<>();
    annotations.add(new MarkerAnnotationExpr(ASTHelper.createNameExpr("Override")));
    migrateMethod.setAnnotations(annotations);

    BlockStmt block = new BlockStmt();
    migrateMethod.setBody(block);

    TryStmt tryStmt = new TryStmt(createStatementExecuteBlock(), null, null);
    tryStmt.setResources(Collections.singletonList(createAssignStatement()));
    ASTHelper.addStmt(block, tryStmt);

    try (Writer writer = new OutputStreamWriter(
            pathResolver.destinationAsStream(
                    "src/main/java/db/migration/" + migrationClass.getName() + ".java"))) {
        writer.write(cu.toString());
    }
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:44,代码来源:FlywayTask.java


示例18: visit

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override
public void visit(TryStmt n, Script arg) {
}
 
开发者ID:Nosorog,项目名称:nosorog-core,代码行数:4,代码来源:NoOpVisitor.java


示例19: doIsEquals

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Override public boolean doIsEquals(TryStmt first, TryStmt second) {
  if(!isEqualsUseMerger(first.getResources(),second.getResources())) return false;
  if(!isEqualsUseMerger(first.getCatchs(),second.getCatchs())) return false;

  return true;
}
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:7,代码来源:TryStmtMerger.java


示例20: givenATryStmt

import com.github.javaparser.ast.stmt.TryStmt; //导入依赖的package包/类
@Given("a TryStmt")
public void givenATryStmt() {
    tryStmt = new TryStmt();
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:5,代码来源:ManipulationSteps.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DataTransferProtoUtil类代码示例发布时间:2022-05-22
下一篇:
Java ItemStream类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap