Java Code Examples for org.eclipse.jdt.core.dom.SwitchCase#isDefault()

The following examples show how to use org.eclipse.jdt.core.dom.SwitchCase#isDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScopeAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 6 votes vote down vote up
public boolean visit(SwitchCase stmnt){
	/*
	 * case Expression  :
               default :
	 */
	if (stmnt.isDefault()){
		styledString.append("default", new StyledStringStyler(keywordStyle));
		appendColon();
	}
	else {
		styledString.append("case", new StyledStringStyler(keywordStyle));
		appendSpace();
		handleExpression((Expression) stmnt.getExpression());
		appendColon();
	}
	return false;
}
 
Example 3
Source File: MethodControlFlowVisitor.java    From DesigniteJava with Apache License 2.0 5 votes vote down vote up
public boolean visit(SwitchCase node) {
	switchCases.add(node);
	if (!node.isDefault()) {
		switchCasesWitoutDefaults.add(node);
	}
	return true;
}
 
Example 4
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected SwitchData createSwitchData(SwitchStatement node) {
	SwitchData result = new SwitchData();
	List<Statement> statements = node.statements();
	if (statements.isEmpty()) {
		return result;
	}

	int start = -1, end = -1;
	GenericSequentialFlowInfo info = null;

	for (Iterator<Statement> iter = statements.iterator(); iter.hasNext();) {
		Statement statement = iter.next();
		if (statement instanceof SwitchCase) {
			SwitchCase switchCase = (SwitchCase) statement;
			if (switchCase.isDefault()) {
				result.setHasDefaultCase();
			}
			if (info == null) {
				info = createSequential();
				start = statement.getStartPosition();
			} else {
				if (info.isReturn() || info.isPartialReturn() || info.branches()) {
					result.add(new Region(start, end - start + 1), info);
					info = createSequential();
					start = statement.getStartPosition();
				}
			}
		} else {
			info.merge(getFlowInfo(statement), fFlowContext);
		}
		end = statement.getStartPosition() + statement.getLength() - 1;
	}
	result.add(new Region(start, end - start + 1), info);
	return result;
}
 
Example 5
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final SwitchCase node) {
  this.appendLineWrapToBuffer();
  boolean _isDefault = node.isDefault();
  if (_isDefault) {
    this.appendToBuffer("default ");
  } else {
    this.appendToBuffer("case ");
    node.getExpression().accept(this);
  }
  return false;
}
 
Example 6
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected SwitchData createSwitchData(SwitchStatement node) {
	SwitchData result= new SwitchData();
	List<Statement> statements= node.statements();
	if (statements.isEmpty())
		return result;

	int start= -1, end= -1;
	GenericSequentialFlowInfo info= null;

	for (Iterator<Statement> iter= statements.iterator(); iter.hasNext(); ) {
		Statement statement= iter.next();
		if (statement instanceof SwitchCase) {
			SwitchCase switchCase= (SwitchCase)statement;
			if (switchCase.isDefault()) {
				result.setHasDefaultCase();
			}
			if (info == null) {
				info= createSequential();
				start= statement.getStartPosition();
			} else {
				if (info.isReturn() || info.isPartialReturn() || info.branches()) {
					result.add(new Region(start, end - start + 1), info);
					info= createSequential();
					start= statement.getStartPosition();
				}
			}
		} else {
			info.merge(getFlowInfo(statement), fFlowContext);
		}
		end= statement.getStartPosition() + statement.getLength() - 1;
	}
	result.add(new Region(start, end - start + 1), info);
	return result;
}
 
Example 7
Source File: CFGSwitchCaseNode.java    From JDeodorant with MIT License 5 votes vote down vote up
public CFGSwitchCaseNode(AbstractStatement statement) {
	super(statement);
	SwitchCase switchCase = (SwitchCase)statement.getStatement();
	if(switchCase.isDefault())
		isDefault = true;
	else
		isDefault = false;
}
 
Example 8
Source File: SwitchControlCase.java    From JDeodorant with MIT License 5 votes vote down vote up
@Override
public boolean match(SwitchControlCase otherCase, ASTNodeMatcher matcher)
{
	if (this.body.size() == otherCase.body.size())
	{
		boolean caseStatementsMatch = true;
		for (int i = 0; i < this.body.size(); i++)
		{
			Statement currentThisStatement = this.body.get(i);
			Statement currentOtherStatement = otherCase.body.get(i);
			boolean switchCaseStatementMatch = false;
			if (currentThisStatement instanceof SwitchCase && currentOtherStatement instanceof SwitchCase)
			{
				SwitchCase currentThisSwitchCase = (SwitchCase)currentThisStatement;
				SwitchCase currentOtherSwitchCase = (SwitchCase)currentOtherStatement;
				if(currentThisSwitchCase.isDefault() && currentOtherSwitchCase.isDefault())
				{
					switchCaseStatementMatch = true;
				}
				else
				{
					switchCaseStatementMatch = matchCaseCondition(currentThisSwitchCase.getExpression(), currentOtherSwitchCase.getExpression());
				}
			}
			boolean endStatementMatch = ((currentThisStatement instanceof BreakStatement && currentOtherStatement instanceof BreakStatement) ||
					(currentThisStatement instanceof ContinueStatement && currentOtherStatement instanceof ContinueStatement) ||
					(currentThisStatement instanceof ReturnStatement && currentOtherStatement instanceof ReturnStatement));
			if (!switchCaseStatementMatch && !endStatementMatch)
			{
				caseStatementsMatch = false;
			}
		}
		return caseStatementsMatch;
	}
	return false;
}
 
Example 9
Source File: MethodVisitor.java    From repositoryminer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(SwitchCase node) {
	if (node.isDefault()) {
		statements.add(new AbstractStatement(NodeType.SWITCH_DEFAULT, null));
	} else {
		statements.add(new AbstractStatement(NodeType.SWITCH_CASE, node.getExpression().toString()));
	}
	return true;
}