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


Java Compiler.reportCodeChange方法代码示例

本文整理汇总了Java中com.google.javascript.jscomp.Compiler.reportCodeChange方法的典型用法代码示例。如果您正苦于以下问题:Java Compiler.reportCodeChange方法的具体用法?Java Compiler.reportCodeChange怎么用?Java Compiler.reportCodeChange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.jscomp.Compiler的用法示例。


在下文中一共展示了Compiler.reportCodeChange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: contractEval

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
/**
 * Undoes the constant folding previously done.
 */
private String contractEval(AnalyzerCallback callback, Compiler comp, Set<String> map, String resVar) {
    Node stringRoot = getParentOfFirstInterestingNode(comp).getLastChild();

    // LHS of the assignment to the result of the eval
    String res;
    if (resVar == null)
        res = "";
    else
        res = resVar + " = ";
    
    // log("Map of holes: " + map.toString());
    boolean unevalSucceed = contractEvalHelper(callback, comp, stringRoot, map);
    // The helper modifies the AST.
    comp.reportCodeChange();

    if (!unevalSucceed)
        return null;

    String result = res + comp.toSource();
    
    // log("Retval:" + result);
    return result;
}
 
开发者ID:cursem,项目名称:ScriptCompressor,代码行数:27,代码来源:Unevalizer.java

示例2: fillHolesAndConstantFold

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
/**
 * Constant folds root, on the form ".." + x1 + ".." + .., into "..x1...."
 */
private void fillHolesAndConstantFold(Compiler compiler, Node root, Set<String> map) {
    boolean b = true;
    
    while (b) {
        b = convertNamesToStrings(root.getLastChild().getLastChild().getLastChild().getLastChild(), map);
    }
    
    b = true;
    
    while (b) {
        b = constantFoldStrings(root.getLastChild().getLastChild().getLastChild().getLastChild());
    }
    compiler.reportCodeChange();
}
 
开发者ID:cursem,项目名称:ScriptCompressor,代码行数:18,代码来源:Unevalizer.java

示例3: unevalConst

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
/**
 * The main function for unevaling constant strings.
 */
private String unevalConst(AnalyzerCallback callback, Compiler comp, String resVar) {
    Set<String> boundVariables = boundVariables(comp);
    // Fail if there's name capture (bv(s) \cap (D_G \cup D_L \cup D_M) \neq \emptyset).
    if (callback.anyDeclared(boundVariables)) {
    	logger.debug("Failed due to name capture");
        return null;
    }

    logger.debug("No name capture");

    // We're done if nobody cares about the result value (r == false or \mathcal{C} = \epsilon).
    if (resVar == null)
        return comp.toSource();

    logger.debug("Return value of eval is used");

    // Our input is "s1; s2; ..; sn". Get sn and detach it from the parent for closure compiler reasons.
    Node sn = getLastStmt(getParentOfFirstInterestingNode(comp));
    sn.detachFromParent();
    comp.reportCodeChange();

    // If the last statement in our input doesn't have a value we need to abort (hv(sn))
    // TODO: isExpr needed here? Remove isExpr
    if (!hasValue(sn) || !isExpr(sn)) {
    	logger.debug("Last expression is NOT the value yielding one");
        return null;
     }

    logger.debug("Last expression has value");

    // Getting the program back from the compiler. A play in two acts.
    // AST -> String for s1..s(n-1)
    Compiler.CodeBuilder cb1 = new Compiler.CodeBuilder();
    // AST -> String for s_n
    Compiler.CodeBuilder cb2 = new Compiler.CodeBuilder();
    comp.toSource(cb1, 1, comp.getRoot());
    comp.toSource(cb2, 1, sn);       

    return cb1.toString() + resVar + " = " + cb2.toString();
}
 
开发者ID:cursem,项目名称:ScriptCompressor,代码行数:44,代码来源:Unevalizer.java

示例4: contractEvalHelper

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
/**
 * Helper function that does most of the actual work for contractEval.
 */
private boolean contractEvalHelper(AnalyzerCallback callback, Compiler comp, Node root, Set<String> holes) {

    for (Node n : root.children()) {
        if (!contractEvalHelper(callback, comp, n, holes))
            return false;

        // log("Looping: " + n.toStringTree() + ":" +  n.getClass().getSimpleName());
        // Our names ended up in name or string nodes; check all such nodes for occurrences and transform accordingly.
        if (n.isName() || n.isString()) {
            String v = n.getString();               
            for (String hole : holes) {
                int i = v.indexOf(hole);
                // Hole exists somewhere in the name
                if (i != -1) {
                    Node nam = newString(Token.NAME, hole);

                    Node tmpNode1, tmpRoot;
                    // The part of the name to the left of the variable. Might be empty.
                    String lsub = v.substring(0, i);
                    // The part to the right of the variable. Might be empty.
                    String rsub = v.substring(i + hole.length(), v.length());
                    if (lsub.length() > 0) {
                        if (!(callback.isDefinitelyIdentifierFragment(hole) || callback.isDefinitelyInteger(hole))) {
                            logger.debug("Failed due to non IdentifierFragment and non Integer");
                            return false;
                        }
                        // If there isn't a global identifier starting with lsub we're smoked.
                        if (!isGlobalIdentifierPrefix(callback, lsub))  {
                            logger.debug("Failed due to local shadowing");
                            return false;
                        }
                        tmpNode1 = new Node(Token.ADD, newString(lsub), nam);
                        // Copy AST properties to the new node.
                        tmpNode1.clonePropsFrom(nam);
                    } else {
                        if (!(callback.isDefinitelyIdentifier(hole) || callback.isDefinitelyBoolean(hole) || callback.isDefinitelyInteger(hole))) {
                        	logger.debug("Not an identifier for sure: " + hole);
                            return false;
                        }
                        tmpNode1 = nam;
                    }

                    if (rsub.length() > 0) {
                        if (!isGlobalIdentifierSuffix(callback, rsub)) {
                        	logger.debug("Failed due to local shadowing");
                            return false;
                        }
                        // Check if there are more than one hole in this node, and if so, give up.
                        for (String hole2 : holes) {
                            if (rsub.contains(hole2)) {
                            	logger.debug("Failed due to multiple holes in same node");
                                return false;
                            }
                        }
                        tmpRoot = new Node(Token.ADD, tmpNode1, newString(rsub));
                    } else
                        tmpRoot = tmpNode1;

                    // Replace the old node with the newly constructed tree in the AST
                    Node p = n.getParent();                       
                    p.replaceChild(n, tmpRoot);
                    comp.reportCodeChange();
                    n = tmpRoot;
                    if (!fixupParent(callback, comp, p, n, hole, lsub.isEmpty() && rsub.isEmpty()))
                         return false;
                }
            }
        }
    }
    return true;
}
 
开发者ID:cursem,项目名称:ScriptCompressor,代码行数:75,代码来源:Unevalizer.java


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