當前位置: 首頁>>代碼示例>>Java>>正文


Java JCodeModel.countArtifacts方法代碼示例

本文整理匯總了Java中com.sun.codemodel.JCodeModel.countArtifacts方法的典型用法代碼示例。如果您正苦於以下問題:Java JCodeModel.countArtifacts方法的具體用法?Java JCodeModel.countArtifacts怎麽用?Java JCodeModel.countArtifacts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.codemodel.JCodeModel的用法示例。


在下文中一共展示了JCodeModel.countArtifacts方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mapSchemaToPojo

import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
/**
 * Maps a JSON Schema to a JCodeModel using JSONSchema2Pojo and encapsulates it along with some
 * metadata into an {@link ApiBodyMetadata} object.
 *
 * @param document
 *            The Raml document being parsed
 * @param schema
 *            The Schema (full schema or schema name to be resolved)
 * @param basePackage
 *            The base package for the classes we are generating
 * @param name
 *            The suggested name of the class based on the api call and whether it's a
 *            request/response. This will only be used if no suitable alternative is found in
 *            the schema
 * @param schemaLocation
 *            Base location of this schema, will be used to create absolute URIs for $ref tags
 *            eg "classpath:/"
 * @return Object representing this Body
 */
public static ApiBodyMetadata mapSchemaToPojo(RamlRoot document, String schema, String basePackage, String name, String schemaLocation) {
    String resolvedName = null;
    String schemaName = schema;

    // Check if we have the name of a schema or an actual schema
    String resolvedSchema = SchemaHelper.resolveSchema(schema, document);
    if (resolvedSchema == null) {
        resolvedSchema = schema;
        schemaName = null;
    }

    // Extract name from schema
    resolvedName = extractNameFromSchema(resolvedSchema, schemaName, name);
    JCodeModel codeModel = buildBodyJCodeModel(basePackage, StringUtils.hasText(schemaLocation) ? schemaLocation : "classpath:/", resolvedName, resolvedSchema, null, null);
    if (codeModel != null) {
        if (codeModel.countArtifacts() == 1) {
            try {
                // checking has next twice might be more efficient but this is more readable, if
                // we ever run into speed issues here..optimise
                Iterator<JPackage> packages = codeModel.packages();

                // in the case that we have empty packages we need to skip them to get to the
                // class
                JPackage nextPackage = packages.next();
                while (!nextPackage.classes().hasNext() && packages.hasNext()) {
                    nextPackage = packages.next();
                }
                resolvedName = nextPackage.classes().next().name();
            }
            catch (NullPointerException npe) {
                // do nothing, use previous name
            }
        }
        return new ApiBodyMetadata(resolvedName, resolvedSchema, codeModel);
    }
    else {
        return null;
    }
}
 
開發者ID:phoenixnap,項目名稱:springmvc-raml-plugin,代碼行數:59,代碼來源:SchemaHelper.java

示例2: ApiBodyMetadata

import com.sun.codemodel.JCodeModel; //導入方法依賴的package包/類
public ApiBodyMetadata (String name, String schema, JCodeModel codeModel) {
	super();
	this.schema = schema;
	this.name = name;
	this.codeModel = codeModel;
	
	boolean typeFound = false;
	
	int typeIdx = schema.indexOf("type");
	
	while (!typeFound) {
		if (typeIdx == -1) {
			typeFound = true;
			break;
		}
		if (nestingCounter(schema, typeIdx) == 1) {
			typeFound = true;
		} else {
			typeIdx = schema.indexOf("type", typeIdx+1);
		}
	}
	
	if (typeIdx != -1) {
		int quoteIdx = schema.indexOf("\"", typeIdx + 6);
		if (quoteIdx != -1) {
			int nextQuoteIdxIdx = schema.indexOf("\"", quoteIdx+1);
			if (nextQuoteIdxIdx != -1) {
				String possibleType = schema.substring(quoteIdx+1, nextQuoteIdxIdx);
				this.name = NamingHelper.getResourceName(this.name, true);
				if ("array".equals(possibleType.toLowerCase())) {
					array = true;
				}
				if (codeModel.countArtifacts() == 0) {
					if (!"object".equals(possibleType.toLowerCase())) {
						try {
							this.name = SchemaHelper.mapSimpleType(RamlParamType.valueOf(possibleType.toUpperCase()), null).getSimpleName();
						} catch (Exception ex) {
							this.name = String.class.getSimpleName(); //default to string
						}
						this.codeModel = null;
					}
					
			}
		}
	}
	}
}
 
開發者ID:phoenixnap,項目名稱:springmvc-raml-plugin,代碼行數:48,代碼來源:ApiBodyMetadata.java


注:本文中的com.sun.codemodel.JCodeModel.countArtifacts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。