for (FormItem userFormItemEntity : formItemList) { if (typeEnumList.contains(userFormItemEntity.getType())) { // id and label FormReportVO.Analysis analysis = new FormReportVO.Analysis(); analysis.setLabel(userFormItemEntity.getLabel()); analysis.setType(userFormItemEntity.getType().getDesc()); formMap.put(userFormItemEntity.getFormItemId(), analysis); idList.add(userFormItemEntity.getFormItemId()); } }
时间: 2024-02-15 08:28:22 浏览: 23
这段代码主要是对表单项列表 `formItemList` 进行遍历,筛选出指定类型的表单项,并将符合条件的表单项的标题(label)、类型(type)、id等信息存储到 `formMap` 和 `idList` 中。
具体来说,`for` 循环遍历 `formItemList` 中的每一个 `userFormItemEntity`(即表单项实体对象),检查其类型是否在 `typeEnumList` 中。`typeEnumList` 是一个预定义的表单项类型列表,表示需要进行分析的表单项类型。
如果该表单项的类型在 `typeEnumList` 中,则创建一个 `FormReportVO.Analysis` 对象,将该表单项的标题(label)和类型(type)设置到该对象中,并将该对象存储到 `formMap` 中,以表单项的 id 为 key,分析结果对象为 value。
同时,将该表单项的 id 存储到 `idList` 中,以备后续使用。
最终,`formMap` 中存储了符合条件的表单项的标题和分析结果,`idList` 中存储了这些表单项的 id。
相关问题
https://github.com/leozhang1/QtInterpreter ASTNode cpp代码展示
以下是ASTNode.cpp的代码展示:
```cpp
#include "ASTNode.h"
#include <iostream>
ASTNode::~ASTNode()
{
for (auto child : children)
{
delete child;
}
}
void ASTNode::addChild(ASTNode *node)
{
children.push_back(node);
}
void ASTNode::print(int indent)
{
std::cout << std::string(indent, ' ') << type << " " << value << std::endl;
for (auto child : children)
{
child->print(indent + 2);
}
}
std::string ASTNode::getType()
{
return type;
}
std::string ASTNode::getValue()
{
return value;
}
std::vector<ASTNode *> ASTNode::getChildren()
{
return children;
}
```
这是一个简单的AST节点类,用于表示解析后的抽象语法树。它有一个类型(type)、值(value)和子节点(children)。还有一些简单的方法,例如添加子节点、打印节点以及获取节点类型、值和子节点。
https://github.com/leozhang1/QtInterpreter ASTNode.h代码展示
下面是ASTNode.h的代码展示:
```c++
#ifndef ASTNODE_H
#define ASTNODE_H
#include <vector>
#include <string>
#include <memory>
// Forward declaration of ASTNode class
class ASTNode;
// Type definitions for shared pointer and vector of ASTNode objects
typedef std::shared_ptr<ASTNode> ASTNodePtr;
typedef std::vector<ASTNodePtr> ASTNodeList;
// Enum for different node types
enum class NodeType {
Program,
Statement,
Expression,
NumberLiteral,
StringLiteral,
Identifier,
BinaryExpression,
UnaryExpression,
AssignmentExpression,
VariableDeclaration,
FunctionDeclaration,
CallExpression,
IfStatement,
WhileStatement,
ForStatement,
ReturnStatement
};
// Class for AST nodes
class ASTNode {
public:
// Constructor
ASTNode(NodeType type);
// Destructor
virtual ~ASTNode() {}
// Getter and setter for node type
NodeType getType() const { return m_type; }
void setType(NodeType type) { m_type = type; }
// Getter and setter for node location in source code
int getLine() const { return m_line; }
void setLine(int line) { m_line = line; }
int getColumn() const { return m_column; }
void setColumn(int column) { m_column = column; }
// Add a child node to the list of children
void addChild(const ASTNodePtr& child);
// Get the list of children nodes
const ASTNodeList& getChildren() const { return m_children; }
// Accept method for visitor pattern
virtual void accept(class ASTVisitor& visitor);
private:
NodeType m_type; // Node type
int m_line; // Line number in source code
int m_column; // Column number in source code
ASTNodeList m_children; // List of child nodes
};
#endif // ASTNODE_H
```
这个头文件定义了 ASTNode 类,用于表示抽象语法树中的节点。它包括了节点的类型、位置信息、子节点列表等属性,并提供了一些方法用于添加和获取子节点、访问者模式等。此外,还定义了一些枚举类型用于表示不同的节点类型。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)