本文整理汇总了Java中org.eclipse.jdt.core.dom.SwitchCase.getExpression方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchCase.getExpression方法的具体用法?Java SwitchCase.getExpression怎么用?Java SwitchCase.getExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.SwitchCase
的用法示例。
在下文中一共展示了SwitchCase.getExpression方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isEnumCase
import org.eclipse.jdt.core.dom.SwitchCase; //导入方法依赖的package包/类
public static boolean isEnumCase(ASTNode node) {
if (node instanceof SwitchCase) {
final SwitchCase caze = (SwitchCase) node;
final Expression expression = caze.getExpression();
if (expression instanceof Name) {
final Name name = (Name) expression;
final IBinding binding = name.resolveBinding();
if (binding instanceof IVariableBinding) {
IVariableBinding variableBinding = (IVariableBinding) binding;
return variableBinding.isEnumConstant();
}
}
}
return false;
}
示例2: isEnumCase
import org.eclipse.jdt.core.dom.SwitchCase; //导入方法依赖的package包/类
public static boolean isEnumCase(ASTNode node) {
if (node instanceof SwitchCase) {
final SwitchCase caze= (SwitchCase) node;
final Expression expression= caze.getExpression();
if (expression instanceof Name) {
final Name name= (Name) expression;
final IBinding binding= name.resolveBinding();
if (binding instanceof IVariableBinding) {
IVariableBinding variableBinding= (IVariableBinding) binding;
return variableBinding.isEnumConstant();
}
}
}
return false;
}
示例3: createSwitchCaseCondition
import org.eclipse.jdt.core.dom.SwitchCase; //导入方法依赖的package包/类
private static Expression createSwitchCaseCondition(AST ast, ASTRewrite rewrite, ImportRewrite importRewrite, ImportRewriteContext importRewriteContext, Name switchExpression,
SwitchCase switchCase, boolean isStringsInSwitch, boolean preserveNPE) {
Expression expression= switchCase.getExpression();
if (expression == null)
return null;
if (isStringsInSwitch) {
MethodInvocation methodInvocation= ast.newMethodInvocation();
methodInvocation.setName(ast.newSimpleName("equals")); //$NON-NLS-1$
if (preserveNPE) {
methodInvocation.setExpression((Expression) rewrite.createStringPlaceholder(switchExpression.getFullyQualifiedName(), ASTNode.QUALIFIED_NAME));
methodInvocation.arguments().add(rewrite.createCopyTarget(expression));
} else {
methodInvocation.setExpression((Expression) rewrite.createCopyTarget(expression));
methodInvocation.arguments().add(rewrite.createStringPlaceholder(switchExpression.getFullyQualifiedName(), ASTNode.QUALIFIED_NAME));
}
return methodInvocation;
} else {
InfixExpression condition= ast.newInfixExpression();
condition.setOperator(InfixExpression.Operator.EQUALS);
condition.setLeftOperand((Expression) rewrite.createStringPlaceholder(switchExpression.getFullyQualifiedName(), ASTNode.QUALIFIED_NAME));
Expression rightExpression= null;
if (expression instanceof SimpleName && ((SimpleName) expression).resolveBinding() instanceof IVariableBinding) {
IVariableBinding binding= (IVariableBinding) ((SimpleName) expression).resolveBinding();
if (binding.isEnumConstant()) {
String qualifiedName= importRewrite.addImport(binding.getDeclaringClass(), importRewriteContext) + '.' + binding.getName();
rightExpression= ast.newName(qualifiedName);
}
}
if (rightExpression == null) {
rightExpression= (Expression) rewrite.createCopyTarget(expression);
}
condition.setRightOperand(rightExpression);
return condition;
}
}
示例4: createSwitchCaseCondition
import org.eclipse.jdt.core.dom.SwitchCase; //导入方法依赖的package包/类
private static Expression createSwitchCaseCondition(AST ast, ASTRewrite rewrite, ImportRewrite importRewrite, ImportRewriteContext importRewriteContext, Name switchExpression,
SwitchCase switchCase, boolean isStringsInSwitch) {
Expression expression= switchCase.getExpression();
if (isStringsInSwitch) {
MethodInvocation methodInvocation= ast.newMethodInvocation();
methodInvocation.setExpression((Expression) rewrite.createCopyTarget(expression));
methodInvocation.setName(ast.newSimpleName("equals")); //$NON-NLS-1$
methodInvocation.arguments().add(rewrite.createStringPlaceholder(switchExpression.getFullyQualifiedName(), ASTNode.QUALIFIED_NAME));
return methodInvocation;
} else {
InfixExpression condition= ast.newInfixExpression();
condition.setOperator(InfixExpression.Operator.EQUALS);
condition.setLeftOperand((Expression) rewrite.createStringPlaceholder(switchExpression.getFullyQualifiedName(), ASTNode.QUALIFIED_NAME));
Expression rightExpression= null;
if (expression instanceof SimpleName && ((SimpleName) expression).resolveBinding() instanceof IVariableBinding) {
IVariableBinding binding= (IVariableBinding) ((SimpleName) expression).resolveBinding();
if (binding.isEnumConstant()) {
String qualifiedName= importRewrite.addImport(binding.getDeclaringClass(), importRewriteContext) + '.' + binding.getName();
rightExpression= ast.newName(qualifiedName);
}
}
if (rightExpression == null) {
rightExpression= (Expression) rewrite.createCopyTarget(expression);
}
condition.setRightOperand(rightExpression);
return condition;
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:30,代码来源:AdvancedQuickAssistProcessor.java
示例5: visit
import org.eclipse.jdt.core.dom.SwitchCase; //导入方法依赖的package包/类
/**
* SwitchStatement: 'switch' '(' expression ')' '{' SwitchCase | statement '}'
*
* SwitchCase: 'case' expression ':' | 'default' ':'
*/
@Override
public boolean visit(final SwitchStatement node)
{
final int lineNo = lineStart(node);
// new dependence
final IResolvedLine rl = createDependence(LK_SWITCH, lineNo, mdg.parent());
// append control dependences
appendDependences(rl, node.getExpression(), null, false);
// the next switch case statement
IResolvedLine scl = null;
// recursively append dependences
for (final Object o : node.statements())
{
// the uses of a case statement accumulate as we drill down each case
if (o instanceof SwitchCase)
{
final SwitchCase caseNode = (SwitchCase) o;
// if we were in statement mode, then it's time to create a case line
scl = createDependence(LK_SWITCH_CASE, lineStart(caseNode), scl == null ? rl : scl);
// default case has no additional expressions to append
if (caseNode.getExpression() != null)
{
// the resolved case expression as a use
final IResolvedData rd = factory.resolveExpression(caseNode.getExpression(), node, null,
false, false);
// collect uses
scl.uses().add(rd);
}
// do not append recursive-- statements are appended recursively under the respective case
continue;
}
appendRecursive(lineNo, scl, (ASTNode) o);
}
// do not visit children
return false;
}