mirror of
https://github.com/Noratrieb/UMLetClassParser.git
synced 2026-01-14 16:45:05 +01:00
fixed regex bug and renamed regex patterns
This commit is contained in:
parent
f85d1f34bc
commit
b90e34f501
2 changed files with 63 additions and 14 deletions
|
|
@ -5,9 +5,30 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
public abstract class Regex {
|
||||
|
||||
/**
|
||||
* Matches any method in the UML format, including a constructor, encapsulation optional
|
||||
*
|
||||
* <p>Examples:</p>
|
||||
* <ul>
|
||||
* <li>+ doStuff(foo: int, foo: int): int</li>
|
||||
* <li>+ getFoo(): int</li>
|
||||
* <li>work()</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> Groups:
|
||||
* <ul>
|
||||
* <li>1 The encapsulate modifier (+-~#)</li>
|
||||
* <li>2 The name</li>
|
||||
* <li>3 All Arguments</li>
|
||||
* <li>4 The return type, "" if no return type is specified (void)</li>
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
public static final Pattern METHOD_FIND_REGEX = Pattern.compile(" *(?<capsule>[+\\-~#])? *(?<name>\\w+) *\\( *(?<args>(?: *\\w+ *: *[\\w<>]+ *,? *)*) *\\) *(?:: *(?<return>[\\w<>]+))?");
|
||||
|
||||
|
||||
/**
|
||||
* Matches any method in the UML format, including a constructor
|
||||
* Matches any method in the UML format, including a constructor, forces the encapsulation modifier
|
||||
*
|
||||
* <p>Examples:</p>
|
||||
* <ul>
|
||||
|
|
@ -25,10 +46,32 @@ public abstract class Regex {
|
|||
* </ul>
|
||||
*
|
||||
*/
|
||||
public static final Pattern METHOD_FIND_REGEX = Pattern.compile(" *(?<capsule>[+\\-~#]) *(?<name>\\w+) *\\( *(?<args>(?: *\\w+ *: *[\\w<>]+ *,? *)*) *\\) *(?:: *(?<return>[\\w<>]+))?");
|
||||
public static final Pattern METHOD_FIND_REGEX_FORCE_ENCAPSULATION = Pattern.compile(" *(?<capsule>[+\\-~#]) *(?<name>\\w+) *\\( *(?<args>(?: *\\w+ *: *[\\w<>]+ *,? *)*) *\\) *(?:: *(?<return>[\\w<>]+))?");
|
||||
|
||||
|
||||
/**
|
||||
* Matches any Field in the UML format, including a constructor
|
||||
* Matches any Field in the UML format, including a constructor, encapsulation optional
|
||||
*y
|
||||
* <p>Examples:</p>
|
||||
* <ul>
|
||||
* <li>- age: int</li>
|
||||
* <li>- name: String</li>
|
||||
* <li>age: int</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> Groups:
|
||||
* <ul>
|
||||
* <li>1 The encapsulate modifier (+-~#)</li>
|
||||
* <li>2 The name</li>
|
||||
* <li>3 The datatype</li>
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
public static final Pattern FIELD_FIND_REGEX = Pattern.compile(" *(?<capsule>[+\\-~#])? *(?<name>\\w+) *: *(?<type>[\\w<>]+)");
|
||||
|
||||
|
||||
/**
|
||||
* Matches any Field in the UML format, including a constructor, forces the encapsulation modifier
|
||||
*y
|
||||
* <p>Examples:</p>
|
||||
* <ul>
|
||||
|
|
@ -45,7 +88,8 @@ public abstract class Regex {
|
|||
* </ul>
|
||||
*
|
||||
*/
|
||||
public static final Pattern FIELD_FIND_REGEX = Pattern.compile(" *(?<capsule>[+\\-~#]) *(?<name>\\w+) *: *(?<type>[\\w<>]+)");
|
||||
public static final Pattern FIELD_FIND_REGEX_FORCE_ENCAPSULATION = Pattern.compile(" *(?<capsule>[+\\-~#]) *(?<name>\\w+) *: *(?<type>[\\w<>]+)");
|
||||
|
||||
|
||||
/**
|
||||
* Matches a single arg in a method
|
||||
|
|
@ -58,17 +102,22 @@ public abstract class Regex {
|
|||
*/
|
||||
public static final Pattern ARG_SPLIT_REGEX = Pattern.compile(" *(\\w+) *: *([\\w<>]+)");
|
||||
|
||||
public static final Pattern FIELD_FIND_REGEX_NO_ENCAPSULATION = Pattern.compile(" *(?<capsule>[+\\-~#])? *(?<name>\\w+) *: *(?<type>[\\w<>]+)");
|
||||
|
||||
public static final Pattern METHOD_FIND_REGEX_NO_ENCAPSULATION = Pattern.compile(" *(?<capsule>[+\\-~#])? *(?<name>\\w+) *\\( *(?<args>(?: *\\w+ *: *[\\w<>]+ *,? *)*) *\\) *(?:: *(?<return>[\\w<>]+))?");
|
||||
|
||||
|
||||
public static String getMethodPattern(boolean encapsulation){
|
||||
return encapsulation ? METHOD_FIND_REGEX_NO_ENCAPSULATION.pattern() : METHOD_FIND_REGEX.pattern();
|
||||
/**
|
||||
* Get a method pattern
|
||||
* @param encapsulationOptional True: Do not force encapsulation, False: Force encapsulation
|
||||
* @return The pattern as a String
|
||||
*/
|
||||
public static String getMethodPattern(boolean encapsulationOptional){
|
||||
return encapsulationOptional ? METHOD_FIND_REGEX.pattern() : METHOD_FIND_REGEX_FORCE_ENCAPSULATION.pattern();
|
||||
}
|
||||
|
||||
public static String getFieldPattern(boolean encapsulation){
|
||||
return encapsulation ? FIELD_FIND_REGEX_NO_ENCAPSULATION.pattern() : FIELD_FIND_REGEX.pattern();
|
||||
/**
|
||||
* Get a field pattern
|
||||
* @param encapsulationOptional True: Do not force encapsulation, False: Force encapsulation
|
||||
* @return The pattern as a String
|
||||
*/
|
||||
public static String getFieldPattern(boolean encapsulationOptional){
|
||||
return encapsulationOptional ? FIELD_FIND_REGEX.pattern() : FIELD_FIND_REGEX_FORCE_ENCAPSULATION.pattern();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Stores all information about a method in a class and converts it into Java code using the {@link #toString()} method
|
||||
|
|
@ -42,7 +43,6 @@ public class UMLMethod {
|
|||
};
|
||||
} else {
|
||||
this.encapsulation = manager.getDefaultEncapsulation();
|
||||
System.out.println(manager.getDefaultEncapsulation());
|
||||
}
|
||||
|
||||
this.name = parts[2];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue