Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
taylerhow committed Feb 11, 2016
2 parents 0a1cdb8 + 1c4d4e6 commit 320ac5c
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CSSE374-Eleven/patternTypesConfig.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SINGLETON-blue
DECORATOR-green
ADAPTER-red
COMPOSITE-yellow
39 changes: 34 additions & 5 deletions CSSE374-Eleven/src/src/problem/components/Class.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,15 +19,32 @@ public class Class implements IClass {
private boolean isInterface;
private List<String> interfaces;
private String superClass;
private PatternType pattern;
private String pattern;
private String stereotype;
private Set<String> patternTypes;

public Class() {
this.fields = new ArrayList<IField>();
this.methods = new ArrayList<IMethod>();
this.interfaces = new ArrayList<String>();
this.isInterface = false;
this.pattern = PatternType.NONE;
patternTypes = new HashSet<String>();
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
Expand Down Expand Up @@ -106,7 +128,7 @@ public void accept(IVisitor v) {
v.postVisit(this);
}

public PatternType getPattern() {
public String getPattern() {
return this.pattern;
}

Expand All @@ -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<String> getPatternTypes() {
return patternTypes;
}
}
7 changes: 5 additions & 2 deletions CSSE374-Eleven/src/src/problem/components/IClass.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package src.problem.components;

import java.util.List;
import java.util.Set;

import src.problem.outputvisitor.ITraverser;

Expand Down Expand Up @@ -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<String> getPatternTypes();

}
5 changes: 0 additions & 5 deletions CSSE374-Eleven/src/src/problem/components/PatternType.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,27 +14,39 @@
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<String, String> relationTypeOutput;
private Map<String, String> patternTypeOutput;


public GraphVizOutputStream(OutputStream out) {
super(out);
this.visitor = new Visitor();
this.setupVisitors();
relationTypeOutput = new HashMap<String, String>();
patternTypeOutput = new HashMap<String, String>();
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 = "";
Expand Down Expand Up @@ -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 "";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ private boolean checkForAdapter(String s, Set<IRelation> 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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}

Expand All @@ -74,24 +73,24 @@ 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");
}
}
}
}
}

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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,7 +86,7 @@ private void checkForDecorator(IModel model, IClass clazz, List<String> 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) {
Expand All @@ -102,7 +102,7 @@ private void checkForDecorator(IModel model, IClass clazz, List<String> aggs) {
if (c.getName().equals(decoratee)) {
//System.out.println("decoratee: " + decoratee);
c.setStereotype("component");
c.setPattern(PatternType.DECORATOR);
c.setPattern("DECORATOR");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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");
}
}
Expand Down

0 comments on commit 320ac5c

Please sign in to comment.