Search in sources :

Example 1 with DeclarationStmtImpl

use of com.android.tools.idea.experimental.codeanalysis.datastructs.stmt.impl.DeclarationStmtImpl in project android by JetBrains.

the class CFGBuilder method dfsDeclarationStatementBuilder.

/**
   * Declaration Statement will not return a value, therefore always return null;
   *
   * @param resultArray
   * @param currentDeclStmt
   * @return
   */
public Value dfsDeclarationStatementBuilder(PsiDeclarationStatement currentDeclStmt) {
    PsiElement[] retElements = currentDeclStmt.getDeclaredElements();
    for (PsiElement curElement : retElements) {
        if (curElement == null) {
            PsiCFGDebugUtil.LOG.warning("element in DeclarationStatement " + currentDeclStmt.getText() + " is null");
            continue;
        }
        if (curElement instanceof PsiLocalVariable) {
            //So it is a local variable
            PsiLocalVariable curLocal = (PsiLocalVariable) curElement;
            PsiType localType = curLocal.getType();
            //Generate the decl statement
            DeclarationStmtImpl newDecl = new DeclarationStmtImpl(localType, curLocal, currentDeclStmt);
            connectGeneratedStmt(newDecl);
            if (this.mGraph instanceof BlockGraph) {
                ((BlockGraph) (this.mGraph)).addLocal(curLocal, (LocalImpl) newDecl.getLocal());
            }
            if (curLocal.hasInitializer()) {
                //Generate Statement for the initializer
                PsiExpression initializer = curLocal.getInitializer();
                Value initExpr = dfsExpressionBuilder(initializer);
                AssignStmtImpl initializerStmt = new AssignStmtImpl(true, null, JavaTokenType.EQ);
                LocalImpl localExpr = (LocalImpl) newDecl.getLocal();
                initializerStmt.setROp(initExpr);
                initializerStmt.setLOp(localExpr);
                connectGeneratedStmt(initializerStmt);
            }
        } else if (curElement instanceof PsiClass) {
            //It declares a nested class
            mScene.getOrCreateNestedClass((PsiClass) curElement, this.containerClass, retrieveDeclaringMethod(), this.mGraph);
        } else {
            PsiCFGDebugUtil.LOG.warning("element " + curElement.getText() + " in DeclarationStmt " + currentDeclStmt.getText() + " cannot be resolved");
        }
    }
    return null;
}
Also used : AssignStmtImpl(com.android.tools.idea.experimental.codeanalysis.datastructs.stmt.impl.AssignStmtImpl) BlockGraph(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.BlockGraph) DeclarationStmtImpl(com.android.tools.idea.experimental.codeanalysis.datastructs.stmt.impl.DeclarationStmtImpl)

Aggregations

BlockGraph (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.BlockGraph)1 AssignStmtImpl (com.android.tools.idea.experimental.codeanalysis.datastructs.stmt.impl.AssignStmtImpl)1 DeclarationStmtImpl (com.android.tools.idea.experimental.codeanalysis.datastructs.stmt.impl.DeclarationStmtImpl)1