Search in sources :

Example 6 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project lastaflute by lastaflute.

the class SimpleTemplateManager method setupOrElseValueIfNeeds.

// -----------------------------------------------------
// orElse()
// --------
protected void setupOrElseValueIfNeeds(BoundValue boundValue, String optionDef) {
    if (Srl.is_Null_or_TrimmedEmpty(optionDef)) {
        return;
    }
    final Object targetValue = boundValue.getTargetValue();
    if (targetValue != null) {
        return;
    }
    final List<String> optionList = Srl.splitListTrimmed(optionDef, "|");
    final String orElseBegin = "orElse(";
    final String orElseEnd = ")";
    optionList.stream().filter(op -> {
        return op.startsWith(orElseBegin) && op.endsWith(orElseEnd);
    }).findFirst().ifPresent(op -> {
        // e.g. /*pmb.sea:orElse('land')*/
        final ScopeInfo scope = Srl.extractScopeWide(op, orElseBegin, orElseEnd);
        final String content = scope.getContent().trim();
        if (!Srl.isQuotedSingle(content)) {
            // string only supported, is enough here
            throwTemplateOrElseValueNotQuotedException(optionDef);
        }
        boundValue.setTargetValue(Srl.unquoteSingle(content));
    });
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 7 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class JavaPropertiesReader method read.

// ===================================================================================
// Read
// ====
public JavaPropertiesResult read() {
    final List<JavaPropertiesProperty> propertyList = newArrayList();
    final List<String> duplicateKeyList = newArrayList();
    final Map<String, String> keyCommentMap = readKeyCommentMap(duplicateKeyList);
    final Properties prop = readPlainProperties();
    final List<String> keyList = orderKeyList(prop, keyCommentMap);
    for (String key : keyList) {
        final String value = prop.getProperty(key);
        final String comment = keyCommentMap.get(key);
        final JavaPropertiesProperty property = new JavaPropertiesProperty(key, value);
        final String defName = Srl.replace(key, ".", "_").toUpperCase();
        property.setDefName(defName);
        final String camelizedName = Srl.camelize(defName);
        property.setCamelizedName(camelizedName);
        property.setCapCamelName(Srl.initCap(camelizedName));
        property.setUncapCamelName(Srl.initUncap(camelizedName));
        final List<ScopeInfo> variableScopeList = analyzeVariableScopeList(value);
        final List<Integer> variableNumberList = DfCollectionUtil.newArrayListSized(variableScopeList.size());
        final List<String> variableStringList = DfCollectionUtil.newArrayListSized(variableScopeList.size());
        reflectToVariableList(key, variableScopeList, variableNumberList, variableStringList);
        property.setVariableNumberList(variableNumberList);
        property.setVariableStringList(variableStringList);
        final List<String> variableArgNameList = prepareVariableArgNameList(variableStringList);
        property.setVariableArgNameList(variableArgNameList);
        property.setVariableArgDef(buildVariableArgDef(variableArgNameList));
        property.setVariableArgSet(buildVariableArgSet(variableArgNameList));
        property.setComment(comment);
        if (containsSecureAnnotation(property)) {
            property.toBeSecure();
        }
        propertyList.add(property);
    }
    return prepareResult(prop, propertyList, duplicateKeyList);
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo) Properties(java.util.Properties)

Example 8 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfSql2EntityMarkAnalyzer method getDescription.

public String getDescription(String sql) {
    final String oldStyleDescription = findOldStyleDescription(sql);
    if (oldStyleDescription != null) {
        return oldStyleDescription;
    }
    if (sql.startsWith("/*") && sql.contains("*/")) {
        // new style
        final ScopeInfo commentScope = Srl.extractScopeFirst(sql, "/*", "*/");
        final String comment = commentScope.getContent();
        final ScopeInfo descScope = Srl.extractScopeFirst(comment, "[", "]");
        if (descScope != null) {
            final String desc = Srl.substringFirstRear(comment, "]").trim();
            if (!desc.isEmpty()) {
                return desc;
            }
        }
    }
    return null;
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 9 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfSql2EntityMarkAnalyzer method getListBetweenBeginEndMark.

protected List<DfSql2EntityMark> getListBetweenBeginEndMark(String targetStr, String beginMark, String endMark) {
    final List<DfSql2EntityMark> markList = DfCollectionUtil.newArrayList();
    final List<String> lineList = Srl.splitListTrimmed(targetStr, "\n");
    final String outsideCommentMark = "//";
    for (String line : lineList) {
        final ScopeInfo scopeInfo = Srl.extractScopeFirst(line, beginMark, endMark);
        if (scopeInfo == null) {
            continue;
        }
        final DfSql2EntityMark markInfo = new DfSql2EntityMark();
        markInfo.setContent(scopeInfo.getContent());
        final int endIndex = scopeInfo.getEndIndex();
        String outsideComment = null;
        final String rearAll = line.substring(endIndex);
        if (rearAll.contains(outsideCommentMark)) {
            outsideComment = Srl.substringFirstRear(rearAll, outsideCommentMark);
        }
        markInfo.setComment(outsideComment);
        markList.add(markInfo);
    }
    return markList;
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 10 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfSql2EntityMarkAnalyzer method getFloatingParameterCommentMap.

public Map<String, String> getFloatingParameterCommentMap(String sql) {
    final Map<String, String> commentMap = StringKeyMap.createAsFlexible();
    final List<String> splitList = Srl.splitList(sql, "\n");
    final String lineCommentMark = " --";
    final String columnCommentMark = " //";
    final String pmbMark = "pmb.";
    final String bindVariableBeginMark = "/*" + pmbMark;
    final String ifCommentBeginMark = "/*IF " + pmbMark;
    final String forCommentBeginMark = "/*FOR " + pmbMark;
    final String parameterEndMark = "*/";
    for (String line : splitList) {
        if (!Srl.containsAll(line, lineCommentMark, columnCommentMark)) {
            continue;
        }
        if (!Srl.containsAny(line, bindVariableBeginMark, ifCommentBeginMark, forCommentBeginMark)) {
            continue;
        }
        if (Srl.count(line, pmbMark) >= 2) {
            continue;
        }
        ScopeInfo scopeInfo = Srl.extractScopeFirst(line, bindVariableBeginMark, parameterEndMark);
        if (scopeInfo == null) {
            scopeInfo = Srl.extractScopeFirst(line, ifCommentBeginMark, parameterEndMark);
            if (scopeInfo == null) {
                scopeInfo = Srl.extractScopeFirst(line, forCommentBeginMark, parameterEndMark);
                if (scopeInfo == null) {
                    continue;
                }
            }
        }
        final String property = Srl.substringFirstFront(scopeInfo.getContent().trim(), " ", ".", "=", "!", "<", ">", ":");
        final String lineComment = Srl.substringFirstRear(line, lineCommentMark);
        if (!lineComment.contains(columnCommentMark)) {
            continue;
        }
        final String columnComment = Srl.substringFirstRear(lineComment, columnCommentMark);
        if (Srl.is_Null_or_TrimmedEmpty(columnComment)) {
            continue;
        }
        // e.g. ... = /*pmb.memberName*/'S%' -- // comment
        final String trimmedComment = columnComment.trim();
        final String existingComment = commentMap.get(property);
        final String realComment;
        if (existingComment != null) {
            realComment = existingComment + " / " + trimmedComment;
        } else {
            realComment = trimmedComment;
        }
        commentMap.put(property, realComment);
    }
    return commentMap;
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Aggregations

ScopeInfo (org.dbflute.util.Srl.ScopeInfo)42 File (java.io.File)7 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 FileTextIO (org.dbflute.helper.filesystem.FileTextIO)6 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 LinkedHashSet (java.util.LinkedHashSet)4 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3 Set (java.util.Set)3 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)3 DateTimeFormatter (java.time.format.DateTimeFormatter)2 TemporalAccessor (java.time.temporal.TemporalAccessor)2 DfBuildProperties (org.dbflute.DfBuildProperties)2 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 FileHierarchyTracer (org.dbflute.helper.filesystem.FileHierarchyTracer)2