-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaMethod.swift
More file actions
95 lines (80 loc) · 2.78 KB
/
JavaMethod.swift
File metadata and controls
95 lines (80 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// JavaMethod.swift
// textToCode
//
// Created by Michael Smith on 4/21/19.
// Copyright © 2019 Michael Smith. All rights reserved.
//
import Foundation
import UIKit
class JavaMethod{
private var INDENT = " ";
private var name: String;
private var visability: ItemVisability;
private var returnType: String;
var expressions: [JavaExpression] = [];
private var inStructure = false;
init(name: String, vis: String, returnType: String) {
self.name = name;
self.visability = ItemVisability(rawValue: vis) ?? ItemVisability.defaultItem;
self.returnType = returnType.uppercasingFirst;
}
func exitExpression(){
inStructure = false;
}
func getVariables()->[JavaExpVariables]{
var currentVars: [JavaExpVariables] = [];
for exp in expressions{
if exp is JavaExpVariables{
currentVars.append(exp as! JavaExpVariables);
}
}
return currentVars;
}
func addExpression(exp: JavaExpression){
if(inStructure){
expressions[expressions.count - 1].addExpression(exp: exp);
}else{
if(exp is JavaExpVariables || exp is JavaPrint || exp is JavaCode || exp is JavaComment){
expressions.append(exp);
}else{
expressions.append(exp);
inStructure = true;
}
}
}
func toFormattedString() -> NSMutableAttributedString{
var output = NSMutableAttributedString()
output = NSMutableAttributedString(string: self.toString());
if let xmethod = SpeechProcessor.state.currentMethod{
if xmethod.name == self.name{
output.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.init(red: 0.7, green: 0.0, blue: 1.0, alpha: 1.0)] as [NSAttributedString.Key: Any], range: NSRange(location: 0, length: self.toString().count));
}
}
return output
}
func copy() -> JavaMethod{
let copy = JavaMethod(name: name, vis: visability.rawValue, returnType: returnType)
for expression in expressions{
copy.expressions.append(expression.copy())
}
copy.inStructure = inStructure
return copy
}
func toString() -> String{
var outputStr: String = "";
outputStr += " \(visability.rawValue) \(returnType) \(name)(){ \n"
for expression in expressions{
outputStr += INDENT;
outputStr += "\(expression.toString()) \n";
}
outputStr += " } \n";
return outputStr;
}
func getName() -> String{
return name
}
func getExpression()-> [JavaExpression]{
return expressions;
}
}