Method* ClassData:: lookupInterfaceMethod(const char *name,const char *desc) { //printf("look up interface method\n"); if(! (this->isInterface()) ) ;//////////////////////// u2 i; /* search in this interface */ //printf("search in this interface\n"); for(i=0; i<methodsCount ; i++) { if( (strcmp(name ,methods[i]-> getName())==0) && (strcmp(desc , methods[i]->getDesc() )==0) ) /* another method */ return methods[i]; } //printf("search in this super interfaces\n"); /* search the super interfaces */ /* what is meant by sueprinterface of interfaces * directly implemented by this class */ ClassData * interface; Method * method; for(i=0; i<interfacesCount ; i++) { interface = constantPool-> getClassData(interfaces[i]); if( (method = interface->lookupInterfaceMethod(name,desc)) != NULL) return method; } /* search in class Object */ return NULL; }
NBaseObj* NReflect::Create(LPCTSTR szNamespace, LPCTSTR szClassName, LPCSTR filePath, int line) { NBaseObj* result = NULL; ClassData* pClassData; if(GetClassData(szNamespace, szClassName, pClassData)) { if(pClassData->flag == None) { result = pClassData->creator(filePath, line); } else if(pClassData->flag == Singleton) { if(pClassData->existObj == NULL) { pClassData->existObj = pClassData->creator(filePath, line); if(pClassData->existObj != NULL) { pClassData->existObj->AddRef(); } } result = pClassData->existObj; } } if(result != NULL) result->AddRef(); NAssertError(result != NULL, _T("Invalid data in NReflect::Create")); return result; }
Field * ClassData:: lookupField(const char *name,const char*desc) { //printf("return the Field block using its name and descriptor\n"); u2 i; /* search in this class */ for(i=0; i<fieldsCount ; i++) { if( (strcmp(name , fields[i]-> getName())==0 ) && (strcmp(desc , fields[i]->getDesc() )==0) ) /* another method */ return fields[i]; } //printf("searching the super interfaces for this field\n"); /* search the super interfaces */ /* what is meant by interface extended by this class */ ClassData * interface; Field * field; for(i=0; i<interfacesCount ; i++) { interface = constantPool-> getClassData(interfaces[i]); if( (field = interface->lookupField(name,desc)) != NULL) return field; } /* search in the super class */ //printf("searching the super class for this field\n"); ClassData * myParent=constantPool->getClassData(superClass); return myParent->lookupField(name,desc); }
Method * ClassData:: lookupMethod(const char *name, const char*desc) { //printf("return the Method block using its name and descriptor\n"); if(this->isInterface()) ;/////////exception(); u2 i; /* search in this class */ for(i=0; i<methodsCount ; i++) { if( (strcmp(name , methods[i]-> getName() )==0) && (strcmp(desc , methods[i]->getDesc() )==0) ) /* another method */ return methods[i]; } //printf("searching the super class for this Method\n"); /* search in the super class */ Method * method; ClassData * myParent=constantPool->getClassData(superClass); if( (method=myParent->lookupMethod(name,desc)) != NULL) return method; /* search the super interfaces */ /* what is meant by sueprinterface of interfaces * directly implemented by this class */ //printf("searching the super interfaces for this Method\n"); ClassData * interface; for(i=0; i<interfacesCount ; i++) { interface = constantPool-> getClassData(interfaces[i]); if( (method = interface->lookupMethod(name,desc)) != NULL) return method; } return NULL; }
void ClassData:: initialize(void) { //printf("initializing the class--> commented now \n"); //printf("\tso it does only a loop to get the method clinit from the methods array\n"); ClassData * myParent; Method * clInit=NULL; u2 i; // if(strcmp(constantPool->getClassName(superClass),"java/lang/Object")!=0) if(superClass!=0) { myParent = constantPool->getClassData(superClass); if( !(myParent->isInitialized()) ) myParent->initialize(); } /* search in this class */ for(i=0; i<methodsCount ; i++) { if(strcmp(methods[i]-> getName() ,"<clinit>")==0 ) /* another method */ { clInit = methods[i]; break; } } initialized = true; if(clInit) { ExecutionEng * exec=ExecutionEng::getInstance(); exec->executeMethod(NULL,clInit); //;//execEng->exec(clInit); } //initialized = true; }
QString get_python_name(const BrowserClass * cl, ShowContextMode mode) { ClassData * d = (ClassData *) cl->get_data(); if (! d->python_is_external()) return cl->contextual_name(mode); QString name = cl->get_name(); QString s = d->get_pythondecl(); int index = s.indexOf('\n'); s = (index == -1) ? s.trimmed() : s.left(index).trimmed(); if ((index = s.indexOf("${name}")) != -1) s.replace(index, 7, name); else if ((index = s.indexOf("${Name}")) != -1) s.replace(index, 7, capitalize(name)); else if ((index = s.indexOf("${NAME}")) != -1) s.replace(index, 7, name.toUpper()); else if ((index = s.indexOf("${nAME}")) != -1) s.replace(index, 7, name.toLower()); return s; }
QString get_idl_name(const BrowserClass * cl, ShowContextMode mode) { ClassData * d = (ClassData *) cl->get_data(); if (! d->idl_is_external()) return cl->contextual_name(mode); QString name = cl->get_name(); QString s = d->get_idldecl(); int index = s.find('\n'); s = (index == -1) ? s.stripWhiteSpace() : s.left(index).stripWhiteSpace(); if ((index = s.find("${name}")) != -1) s.replace(index, 7, name); else if ((index = s.find("${Name}")) != -1) s.replace(index, 7, capitalize(name)); else if ((index = s.find("${NAME}")) != -1) s.replace(index, 7, name.upper()); else if ((index = s.find("${nAME}")) != -1) s.replace(index, 7, name.lower()); return s; }
void TMDIChild::InitFrm(WorkSpace * workSpace, IParseEngine * engine) { m_ParseEngine = engine; m_WorkSpace = workSpace; m_WorkSpace->GetFileManager()->BindView(lvWorkSpace); m_bTreeModify = false; m_WorkSpace->Open(); SetModify(); //初始化 m_ParseTree = new ParseTree(m_ParseEngine, m_WorkSpace->GetClassManager()); if(lvWorkSpace->Items->Count == 0) { actNewVersionExecute(NULL); } else { lvWorkSpace->ItemIndex = 0; LoadCurWork(); } //绑定树控件 m_ParseTree->BindView(tvParseTree->Items); m_bFastParseMode = false; m_FastParsePos = 0; String structName = workSpace->GetStructName(); if(structName != "") { bool needAddStruct = true; for(int i=0; i<workSpace->GetClassManager()->GetClassCount(); i++) { if(workSpace->GetClassManager()->GetClassDataByIndex(i)->GetName() == structName) { needAddStruct = false; break; } } if(needAddStruct) { ClassData *curClass = m_WorkSpace->GetClassManager()->AddClass(); curClass->Init(structName, workSpace->GetComment()); int index = m_WorkSpace->GetClassManager()->GetClassIndexByClassData(curClass); RefreshAllClassView(); lvAllClasses->ItemIndex = index; lvAllClassesClick(NULL); } } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // inline bool RegisteredClass::IsDerivedFrom(RegisteredClass__ClassData* parent) const { Check_Object(this); Check_Object(classData); return classData->IsDerivedFrom(parent); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // inline bool RegisteredClass::IsDerivedFrom(ClassID class_id) const { Check_Object(this); Check_Object(classData); return classData->IsDerivedFrom(FindClassData(class_id)); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // inline bool RegisteredClass::IsDerivedFrom(const char* parent) const { Check_Object(this); Check_Object(classData); return classData->IsDerivedFrom(FindClassData(parent)); }
void __fastcall TMDIChild::FastParseExecute(TObject *Sender) { TMenuItem * selMenu = (TMenuItem * )Sender; String typeName = selMenu->Caption; //修正typeName if(selMenu->Caption == "-") return; if(typeName.Pos("[")) typeName = LeftString(typeName, "["); ClassData * curClass = GetCurParseClass(); // bool haveResult = false; String defaultName; if(curClass == NULL) { //当前无结构体, 新建结构体 int classCount = m_WorkSpace->GetClassManager()->GetClassCount(); defaultName = FormatStr("tagUnNamedStruct%d", classCount); curClass = m_WorkSpace->GetClassManager()->AddClass(); curClass->Init(defaultName, ""); RefreshAllClassView(); } String arrayVar; if(selMenu->Tag == 0) arrayVar = ""; else arrayVar = IntToStr(selMenu->Tag); ClassMember * curMember = curClass->AddMember(); defaultName = FormatStr("UnKnown%d", m_ParseTree->GetSize() + m_FastParsePos); curMember->Init(typeName, defaultName, "", arrayVar); m_ParseTree->BindClass(curClass); ExpandFirstNode(); ParseData(false); tagSelRect selRect; if(GetTreeSelRect(selRect) == false) return; GotoPosition(selRect.SelStart + selRect.SelLength); }
void createRanDataSet(ClassData & cdat) { // assign random feature values drawn from random distribution // create two gaussian clusters std::cout<<" label : "<< cdat.getLabel(3)<< std::endl; std::cout<<" data : "<< cdat.getData(0,2)<< std::endl; randn(cdat.dset,0,10); // create two Gauss Clusteres: shift one half and assign label int idat,idim; for(idat=cdat.nele/2; idat<cdat.nele;++idat) { cdat.setLabel(idat, 1); for(idim=0;idim<cdat.ndim;++idim) { //shift cluster cdat.setData(idat,idim, 15+ cdat.getData(idat,idim) ); } } //check std::cout<<" label : "<< cdat.getLabel(3)<< std::endl; std::cout<<" data : "<< cdat.getData(0,2)<< std::endl; }
void ClassItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QMenu menu; menu.addAction("Edit class"); QAction *a = menu.exec(event->screenPos()); if(a) { drawing::DrawingGanttWidget *parent_w = qfc::Utils::findParent<drawing::DrawingGanttWidget*>(scene()); auto *w = new ClassDefWidget(); w->setWindowTitle(tr("Edit class")); qfd::Dialog dlg(QDialogButtonBox::Save | QDialogButtonBox::Cancel, parent_w); dlg.setDefaultButton(QDialogButtonBox::Save); dlg.setCentralWidget(w); w->load(data().id(), qfm::DataDocument::ModeEdit); bool ok = dlg.exec(); if(ok) { //qfInfo() << "OK"; qf::core::model::DataDocument *doc = w->dataDocument(); ClassData dt = data(); dt.setStartTimeMin(doc->value("startTimeMin").toInt()); dt.setStartIntervalMin(doc->value("startIntervalMin").toInt()); dt.setVacantsBefore(doc->value("vacantsBefore").toInt()); dt.setVacantEvery(doc->value("vacantEvery").toInt()); dt.setVacantsAfter(doc->value("vacantsAfter").toInt()); dt.setMapCount(doc->value("mapCount").toInt()); setData(dt); startSlotItem()->updateGeometry(); } } }
void ClassData::get_class_spec(QString & templates, QString & names, QString & templates_tmplop, QString & names_tmplop) const { bool browserNodeIsUMLClass = ((BrowserNode *) browser_node->parent())->get_type() == UmlClass; if (browserNodeIsUMLClass) { ClassData * cd = ((ClassData *)((BrowserNode *) browser_node->parent())->get_data()); cd->get_class_spec(templates, names, templates_tmplop, names_tmplop); names += "::"; } QString t1; QString t2; get_template_prefixes(t1, t2); templates_tmplop = templates + "template<>\n"; templates += t1; names_tmplop = names + true_name(browser_node->get_name(), cpp_decl); names = names_tmplop + t2; }
void __fastcall TMDIChild::actDelCurNodeExecute(TObject *Sender) { if(tvParseTree->Selected == NULL) return; ParseTreeNode * curParseTree = (ParseTreeNode *)tvParseTree->Selected->Data; ClassData * curClass = GetCurParseClass(); if(curClass == NULL) return; if(curParseTree == NULL) { //选择的是结构体 DeleteCurClass(); curClass = NULL; DeleteCurClass(); } else { //选择的是变量 if(curParseTree->GetParent() == NULL) { //只能够删除成员变量 curClass->DeleteMember(curParseTree->GetClassMember()); if(curClass->GetMemberDataCount() == 0) { DeleteCurClass(); } else { m_ParseTree->BindClass(curClass); ExpandFirstNode(); ParseData(); } } } SetModify(); }
void TMDIChild::ChangeNodeName(ParseTreeNode * curParseTree, bool needRefresh, int changeType) { ClassData * curClass = GetCurParseClass(); if(curClass == NULL) return; String showName; if(changeType == 0) { showName = "输入新名称"; } else { showName = "输入新注释"; } String name; int haveResult = 0; if(curParseTree == NULL) { //选择的是结构体 if(changeType==0) { name = curClass->GetName(); } else { name = curClass->GetComment(); } if(InputQuery(showName, showName, name)) { haveResult = 1; if(changeType==0) { curClass->SetName(name); } else { curClass->SetComment(name); } } } else { //选择的是变量 String curName; if(changeType==0) { curName = curParseTree->GetClassMember()->GetName(); } else { curName = curParseTree->GetClassMember()->GetComment(); } if(curName.Pos("[")) { //是数组中的一个 ParseTreeNode * parent = curParseTree->GetParent(); ChangeNodeName(parent, false); parent->SetExNodeName(); haveResult = 1; } else { ClassMember * curModifyMember = NULL; for(int i=0; i<curClass->GetMemberDataCount(); i++) { if((IClassMember *)curClass->GetMemberData(i) == curParseTree->GetClassMember()) { curModifyMember = curClass->GetMemberByIndex(i); } } if(curModifyMember) { if(changeType==0) { name = curModifyMember->GetName(); } else { name = curModifyMember->GetComment(); } if(InputQuery(showName, showName, name)) { haveResult = 1; if(changeType==0) { curModifyMember->SetName(name); } else { curModifyMember->SetComment(name); } curParseTree->SetExNodeName(); } } } } if(haveResult && needRefresh) { RefreshAllClassView(); m_ParseTree->RefreshViewText(); } }
AttributeDialog::AttributeDialog(AttributeData * a, bool new_st_attr) : Q3TabDialog(0, 0, FALSE, Qt::WDestructiveClose), new_in_st(new_st_attr), att(a) { a->browser_node->edit_start(); if (a->browser_node->is_writable()) { setOkButton(TR("OK")); setCancelButton(TR("Cancel")); } else { setOkButton(QString::null); setCancelButton(TR("Close")); } visit = !hasOkButton(); ClassData * cld = (ClassData *) ((BrowserNode *) a->browser_node->parent())->get_data(); QString stereotype = cld->get_stereotype(); QString lang_st; in_enum = (stereotype == "enum"); lang_st = GenerationSettings::cpp_class_stereotype(stereotype); cpp_in_enum = in_enum || (lang_st == "enum"); cpp_ignored = !cpp_in_enum && ((lang_st == "typedef") || (lang_st == "ignored")); lang_st = GenerationSettings::java_class_stereotype(stereotype); java_in_enum = in_enum || (lang_st == "enum"); java_in_enum_pattern = !java_in_enum && (lang_st == "enum_pattern"); java_ignored = (lang_st == "ignored"); lang_st = GenerationSettings::php_class_stereotype(stereotype); php_in_enum = in_enum || (lang_st == "enum"); php_ignored = !php_in_enum && (lang_st == "ignored"); lang_st = GenerationSettings::python_class_stereotype(stereotype); python_in_enum = in_enum || (lang_st == "enum"); python_ignored = !python_in_enum && (lang_st == "ignored"); lang_st = GenerationSettings::idl_class_stereotype(stereotype); idl_in_enum = in_enum || (lang_st == "enum"); idl_in_typedef = !idl_in_enum && (lang_st == "typedef"); idl_in_struct = !idl_in_enum && ((lang_st == "struct") || (lang_st == "exception")); idl_in_union = !idl_in_enum && (lang_st == "union"); setCaption((in_enum || java_in_enum_pattern) ? TR("Enum item dialog") : TR("Attribute dialog")); Q3Grid * grid; Q3HBox * htab; QString s; // general tab grid = new Q3Grid(2, this); umltab = grid; grid->setMargin(5); grid->setSpacing(5); new QLabel(TR("class : "), grid); new QLabel(((BrowserNode *) a->get_browser_node()->parent())->full_name(TRUE), grid); new QLabel(TR("name :"), grid); edname = new LineEdit(a->name(), grid); edname->setReadOnly(visit); QFont font = edname->font(); if (! hasCodec()) font.setFamily("Courier"); font.setFixedPitch(TRUE); if (!java_in_enum_pattern) { new QLabel(TR("stereotype :"), grid); htab = new Q3HBox(grid); edstereotype = new Q3ComboBox(!visit, htab); edstereotype->insertItem(toUnicode(a->get_stereotype())); if (!visit) { edstereotype->insertStringList(BrowserAttribute::default_stereotypes()); edstereotype->insertStringList(ProfiledStereotypes::defaults(UmlAttribute)); if (java_in_enum) { int n = edstereotype->count(); for (attribute_st_rank = 0; attribute_st_rank != n; attribute_st_rank += 1) if (edstereotype->text(attribute_st_rank) == "attribute") break; if (attribute_st_rank == n) { edstereotype->insertItem("attribute"); n += 1; } for (empty_st_rank = 0; empty_st_rank != n; empty_st_rank += 1) if (edstereotype->text(empty_st_rank).isEmpty()) break; if (empty_st_rank == n) edstereotype->insertItem(""); } edstereotype->setAutoCompletion(completion()); } edstereotype->setCurrentItem(0); QSizePolicy sp = edstereotype->sizePolicy(); sp.setHorData(QSizePolicy::Expanding); edstereotype->setSizePolicy(sp); new QLabel(TR(" multiplicity : "), htab); multiplicity = new Q3ComboBox(!visit, htab); multiplicity->setSizePolicy(sp); previous_multiplicity = a->get_multiplicity(); multiplicity->insertItem(previous_multiplicity); if (!visit) { multiplicity->insertItem("1"); multiplicity->insertItem("0..1"); multiplicity->insertItem("*"); multiplicity->insertItem("1..*"); } connect(new SmallPushButton(TR("type :"), grid), SIGNAL(clicked()), this, SLOT(menu_type())); edtype = new Q3ComboBox(!visit, grid); edtype->insertItem(a->get_type().get_full_type()); BrowserClass::instances(nodes); nodes.full_names(list); if (!visit) { QStringList l = GenerationSettings::basic_types(); cld->addFormals(l); edtype->insertStringList(l); offset = edtype->count(); edtype->insertStringList(list); edtype->setAutoCompletion(completion()); view = a->browser_node->container(UmlClass); } edtype->setCurrentItem(0); edtype->setSizePolicy(sp); new QLabel(TR("initial value :"), grid); } else { multiplicity = 0; new QLabel(TR("value :"), grid); } htab = new Q3HBox(grid); edinit = new LineEdit(a->get_init_value(), htab); if (visit) edinit->setReadOnly(TRUE); else connect(new SmallPushButton(TR("Editor"), htab), SIGNAL(clicked()), this, SLOT(edit_init())); Q3ButtonGroup * bg; if (!java_in_enum_pattern) { new QLabel(grid); htab = new Q3HBox(grid); bg = uml_visibility.init(htab, a->get_uml_visibility(), TRUE); if (visit) bg->setEnabled(FALSE); bg = new Q3ButtonGroup(7, Qt::Horizontal, QString::null, htab); bg->setExclusive(FALSE); classattribute_cb = new QCheckBox("static", bg); if (a->get_isa_class_attribute()) classattribute_cb->setChecked(TRUE); classattribute_cb->setDisabled(visit); volatile_cb = new QCheckBox("volatile", bg); if (a->isa_volatile_attribute) volatile_cb->setChecked(TRUE); volatile_cb->setDisabled(visit); constattribute_cb = new QCheckBox(TR("read-only"), bg); if (a->get_isa_const_attribute()) constattribute_cb->setChecked(TRUE); constattribute_cb->setDisabled(visit); derived_cb = new QCheckBox(TR("derived"), bg); if (a->get_is_derived()) derived_cb->setChecked(TRUE); derived_cb->setDisabled(visit); connect(derived_cb, SIGNAL(toggled(bool)), SLOT(derived_changed(bool))); derivedunion_cb = new QCheckBox("union", bg); if (a->get_is_derivedunion()) derivedunion_cb->setChecked(TRUE); derivedunion_cb->setDisabled(visit || !derived_cb->isChecked()); ordered_cb = new QCheckBox(TR("ordered"), bg); if (a->get_is_ordered()) ordered_cb->setChecked(TRUE); ordered_cb->setDisabled(visit); unique_cb = new QCheckBox("unique", bg); if (a->get_is_unique()) unique_cb->setChecked(TRUE); unique_cb->setDisabled(visit); } Q3VBox * vtab = new Q3VBox(grid); new QLabel(TR("description :"), vtab); if (! visit) { connect(new SmallPushButton(TR("Editor"), vtab), SIGNAL(clicked()), this, SLOT(edit_description())); connect(new SmallPushButton(TR("Default"), vtab), SIGNAL(clicked()), this, SLOT(default_description())); } comment = new MultiLineEdit(grid); comment->setReadOnly(visit); comment->setText(a->browser_node->get_comment()); comment->setFont(font); vtab = new Q3VBox(grid); new QLabel(TR("constraint :"), vtab); if (! visit) { connect(new SmallPushButton(TR("Editor"), vtab), SIGNAL(clicked()), this, SLOT(edit_constraint())); } constraint = new MultiLineEdit(grid); constraint->setReadOnly(visit); constraint->setText(a->constraint); constraint->setFont(font); addTab(grid, "Uml"); // C++ if (! cpp_ignored) { grid = new Q3Grid(2, this); cpptab = grid; grid->setMargin(5); grid->setSpacing(5); if (!cpp_in_enum) { new QLabel(TR("Visibility :"), grid); htab = new Q3HBox(grid); Q3ButtonGroup * bg = cpp_visibility.init(htab, a->get_cpp_visibility(), FALSE, 0, TR("follow uml")); if (visit) bg->setEnabled(FALSE); new QLabel(" ", htab); mutable_cb = new QCheckBox("mutable", htab); if (a->cpp_mutable) mutable_cb->setChecked(TRUE); if (visit) mutable_cb->setDisabled(TRUE); else connect(mutable_cb, SIGNAL(toggled(bool)), this, SLOT(cpp_update())); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // inline RegisteredClass::ClassData* RegisteredClass::FindClassData(PCSTR name) { return DefaultData->FindClassData(name); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // inline RegisteredClass::ClassData* RegisteredClass::FindClassData(const char* name) { return DefaultData->FindClassData(name); }