diff --git a/CSSE374-Eleven/patternTypesConfig.txt b/CSSE374-Eleven/patternTypesConfig.txt new file mode 100644 index 0000000..0efc99a --- /dev/null +++ b/CSSE374-Eleven/patternTypesConfig.txt @@ -0,0 +1,4 @@ +SINGLETON-blue +DECORATOR-green +ADAPTER-red +COMPOSITE-yellow \ No newline at end of file diff --git a/CSSE374-Eleven/src/src/problem/components/Class.java b/CSSE374-Eleven/src/src/problem/components/Class.java index d01b659..1a526f5 100644 --- a/CSSE374-Eleven/src/src/problem/components/Class.java +++ b/CSSE374-Eleven/src/src/problem/components/Class.java @@ -1,7 +1,12 @@ package src.problem.components; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import src.problem.outputvisitor.ITraverser; import src.problem.outputvisitor.IVisitor; @@ -14,15 +19,32 @@ public class Class implements IClass { private boolean isInterface; private List interfaces; private String superClass; - private PatternType pattern; + private String pattern; private String stereotype; + private Set patternTypes; public Class() { this.fields = new ArrayList(); this.methods = new ArrayList(); this.interfaces = new ArrayList(); this.isInterface = false; - this.pattern = PatternType.NONE; + patternTypes = new HashSet(); + try { + loadPatternTypes(); + } catch (IOException e) { + System.out.println("Error loading pattern type configuration."); + } + this.pattern = "NONE"; + } + + private void loadPatternTypes() throws IOException { + BufferedReader in = new BufferedReader(new FileReader("patternTypesConfig.txt")); + String line = ""; + while ((line = in.readLine()) != null) { + String[] current = line.split("-"); + patternTypes.add(current[0]); + } + in.close(); } @Override @@ -106,7 +128,7 @@ public void accept(IVisitor v) { v.postVisit(this); } - public PatternType getPattern() { + public String getPattern() { return this.pattern; } @@ -121,7 +143,14 @@ public String getStereotype() { } @Override - public void setPattern(PatternType pattern) { - this.pattern = pattern; + public void setPattern(String pattern) { + if(patternTypes.contains(pattern)) { + this.pattern = pattern; + } + } + + @Override + public Set getPatternTypes() { + return patternTypes; } } diff --git a/CSSE374-Eleven/src/src/problem/components/IClass.java b/CSSE374-Eleven/src/src/problem/components/IClass.java index e5d05ff..7222ef1 100644 --- a/CSSE374-Eleven/src/src/problem/components/IClass.java +++ b/CSSE374-Eleven/src/src/problem/components/IClass.java @@ -1,6 +1,7 @@ package src.problem.components; import java.util.List; +import java.util.Set; import src.problem.outputvisitor.ITraverser; @@ -34,8 +35,10 @@ public interface IClass extends ITraverser{ public String getStereotype(); - public void setPattern(PatternType pattern); + public void setPattern(String pattern); - public PatternType getPattern(); + public String getPattern(); + + public Set getPatternTypes(); } diff --git a/CSSE374-Eleven/src/src/problem/components/PatternType.java b/CSSE374-Eleven/src/src/problem/components/PatternType.java deleted file mode 100644 index df1fff7..0000000 --- a/CSSE374-Eleven/src/src/problem/components/PatternType.java +++ /dev/null @@ -1,5 +0,0 @@ -package src.problem.components; - -public enum PatternType { - NONE, SINGLETON, DECORATOR, ADAPTER, COMPOSITE -} diff --git a/CSSE374-Eleven/src/src/problem/outputvisitor/GraphVizOutputStream.java b/CSSE374-Eleven/src/src/problem/outputvisitor/GraphVizOutputStream.java index 2cef16e..b7f17da 100644 --- a/CSSE374-Eleven/src/src/problem/outputvisitor/GraphVizOutputStream.java +++ b/CSSE374-Eleven/src/src/problem/outputvisitor/GraphVizOutputStream.java @@ -1,7 +1,6 @@ package src.problem.outputvisitor; import java.io.BufferedReader; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FilterOutputStream; import java.io.IOException; @@ -15,13 +14,13 @@ import src.problem.components.Method; import src.problem.components.Model; import src.problem.components.Parameter; -import src.problem.components.PatternType; import src.problem.components.Relation; public class GraphVizOutputStream extends FilterOutputStream { private final IVisitor visitor; private Map relationTypeOutput; + private Map patternTypeOutput; public GraphVizOutputStream(OutputStream out) { @@ -29,13 +28,25 @@ public GraphVizOutputStream(OutputStream out) { this.visitor = new Visitor(); this.setupVisitors(); relationTypeOutput = new HashMap(); + patternTypeOutput = new HashMap(); try { loadRelationTypeOutput(); + loadPatternTypeOutput(); } catch (IOException e) { - System.out.println("Error loading relation type configuration."); + System.out.println("Error loading configurations."); } } + private void loadPatternTypeOutput() throws IOException { + BufferedReader in = new BufferedReader(new FileReader("patternTypesConfig.txt")); + String line = ""; + while ((line = in.readLine()) != null) { + String[] current = line.split("-"); + relationTypeOutput.put(current[0], current[1]); + } + in.close(); + } + private void loadRelationTypeOutput() throws IOException { BufferedReader in = new BufferedReader(new FileReader("relationTypesConfig.txt")); String line = ""; @@ -108,17 +119,11 @@ private void setupPreVisitClass() { } - private Object getColor(PatternType pattern) { - switch(pattern) { - case SINGLETON: - return "style=filled fillcolor=blue"; - case DECORATOR: - return "style=filled fillcolor=green"; - case ADAPTER: - return "style=filled fillcolor=red"; - case COMPOSITE: - return "style=filled fillcolor=yellow"; - default: + private Object getColor(String pattern) { + if(patternTypeOutput.containsKey(pattern)) { + String[] output = relationTypeOutput.get(pattern).split("-"); + return "style=filled fillcolor=" + output[1]; + } else { return ""; } } diff --git a/CSSE374-Eleven/src/src/problem/patternrecognition/AdapterSpotter.java b/CSSE374-Eleven/src/src/problem/patternrecognition/AdapterSpotter.java index 4dd77a0..4edc044 100644 --- a/CSSE374-Eleven/src/src/problem/patternrecognition/AdapterSpotter.java +++ b/CSSE374-Eleven/src/src/problem/patternrecognition/AdapterSpotter.java @@ -72,9 +72,9 @@ private boolean checkForAdapter(String s, Set filtered) { adapter.setStereotype("adapter"); adaptee.setStereotype("adaptee"); target.setStereotype("target"); - adapter.setPattern(PatternType.ADAPTER); - adaptee.setPattern(PatternType.ADAPTER); - target.setPattern(PatternType.ADAPTER); + adapter.setPattern("ADAPTER"); + adaptee.setPattern("ADAPTER"); + target.setPattern("ADAPTER"); // System.out.println("adapter alert"); for(IRelation r : m.getRelations()) { if(r.getSrc().equals(s) && r.getDest().equals(adaptee.getName()) && r.getType().equals("ASSOCIATION")) { diff --git a/CSSE374-Eleven/src/src/problem/patternrecognition/CompositeSpotter.java b/CSSE374-Eleven/src/src/problem/patternrecognition/CompositeSpotter.java index 7ab6a8a..1b6555d 100644 --- a/CSSE374-Eleven/src/src/problem/patternrecognition/CompositeSpotter.java +++ b/CSSE374-Eleven/src/src/problem/patternrecognition/CompositeSpotter.java @@ -7,7 +7,6 @@ import src.problem.components.IField; import src.problem.components.IModel; import src.problem.components.IRelation; -import src.problem.components.PatternType; public class CompositeSpotter implements IPatternSpotter { private IModel model; @@ -54,12 +53,12 @@ private void checkForComposite(IModel model, IClass clazz) { if (inherits.contains(type)) { component = type; clazz.setStereotype("composite"); - clazz.setPattern(PatternType.COMPOSITE); + clazz.setPattern("COMPOSITE"); for (IClass clazz2 : model.getClasses()) { if (clazz2.getName().equals(type)) { clazz2.setStereotype("component"); - clazz2.setPattern(PatternType.COMPOSITE); + clazz2.setPattern("COMPOSITE"); } } @@ -74,13 +73,13 @@ private void checkForSubClasses(IModel model) { if (r.getType().equals("EXTENDS") || r.getType().equals("IMPLEMENTS")) { IClass src = findClass(r.getSrc()); if (src != null) { - if (src.getPattern() == PatternType.COMPOSITE) { + if (src.getPattern().equals("COMPOSITE")) { IClass dest = findClass(r.getDest()); if (dest != null) { if (src.getStereotype().equals("composite")) { if (dest.getStereotype() == null || !dest.getStereotype().equals("composite")) { dest.setStereotype("component"); - dest.setPattern(PatternType.COMPOSITE); + dest.setPattern("COMPOSITE"); } } } @@ -88,10 +87,10 @@ private void checkForSubClasses(IModel model) { } IClass dest = findClass(r.getDest()); - if (dest != null) { - if (dest.getPattern() == PatternType.COMPOSITE) { - if (src != null && src.getPattern() != PatternType.COMPOSITE) { - src.setPattern(PatternType.COMPOSITE); + if (dest != null ) { + if (dest.getPattern().equals("COMPOSITE")) { + if (src != null && !src.getPattern().equals("COMPOSITE")) { + src.setPattern("COMPOSITE"); if (dest.getStereotype().equals("composite")) { if (src.getStereotype() == null || !src.getStereotype().equals("composite")) { src.setStereotype("composite"); diff --git a/CSSE374-Eleven/src/src/problem/patternrecognition/DecoratorSpotter.java b/CSSE374-Eleven/src/src/problem/patternrecognition/DecoratorSpotter.java index b8cf78f..a0807c8 100644 --- a/CSSE374-Eleven/src/src/problem/patternrecognition/DecoratorSpotter.java +++ b/CSSE374-Eleven/src/src/problem/patternrecognition/DecoratorSpotter.java @@ -27,11 +27,11 @@ private void checkForSubClasses(IModel model) { if(r.getType().equals("EXTENDS") || r.getType().equals("IMPLEMENTS")) { IClass dest = findClass(r.getDest()); if(dest != null) { - if(dest.getPattern() == PatternType.DECORATOR) { + if(dest.getPattern().equals("DECORATOR")) { IClass src = findClass(r.getSrc()); if(src != null) { if (src.getStereotype() == null || !src.getStereotype().equals("decorator")) { - src.setPattern(PatternType.DECORATOR); + src.setPattern("DECORATOR"); src.setStereotype("decorator"); checkForSubClasses(model); return; @@ -86,7 +86,7 @@ private void checkForDecorator(IModel model, IClass clazz, List aggs) { //add decorator stereotype and pattern type to class clazz.setStereotype("decorator"); - clazz.setPattern(PatternType.DECORATOR); + clazz.setPattern("DECORATOR"); //change relation to "decorates" relation for (IRelation relation : relations) { @@ -102,7 +102,7 @@ private void checkForDecorator(IModel model, IClass clazz, List aggs) { if (c.getName().equals(decoratee)) { //System.out.println("decoratee: " + decoratee); c.setStereotype("component"); - c.setPattern(PatternType.DECORATOR); + c.setPattern("DECORATOR"); } } diff --git a/CSSE374-Eleven/src/src/problem/patternrecognition/SingletonSpotter.java b/CSSE374-Eleven/src/src/problem/patternrecognition/SingletonSpotter.java index 90b2742..932c20d 100644 --- a/CSSE374-Eleven/src/src/problem/patternrecognition/SingletonSpotter.java +++ b/CSSE374-Eleven/src/src/problem/patternrecognition/SingletonSpotter.java @@ -7,7 +7,6 @@ import src.problem.components.IMethod; import src.problem.components.IMethodCall; import src.problem.components.IModel; -import src.problem.components.PatternType; public class SingletonSpotter implements IPatternSpotter { @@ -19,7 +18,7 @@ private void spot(IClass c) { boolean hasPublicStaticMethod = this.checkMethods(c.getMethods()); boolean hasStaticGetterThatCallsConstructor = this.checkForStaticGetterThatCallsConstructor(c.getMethods()); if (hasPrivateStaticInstance && hasPublicStaticMethod || hasStaticGetterThatCallsConstructor) { - c.setPattern(PatternType.SINGLETON); + c.setPattern("SINGLETON"); c.setStereotype("Singleton"); } }