use of com.android.tools.idea.experimental.codeanalysis.datastructs.graph.SwitchCaseGraph in project android by JetBrains.
the class CFGBuilder method dfsPsiSwitchLabelStatementBuilder.
/**
* Build nodes for case "label" statement.
* @param statement
*/
public void dfsPsiSwitchLabelStatementBuilder(PsiSwitchLabelStatement statement) {
PsiExpression caseValueExpr = statement.getCaseValue();
if (!(this.mGraph instanceof SwitchCaseGraph)) {
//Not a inside a switch but encountered case?
PsiCFGDebugUtil.LOG.warning("Case statement out side of switch in :");
PsiCFGDebugUtil.debugOutputPsiElement(statement);
return;
}
SwitchCaseGraphImpl switchGraph = (SwitchCaseGraphImpl) this.mGraph;
SwitchBranchingNodeImpl switchNode = (SwitchBranchingNodeImpl) switchGraph.getSwitchBranchingNode();
//Create a case node for this statement
CaseNodeImpl curCaseNode = new CaseNodeImpl(this.mGraph);
Value caseValue;
//Evaluate the constant
if (statement.isDefaultCase()) {
//It is a default case
curCaseNode.setDefault();
switchNode.setDefaultTarget(curCaseNode);
} else {
//A "case value: " statement
if (caseValueExpr == null) {
PsiCFGDebugUtil.LOG.warning("CaseExpr is null in " + statement.getText());
return;
}
if (caseValueExpr instanceof PsiLiteralExpression) {
caseValue = dfsLiteralExpressionBuilder((PsiLiteralExpression) caseValueExpr);
} else if (caseValueExpr instanceof PsiReferenceExpression) {
//TODO: Add more sophisticate check for Reference Expression
//Only primitive types are allowed in switch case.
caseValue = dfsRHSReferenceExpressionBuilder((PsiReferenceExpression) caseValueExpr);
} else {
PsiCFGDebugUtil.LOG.warning("Case is not using a constant or reference");
PsiCFGDebugUtil.debugOutputPsiElement(caseValueExpr);
caseValue = new DummyRef(caseValueExpr.getType(), caseValueExpr);
}
curCaseNode.setLabelValue(caseValue);
switchNode.setTargetViaKey(caseValue, curCaseNode);
}
switchGraph.addCase(curCaseNode);
if (curWorkingNodeList.size() != 0) {
connectCurrentWorkingNode(curCaseNode);
}
curWorkingNodeList.clear();
curWorkingNodeList.add(curCaseNode);
}
Aggregations