Skip to content

πŸ“š 포괄적인 ν”„λ‘œμ νŠΈ λ¬Έμ„œν™” μΆ”κ°€ #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
278 changes: 278 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
# API λ¬Έμ„œ

StarUML C# ν™•μž₯ ν”„λ‘œκ·Έλž¨μ˜ API λ¬Έμ„œμž…λ‹ˆλ‹€.

## πŸ“‹ λͺ©μ°¨

- [CsharpCodeGenerator](#csharpcodegenerator)
- [CsharpPreferences](#csharppreferences)
- [CodeGenUtils](#codegenutils)
- [λͺ…λ Ήμ–΄ ID](#λͺ…λ Ήμ–΄-id)

## CsharpCodeGenerator

C# μ½”λ“œ 생성을 λ‹΄λ‹Ήν•˜λŠ” 메인 ν΄λž˜μŠ€μž…λ‹ˆλ‹€.

### μƒμ„±μž

```javascript
CsharpCodeGenerator(baseModel, basePath)
```

**λ§€κ°œλ³€μˆ˜:**
- `baseModel` (type.UMLPackage): μ½”λ“œ μƒμ„±μ˜ 기쀀이 λ˜λŠ” UML νŒ¨ν‚€μ§€
- `basePath` (string): μƒμ„±λœ νŒŒμΌλ“€μ΄ μ €μž₯될 κΈ°λ³Έ 경둜

### μ£Όμš” λ©”μ„œλ“œ

#### generate(baseModel, basePath, options)

UML λͺ¨λΈμ—μ„œ C# μ½”λ“œλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.

**λ§€κ°œλ³€μˆ˜:**
- `baseModel` (type.UMLPackage): μ½”λ“œ 생성 λŒ€μƒ λͺ¨λΈ
- `basePath` (string): 좜λ ₯ 경둜
- `options` (Object): 생성 μ˜΅μ…˜

**λ°˜ν™˜κ°’:**
- `Promise`: μ½”λ“œ 생성 μ™„λ£Œ μ‹œ resolveλ˜λŠ” Promise

**μ˜΅μ…˜ 객체:**
```javascript
{
csharpDoc: boolean, // CsharpDoc 주석 생성 μ—¬λΆ€
useTab: boolean, // νƒ­ μ‚¬μš© μ—¬λΆ€
indentSpaces: number // λ“€μ—¬μ“°κΈ° 슀페이슀 수
}
```

### λ‚΄λΆ€ λ©”μ„œλ“œ

#### writePackage(elem)
νŒ¨ν‚€μ§€λ₯Ό μ²˜λ¦¬ν•˜μ—¬ λ„€μž„μŠ€νŽ˜μ΄μŠ€λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.

#### writeClass(elem)
UML 클래슀λ₯Ό C# 클래슀둜 λ³€ν™˜ν•©λ‹ˆλ‹€.

#### writeInterface(elem)
UML μΈν„°νŽ˜μ΄μŠ€λ₯Ό C# μΈν„°νŽ˜μ΄μŠ€λ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€.

#### writeEnumeration(elem)
UML μ—΄κ±°ν˜•μ„ C# enum으둜 λ³€ν™˜ν•©λ‹ˆλ‹€.

#### writeAttribute(attr)
UML 속성을 C# ν•„λ“œ/ν”„λ‘œνΌν‹°λ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€.

#### writeOperation(op)
UML 연산을 C# λ©”μ„œλ“œλ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€.

## CsharpPreferences

μ‚¬μš©μž 섀정을 κ΄€λ¦¬ν•˜λŠ” ν΄λž˜μŠ€μž…λ‹ˆλ‹€.

### μ„€μ • ν•­λͺ©

#### csharp.gen.csharpDoc
- **νƒ€μž…**: Boolean
- **κΈ°λ³Έκ°’**: true
- **μ„€λͺ…**: CsharpDoc XML 주석 생성 μ—¬λΆ€

#### csharp.gen.useTab
- **νƒ€μž…**: Boolean
- **κΈ°λ³Έκ°’**: false
- **μ„€λͺ…**: 듀여쓰기에 νƒ­ μ‚¬μš© μ—¬λΆ€

#### csharp.gen.indentSpaces
- **νƒ€μž…**: Number
- **κΈ°λ³Έκ°’**: 4
- **μ„€λͺ…**: 슀페이슀 λ“€μ—¬μ“°κΈ° 크기

### λ©”μ„œλ“œ

#### getId()
μ„€μ • IDλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

**λ°˜ν™˜κ°’:**
- `string`: "csharp"

#### getGenOptions()
ν˜„μž¬ μ„€μ •λœ μ½”λ“œ 생성 μ˜΅μ…˜μ„ λ°˜ν™˜ν•©λ‹ˆλ‹€.

**λ°˜ν™˜κ°’:**
- `Object`: μ½”λ“œ 생성 μ˜΅μ…˜ 객체

## CodeGenUtils

μ½”λ“œ 생성을 μœ„ν•œ μœ ν‹Έλ¦¬ν‹° ν΄λž˜μŠ€λ“€μ„ μ œκ³΅ν•©λ‹ˆλ‹€.

### CodeWriter

μ½”λ“œ μž‘μ„±μ„ λ„μ™€μ£ΌλŠ” μœ ν‹Έλ¦¬ν‹° ν΄λž˜μŠ€μž…λ‹ˆλ‹€.

#### μƒμ„±μž

```javascript
CodeWriter(indentString)
```

**λ§€κ°œλ³€μˆ˜:**
- `indentString` (string): λ“€μ—¬μ“°κΈ° λ¬Έμžμ—΄ (κΈ°λ³Έκ°’: 4개 슀페이슀)

#### λ©”μ„œλ“œ

##### writeLine(line)
ν•œ 쀄을 μž‘μ„±ν•©λ‹ˆλ‹€.

**λ§€κ°œλ³€μˆ˜:**
- `line` (string): μž‘μ„±ν•  ν…μŠ€νŠΈ

##### indent()
λ“€μ—¬μ“°κΈ° λ ˆλ²¨μ„ μ¦κ°€μ‹œν‚΅λ‹ˆλ‹€.

##### outdent()
λ“€μ—¬μ“°κΈ° λ ˆλ²¨μ„ κ°μ†Œμ‹œν‚΅λ‹ˆλ‹€.

##### getIndentString()
ν˜„μž¬ λ“€μ—¬μ“°κΈ° λ¬Έμžμ—΄μ„ λ°˜ν™˜ν•©λ‹ˆλ‹€.

**λ°˜ν™˜κ°’:**
- `string`: ν˜„μž¬ λ“€μ—¬μ“°κΈ° λ¬Έμžμ—΄

##### getData()
μž‘μ„±λœ λͺ¨λ“  μ½”λ“œλ₯Ό λ¬Έμžμ—΄λ‘œ λ°˜ν™˜ν•©λ‹ˆλ‹€.

**λ°˜ν™˜κ°’:**
- `string`: μ™„μ„±λœ μ½”λ“œ λ¬Έμžμ—΄

## λͺ…λ Ήμ–΄ ID

ν™•μž₯ ν”„λ‘œκ·Έλž¨μ—μ„œ μ‚¬μš©ν•˜λŠ” λͺ…λ Ήμ–΄ IDλ“€μž…λ‹ˆλ‹€.

### μƒμˆ˜

- `CMD_CSHARP`: "csharp" - 메인 C# λͺ…λ Ήμ–΄
- `CMD_CSHARP_GENERATE`: "csharp.generate" - μ½”λ“œ 생성 λͺ…λ Ήμ–΄
- `CMD_CSHARP_REVERSE`: "csharp.reverse" - 역곡학 λͺ…λ Ήμ–΄ (λ―Έκ΅¬ν˜„)
- `CMD_CSHARP_CONFIGURE`: "csharp.configure" - μ„€μ • λͺ…λ Ήμ–΄

### λͺ…λ Ήμ–΄ ν•Έλ“€λŸ¬

#### _handleGenerate(base, path, options)
C# μ½”λ“œ 생성을 μ²˜λ¦¬ν•©λ‹ˆλ‹€.

**λ§€κ°œλ³€μˆ˜:**
- `base` (Element): κΈ°μ€€ λͺ¨λΈ (선택사항)
- `path` (string): 좜λ ₯ 경둜 (선택사항)
- `options` (Object): 생성 μ˜΅μ…˜ (선택사항)

**λ°˜ν™˜κ°’:**
- `Promise`: 처리 μ™„λ£Œ μ‹œ resolveλ˜λŠ” Promise

#### _handleReverse()
역곡학을 μ²˜λ¦¬ν•©λ‹ˆλ‹€. (ν˜„μž¬ λ―Έκ΅¬ν˜„)

#### _handleConfigure()
μ„€μ • λŒ€ν™”μƒμžλ₯Ό μ—½λ‹ˆλ‹€.

## μ‚¬μš© μ˜ˆμ‹œ

### ν”„λ‘œκ·Έλž˜λ° λ°©μ‹μœΌλ‘œ μ½”λ“œ 생성

```javascript
// λͺ¨λ“ˆ λ‘œλ“œ
var CsharpCodeGenerator = require("CsharpCodeGenerator");
var CsharpPreferences = require("CsharpPreferences");

// μ˜΅μ…˜ μ„€μ •
var options = CsharpPreferences.getGenOptions();
options.csharpDoc = true;
options.useTab = false;
options.indentSpaces = 4;

// μ½”λ“œ 생성
var generator = new CsharpCodeGenerator(baseModel, "/output/path");
generator.generate(baseModel, "/output/path", options)
.then(function() {
console.log("μ½”λ“œ 생성 μ™„λ£Œ");
})
.catch(function(error) {
console.error("μ½”λ“œ 생성 μ‹€νŒ¨:", error);
});
```

### μ‚¬μš©μž μ •μ˜ CodeWriter μ‚¬μš©

```javascript
var CodeGenUtils = require("CodeGenUtils");

// CodeWriter 생성
var writer = new CodeGenUtils.CodeWriter(" "); // 4 슀페이슀 λ“€μ—¬μ“°κΈ°

// μ½”λ“œ μž‘μ„±
writer.writeLine("public class MyClass");
writer.writeLine("{");
writer.indent();
writer.writeLine("private string name;");
writer.writeLine("");
writer.writeLine("public string Name");
writer.writeLine("{");
writer.indent();
writer.writeLine("get { return name; }");
writer.writeLine("set { name = value; }");
writer.outdent();
writer.writeLine("}");
writer.outdent();
writer.writeLine("}");

// κ²°κ³Ό 좜λ ₯
console.log(writer.getData());
```

## ν™•μž₯ 및 μ»€μŠ€ν„°λ§ˆμ΄μ§•

### μƒˆλ‘œμš΄ μ½”λ“œ 생성 κ·œμΉ™ μΆ”κ°€

`CsharpCodeGenerator.js`λ₯Ό μˆ˜μ •ν•˜μ—¬ μƒˆλ‘œμš΄ UML μš”μ†Œλ‚˜ C# κΈ°λŠ₯을 지원할 수 μžˆμŠ΅λ‹ˆλ‹€:

1. μƒˆλ‘œμš΄ `write*` λ©”μ„œλ“œ μΆ”κ°€
2. `generate` λ©”μ„œλ“œμ—μ„œ ν•΄λ‹Ή λ©”μ„œλ“œ 호좜
3. ν•„μš”ν•œ 경우 μ„€μ • μ˜΅μ…˜ μΆ”κ°€

### μƒˆλ‘œμš΄ μ„€μ • μ˜΅μ…˜ μΆ”κ°€

`CsharpPreferences.js`μ—μ„œ μƒˆλ‘œμš΄ 섀정을 μΆ”κ°€ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

```javascript
"csharp.gen.newOption": {
text: "μƒˆ μ˜΅μ…˜",
description: "μƒˆλ‘œμš΄ μ˜΅μ…˜μ— λŒ€ν•œ μ„€λͺ…",
type: "Check", // λ˜λŠ” "Number", "String" λ“±
default: false
}
```

## 였λ₯˜ 처리

### 일반적인 였λ₯˜ 상황

1. **파일 μ‹œμŠ€ν…œ 였λ₯˜**: 좜λ ₯ κ²½λ‘œμ— μ“°κΈ° κΆŒν•œμ΄ μ—†λŠ” 경우
2. **λͺ¨λΈ 였λ₯˜**: 잘λͺ»λœ UML λͺ¨λΈμ΄ μ „λ‹¬λœ 경우
3. **μ„€μ • 였λ₯˜**: 잘λͺ»λœ 섀정값이 μ „λ‹¬λœ 경우

### 였λ₯˜ 처리 방법

```javascript
generator.generate(baseModel, basePath, options)
.then(function(result) {
// 성곡 처리
})
.catch(function(error) {
if (error === FileSystem.USER_CANCELED) {
// μ‚¬μš©μž μ·¨μ†Œ
} else {
// 기타 였λ₯˜ 처리
console.error("였λ₯˜ λ°œμƒ:", error);
}
});
```

Loading