From fc7aef1abda18018cc3303bc16e5832544307137 Mon Sep 17 00:00:00 2001 From: Lars Hamann Date: Wed, 21 Dec 2022 15:26:21 +0100 Subject: [PATCH] Cleanup Sourcecode - Removed unfinished metrics package --- .../metrics/AbstractMetricVisitor.java | 353 ------------------ .../AbstractShellCommandProcessor.java | 56 --- .../use/analysis/metrics/CSVFileReader.java | 93 ----- .../analysis/metrics/ConfigurationEntry.java | 57 --- .../use/analysis/metrics/ExpressionProxy.java | 48 --- .../tzi/use/analysis/metrics/GSMetric.java | 93 ----- .../metrics/GSMetricConfiguration.java | 82 ---- .../use/analysis/metrics/GSMetricVisitor.java | 166 -------- .../tzi/use/analysis/metrics/Measurement.java | 99 ----- .../analysis/metrics/MeasurementReport.java | 88 ----- .../metrics/MeasurementResultElement.java | 59 --- .../analysis/metrics/MeasurementStrategy.java | 55 --- .../use/analysis/metrics/MeasuringObject.java | 38 -- .../metrics/ShellMetricCommandProcessor.java | 82 ---- .../tzi/use/analysis/metrics/SingleShot.java | 70 ---- .../examples/metrics/gs-metric/default.csv | 19 - 16 files changed, 1458 deletions(-) delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/AbstractMetricVisitor.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/AbstractShellCommandProcessor.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/CSVFileReader.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/ConfigurationEntry.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/ExpressionProxy.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetric.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetricConfiguration.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetricVisitor.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/Measurement.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementReport.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementResultElement.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementStrategy.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/MeasuringObject.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/ShellMetricCommandProcessor.java delete mode 100644 use-core/src/main/java/org/tzi/use/analysis/metrics/SingleShot.java delete mode 100644 use-core/src/main/resources/examples/metrics/gs-metric/default.csv diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/AbstractMetricVisitor.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/AbstractMetricVisitor.java deleted file mode 100644 index 9b894ab21..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/AbstractMetricVisitor.java +++ /dev/null @@ -1,353 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -package org.tzi.use.analysis.metrics; - -import java.util.Stack; - -import org.tzi.use.uml.mm.MOperation; -import org.tzi.use.uml.ocl.expr.ExpAllInstances; -import org.tzi.use.uml.ocl.expr.ExpAny; -import org.tzi.use.uml.ocl.expr.ExpAsType; -import org.tzi.use.uml.ocl.expr.ExpAttrOp; -import org.tzi.use.uml.ocl.expr.ExpBagLiteral; -import org.tzi.use.uml.ocl.expr.ExpClosure; -import org.tzi.use.uml.ocl.expr.ExpCollect; -import org.tzi.use.uml.ocl.expr.ExpCollectNested; -import org.tzi.use.uml.ocl.expr.ExpCollectionLiteral; -import org.tzi.use.uml.ocl.expr.ExpConstBoolean; -import org.tzi.use.uml.ocl.expr.ExpConstEnum; -import org.tzi.use.uml.ocl.expr.ExpConstInteger; -import org.tzi.use.uml.ocl.expr.ExpConstReal; -import org.tzi.use.uml.ocl.expr.ExpConstString; -import org.tzi.use.uml.ocl.expr.ExpConstUnlimitedNatural; -import org.tzi.use.uml.ocl.expr.ExpEmptyCollection; -import org.tzi.use.uml.ocl.expr.ExpExists; -import org.tzi.use.uml.ocl.expr.ExpForAll; -import org.tzi.use.uml.ocl.expr.ExpIf; -import org.tzi.use.uml.ocl.expr.ExpIsKindOf; -import org.tzi.use.uml.ocl.expr.ExpIsTypeOf; -import org.tzi.use.uml.ocl.expr.ExpIsUnique; -import org.tzi.use.uml.ocl.expr.ExpIterate; -import org.tzi.use.uml.ocl.expr.ExpLet; -import org.tzi.use.uml.ocl.expr.ExpNavigation; -import org.tzi.use.uml.ocl.expr.ExpNavigationClassifierSource; -import org.tzi.use.uml.ocl.expr.ExpObjAsSet; -import org.tzi.use.uml.ocl.expr.ExpObjOp; -import org.tzi.use.uml.ocl.expr.ExpObjRef; -import org.tzi.use.uml.ocl.expr.ExpObjectByUseId; -import org.tzi.use.uml.ocl.expr.ExpOclInState; -import org.tzi.use.uml.ocl.expr.ExpOne; -import org.tzi.use.uml.ocl.expr.ExpOrderedSetLiteral; -import org.tzi.use.uml.ocl.expr.ExpQuery; -import org.tzi.use.uml.ocl.expr.ExpRange; -import org.tzi.use.uml.ocl.expr.ExpReject; -import org.tzi.use.uml.ocl.expr.ExpSelect; -import org.tzi.use.uml.ocl.expr.ExpSelectByKind; -import org.tzi.use.uml.ocl.expr.ExpSelectByType; -import org.tzi.use.uml.ocl.expr.ExpSequenceLiteral; -import org.tzi.use.uml.ocl.expr.ExpSetLiteral; -import org.tzi.use.uml.ocl.expr.ExpSortedBy; -import org.tzi.use.uml.ocl.expr.ExpStdOp; -import org.tzi.use.uml.ocl.expr.ExpTupleLiteral; -import org.tzi.use.uml.ocl.expr.ExpTupleSelectOp; -import org.tzi.use.uml.ocl.expr.ExpUndefined; -import org.tzi.use.uml.ocl.expr.ExpVariable; -import org.tzi.use.uml.ocl.expr.Expression; -import org.tzi.use.uml.ocl.expr.ExpressionVisitor; -import org.tzi.use.uml.ocl.expr.ExpressionWithValue; -import org.tzi.use.uml.ocl.expr.VarDecl; -import org.tzi.use.uml.ocl.expr.VarDeclList; - -/** - * Abstract metrics visitor implementation. - * - * @author ms - * - */ -public abstract class AbstractMetricVisitor implements ExpressionVisitor { - - protected final MeasurementStrategy measurement; - protected final boolean expandOperations; - - public AbstractMetricVisitor(MeasurementStrategy measurement, boolean expandOperations) { - this.measurement = measurement; - this.expandOperations = expandOperations; - } - - @Override - public void visitAllInstances(ExpAllInstances exp) { - } - - @Override - public void visitAny(ExpAny exp) { - visitQuery(exp); - } - - @Override - public void visitAsType(ExpAsType exp) { - } - - @Override - public void visitAttrOp(ExpAttrOp exp) { - exp.objExp().processWithVisitor(this); - } - - @Override - public void visitBagLiteral(ExpBagLiteral exp) { - visitCollectionLiteral(exp); - } - - @Override - public void visitCollect(ExpCollect exp) { - visitQuery(exp); - } - - @Override - public void visitCollectNested(ExpCollectNested exp) { - visitQuery(exp); - } - - @Override - public void visitConstBoolean(ExpConstBoolean exp) { - } - - @Override - public void visitConstEnum(ExpConstEnum exp) { - } - - @Override - public void visitConstInteger(ExpConstInteger exp) { - } - - @Override - public void visitConstReal(ExpConstReal exp) { - } - - @Override - public void visitConstString(ExpConstString exp) { - } - - @Override - public void visitEmptyCollection(ExpEmptyCollection exp) { - } - - @Override - public void visitExists(ExpExists exp) { - visitQuery(exp); - } - - @Override - public void visitForAll(ExpForAll exp) { - visitQuery(exp); - } - - @Override - public void visitIf(ExpIf exp) { - exp.getCondition().processWithVisitor(this); - exp.getThenExpression().processWithVisitor(this); - exp.getElseExpression().processWithVisitor(this); - } - - @Override - public void visitIsKindOf(ExpIsKindOf exp) { - exp.getSourceExpr().processWithVisitor(this); - } - - @Override - public void visitIsTypeOf(ExpIsTypeOf exp) { - exp.getSourceExpr().processWithVisitor(this); - } - - @Override - public void visitIsUnique(ExpIsUnique exp) { - visitQuery(exp); - } - - @Override - public void visitIterate(ExpIterate exp) { - visitQuery(exp); - } - - @Override - public void visitLet(ExpLet exp) { - exp.getVarExpression().processWithVisitor(this); - exp.getInExpression().processWithVisitor(this); - } - - @Override - public void visitNavigation(ExpNavigation exp) { - exp.getObjectExpression().processWithVisitor(this); - } - - @Override - public void visitNavigationClassifierSource( - ExpNavigationClassifierSource exp) { - exp.getObjectExpression().processWithVisitor(this); - } - - @Override - public void visitObjAsSet(ExpObjAsSet exp) { - exp.getObjectExpression().processWithVisitor(this); - } - - private Stack operationStack = new Stack(); - - @Override - public void visitObjOp(ExpObjOp exp) { - for (Expression ex : exp.getArguments()) { - ex.processWithVisitor(this); - } - - if (expandOperations && exp.getOperation().hasExpression() - && !operationStack.contains(exp.getOperation())) { - operationStack.push(exp.getOperation()); - exp.getOperation().expression().processWithVisitor(this); - operationStack.pop(); - } - } - - @Override - public void visitObjRef(ExpObjRef exp) { - exp.processWithVisitor(this); - } - - @Override - public void visitOne(ExpOne exp) { - visitQuery(exp); - } - - @Override - public void visitOrderedSetLiteral(ExpOrderedSetLiteral exp) { - visitCollectionLiteral(exp); - } - - @Override - public void visitQuery(ExpQuery exp) { - exp.getRangeExpression().processWithVisitor(this); - exp.getQueryExpression().processWithVisitor(this); - } - - @Override - public void visitReject(ExpReject exp) { - visitQuery(exp); - } - - @Override - public void visitWithValue(ExpressionWithValue exp) { - } - - @Override - public void visitSelect(ExpSelect exp) { - visitQuery(exp); - } - - @Override - public void visitSequenceLiteral(ExpSequenceLiteral exp) { - visitCollectionLiteral(exp); - } - - @Override - public void visitSetLiteral(ExpSetLiteral exp) { - visitCollectionLiteral(exp); - } - - @Override - public void visitSortedBy(ExpSortedBy exp) { - visitQuery(exp); - } - - @Override - public void visitStdOp(ExpStdOp exp) { - for (Expression expArg : exp.args()) { - expArg.processWithVisitor(this); - } - } - - @Override - public void visitTupleLiteral(ExpTupleLiteral exp) { - for (ExpTupleLiteral.Part part : exp.getParts()) { - part.getExpression().processWithVisitor(this); - } - } - - @Override - public void visitTupleSelectOp(ExpTupleSelectOp exp) { - } - - @Override - public void visitUndefined(ExpUndefined exp) { - } - - @Override - public void visitVariable(ExpVariable exp) { - } - - protected void visitCollectionLiteral(ExpCollectionLiteral exp) { - for (Expression ex : exp.getElemExpr()) { - ex.processWithVisitor(this); - } - } - - @Override - public void visitClosure(ExpClosure expClosure) { - visitQuery(expClosure); - } - - @Override - public void visitOclInState(ExpOclInState expOclInState) { - expOclInState.getSourceExpr().processWithVisitor(this); - } - - @Override - public void visitVarDeclList(VarDeclList varDeclList) { - for (int i = 0; i < varDeclList.size(); ++i) { - varDeclList.varDecl(i).processWithVisitor(this); - } - } - - @Override - public void visitVarDecl(VarDecl varDecl) { - } - - @Override - public void visitObjectByUseId(ExpObjectByUseId expObjectByUseId) { - expObjectByUseId.getIdExpression().processWithVisitor(this); - } - - @Override - public void visitConstUnlimitedNatural( - ExpConstUnlimitedNatural expressionConstUnlimitedNatural) { - } - - @Override - public void visitSelectByKind(ExpSelectByKind expSelectByKind) { - expSelectByKind.getSourceExpression().processWithVisitor(this); - } - - @Override - public void visitExpSelectByType(ExpSelectByType expSelectByType) { - expSelectByType.getSourceExpression().processWithVisitor(this); - } - - @Override - public void visitRange(ExpRange exp) { - exp.getStart().processWithVisitor(this); - exp.getEnd().processWithVisitor(this); - } -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/AbstractShellCommandProcessor.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/AbstractShellCommandProcessor.java deleted file mode 100644 index a996fb235..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/AbstractShellCommandProcessor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import org.tzi.use.uml.mm.MModel; -import org.tzi.use.util.Log; - -/** - * TODO - * @author ms - * - */ -public abstract class AbstractShellCommandProcessor { - - protected final MModel model; - protected final String line; - - public AbstractShellCommandProcessor(MModel model, String line) { - this.model = model; - this.line = line; - } - - public void run() { - if (checkModelAvailable()) { - dispatch(); - } else { - Log.error("No model loaded"); - return; - } - } - - private boolean checkModelAvailable() { - return model != null; - } - - protected void dispatch() { - } - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/CSVFileReader.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/CSVFileReader.java deleted file mode 100644 index 9174bca34..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/CSVFileReader.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; - -import jline.internal.Log; - -/** - * TODO - * @author ms - * - */ - -public class CSVFileReader { - - private final String tailPath; - private ArrayList> lines = new ArrayList>(); - - /** - * - */ - public CSVFileReader(String tailPath) { - this.tailPath = tailPath; - try { - parse(); - } - catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - - private void parse() throws FileNotFoundException { - BufferedReader csvBuffer = null; - try { - - Log.info(); - Log.info("Loading" + " " + path()); - Log.info(); - - csvBuffer = new BufferedReader(new FileReader(path())); - - String csvLine; - while((csvLine = csvBuffer.readLine()) != null) { - - // skip comment lines starting with # - if(csvLine.startsWith("#")) continue; - - String[] splits = csvLine.split("\\s*,\\s*"); - ArrayList result = new ArrayList(Arrays.asList(splits)); - lines.add(result); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - if (csvBuffer != null) csvBuffer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - private String path() { - return System.getProperty("user.dir") + "/" + tailPath + ".csv"; - } - - public ArrayList> getLines() { - return lines; - } -} \ No newline at end of file diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/ConfigurationEntry.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/ConfigurationEntry.java deleted file mode 100644 index 7dde9afb7..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/ConfigurationEntry.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.List; - -/** - * TODO - * @author ms - * - */ -public class ConfigurationEntry { - - private final String key; - private List values; - - /** - * @param key - * @param values - */ - public ConfigurationEntry(String key, List values) { - this.key = key; - this.values = values; - } - - public float getWeightValue() { - // for now assuming format (name -> weight) - return Float.parseFloat(values.get(0)); - } - - public boolean deliversWeightValueByDepth(int depth) { - return true; - } - - public float getWeightValueByDepth() { - // for now assuming format (name -> depth, weight) - return Float.parseFloat(values.get(0)); - } - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/ExpressionProxy.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/ExpressionProxy.java deleted file mode 100644 index 2d647174d..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/ExpressionProxy.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import org.tzi.use.uml.ocl.expr.Expression; - -/** - * TODO - * @author ms - * - */ -public abstract class ExpressionProxy { - - protected final Expression client; - - /** - * @param client - */ - public ExpressionProxy(Expression client) { - this.client = client; - } - - public String name() { - return client.name(); - } - - public void accept(AbstractMetricVisitor visitor) { - client.processWithVisitor(visitor); - } - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetric.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetric.java deleted file mode 100644 index a3ea88ca0..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetric.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.ArrayList; - -import org.tzi.use.uml.ocl.expr.Expression; - - -/** - * TODO - * @author ms - * - */ -public class GSMetric extends MeasurementStrategy { - - private final GSMetricConfiguration configuration; - private ArrayList singleShots = new ArrayList(); - - // TODO abstract input argument wrapper - public enum NestingMode { - none, // does not consider depth at all - simpleNesting, // just considers depth value - simpleSymmetricNestingCustom, // considers custom depth value for symmetric nesting (ex: forAll,sd2,5) - simpleAsymmetricNestingCustom, // considers custom depth value for asymmetric nesting (ex: forAll,ad2,7) - traceNestingCustom // considers traces/paths (ex: forAll:forAll:one,8) - } - - // TODO argument input - private final NestingMode nestingMode = NestingMode.none; - - /** - * - */ - public GSMetric(String fileName) { - super(); - configuration = GSMetricConfiguration.load(fileName); - } - - @Override - public void apply(MeasuringObject object) { - - // TODO Handle expandOperations properly - GSMetricVisitor visitor = new GSMetricVisitor(this, true); - - object.accept(visitor); - } - - public void pushSingleShot(Expression expression, ArrayList stackTrace) { - SingleShot singleShot = new SingleShot(this, nestingMode, expression, stackTrace); - singleShots.add(singleShot); - } - - // total is the sum of all single shot measurements - // each single shot represents the measurement of one compound OCL expression - public float inject() { - float total = 0; - for(SingleShot singleShot: singleShots) total += singleShot.measuredValue(); - return total; - } - - public void reset() { - singleShots.clear(); - } - - // [SingleShot] -delegate-> GSMetricConfiguration - public float getWeightFor(String name) { - return configuration.getWeightFor(name); - } - - // [SingleShot] -delegate-> GSMetricConfiguration - public float getWeightForDepth(String name, int depth) { - return configuration.getWeightForDepth(name, depth); - } - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetricConfiguration.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetricConfiguration.java deleted file mode 100644 index ef1525b20..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetricConfiguration.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.ArrayList; -import java.util.HashMap; - -import org.tzi.use.util.Log; - -/** - * TODO - * @author ms - * - */ -public class GSMetricConfiguration { - - private CSVFileReader csvProxy; - private HashMap entries = new HashMap(); - - public static GSMetricConfiguration load(String fileName) { - CSVFileReader csvProxy = new CSVFileReader("metrics/gs-metric/" + fileName); - return new GSMetricConfiguration(csvProxy); - } - - /** - * - */ - public GSMetricConfiguration(CSVFileReader csvProxy) { - super(); - this.csvProxy = csvProxy; - load(); - } - - private void load() { - for(ArrayList tuple: csvProxy.getLines()) { - String key = tuple.get(0); - tuple.remove(0); - entries.put(key, new ConfigurationEntry(key, tuple)); - } - } - - public float getWeightFor(String name) { - - if(!entries.containsKey(name)) { - Log.error("No weight found for >" + name + "< expressions, using 0."); - return 0; - } - - ConfigurationEntry entry = entries.get(name); - return entry.getWeightValue(); - } - - public float getWeightForDepth(String name, int depth) { - - // TODO each key (i.e. operation name) has multiple value definitions assigned - // TODO change entries to array of tuples or introduce ConfigurationEntryGroups per - // TODO operation name ->* depth/value specifications - - //ConfigurationEntry entry = entries.get(name); - //return entry.getWeightValueByDepth(depth); - - return 1; - } - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetricVisitor.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetricVisitor.java deleted file mode 100644 index cfd02b8f9..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/GSMetricVisitor.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Stack; - -import org.tzi.use.uml.ocl.expr.ExpAllInstances; -import org.tzi.use.uml.ocl.expr.ExpAny; -import org.tzi.use.uml.ocl.expr.ExpAsType; -import org.tzi.use.uml.ocl.expr.ExpCollect; -import org.tzi.use.uml.ocl.expr.ExpCollectNested; -import org.tzi.use.uml.ocl.expr.ExpExists; -import org.tzi.use.uml.ocl.expr.ExpForAll; -import org.tzi.use.uml.ocl.expr.ExpIterate; -import org.tzi.use.uml.ocl.expr.ExpOne; -import org.tzi.use.uml.ocl.expr.ExpReject; -import org.tzi.use.uml.ocl.expr.ExpSelect; -import org.tzi.use.uml.ocl.expr.ExpSortedBy; -import org.tzi.use.uml.ocl.expr.Expression; - -/** - * TODO - * @author ms - * - */ -public class GSMetricVisitor extends AbstractMetricVisitor { - - private HashMap> stackMap = new HashMap>(); - - /** - * @param expandOperations - */ - public GSMetricVisitor(GSMetric measurement, boolean expandOperations) { - super(measurement, expandOperations); - } - - // TODO visitPlain, visitDescend - - @Override - public void visitAllInstances(ExpAllInstances exp) { - visitExpression(exp); - popFromStack(exp); - } - - @Override - public void visitAny(ExpAny exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - @Override - public void visitAsType(ExpAsType exp) { - visitExpression(exp); - popFromStack(exp); - } - - @Override - public void visitCollect(ExpCollect exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - @Override - public void visitCollectNested(ExpCollectNested exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - @Override - public void visitExists(ExpExists exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - @Override - public void visitForAll(ExpForAll exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - @Override - public void visitIterate(ExpIterate exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - @Override - public void visitOne(ExpOne exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - @Override - public void visitReject(ExpReject exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - @Override - public void visitSelect(ExpSelect exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - @Override - public void visitSortedBy(ExpSortedBy exp) { - visitExpression(exp); - visitQuery(exp); - popFromStack(exp); - } - - /** private section **/ - - private String pushToStack(Expression expression) { - String stackKey = expression.getClass().getName(); - Stack stack = stackMap.get(stackKey); - - if(stack == null) { - stack = new Stack(); - stackMap.put(stackKey, stack); - } - - stackMap.get(stackKey).push(expression); - - return stackKey; - } - - private void popFromStack(Expression expression) { - String stackKey = expression.getClass().getName(); - stackMap.get(stackKey).pop(); - } - - private void visitExpression(Expression expression) { - String stackKey = pushToStack(expression); - measurement.pushSingleShot(expression, new ArrayList(stackMap.get(stackKey))); - } - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/Measurement.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/Measurement.java deleted file mode 100644 index 477cac709..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/Measurement.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.HashMap; - -import org.tzi.use.uml.mm.MClassInvariant; -import org.tzi.use.uml.mm.MModel; -import org.tzi.use.uml.mm.MModelElement; -import org.tzi.use.uml.mm.MPrePostCondition; - -/** - * TODO - * @author ms - * - */ -public class Measurement { - - private MeasurementStrategy strategy; - private MModel model; - - private MeasurementReport report = new MeasurementReport(); - private HashMap interimResult = new HashMap(); - - /** - * @param strategy - */ - public Measurement(MeasurementStrategy strategy, MModel model) { - this.strategy = strategy; - this.model = model; - } - - public void perform() { - _performPreconditions(); - _performPostconditions(); - _performInvariants(); - } - - private void _performPreconditions() { - for (MPrePostCondition pres : model.preConditions()) { - MeasuringObject object = new MeasuringObject(pres.expression()); - strategy.apply(object); - interimResult.put(pres, Float.valueOf(strategy.inject())); - - strategy.reset(); - } - - MeasurementResultElement resultElement = new MeasurementResultElement("pre", interimResult); - report.addObject(resultElement); - } - - private void _performPostconditions() { - for (MPrePostCondition posts : model.postConditions()) { - MeasuringObject object = new MeasuringObject(posts.expression()); - strategy.apply(object); - interimResult.put(posts, Float.valueOf(strategy.inject())); - - strategy.reset(); - } - - MeasurementResultElement resultElement = new MeasurementResultElement("post", interimResult); - report.addObject(resultElement); - } - - private void _performInvariants() { - for (MClassInvariant invariant : model.classInvariants()) { - MeasuringObject object = new MeasuringObject(invariant.expandedExpression()); - strategy.apply(object); - interimResult.put(invariant, Float.valueOf(strategy.inject())); - - strategy.reset(); - } - - MeasurementResultElement resultElement = new MeasurementResultElement("inv", interimResult); - report.addObject(resultElement); - } - - public MeasurementReport getReport() { - return report; - } - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementReport.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementReport.java deleted file mode 100644 index e7457c1b2..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementReport.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.ArrayList; -import java.util.Iterator; - -import jline.internal.Log; - -/** - * TODO - * @author ms - * - */ -public class MeasurementReport { - - private ArrayList objects = new ArrayList(); - - public void addObject(MeasurementResultElement resultElement) { - this.objects.add(resultElement); - } - - // TODO categorize output, therefore group and sort objects - // TODO delegate sorting to objects - - // TODO see http://www.dynamicreports.org/getting-started for sophisticated report output - - public void publishPlain() { - - Log.info(); - - Log.info("Results:"); - Log.info("========"); - - Iterator each = objects.iterator(); - - while(each.hasNext()) { - MeasurementResultElement resultElement = each.next(); - - // Log.info(String.join("\r\n", resultElement.publishPlain())); - Log.info(resultElement.publishPlain()); - - each.remove(); // avoids ConcurrentModificationExceptions - } - - Log.info(); - } - - /** - public void _perform() { - - Collection invariants = model.classInvariants(); - List lsInvariants = new ArrayList(invariants); - - Collections.sort(lsInvariants, new Comparator(){ - - @Override - public int compare(MClassInvariant o1, MClassInvariant o2) { - int clsCmp = o1.cls().compareTo(o2); - if (clsCmp == 0) { - return o1.name().compareTo(o2.name()); - } else { - return clsCmp; - } - } - - }); - } - **/ - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementResultElement.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementResultElement.java deleted file mode 100644 index cbc4ea573..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementResultElement.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; - -import org.tzi.use.uml.mm.MModelElement; - -/** - * TODO - * @author ms - * - */ -public class MeasurementResultElement { - - String scope; - HashMap client; - - /** - * @param interimResult - */ - public MeasurementResultElement(String scope, HashMap interimResult) { - this.scope = scope; - this.client = interimResult; - } - - public ArrayList publishPlain() { - ArrayList buffer = new ArrayList(); - - Iterator> each = client.entrySet().iterator(); - while (each.hasNext()) { - Entry tuple = each.next(); - buffer.add("O(" + tuple.getKey().name() + "): " + tuple.getValue()); - each.remove(); // avoids ConcurrentModificationExceptions - } - return buffer; - } - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementStrategy.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementStrategy.java deleted file mode 100644 index b256034b2..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasurementStrategy.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.ArrayList; - -import org.tzi.use.uml.ocl.expr.Expression; - - - -/** - * TODO - * @author ms - * - */ -public class MeasurementStrategy { - - public void apply(MeasuringObject object) { - } - - public float getWeightFor(String name) { - return 0; - } - - public void pushSingleShot(Expression expression, ArrayList stackTrace) { - } - - public float inject() { - return 0; - } - - public void reset() { - } - - public float getWeightForDepth(String name, int depth) { - return 0; - } -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasuringObject.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasuringObject.java deleted file mode 100644 index ffe7a30cc..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/MeasuringObject.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import org.tzi.use.uml.ocl.expr.Expression; - -/** - * TODO - * @author ms - * - */ -public class MeasuringObject extends ExpressionProxy { - - /** - * @param client - */ - public MeasuringObject(Expression client) { - super(client); - } - -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/ShellMetricCommandProcessor.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/ShellMetricCommandProcessor.java deleted file mode 100644 index fcd417451..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/ShellMetricCommandProcessor.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.Set; - -import jline.internal.Log; - -import org.tzi.use.uml.mm.MModel; - -import com.google.common.collect.Sets; - -/** - * Provides logic for the shell coverage command. - * - * @author ms - * - */ -public class ShellMetricCommandProcessor extends AbstractShellCommandProcessor { - - /** - * @param model - * @param line - */ - public ShellMetricCommandProcessor(MModel model, String line) { - super(model, line); - } - - protected void dispatch() { - Set actualArgs = Sets.newHashSet(line.split(" ")); - Set validArgs = Sets.newHashSet("metrics", "--run"); - Set delta = Sets.difference(actualArgs, validArgs); - - if(delta.isEmpty()) { - //Log.info("Arguments valid"); - - // TODO Extract metric name. - // TODO Extract configuration file name. - if(actualArgs.contains("--run")) _measure("sg", "default"); - } - else { - Log.error("Invalid arguments: ", delta); - } - } - - private void _measure(String metricName, String fileName) { - //Log.info("Measuring"); - - MeasurementStrategy strategy = null; - - switch(metricName) { - case "sg": - strategy = new GSMetric(fileName); - break; - } - - Measurement measurement = new Measurement(strategy, model); - measurement.perform(); - MeasurementReport report = measurement.getReport(); - report.publishPlain(); - - //Log.info("Result/Complexity: " + measurement.getResult()); - - } -} diff --git a/use-core/src/main/java/org/tzi/use/analysis/metrics/SingleShot.java b/use-core/src/main/java/org/tzi/use/analysis/metrics/SingleShot.java deleted file mode 100644 index a45925b8b..000000000 --- a/use-core/src/main/java/org/tzi/use/analysis/metrics/SingleShot.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * USE - UML based specification environment - * Copyright (C) 1999-2010 Mark Richters, University of Bremen - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.tzi.use.analysis.metrics; - -import java.util.ArrayList; - -import org.tzi.use.analysis.metrics.GSMetric.NestingMode; -import org.tzi.use.uml.ocl.expr.Expression; - - -/** - * TODO - * @author ms - * - */ -public class SingleShot extends ExpressionProxy { - - private final MeasurementStrategy metric; - private final NestingMode nestingMode; - private final ArrayList stackTrace; - - public SingleShot(MeasurementStrategy metric, NestingMode nestingMode, Expression client, ArrayList stackTrace) { - super(client); - this.metric = metric; - this.nestingMode = nestingMode; - this.stackTrace = stackTrace; - } - - public float measuredValue() { - float interim = 0; - - switch(nestingMode) { - case none: - interim = metric.getWeightFor(name()); - break; - case simpleNesting: - interim = metric.getWeightFor(name()) * depth(); - break; - case simpleSymmetricNestingCustom: - interim = metric.getWeightForDepth(name(), depth()); - break; - default: - break; - } - - return interim; - } - - public int depth() { - return stackTrace.size(); - } - -} diff --git a/use-core/src/main/resources/examples/metrics/gs-metric/default.csv b/use-core/src/main/resources/examples/metrics/gs-metric/default.csv deleted file mode 100644 index dfedce7af..000000000 --- a/use-core/src/main/resources/examples/metrics/gs-metric/default.csv +++ /dev/null @@ -1,19 +0,0 @@ -forAll,1.0 -select,1.0 -exists,1.0 -one,1.0 -allInstances,5.0 -collect,4.0 -any,2.0 - -# vollst. kanonische Konf. am Beispiel TAP paper -# ausg. gesamtkompl. summe -# class,state-inv/pre/post/ops/transitions/query - -# one,d3,50 - -# one,sd3,50 one->one->one -# one,ad3,50 x->y->one - -# forAll:select:one,25 -