Example usage for com.liferay.portal.kernel.util StringPool TAB

List of usage examples for com.liferay.portal.kernel.util StringPool TAB

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool TAB.

Prototype

String TAB

To view the source code for com.liferay.portal.kernel.util StringPool TAB.

Click Source Link

Usage

From source file:com.liferay.frontend.taglib.form.navigator.internal.osgi.commands.FormNavigatorOSGiCommands.java

License:Open Source License

public void getPossibleConfigurations() {
    for (String formNavigatorId : _getAllFormNavigatorIds()) {
        String[] formNavigatorCategoryKeys = FormNavigatorCategoryUtil.getKeys(formNavigatorId);

        System.out.println(formNavigatorId);

        for (String formNavigatorCategoryKey : formNavigatorCategoryKeys) {
            String line = _getCategoryLine(formNavigatorId, formNavigatorCategoryKey);

            System.out.print(StringPool.TAB);
            System.out.print(line);
        }/* www . j a va2s .  co  m*/
    }
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected String formatJavaTerms(String javaClassName, String fileName, String absolutePath, String content,
        String javaClassContent, int javaClassLineCount, List<String> checkJavaFieldTypesExclusions,
        List<String> javaTermAccessLevelModifierExclusions, List<String> javaTermSortExclusions,
        List<String> testAnnotationsExclusions) throws Exception {

    JavaClass javaClass = new JavaClass(javaClassName, fileName, absolutePath, javaClassContent,
            javaClassLineCount, StringPool.TAB, null, javaTermAccessLevelModifierExclusions);

    String newJavaClassContent = javaClass.formatJavaTerms(getAnnotationsExclusions(), getImmutableFieldTypes(),
            checkJavaFieldTypesExclusions, javaTermSortExclusions, testAnnotationsExclusions);

    if (!javaClassContent.equals(newJavaClassContent)) {
        return StringUtil.replaceFirst(content, javaClassContent, newJavaClassContent);
    }//w w w .  j  a v a 2s.  c  o m

    return content;
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected String trimLine(String line, boolean allowLeadingSpaces) {
    if (line.trim().length() == 0) {
        return StringPool.BLANK;
    }//from w ww  .  j av a 2  s .c om

    line = StringUtil.trimTrailing(line);

    if (allowLeadingSpaces || !line.startsWith(StringPool.SPACE) || line.startsWith(" *")) {

        return line;
    }

    if (!line.startsWith(StringPool.FOUR_SPACES)) {
        while (line.startsWith(StringPool.SPACE)) {
            line = StringUtil.replaceFirst(line, StringPool.SPACE, StringPool.BLANK);
        }
    } else {
        int pos = 0;

        String temp = line;

        while (temp.startsWith(StringPool.FOUR_SPACES)) {
            line = StringUtil.replaceFirst(line, StringPool.FOUR_SPACES, StringPool.TAB);

            pos++;

            temp = line.substring(pos);
        }
    }

    return line;
}

From source file:com.liferay.tools.sourceformatter.JavaClass.java

License:Open Source License

protected String fixLeadingTabs(String content, String line, int expectedTabCount) {

    int leadingTabCount = JavaSourceProcessor.getLeadingTabCount(line);

    String newLine = line;//  w  ww  .  j  a  v a 2s.c  om

    while (leadingTabCount != expectedTabCount) {
        if (leadingTabCount > expectedTabCount) {
            newLine = StringUtil.replaceFirst(newLine, StringPool.TAB, StringPool.BLANK);

            leadingTabCount--;
        } else {
            newLine = StringPool.TAB + newLine;

            leadingTabCount++;
        }
    }

    return StringUtil.replace(content, line, newLine);
}

From source file:com.liferay.tools.sourceformatter.JavaClass.java

License:Open Source License

protected void fixTabsAndIncorrectEmptyLines(JavaTerm javaTerm) {
    if (!javaTerm.isConstructor() && !javaTerm.isMethod()) {
        return;/*w  ww  . j a  v a2  s .c o  m*/
    }

    String javaTermContent = "\n" + javaTerm.getContent();

    Pattern methodNameAndParametersPattern = Pattern
            .compile("\n" + _indent + "(private |protected |public )(.|\n)*?(\\{|;)\n");

    Matcher matcher = methodNameAndParametersPattern.matcher(javaTermContent);

    if (!matcher.find()) {
        return;
    }

    String methodNameAndParameters = matcher.group();

    String[] lines = StringUtil.splitLines(methodNameAndParameters);

    if (lines.length == 1) {
        if (methodNameAndParameters.endsWith("{\n") && javaTermContent.contains(methodNameAndParameters + "\n")
                && !javaTermContent.contains(methodNameAndParameters + "\n" + _indent + StringPool.TAB + "/*")
                && !javaTermContent
                        .contains(methodNameAndParameters + "\n" + _indent + StringPool.TAB + "// ")) {

            String trimmedJavaTermContent = StringUtil.trimTrailing(javaTermContent);

            if (!trimmedJavaTermContent.endsWith("\n\n" + _indent + StringPool.CLOSE_CURLY_BRACE)) {

                _content = StringUtil.replace(_content, methodNameAndParameters + "\n",
                        methodNameAndParameters);
            }
        }

        return;
    }

    if (methodNameAndParameters.endsWith("{\n") && !javaTermContent.contains(methodNameAndParameters + "\n")
            && !javaTermContent.contains(methodNameAndParameters + _indent + StringPool.CLOSE_CURLY_BRACE)) {

        _content = StringUtil.replace(_content, methodNameAndParameters, methodNameAndParameters + "\n");
    }

    boolean throwsException = methodNameAndParameters.contains(_indent + "throws ");

    String newMethodNameAndParameters = methodNameAndParameters;

    int expectedTabCount = -1;

    for (int i = 0; i < lines.length; i++) {
        String line = lines[i];

        if (line.contains(_indent + "throws ")) {
            newMethodNameAndParameters = fixLeadingTabs(newMethodNameAndParameters, line, _indent.length() + 1);

            break;
        }

        if (expectedTabCount == -1) {
            if (line.endsWith(StringPool.OPEN_PARENTHESIS)) {
                expectedTabCount = Math.max(JavaSourceProcessor.getLeadingTabCount(line), _indent.length()) + 1;

                if (throwsException && (expectedTabCount == (_indent.length() + 1))) {

                    expectedTabCount += 1;
                }
            }
        } else {
            String previousLine = lines[i - 1];

            if (previousLine.endsWith(StringPool.COMMA) || previousLine.endsWith(StringPool.OPEN_PARENTHESIS)) {

                newMethodNameAndParameters = fixLeadingTabs(newMethodNameAndParameters, line, expectedTabCount);
            } else {
                newMethodNameAndParameters = fixLeadingTabs(newMethodNameAndParameters, line,
                        JavaSourceProcessor.getLeadingTabCount(previousLine) + 1);
            }
        }
    }

    _content = StringUtil.replace(_content, methodNameAndParameters, newMethodNameAndParameters);
}

From source file:com.liferay.tools.sourceformatter.JavaClass.java

License:Open Source License

protected Set<JavaTerm> getJavaTerms() throws Exception {
    if (_javaTerms != null) {
        return _javaTerms;
    }//from  w  w w  .ja v  a  2s.  c o m

    Set<JavaTerm> javaTerms = new TreeSet<JavaTerm>(new JavaTermComparator(false));
    List<JavaTerm> staticBlocks = new ArrayList<JavaTerm>();

    UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new UnsyncStringReader(_content));

    int index = 0;
    int lineCount = _lineCount - 1;

    String line = null;

    JavaTerm javaTerm = null;

    String javaTermName = null;
    int javaTermLineCount = -1;
    int javaTermStartPosition = -1;
    int javaTermType = -1;

    int lastCommentOrAnnotationPos = -1;

    while ((line = unsyncBufferedReader.readLine()) != null) {
        lineCount++;

        if (JavaSourceProcessor.getLeadingTabCount(line) != _indent.length()) {

            index = index + line.length() + 1;

            continue;
        }

        if (line.startsWith(_indent + "private ") || line.equals(_indent + "private")
                || line.startsWith(_indent + "protected ") || line.equals(_indent + "protected")
                || line.startsWith(_indent + "public ") || line.equals(_indent + "public")
                || line.equals(_indent + "static {")) {

            Tuple tuple = getJavaTermTuple(line, _content, index);

            if (tuple == null) {
                return null;
            }

            int javaTermEndPosition = 0;

            if (lastCommentOrAnnotationPos == -1) {
                javaTermEndPosition = index;
            } else {
                javaTermEndPosition = lastCommentOrAnnotationPos;
            }

            if ((javaTermStartPosition != -1) && (javaTermEndPosition < _content.length())) {

                String javaTermContent = _content.substring(javaTermStartPosition, javaTermEndPosition);

                if (!isValidJavaTerm(javaTermContent)) {
                    return null;
                }

                if (Validator.isNotNull(javaTermName)) {
                    javaTerm = new JavaTerm(javaTermName, javaTermType, javaTermContent, javaTermLineCount);

                    if (javaTermType == JavaTerm.TYPE_STATIC_BLOCK) {
                        staticBlocks.add(javaTerm);
                    } else {
                        javaTerms.add(javaTerm);

                        if (javaTerm.isClass()) {
                            JavaClass innerClass = new JavaClass(javaTermName, _fileName, _absolutePath,
                                    javaTermContent, javaTermLineCount, _indent + StringPool.TAB, this,
                                    _javaTermAccessLevelModifierExclusions);

                            _innerClasses.add(innerClass);
                        }
                    }
                }
            }

            javaTermLineCount = lineCount;
            javaTermName = (String) tuple.getObject(0);
            javaTermStartPosition = javaTermEndPosition;
            javaTermType = (Integer) tuple.getObject(1);

            lastCommentOrAnnotationPos = -1;
        } else if (hasAnnotationCommentOrJavadoc(line)) {
            if (lastCommentOrAnnotationPos == -1) {
                lastCommentOrAnnotationPos = index;
            }
        } else if (!line.startsWith(_indent + StringPool.CLOSE_CURLY_BRACE)
                && !line.startsWith(_indent + StringPool.CLOSE_PARENTHESIS)
                && !line.startsWith(_indent + "extends") && !line.startsWith(_indent + "implements")
                && !BaseSourceProcessor.isExcluded(_javaTermAccessLevelModifierExclusions, _absolutePath,
                        lineCount)) {

            Matcher matcher = _classPattern.matcher(_content);

            if (matcher.find()) {
                String insideClass = _content.substring(matcher.end());

                if (insideClass.contains(line)) {
                    BaseSourceProcessor.processErrorMessage(_fileName,
                            "Missing access level modifier: " + _fileName + " " + lineCount);
                }
            }
        }

        index = index + line.length() + 1;
    }

    if (javaTermStartPosition != -1) {
        int javaTermEndPosition = _content.lastIndexOf(StringPool.CLOSE_CURLY_BRACE) - _indent.length();

        String javaTermContent = _content.substring(javaTermStartPosition, javaTermEndPosition);

        if (!isValidJavaTerm(javaTermContent)) {
            return null;
        }

        javaTerm = new JavaTerm(javaTermName, javaTermType, javaTermContent, javaTermLineCount);

        if (javaTermType == JavaTerm.TYPE_STATIC_BLOCK) {
            staticBlocks.add(javaTerm);
        } else {
            javaTerms.add(javaTerm);

            if (javaTerm.isClass()) {
                JavaClass innerClass = new JavaClass(javaTermName, _fileName, _absolutePath, javaTermContent,
                        javaTermLineCount, _indent + StringPool.TAB, this,
                        _javaTermAccessLevelModifierExclusions);

                _innerClasses.add(innerClass);
            }
        }
    }

    _javaTerms = addStaticBlocks(javaTerms, staticBlocks);

    return _javaTerms;
}

From source file:com.liferay.tools.sourceformatter.JavaClass.java

License:Open Source License

protected boolean isValidJavaTerm(String content) {
    if (content.startsWith(_indent + "static {")) {
        return true;
    }/* w  w w.j a  va2  s  .  co  m*/

    while (!content.startsWith(_indent + "private") && !content.startsWith(_indent + "protected")
            && !content.startsWith(_indent + "public")) {

        content = content.substring(content.indexOf("\n") + 1);
    }

    int indentLinesCount = StringUtil.count(content, "\n" + _indent)
            - StringUtil.count(content, "\n" + _indent + StringPool.TAB);

    content = StringUtil.trim(content);

    if (content.endsWith(StringPool.CLOSE_CURLY_BRACE)
            && ((indentLinesCount == 1) || (((indentLinesCount == 2) || (indentLinesCount == 3))
                    && content.contains("\n" + _indent + "static {")))) {

        return true;
    } else if ((content.endsWith("};") && (indentLinesCount == 1))
            || (content.endsWith(StringPool.SEMICOLON) && (indentLinesCount == 0))) {

        return true;
    }

    return false;
}

From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java

License:Open Source License

protected static int getLeadingTabCount(String line) {
    int leadingTabCount = 0;

    while (line.startsWith(StringPool.TAB)) {
        line = line.substring(1);//from ww w . j  av a  2 s .  com

        leadingTabCount++;
    }

    return leadingTabCount;
}

From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java

License:Open Source License

protected static String sortAnnotations(String content, String indent) throws IOException {

    UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new UnsyncStringReader(content));

    String line = null;/*from ww w  . j  av a 2s. c  o m*/

    String annotation = StringPool.BLANK;
    String previousAnnotation = StringPool.BLANK;

    while ((line = unsyncBufferedReader.readLine()) != null) {
        if (line.equals(indent + StringPool.CLOSE_CURLY_BRACE)) {
            return content;
        }

        if (StringUtil.count(line, StringPool.TAB) == indent.length()) {
            if (Validator.isNotNull(previousAnnotation) && (previousAnnotation.compareTo(annotation) > 0)) {

                content = StringUtil.replaceFirst(content, previousAnnotation, annotation);
                content = StringUtil.replaceLast(content, annotation, previousAnnotation);

                return sortAnnotations(content, indent);
            }

            if (line.startsWith(indent + StringPool.AT)) {
                if (Validator.isNotNull(annotation)) {
                    previousAnnotation = annotation;
                }

                annotation = line + "\n";
            } else {
                annotation = StringPool.BLANK;
                previousAnnotation = StringPool.BLANK;
            }
        } else {
            if (Validator.isNull(annotation)) {
                return content;
            }

            annotation += line + "\n";
        }
    }

    return content;
}

From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java

License:Open Source License

protected String checkIfClause(String ifClause, String fileName, int lineCount) throws IOException {

    String ifClauseSingleLine = StringUtil.replace(ifClause,
            new String[] { StringPool.TAB + StringPool.SPACE, StringPool.TAB,
                    StringPool.OPEN_PARENTHESIS + StringPool.NEW_LINE, StringPool.NEW_LINE },
            new String[] { StringPool.TAB, StringPool.BLANK, StringPool.OPEN_PARENTHESIS, StringPool.SPACE });

    checkIfClauseParentheses(ifClauseSingleLine, fileName, lineCount);

    return checkIfClauseTabsAndSpaces(ifClause);
}