private void createTemplateParamterFromTemprateparamlist( CompounddefType compounddefType, IClass clazz) throws ProjectNotFoundException, InvalidEditingException { TemplateparamlistType templateparamlist = compounddefType.getTemplateparamlist(); if (templateparamlist != null) { List<ParamType> params = templateparamlist.getParam(); for (ParamType param : params) { Type type = this.typeUtil.createType(param); try { IClass findClass = this.findClass(type); if (findClass == null) { this.basicModelEditor.createTemplateParameter( clazz, type.getName(), (IClass) null, null); } else { this.basicModelEditor.createTemplateParameter( clazz, type.getName(), (IClass) null, findClass); } } catch (InvalidEditingException e) { if (!e.getKey().equals(InvalidEditingException.NAME_DOUBLE_ERROR_KEY)) { throw e; } LOG.info("invalid editing {},{}", clazz.getName(), type.getName()); } } } }
private void createOperationOrAttributeFromSectionDefTypes( CompounddefType compounddefType, IClass clazz) throws ProjectNotFoundException, InvalidEditingException { List<SectiondefType> sectiondefTypes = compounddefType.getSectiondef(); for (SectiondefType sectiondefType : sectiondefTypes) { List<MemberdefType> memberdefTypes = sectiondefType.getMemberdef(); for (MemberdefType memberdefType : memberdefTypes) { if (!(memberdefType.getKind() == DoxMemberKind.FUNCTION || memberdefType.getKind() == DoxMemberKind.VARIABLE || memberdefType.getKind() == DoxMemberKind.PROPERTY)) { continue; } Type type = this.typeUtil.createType(memberdefType); try { IClass findClass = this.findClass(type); if (memberdefType.getKind() == DoxMemberKind.FUNCTION) { this.createOperation(clazz, type, memberdefType, findClass); } else if (memberdefType.getKind() == DoxMemberKind.VARIABLE || memberdefType.getKind() == DoxMemberKind.PROPERTY) { this.createAttribute(clazz, type, memberdefType, findClass); } else { LOG.trace(format("ここでは使用しないDoxMemberKind : %s", memberdefType.getKind().toString())); } } catch (InvalidEditingException e) { if (!e.getKey().equals(InvalidEditingException.NAME_DOUBLE_ERROR_KEY)) { throw e; } LOG.info("invalid editing {},{}", clazz.getName(), type.getName()); } } } }
protected <M extends INamedElement> M createModel( Class<M> clazz, String namespace, CompounddefType compounddefType) throws InvalidEditingException, ProjectNotFoundException { NamespaceClass parent = this.astahModelUtil.getParentNamespace(namespace); INamedElement parentElement = this.astahModelUtil.getParentModel(project, parent.namespace); if (parentElement == null) { // インナークラスの場合、親クラスを作る return this.createModel(clazz, parent.namespace, compounddefType); } INamedElement element = this.astahModelUtil.getParentModel(project, parent.getFullName()); if (element != null) { @SuppressWarnings("unchecked") M m = (M) element; return m; } if (parentElement instanceof IPackage) { element = this.basicModelEditor.createClass((IPackage) parentElement, parent.clazz); } else if (parentElement instanceof IClass) { element = this.basicModelEditor.createClass((IClass) parentElement, parent.clazz); } LOG.trace(format("create model : %s", parent.getFullName())); this.setLanguage(CPLUS_CLASS, element); element.setDefinition(this.parseDescription(compounddefType.getDetaileddescription())); // クラス内のenumを作成する this.createEnum(compounddefType, element); @SuppressWarnings("unchecked") M m = (M) element; return m; }
private void addStereotypeFromCompounddefTypeKind(CompounddefType compounddefType, IClass clazz) throws InvalidEditingException { try { switch (compounddefType.getKind()) { case STRUCT: clazz.addStereotype(DoxCompoundKind.STRUCT.value()); break; case UNION: clazz.addStereotype(DoxCompoundKind.UNION.value()); break; default: break; } } catch (InvalidEditingException e) { if (!e.getKey().equals(InvalidEditingException.NAME_DOUBLE_ERROR_KEY)) { throw e; } LOG.info("invalid editing {},{}", clazz.getName(), compounddefType.getKind()); } }
public void modifyClass(CompounddefType compounddefType) throws ProjectNotFoundException, InvalidEditingException { // class, struct, union だけ処理する switch (compounddefType.getKind()) { case CLASS: case STRUCT: case UNION: break; case NAMESPACE: case CATEGORY: case DIR: case EXAMPLE: case EXCEPTION: case FILE: case GROUP: case INTERFACE: case PAGE: case PROTOCOL: default: LOG.trace(format("ここでは使用しないDoxCompoundKind : %s", compounddefType.getKind().toString())); return; } // IClass を 取得して、属性、操作等をセットする IClass clazz = this.astahModelUtil.getModelWithPath( IClass.class, project, compounddefType.getCompoundname()); if (clazz == null) { LOG.debug( format( "class is null. Compoundname : %s, id : %s", compounddefType.getCompoundname(), compounddefType.getId())); return; } addStereotypeFromCompounddefTypeKind(compounddefType, clazz); // テンプレートパラメーター createTemplateParamterFromTemprateparamlist(compounddefType, clazz); // 継承 createInheritanceFromBaseCompoundDef(compounddefType, clazz); // 属性、操作 createOperationOrAttributeFromSectionDefTypes(compounddefType, clazz); }
public void createNamespace(IModel model, CompounddefType compounddefType) throws InvalidEditingException { if (compounddefType.getKind() == DoxCompoundKind.NAMESPACE) { String[] namespaces = compounddefType.getCompoundname().split("::"); IPackage parentModel = model; for (String namespace : namespaces) { IPackage pkg; if ((pkg = this.getNamespace(parentModel, namespace)) == null) { // 無名名前空間で、doxygenの設定で表示しない場合(@から始まるパッケージ)は作成しない。 if (!namespace.startsWith("@")) { parentModel = this.basicModelEditor.createPackage(parentModel, namespace); LOG.trace(format("create model : %s", parentModel.getFullName("::"))); // パッケージ内のenumを作成する this.createEnum(compounddefType, parentModel); } } else { LOG.debug(String.format("%s is exits.", pkg.getFullName("::"))); parentModel = pkg; } } } }
protected void createEnum(CompounddefType compounddefType, INamedElement element) throws InvalidEditingException { List<SectiondefType> sectiondefTypes = compounddefType.getSectiondef(); for (SectiondefType sectiondefType : sectiondefTypes) { List<MemberdefType> memberdefTypes = sectiondefType.getMemberdef(); for (MemberdefType memberdefType : memberdefTypes) { if (memberdefType.getKind() != DoxMemberKind.ENUM) { continue; } Type type = this.typeUtil.createEnumType(memberdefType); IClass enumClass = null; try { if (element instanceof IPackage) { enumClass = this.basicModelEditor.createClass((IPackage) element, type.getName()); } else if (element instanceof IClass) { enumClass = this.basicModelEditor.createClass((IClass) element, type.getName()); } } catch (InvalidEditingException e) { // グローバルで同名は存在するので無視する if (!e.getKey().equals(InvalidEditingException.NAME_DOUBLE_ERROR_KEY)) { throw e; } } if (enumClass == null) { break; } enumClass.addStereotype(STEREOTYPE_ENUM); enumClass.setVisibility(type.getVisiblity()); List<EnumvalueType> enumvalues = memberdefType.getEnumvalue(); if (enumvalues == null) { break; } for (EnumvalueType enumvalue : enumvalues) { Type enumtype = this.typeUtil.createEnumType(enumvalue); try { IAttribute enumAttribute = this.basicModelEditor.createAttribute(enumClass, enumtype.getName(), enumClass); enumAttribute.setVisibility(enumtype.getVisiblity()); enumAttribute.setInitialValue(enumtype.getInitialValue()); // enum なので static とする enumAttribute.setStatic(true); } catch (InvalidEditingException e) { // 同じネームスペース名で同じ名前のEnumの中に同じ名前の定数を宣言しているときは例外を出したくない if (!e.getKey().equals(InvalidEditingException.NAME_DOUBLE_ERROR_KEY)) { throw e; } } } } } }
protected boolean isCreateGlobalClass(CompounddefType compounddefType) { if (!(compounddefType.getKind() == DoxCompoundKind.FILE || compounddefType.getKind() == DoxCompoundKind.NAMESPACE)) { return false; } List<SectiondefType> sectiondefTypes = compounddefType.getSectiondef(); if (compounddefType.getSectiondef() == null || compounddefType.getSectiondef().isEmpty()) { return false; } for (SectiondefType sectiondefType : sectiondefTypes) { if (!isCreateGlobalSectiondefType(sectiondefType)) { continue; } List<MemberdefType> memberdefTypes = sectiondefType.getMemberdef(); for (MemberdefType memberdefType : memberdefTypes) { if (!isCreateGlobalMemberdefType(memberdefType)) { continue; } return true; } } return false; }
public void createGlobalClass(CompounddefType compounddefType) throws InvalidEditingException, ProjectNotFoundException { initProject(); if (!isCreateGlobalClass(compounddefType)) { return; } Type type = this.typeUtil.createEnumType(compounddefType); if (isEmpty(type.getNamespaceClass().clazz)) { return; } if (this.findClass(type) != null) { return; } IPackage pkg = project; if (compounddefType.getKind() == DoxCompoundKind.NAMESPACE) { pkg = this.astahModelUtil.getModelWithPath( IPackage.class, project, compounddefType.getCompoundname()); } IClass clazz = this.basicModelEditor.createClass(pkg, type.getNamespaceClass().clazz); this.setLanguage(CPLUS_CLASS, clazz); // グローバルな enum を作成 this.createEnum(compounddefType, pkg); }
private void createInheritanceFromBaseCompoundDef(CompounddefType compounddefType, IClass clazz) throws ProjectNotFoundException, InvalidEditingException { List<CompoundRefType> basecompoundrefs = compounddefType.getBasecompoundref(); // 2つ同名の親が設定されているxmlがあるので、同じものは親としないためのチェック用。 Set<String> generalizations = new HashSet<>(); for (CompoundRefType basecompoundref : basecompoundrefs) { Type type = this.typeUtil.createType(basecompoundref); IGeneralization generalization = null; try { IClass baseClass = this.findClass(type); if (baseClass == null) { if (type.getNamespaceClass() != null || !isEmpty(type.getNamespaceClass().clazz)) { IClass generalizationClass = this.basicModelEditor.createClass( createPackage(type), type.getNamespaceClass().clazz); generalization = this.basicModelEditor.createGeneralization(clazz, generalizationClass, ""); generalizations.add(type.getNamespaceClass().getFullName()); } else { LOG.info( "not created generalization. clazz:{}, type:{}", clazz.getName(), type.getName()); continue; } } else { if (!generalizations.contains(type.getNamespaceClass().getFullName())) { generalization = this.basicModelEditor.createGeneralization(clazz, baseClass, ""); generalizations.add(type.getNamespaceClass().getFullName()); } else { LOG.info( "generalization already exists. generalization:{}, clazz:{}, baseClass:{}", type.getNamespaceClass().getFullName(), clazz, baseClass); continue; } } if (!isEmpty(type.getVisiblity())) { generalization.setVisibility(type.getVisiblity()); } } catch (InvalidEditingException e) { if (!e.getKey().equals(InvalidEditingException.NAME_DOUBLE_ERROR_KEY)) { throw e; } LOG.info("invalid editing {},{}", clazz.getName(), type.getName()); } } }
public INamedElement createClass(CompounddefType compounddefType) throws InvalidEditingException, ProjectNotFoundException { IModel project = initProject(); if (compounddefType == null || compounddefType.getKind() == null) { return null; } INamedElement namedElement = this.astahModelUtil.getModelWithPath( IClass.class, project, compounddefType.getCompoundname()); if (namedElement != null) { return namedElement; } switch (compounddefType.getKind()) { case CLASS: namedElement = this.createModel(IClass.class, compounddefType.getCompoundname(), compounddefType); break; case STRUCT: namedElement = this.createModel(IClass.class, compounddefType.getCompoundname(), compounddefType); break; case UNION: namedElement = this.createModel(IClass.class, compounddefType.getCompoundname(), compounddefType); break; case NAMESPACE: namedElement = this.createModel(IPackage.class, compounddefType.getCompoundname(), compounddefType); break; case CATEGORY: case DIR: case EXAMPLE: case EXCEPTION: case FILE: case GROUP: case INTERFACE: case PAGE: case PROTOCOL: default: LOG.trace(format("現在使っていないDoxCompoundKind : %s", compounddefType.getKind().toString())); break; } return namedElement; }
public void modifyGlobalClass(CompounddefType compounddefType) throws InvalidEditingException, ProjectNotFoundException { if (!isCreateGlobalClass(compounddefType)) { return; } Type type = this.typeUtil.createEnumType(compounddefType); IClass findClass = this.findClass(type); if (findClass == null) { return; } // グローバルな属性・関数を作成 List<SectiondefType> sectiondefTypes = compounddefType.getSectiondef(); for (SectiondefType sectiondefType : sectiondefTypes) { if (!isCreateGlobalSectiondefType(sectiondefType)) { continue; } List<MemberdefType> memberdefTypes = sectiondefType.getMemberdef(); for (MemberdefType memberdefType : memberdefTypes) { if (!isCreateGlobalMemberdefType(memberdefType)) { continue; } Type memberType = this.typeUtil.createType(memberdefType); IClass memberdefClass = this.findClass(memberType); if (memberdefType.getKind() == DoxMemberKind.FUNCTION) { this.createOperation(findClass, memberType, memberdefType, memberdefClass); } else if (memberdefType.getKind() == DoxMemberKind.VARIABLE) { try { this.createAttribute(findClass, memberType, memberdefType, memberdefClass, false); } catch (InvalidEditingException e) { // グローバルで同名は存在するので無視する if (!e.getKey().equals(InvalidEditingException.NAME_DOUBLE_ERROR_KEY)) { throw e; } } } } } }