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


Java SwitchCase类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.SwitchCase的典型用法代码示例。如果您正苦于以下问题:Java SwitchCase类的具体用法?Java SwitchCase怎么用?Java SwitchCase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: locationNeedsParentheses

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
	if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
		// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
		return false;
	}
	if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
			|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
			|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
			|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
			|| locationInParent == ForStatement.EXPRESSION_PROPERTY
			|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
			|| locationInParent == DoStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.MESSAGE_PROPERTY
			|| locationInParent == IfStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
			|| locationInParent == ArrayAccess.INDEX_PROPERTY
			|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
			|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
			|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		return false;
	}
	return true;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:NecessaryParenthesesChecker.java

示例2: handleSimpleName

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private void handleSimpleName(SimpleName node) {
  ASTNode firstExpression = node.getParent();
  if (firstExpression instanceof FieldAccess) {
    while (firstExpression instanceof FieldAccess) {
      firstExpression = ((FieldAccess) firstExpression).getExpression();
    }
    if (!(firstExpression instanceof SimpleName)) return;

    node = (SimpleName) firstExpression;
  } else if (firstExpression instanceof SuperFieldAccess) return;

  StructuralPropertyDescriptor parentDescription = node.getLocationInParent();
  if (parentDescription == VariableDeclarationFragment.NAME_PROPERTY
      || parentDescription == SwitchCase.EXPRESSION_PROPERTY) return;

  IBinding binding = node.resolveBinding();
  if (!(binding instanceof IVariableBinding)) return;

  handleVariable(node, (IVariableBinding) binding);
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:CodeStyleFix.java

示例3: getStatementType

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
/**
 * Method that check statement type.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param itStatement
 */
private void getStatementType(Object itStatement) {
	if (itStatement instanceof CatchClause){
		this.visitor.visit((CatchClause)itStatement);
	}else if (itStatement instanceof ForStatement){
		this.visitor.visit((ForStatement)itStatement);
	}else if (itStatement instanceof IfStatement){
		this.visitor.visit((IfStatement)itStatement);
	}else if (itStatement instanceof WhileStatement){
		this.visitor.visit((WhileStatement)itStatement);
	}else if (itStatement instanceof TryStatement){
		this.visitor.visit((TryStatement)itStatement);
	}else if (itStatement instanceof ConditionalExpression){
		this.visitor.visit((ConditionalExpression)itStatement);
	}else if (itStatement instanceof SwitchCase){
		this.visitor.visit((SwitchCase)itStatement);
	}else if (itStatement instanceof DoStatement){
		this.visitor.visit((DoStatement)itStatement);
	}else if (itStatement instanceof ExpressionStatement){
		this.visitor.visit((ExpressionStatement)itStatement);
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:28,代码来源:WeightMethodsPerClassVisitor.java

示例4: visit

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
@Override
public boolean visit(SwitchCase node) {
  // switch on enum allows to use enum constants without qualification
  if (hasFlag(VARIABLES, fFlags) && !node.isDefault() && isInside(node.getExpression())) {
    SwitchStatement switchStatement = (SwitchStatement) node.getParent();
    ITypeBinding binding = switchStatement.getExpression().resolveTypeBinding();
    if (binding != null && binding.isEnum()) {
      IVariableBinding[] declaredFields = binding.getDeclaredFields();
      for (int i = 0; i < declaredFields.length; i++) {
        IVariableBinding curr = declaredFields[i];
        if (curr.isEnumConstant()) {
          fBreak = fRequestor.acceptBinding(curr);
          if (fBreak) return false;
        }
      }
    }
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:ScopeAnalyzer.java

示例5: locationNeedsParentheses

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
  if (locationInParent instanceof ChildListPropertyDescriptor
      && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
    // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation
    // ...
    return false;
  }
  if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
      || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
      || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
      || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
      || locationInParent == ForStatement.EXPRESSION_PROPERTY
      || locationInParent == WhileStatement.EXPRESSION_PROPERTY
      || locationInParent == DoStatement.EXPRESSION_PROPERTY
      || locationInParent == AssertStatement.EXPRESSION_PROPERTY
      || locationInParent == AssertStatement.MESSAGE_PROPERTY
      || locationInParent == IfStatement.EXPRESSION_PROPERTY
      || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
      || locationInParent == SwitchCase.EXPRESSION_PROPERTY
      || locationInParent == ArrayAccess.INDEX_PROPERTY
      || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
      || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
      || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
    return false;
  }
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:28,代码来源:NecessaryParenthesesChecker.java

示例6: canReplace

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private static boolean canReplace(IASTFragment fragment) {
  ASTNode node = fragment.getAssociatedNode();
  ASTNode parent = node.getParent();
  if (parent instanceof VariableDeclarationFragment) {
    VariableDeclarationFragment vdf = (VariableDeclarationFragment) parent;
    if (node.equals(vdf.getName())) return false;
  }
  if (isMethodParameter(node)) return false;
  if (isThrowableInCatchBlock(node)) return false;
  if (parent instanceof ExpressionStatement) return false;
  if (isLeftValue(node)) return false;
  if (isReferringToLocalVariableFromFor((Expression) node)) return false;
  if (isUsedInForInitializerOrUpdater((Expression) node)) return false;
  if (parent instanceof SwitchCase) return false;
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:ExtractTempRefactoring.java

示例7: checkExpression

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private void checkExpression(RefactoringStatus status) {
  ASTNode[] nodes = getSelectedNodes();
  if (nodes != null && nodes.length == 1) {
    ASTNode node = nodes[0];
    if (node instanceof Type) {
      status.addFatalError(
          RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_type_reference,
          JavaStatusContext.create(fCUnit, node));
    } else if (node.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
      status.addFatalError(
          RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_switch_case,
          JavaStatusContext.create(fCUnit, node));
    } else if (node instanceof Annotation || ASTNodes.getParent(node, Annotation.class) != null) {
      status.addFatalError(
          RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_from_annotation,
          JavaStatusContext.create(fCUnit, node));
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:ExtractMethodAnalyzer.java

示例8: canReplace

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private static boolean canReplace(IASTFragment fragment) {
  ASTNode node = fragment.getAssociatedNode();
  ASTNode parent = node.getParent();
  if (parent instanceof VariableDeclarationFragment) {
    VariableDeclarationFragment vdf = (VariableDeclarationFragment) parent;
    if (node.equals(vdf.getName())) return false;
  }
  if (parent instanceof ExpressionStatement) return false;
  if (parent instanceof SwitchCase) {
    if (node instanceof Name) {
      Name name = (Name) node;
      ITypeBinding typeBinding = name.resolveTypeBinding();
      if (typeBinding != null) {
        return !typeBinding.isEnum();
      }
    }
  }
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:ExtractConstantRefactoring.java

示例9: canReplace

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private static boolean canReplace(IASTFragment fragment) {
	ASTNode node= fragment.getAssociatedNode();
	ASTNode parent= node.getParent();
	if (parent instanceof VariableDeclarationFragment) {
		VariableDeclarationFragment vdf= (VariableDeclarationFragment) parent;
		if (node.equals(vdf.getName()))
			return false;
	}
	if (isMethodParameter(node))
		return false;
	if (isThrowableInCatchBlock(node))
		return false;
	if (parent instanceof ExpressionStatement)
		return false;
	if (isLeftValue(node))
		return false;
	if (isReferringToLocalVariableFromFor((Expression) node))
		return false;
	if (isUsedInForInitializerOrUpdater((Expression) node))
		return false;
	if (parent instanceof SwitchCase)
		return false;
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:ExtractTempRefactoring.java

示例10: canReplace

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private static boolean canReplace(IASTFragment fragment) {
	ASTNode node= fragment.getAssociatedNode();
	ASTNode parent= node.getParent();
	if (parent instanceof VariableDeclarationFragment) {
		VariableDeclarationFragment vdf= (VariableDeclarationFragment) parent;
		if (node.equals(vdf.getName()))
			return false;
	}
	if (parent instanceof ExpressionStatement)
		return false;
	if (parent instanceof SwitchCase) {
		if (node instanceof Name) {
			Name name= (Name) node;
			ITypeBinding typeBinding= name.resolveTypeBinding();
			if (typeBinding != null) {
				return !typeBinding.isEnum();
			}
		}
	}
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:ExtractConstantRefactoring.java

示例11: visit

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
@Override
public boolean visit(SwitchCase node) {
	// switch on enum allows to use enum constants without qualification
	if (hasFlag(VARIABLES, fFlags) && !node.isDefault() && isInside(node.getExpression())) {
		SwitchStatement switchStatement= (SwitchStatement) node.getParent();
		ITypeBinding binding= switchStatement.getExpression().resolveTypeBinding();
		if (binding != null && binding.isEnum()) {
			IVariableBinding[] declaredFields= binding.getDeclaredFields();
			for (int i= 0; i < declaredFields.length; i++) {
				IVariableBinding curr= declaredFields[i];
				if (curr.isEnumConstant()) {
					fBreak= fRequestor.acceptBinding(curr);
					if (fBreak)
						return false;
				}
			}
		}
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:ScopeAnalyzer.java

示例12: handleSimpleName

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private void handleSimpleName(SimpleName node) {
	ASTNode firstExpression= node.getParent();
	if (firstExpression instanceof FieldAccess) {
		while (firstExpression instanceof FieldAccess) {
			firstExpression= ((FieldAccess)firstExpression).getExpression();
		}
		if (!(firstExpression instanceof SimpleName))
			return;

		node= (SimpleName)firstExpression;
	} else if (firstExpression instanceof SuperFieldAccess)
		return;

	StructuralPropertyDescriptor parentDescription= node.getLocationInParent();
	if (parentDescription == VariableDeclarationFragment.NAME_PROPERTY || parentDescription == SwitchCase.EXPRESSION_PROPERTY)
		return;

	IBinding binding= node.resolveBinding();
	if (!(binding instanceof IVariableBinding))
		return;

	handleVariable(node, (IVariableBinding) binding);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:CodeStyleFix.java

示例13: addCasesOmittedProposals

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
public static void addCasesOmittedProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
	if (selectedNode instanceof Expression && selectedNode.getLocationInParent() == SwitchStatement.EXPRESSION_PROPERTY) {
		AST ast= selectedNode.getAST();
		SwitchStatement parent= (SwitchStatement) selectedNode.getParent();
		
		for (Statement statement : (List<Statement>) parent.statements()) {
			if (statement instanceof SwitchCase && ((SwitchCase) statement).isDefault()) {
				
				// insert //$CASES-OMITTED$:
				ASTRewrite rewrite= ASTRewrite.create(ast);
				rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer());
				ListRewrite listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY);
				ASTNode casesOmittedComment= rewrite.createStringPlaceholder("//$CASES-OMITTED$", ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
				listRewrite.insertBefore(casesOmittedComment, statement, null);
				
				String label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_cases_omitted;
				Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
				ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_CASES_OMITTED, image);
				proposals.add(proposal);
				break;
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:LocalCorrectionsSubProcessor.java

示例14: evaluateMissingSwitchCases

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
public static boolean evaluateMissingSwitchCases(ITypeBinding enumBindings, List<Statement> switchStatements, ArrayList<String> enumConstNames) {
	IVariableBinding[] fields= enumBindings.getDeclaredFields();
	for (int i= 0; i < fields.length; i++) {
		if (fields[i].isEnumConstant()) {
			enumConstNames.add(fields[i].getName());
		}
	}

	boolean hasDefault=false;
	List<Statement> statements= switchStatements;
	for (int i= 0; i < statements.size(); i++) {
		Statement curr= statements.get(i);
		if (curr instanceof SwitchCase) {
			Expression expression= ((SwitchCase) curr).getExpression();
			if (expression instanceof SimpleName) {
				enumConstNames.remove(((SimpleName) expression).getFullyQualifiedName());
			} else if(expression== null){
				hasDefault=true;
			}
		}
	}
	return hasDefault;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:LocalCorrectionsSubProcessor.java

示例15: getMissingCaseStatementProposals

import org.eclipse.jdt.core.dom.SwitchCase; //导入依赖的package包/类
private static boolean getMissingCaseStatementProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> proposals) {
	if (node instanceof SwitchCase) {
		node= node.getParent();
	}
	if (!(node instanceof SwitchStatement))
		return false;

	SwitchStatement switchStatement= (SwitchStatement)node;
	ITypeBinding expressionBinding= switchStatement.getExpression().resolveTypeBinding();
	if (expressionBinding == null || !expressionBinding.isEnum())
		return false;

	ArrayList<String> missingEnumCases= new ArrayList<String>();
	boolean hasDefault= LocalCorrectionsSubProcessor.evaluateMissingSwitchCases(expressionBinding, switchStatement.statements(), missingEnumCases);
	if (missingEnumCases.size() == 0 && hasDefault)
		return false;

	if (proposals == null)
		return true;

	LocalCorrectionsSubProcessor.createMissingCaseProposals(context, switchStatement, missingEnumCases, proposals);
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:QuickAssistProcessor.java


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