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


Java SwitchCase.getExpression方法代码示例

本文整理汇总了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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:16,代码来源:Checks.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:Checks.java

示例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;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:38,代码来源:AdvancedQuickAssistProcessor.java

示例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;
}
 
开发者ID:UBPL,项目名称:jive,代码行数:42,代码来源:StatementVisitor.java


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