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


Java SwitchStmt类代码示例

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


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

示例1: visit

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

	printJavaComment(n.getComment(), arg);
	printer.print("switch (");
	n.getSelector().accept(this, arg);
	printer.println(") {");

	if (n.getEntries() != null) {
		for (final SwitchEntryStmt e : n.getEntries()) {
			e.accept(this, arg);
		}
	}

	printer.print("}");

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

示例2: visit

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
@Override
public void visit(final SwitchStmt n, final Object arg) {
    printer.printLn("SwitchStmt");
    printJavaComment(n.getComment(), arg);
    printer.print("switch(");
    n.getSelector().accept(this, arg);
    printer.printLn(") {");
    if (n.getEntries() != null) {
        printer.indent();
        for (final SwitchEntryStmt e : n.getEntries()) {
            e.accept(this, arg);
        }
        printer.unindent();
    }
    printer.print("}");

}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:18,代码来源:ASTDumpVisitor.java

示例3: visit

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
@Override
public JCTree visit(final SwitchStmt n, final Object arg) {
    //ARG0: JCExpression selector
    JCExpression arg0 = (JCExpression) n.getSelector().accept(this, arg);

    //ARG1: List<JCCase> cases
    List<JCCase> arg1 = List.<JCCase>nil();
    if (n.getEntries() != null) {
        for (final SwitchEntryStmt e : n.getEntries()) {
            arg1 = arg1.append((JCCase) e.accept(this, arg));
        }
    }

    return new AJCSwitch(make.Switch(arg0, arg1), ((n.getComment() != null) ? n.getComment().getContent() : null));

}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:17,代码来源:JavaParser2JCTree.java

示例4: isBlockStmt

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的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

示例5: parseSwitchStatement

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
/**
 *
 * @param switchStmt
 *      a github javaparser SwithStatement
 * @param attributes
 *      the list of attributes of the class,
 *      to potentially get a type from the name
 * @param bd
 *      a body declaration
 * @return
 *      a SwitchStatement structure
 */
private SwitchStatement parseSwitchStatement(SwitchStmt switchStmt, List<Attribute> attributes, BodyDeclaration bd) {
    SwitchStatement switchStatement = new SwitchStatement();
    switchStatement.setCondition(parseExpression(switchStmt.getSelector(), attributes, bd.getBeginLine()));
    if (switchStmt.getEntries() != null) {
        List<CaseClause> caseClauses = new ArrayList<>();
        for (SwitchEntryStmt switchEntry : switchStmt.getEntries()) {
            CaseClause caseClause = new CaseClause();
            List<Expr> conditions = new ArrayList<>();
            if (switchEntry.getLabel() != null) {
                conditions.add(parseExpression(switchEntry.getLabel(), attributes, bd.getBeginLine()));
                caseClause.setConditions(conditions);
            } else {
                if (switchEntry.getStmts() != null) {
                    switchStatement.setDefaultStmt(parseListStmt(switchEntry.getStmts(), attributes, bd));
                }
            }
            if (switchEntry.getStmts() != null) {
                List<Stmt> body = new ArrayList<>();
                body.addAll(parseListStmt(switchEntry.getStmts(), attributes, bd));
                caseClause.setBody(body);
            }
            caseClauses.add(caseClause);
        }
        switchStatement.setCaseClauses(caseClauses);
    }
    return switchStatement;
}
 
开发者ID:DevMine,项目名称:parsers,代码行数:40,代码来源:Parser.java

示例6: visit

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

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

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

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

示例7: visit

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
@Override public void visit(final SwitchStmt n, final Object arg) {
printJavaComment(n.getComment(), arg);
printer.print("switch(");
n.getSelector().accept(this, arg);
printer.printLn(") {");
if (n.getEntries() != null) {
    printer.indent();
    for (final SwitchEntryStmt e : n.getEntries()) {
	e.accept(this, arg);
    }
    printer.unindent();
}
printer.print("}");

   }
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:16,代码来源:DumpVisitor.java

示例8: visit

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
@Override public void visit(final SwitchStmt n, final A arg) {
	visitComment(n.getComment(), arg);
	n.getSelector().accept(this, arg);
	if (n.getEntries() != null) {
		for (final SwitchEntryStmt e : n.getEntries()) {
			e.accept(this, arg);
		}
	}
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:10,代码来源:VoidVisitorAdapter.java

示例9: visit

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
@Override public void visit(final SwitchStmt n, final A arg) {
    jw.write(n); 
    visitComment(n.getComment(), arg);
    n.getSelector().accept(this, arg);
    if (n.getEntries() != null) {
        for (final SwitchEntryStmt e : n.getEntries()) {
            e.accept(this, arg);
        }
    }
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:11,代码来源:JsonVisitorAdapter.java

示例10: visit

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
@Override public Node visit(final SwitchStmt n, final A arg) {
	n.setSelector((Expression) n.getSelector().accept(this, arg));
	final List<SwitchEntryStmt> entries = n.getEntries();
	if (entries != null) {
		for (int i = 0; i < entries.size(); i++) {
			entries.set(i, (SwitchEntryStmt) entries.get(i).accept(this, arg));
		}
		removeNulls(entries);
	}
	return n;

}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:13,代码来源:ModifierVisitorAdapter.java

示例11: switchOnEnum

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
@Test
public void switchOnEnum() throws ParseException {
    CompilationUnit cu = parseSample("SwitchOnEnum");
    com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SwitchOnEnum");
    MethodDeclaration method = Navigator.demandMethod(clazz, "foo");
    SwitchStmt switchStmt = Navigator.findSwitch(method);
    Expression expression = switchStmt.getEntries().get(0).getLabel().get();

    SymbolReference<? extends ResolvedValueDeclaration> ref = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
    assertTrue(ref.isSolved());
    assertEquals("SwitchOnEnum.MyEnum", ref.getCorrespondingDeclaration().getType().asReferenceType().getQualifiedName());
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:13,代码来源:EnumResolutionTest.java

示例12: visit

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

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

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

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

示例13: visit

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
@Override
public Node visit(SwitchStmt _n, Object _arg) {
	Expression selector = cloneNodes(_n.getSelector(), _arg);
	List<SwitchEntryStmt> entries = visit(_n.getEntries(), _arg);
	Comment comment = cloneNodes(_n.getComment(), _arg);

	SwitchStmt r = new SwitchStmt(
			_n.getRange(),
			selector, entries
	);
	r.setComment(comment);
	return r;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:14,代码来源:CloneVisitor.java

示例14: visit

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
@Override public Node visit(final SwitchStmt n, final A arg) {
	visitComment(n, arg);
	n.setSelector((Expression) n.getSelector().accept(this, arg));
	final List<SwitchEntryStmt> entries = n.getEntries();
	if (entries != null) {
		for (int i = 0; i < entries.size(); i++) {
			entries.set(i, (SwitchEntryStmt) entries.get(i).accept(this, arg));
		}
		removeNulls(entries);
	}
	return n;

}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:14,代码来源:ModifierVisitorAdapter.java

示例15: findSwitch

import com.github.javaparser.ast.stmt.SwitchStmt; //导入依赖的package包/类
public static SwitchStmt findSwitch(Node node) {
    SwitchStmt res = findSwitchHelper(node);
    if (res == null) {
        throw new IllegalArgumentException();
    } else {
        return res;
    }
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:9,代码来源:Navigator.java


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