Java Javascript Mozilla Library oneLineStringOf(AstNode node)

Here you can find the source of oneLineStringOf(AstNode node)

Description

one Line String Of

License

Open Source License

Declaration

public static String oneLineStringOf(AstNode node) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.mozilla.javascript.ast.AstNode;

public class Main {
    public static String oneLineStringOf(AstNode node) {
        if (node == null)
            return "";
        String[] str = node.toSource().split("\n");
        if (str.length == 1)
            return str[0];
        else {/*w  w  w.  j  a va2  s.  c o  m*/
            int numOfShownLine = 2;
            boolean use1 = str.length > 2 && str[0].length() < 10;
            boolean useLast2 = str.length + (use1 ? 1 : 0) > 2 && str[str.length - 1].length() < 10;
            numOfShownLine += (use1 ? 1 : 0) + (useLast2 ? 1 : 0);

            return str[0] + (use1 ? str[1] : "") + " ..(" + (str.length - numOfShownLine) + ").. "
                    + (useLast2 ? str[str.length - 2] : "") + str[str.length - 1];
        }
    }
}

Related

  1. newObject()
  2. numberArg(Object[] args, int pos)
  3. objArg(Object[] args, int pos, Class type, boolean required)
  4. objectToXMLString(Object xml)
  5. omitLineBreak(AstNode node)
  6. parentOfAnyTypes(AstNode node, Set types, boolean isStrict)
  7. parentOfType(AstNode node, Class type)
  8. prototypeCast(Scriptable s, Class type)
  9. removeLinkFromXhtml(Object xhtml, String link)