use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.
the class ConvertBridge method run.
public void run() {
JSONObject json = null;
operator.cleanErrorInfo();
try {
json = parseJSONObject(jsonStr);
} catch (Exception e) {
String jsonTS = removeComment(jsonStr);
jsonTS = jsonTS.replaceAll("^.*?\\{", "{");
try {
json = parseJSONObject(jsonTS);
} catch (Exception e2) {
handleDataError(e2);
}
}
if (json != null) {
try {
ClassEntity classEntity = collectClassAttribute(targetClass, Config.getInstant().isReuseEntity());
if (classEntity != null) {
for (FieldEntity item : classEntity.getFields()) {
declareFields.put(item.getKey(), item);
CheckUtil.getInstant().addDeclareFieldName(item.getKey());
}
}
if (Config.getInstant().isSplitGenerate()) {
collectPackAllClassName();
}
operator.setVisible(false);
parseJson(json);
} catch (Exception e2) {
handleDataError(e2);
operator.setVisible(true);
}
}
declareFields = null;
declareClass = null;
}
use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.
the class ConvertBridge method createInnerClass.
/**
* @param className
* @param json
* @param parentClass
* @return
*/
private ClassEntity createInnerClass(String className, JSONObject json, ClassEntity parentClass) {
if (Config.getInstant().isSplitGenerate()) {
String qualifiedName = packageName == null ? className : packageName + "." + className;
if (CheckUtil.getInstant().containsDeclareClassName(qualifiedName)) {
//存在同名。
PsiClass psiClass = PsiClassUtil.exist(file, qualifiedName);
if (psiClass != null) {
ClassEntity classEntity = collectClassAttribute(psiClass, false);
classEntity.setLock(true);
if (classEntity.isSame(json)) {
// if (Config.getInstant().isReuseEntity()) {
declareClass.put(classEntity.getQualifiedName(), classEntity);
// }
return classEntity;
}
}
}
}
ClassEntity subClassEntity = new ClassEntity();
Set<String> set = json.keySet();
List<String> list = new ArrayList<String>(set);
List<FieldEntity> fields = createFields(json, list, subClassEntity);
subClassEntity.addAllFields(fields);
if (Config.getInstant().isSplitGenerate()) {
subClassEntity.setPackName(packageName);
} else {
subClassEntity.setPackName(parentClass.getQualifiedName());
}
subClassEntity.setClassName(className);
if (handleDeclareClassName(subClassEntity, "")) {
CheckUtil.getInstant().addDeclareClassName(subClassEntity.getQualifiedName());
}
if (Config.getInstant().isReuseEntity()) {
declareClass.put(subClassEntity.getQualifiedName(), subClassEntity);
}
parentClass.addInnerClass(subClassEntity);
return subClassEntity;
}
use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.
the class ConvertBridge method collectClassAttribute.
private ClassEntity collectClassAttribute(PsiClass psiClass, boolean collectInnerClass) {
if (psiClass == null) {
return null;
}
ClassEntity innerClass = new ClassEntity();
innerClass.setLock(true);
declareClass.put(psiClass.getQualifiedName(), innerClass);
CheckUtil.getInstant().addDeclareClassName(psiClass.getQualifiedName());
innerClass.setClassName(psiClass.getName());
innerClass.addAllFields(collectDeclareFields(psiClass));
innerClass.setPsiClass(psiClass);
innerClass.setPackName(getPackName(psiClass));
if (collectInnerClass) {
recursionInnerClass(innerClass);
}
return innerClass;
}
use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.
the class ConvertBridge method existDeclareClass.
private ClassEntity existDeclareClass(JSONObject jsonObject) {
for (ClassEntity classEntity : declareClass.values()) {
Iterator<String> keys = jsonObject.keys();
boolean had = false;
while (keys.hasNext()) {
String key = keys.next();
Object value = jsonObject.get(key);
had = false;
for (FieldEntity fieldEntity : classEntity.getFields()) {
if (fieldEntity.getKey().equals(key) && DataType.isSameDataType(DataType.typeOfString(fieldEntity.getType()), DataType.typeOfObject(value))) {
had = true;
break;
}
}
if (!had) {
break;
}
}
if (had) {
return classEntity;
}
}
return null;
}
use of org.gsonformat.intellij.entity.ClassEntity in project GsonFormat by zzz40500.
the class DataWriter method run.
@Override
protected void run() {
if (targetClass == null) {
return;
}
generateClassList.clear();
new ClassProcessor(factory, cls).generate(targetClass, new IProcessor() {
@Override
public void onStarProcess(ClassEntity classEntity, PsiElementFactory factory, PsiClass cls) {
generateClassList.add(cls.getQualifiedName());
}
@Override
public void onEndProcess(ClassEntity classEntity, PsiElementFactory factory, PsiClass cls) {
}
@Override
public void onStartGenerateClass(PsiElementFactory factory, ClassEntity classEntity, PsiClass parentClass) {
}
@Override
public void onEndGenerateClass(PsiElementFactory factory, ClassEntity classEntity, PsiClass parentClass, PsiClass generateClass) {
generateClassList.add(generateClass.getQualifiedName());
}
});
}
Aggregations