Permalink
Browse files

Fixed tagging bug.

  • Loading branch information...
cderoove committed Jan 11, 2013
1 parent 8f95871 commit 41825f62b54e551cd176eb01e1f55276e29f2554
@@ -15,7 +15,8 @@
import exapus.model.store.Store;
import exapus.model.view.Selection;
import exapus.model.view.View;
-import exapus.model.visitors.SelectiveCopyingForestVisitor;
+import exapus.model.visitors.ICopyingForestVisitor;
+import exapus.model.visitors.SelectiveTopDownCopyingForestVisitor;
import exapus.model.view.evaluator.APICentricTaggingSelectionVisitor;
import exapus.model.view.evaluator.APICentricSelectionVisitor;
@@ -30,7 +31,7 @@ public FactForest getResult() {
return modelResult.getAPICentricForest();
}
- protected SelectiveCopyingForestVisitor newVisitor() {
+ protected ICopyingForestVisitor newVisitor() {
if(Iterables.any(getView().getAPISelections(), new Predicate<Selection>() {
@Override
public boolean apply(Selection selection) {
@@ -44,7 +45,7 @@ public boolean apply(Selection selection) {
@Override
public void evaluate() {
- SelectiveCopyingForestVisitor v = newVisitor();
+ ICopyingForestVisitor v = newVisitor();
InboundFactForest workspaceForest = Store.getCurrent().getWorkspaceModel().getAPICentricForest();
FactForest forest = v.copy(workspaceForest);
calculateMetrics(forest);
@@ -10,7 +10,8 @@
import exapus.model.view.Selection;
public class APICentricSelectionVisitor extends SelectionVisitor {
-
+
+
public APICentricSelectionVisitor(Iterable<Selection> apis, Iterable<Selection> projects) {
super(apis, projects);
}
@@ -4,20 +4,65 @@
import com.google.common.collect.Iterables;
import exapus.model.forest.FactForest;
+import exapus.model.forest.InboundFactForest;
import exapus.model.forest.InboundRef;
+import exapus.model.forest.Member;
+import exapus.model.forest.OutboundFactForest;
import exapus.model.forest.OutboundRef;
+import exapus.model.forest.PackageLayer;
import exapus.model.forest.PackageTree;
import exapus.model.forest.UqName;
import exapus.model.view.Selection;
+import exapus.model.visitors.SelectiveBottomUpCopyingForestVisitor;
-public class APICentricTaggingSelectionVisitor extends APICentricSelectionVisitor {
+public class APICentricTaggingSelectionVisitor extends SelectiveBottomUpCopyingForestVisitor {
- public APICentricTaggingSelectionVisitor(Iterable<Selection> apis, Iterable<Selection> projects) {
- super(apis, projects);
+ protected Iterable<Selection> selections;
+ protected Iterable<Selection> dual_selections;
+
+ public APICentricTaggingSelectionVisitor(Iterable<Selection> selections, Iterable<Selection> dual_selections) {
+ super();
+ this.selections = selections;
+ this.dual_selections = dual_selections;
+ }
+
+ @Override
+ protected boolean select(final PackageTree packageTree) {
+ return Iterables.any(selections, new Predicate<Selection>() {
+ @Override
+ public boolean apply(Selection selection) {
+ return selection.matchPackageTree(packageTree);
+
+ }
+ });
+ }
+
+ @Override
+ protected boolean select(final PackageLayer packageLayer) {
+ return Iterables.any(selections, new Predicate<Selection>() {
+ @Override
+ public boolean apply(Selection selection) {
+ return selection.matchPackageLayer(packageLayer);
+ }
+ });
+ }
+
+ @Override
+ protected boolean select(final Member member) {
+ return Iterables.any(selections, new Predicate<Selection>() {
+ @Override
+ public boolean apply(Selection selection) {
+ return selection.matchMember(member);
+
+ }
+ });
}
+
+
@Override
public boolean visitInboundReference(final InboundRef inboundRef) {
+ FactForest forestCopy = getCopy();
for(Selection selection : selections) {
//have to match all selection as they can each copy the ref to a different packagetree
if(selection.matchRef(inboundRef)
@@ -28,20 +73,38 @@ public boolean apply(Selection selection) {
}
})) {
if(selection.hasTag()) {
- FactForest forestCopy = getCopy();
PackageTree tagTree = forestCopy.getOrAddPackageTree(new UqName(selection.getTagString()));
tagTree.copyReference(inboundRef);
- //enable if we want to keep a copy in the original location
- //copyInboundReference(inboundRef);
return false;
} else {
- copyInboundReference(inboundRef);
+ PackageTree untaggedTree = forestCopy.getOrAddPackageTree(new UqName("<Untagged>"));
+ untaggedTree.copyReference(inboundRef);
return true;
}
}
}
return false;
}
+ @Override
+ protected boolean select(InboundFactForest forest) {
+ return true;
+ }
+
+ @Override
+ protected boolean select(OutboundFactForest forest) {
+ return false;
+ }
+
+ @Override
+ protected boolean select(OutboundRef outboundRef) {
+ return false;
+ }
+
+ @Override
+ protected boolean select(InboundRef inboundRef) {
+ //not called as visitinBoundReference is overridden
+ return false;
+ }
}
@@ -4,7 +4,8 @@
import exapus.model.forest.OutboundFactForest;
import exapus.model.store.Store;
import exapus.model.view.View;
-import exapus.model.visitors.SelectiveCopyingForestVisitor;
+import exapus.model.visitors.ICopyingForestVisitor;
+import exapus.model.visitors.SelectiveTopDownCopyingForestVisitor;
public class ProjectCentricEvaluator extends Evaluator {
@@ -17,13 +18,13 @@ public FactForest getResult() {
return getModelResult().getProjectCentricForest();
}
- protected SelectiveCopyingForestVisitor newVisitor() {
+ protected ICopyingForestVisitor newVisitor() {
return new ProjectCentricSelectionVisitor(getView().getProjectSelections(), getView().getAPISelections());
}
@Override
public void evaluate() {
- SelectiveCopyingForestVisitor v = newVisitor();
+ ICopyingForestVisitor v = newVisitor();
OutboundFactForest workspaceForest = Store.getCurrent().getWorkspaceModel().getProjectCentricForest();
FactForest forest = v.copy(workspaceForest);
calculateMetrics(forest);
@@ -13,9 +13,10 @@
import exapus.model.forest.PackageTree;
import exapus.model.forest.UqName;
import exapus.model.view.Selection;
-import exapus.model.visitors.SelectiveCopyingForestVisitor;
+import exapus.model.visitors.SelectiveTopDownCopyingForestVisitor;
+import exapus.model.visitors.SelectiveBottomUpCopyingForestVisitor;
-public abstract class SelectionVisitor extends SelectiveCopyingForestVisitor {
+public abstract class SelectionVisitor extends SelectiveTopDownCopyingForestVisitor {
protected Iterable<Selection> selections;
protected Iterable<Selection> dual_selections;
@@ -1,88 +1,33 @@
package exapus.model.visitors;
-import java.util.HashMap;
-import java.util.Map;
-
import exapus.model.forest.ExapusModel;
import exapus.model.forest.FactForest;
-import exapus.model.forest.ForestElement;
-import exapus.model.forest.ILayerContainer;
import exapus.model.forest.InboundFactForest;
-import exapus.model.forest.InboundRef;
-import exapus.model.forest.Member;
-import exapus.model.forest.MemberContainer;
import exapus.model.forest.OutboundFactForest;
-import exapus.model.forest.OutboundRef;
-import exapus.model.forest.PackageLayer;
-import exapus.model.forest.PackageTree;
-public class CopyingForestVisitor implements IForestVisitor {
+public abstract class CopyingForestVisitor implements ICopyingForestVisitor {
public CopyingForestVisitor() {
clear();
}
-
- protected void clear() {
- forestCopy = null;
- copies = new HashMap<ForestElement, ForestElement>();
- }
-
+
+ @Override
public FactForest copy(FactForest f) {
clear();
f.acceptVisitor(this);
return getCopy();
}
+
+ protected FactForest forestCopy;
- private Map<ForestElement,ForestElement> copies;
- private FactForest forestCopy;
-
+ protected void clear() {
+ forestCopy = null;
+ }
+
protected FactForest getCopy() {
return forestCopy;
}
- protected void registerCopy(ForestElement original, ForestElement copy) {
- copies.put(original, copy);
- }
-
- protected ForestElement getCopy(ForestElement original) {
- return copies.get(original);
- }
-
- protected boolean hasCopy(ForestElement original) {
- return copies.containsKey(original);
- }
-
- @Override
- public boolean visitPackageTree(PackageTree packageTree) {
- PackageTree copy = new PackageTree(packageTree.getName());
- registerCopy(packageTree,copy);
- forestCopy.addPackageTree(copy);
- return true;
- }
-
- @Override
- public boolean visitPackageLayer(PackageLayer packageLayer) {
- PackageLayer copy = new PackageLayer(packageLayer.getName());
- ForestElement parentCopy = getCopy(packageLayer.getParent());
- //PackageTree or PackageLayer
- ILayerContainer parentCopyAsLayerContainer = (ILayerContainer) parentCopy;
- parentCopyAsLayerContainer.addLayer(copy);
- //copy.setParent(parentCopy);//already performed by addLayer
- registerCopy(packageLayer,copy);
- return true;
- }
-
- @Override
- public boolean visitMember(Member member) {
- Member copy = new Member(member.getName(), member.getElement());
- ForestElement parentCopy = getCopy(member.getParent());
- //PackageLayer or Member
- MemberContainer parentCopyAsMemberContainer = (MemberContainer) parentCopy;
- parentCopyAsMemberContainer.addMember(copy);
- registerCopy(member,copy);
- return true;
- }
-
@Override
public boolean visitInboundFactForest(InboundFactForest forest) {
ExapusModel dummyModel = new ExapusModel();
@@ -97,33 +42,7 @@ public boolean visitOutboundFactForest(OutboundFactForest forest) {
return true;
}
- protected void copyInboundReference(InboundRef inboundRef) {
- InboundRef copy = InboundRef.fromInboundRef(inboundRef);
- ForestElement parentCopy = getCopy(inboundRef.getParent());
- Member parentCopyAsMember = (Member) parentCopy;
- parentCopyAsMember.addAPIReference(copy);
- registerCopy(inboundRef,copy);
- }
-
- protected void copyOutboundReference(OutboundRef outboundRef) {
- OutboundRef copy = OutboundRef.fromOutboundRef(outboundRef);
- copy.setDual(outboundRef.getDual());
- ForestElement parentCopy = getCopy(outboundRef.getParent());
- Member parentCopyAsMember = (Member) parentCopy;
- parentCopyAsMember.addAPIReference(copy);
- registerCopy(outboundRef,copy);
- }
-
- @Override
- public boolean visitInboundReference(InboundRef inboundRef) {
- copyInboundReference(inboundRef);
- return true;
- }
- @Override
- public boolean visitOutboundReference(OutboundRef outboundRef) {
- copyOutboundReference(outboundRef);
- return true;
- }
+
}
@@ -0,0 +1,9 @@
+package exapus.model.visitors;
+
+import exapus.model.forest.FactForest;
+
+public interface ICopyingForestVisitor extends IForestVisitor {
+
+ public FactForest copy(FactForest f);
+
+}
@@ -1,6 +1,5 @@
package exapus.model.visitors;
-import exapus.model.forest.FactForest;
import exapus.model.forest.InboundFactForest;
import exapus.model.forest.InboundRef;
import exapus.model.forest.Member;
Oops, something went wrong.

0 comments on commit 41825f6

Please sign in to comment.