Skip to content

Commit

Permalink
extract language interface
Browse files Browse the repository at this point in the history
  • Loading branch information
uowiy committed Jul 2, 2024
1 parent 12e523f commit 98e3ace
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 63 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.jku.cps</groupId>
<artifactId>travart-core</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public class DefaultPrettyPrinter<T> implements IPrettyPrinter<T> {
* readable format.
*/
public DefaultPrettyPrinter(ISerializer<T> serializer) {
if(!serializer.getFormat().isText() && serializer.getFormat().isHumanReadable()) {

}
this.serializer = serializer;
}

Expand All @@ -50,6 +47,12 @@ public List<REPRESENTATION> representations() {

@Override
public String toText(T model) throws NotSupportedVariabilityTypeException {
if(!serializer.getFormat().isText() || !serializer.getFormat().isHumanReadable()) {
throw new NotSupportedVariabilityTypeException(
"The default pretty printer could not be generated from the given serializer. " +
"The given serializer does not have a human-readable text-based format!"
);
}
return serializer.serialize(model);
}

Expand Down
63 changes: 63 additions & 0 deletions src/main/java/at/jku/cps/travart/core/basic/UVL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* This Source Code Form is subject to the terms of the Mozilla
* Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at
* https://mozilla.org/MPL/2.0/.
*
* Contributors:
* @author Kevin Feichtinger
* @author Prankur Agarwal
* @author Jakob Gretenkort
*
* An implementation of the universal variability language.
*
* Copyright 2023 Johannes Kepler University Linz
* LIT Cyber-Physical Systems Lab
* All rights reserved
*******************************************************************************/
package at.jku.cps.travart.core.basic;

import at.jku.cps.travart.core.FeatureModelStatistics;
import at.jku.cps.travart.core.common.IDeserializer;
import at.jku.cps.travart.core.common.ILanguage;
import at.jku.cps.travart.core.common.ISerializer;
import at.jku.cps.travart.core.common.IStatistics;
import at.jku.cps.travart.core.io.UVLDeserializer;
import at.jku.cps.travart.core.io.UVLSerializer;
import de.vill.model.FeatureModel;

/**
* An implementation of the universal variability language, providing
*/
public class UVL implements ILanguage<FeatureModel> {

@Override
public IDeserializer<FeatureModel> getDeserializer() {
return new UVLDeserializer();
}

@Override
public IStatistics<FeatureModel> getStatistics() {
return FeatureModelStatistics.getInstance();
}

@Override
public ISerializer<FeatureModel> getSerializer() {
return new UVLSerializer();
}

@Override
public String getName() {
return "Universal Variability Language";
}

@Override
public String getAbbreviation(){
return "UVL";
}

@Override
public Iterable<String> getSupportedFileExtensions() {
return getDeserializer().fileExtensions();
}
}
89 changes: 89 additions & 0 deletions src/main/java/at/jku/cps/travart/core/common/ILanguage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*******************************************************************************
* This Source Code Form is subject to the terms of the Mozilla
* Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at
* https://mozilla.org/MPL/2.0/.
*
* Contributors:
* @author Kevin Feichtinger
* @author Prankur Agarwal
* @author Jakob Gretenkort
*
* The base interface for a variability language.
*
* Copyright 2023 Johannes Kepler University Linz
* LIT Cyber-Physical Systems Lab
* All rights reserved
*******************************************************************************/
package at.jku.cps.travart.core.common;

import at.jku.cps.travart.core.basic.DefaultPrettyPrinter;

/**
* A variability language must provide access to a
* {@link ISerializer}/{@link IDeserializer} to serialize/deserialize the
* language's variability model and {@link IStatistics} to get the statistics of
* the variability model.
*
* @author Prankur Agarwal
* @author Kevin Feichtinger
* @author Jakob Gretenkort
*/
public interface ILanguage<T> {
/**
* Returns the deserializer of the language to deserializer the variability
* model.
*
* @return the deserializer of the language to deserializer the variability
* model.
*/
IDeserializer<T> getDeserializer();

/**
* Returns the statistics of the language to get the statistics the variability
* model.
*
* @return the statistics of the language to get the statistics the variability
* model.
*/
IStatistics<T> getStatistics();

/**
* Returns the serializer of the language to serialize the variability model.
*
* @return the serializer of the language to serialize the variability model.
*/
ISerializer<T> getSerializer();

/**
* Returns the pretty printer of the language to create human-readable
* representations of the variability model.
*
* @return the pretty printer to create human-readable representations of
* the variability model.
*/
default IPrettyPrinter<T> getPrinter() {
return new DefaultPrettyPrinter<T>(this.getSerializer());
}

/**
* Returns the variability model type name.
*
* @return the name of the variability model type.
*/
String getName();

/**
* Returns an abbreviation, typically an acronym of the variability type name.
*
* @return the abbreviated version of the variability type name.
*/
String getAbbreviation();

/**
* Returns a iterable of file extensions for which this language is applicable.
*
* @return a unmodifiable list of file extensions.
*/
Iterable<String> getSupportedFileExtensions();
}
64 changes: 5 additions & 59 deletions src/main/java/at/jku/cps/travart/core/common/IPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,70 +19,23 @@

import org.pf4j.ExtensionPoint;

import at.jku.cps.travart.core.basic.DefaultPrettyPrinter;

/**
* A TraVarT plugin extension must provide access to a {@link IModelTransformer}
* to transform a variability model, {@link IReader}/{@link IWriter} to
* read/write the variability model and {@link IStatistics} to get the
* statistics of the variability model. Additionally, some meta-data of the
* plugin should be available.
* A TraVarT plugin must implement a variability language and provide access to
* a {@link IModelTransformer} to transform models in that language.
* Additionally, some meta-data of the plugin should be available.
*
* @author Prankur Agarwal
* @author Kevin Feichtinger
* @author Jakob Gretenkort
*/
public interface IPlugin<T> extends ExtensionPoint {

public interface IPlugin<T> extends ExtensionPoint, ILanguage<T> {
/**
* Returns the transformer of the plugin to transform the variability model.
*
* @return the transformer of the plugin to transform the variability model.
*/
IModelTransformer<T> getTransformer();

/**
* Returns the deserializer of the plugin to deserializer the variability
* model.
*
* @return the deserializer of the plugin to deserializer the variability
* model.
*/
IDeserializer<T> getDeserializer();

/**
* Returns the statistics of the plugin to get the statistics the variability
* model.
*
* @return the statistics of the plugin to get the statistics the variability
* model.
*/
IStatistics<T> getStatistics();

/**
* Returns the serializer of the plugin to serialize the variability model.
*
* @return the serializer of the plugin to serialize the variability model.
*/
ISerializer<T> getSerializer();

/**
* Returns the pretty printer of the plugin to create human-readable
* representations of the variability model.
*
* @return the pretty printer to create human-readable representations of
* the variability model.
*/
default IPrettyPrinter<T> getPrinter() {
return new DefaultPrettyPrinter<T>(getSerializer());
}

/**
* Returns the variability model type name.
*
* @return the name of the variability model type.
*/
String getName();

/**
* Returns the version of the plugin.
*
Expand All @@ -96,11 +49,4 @@ default IPrettyPrinter<T> getPrinter() {
* @return the unique ID of the plugin.
*/
String getId();

/**
* Returns a iterable of file extensions for which this plugin is applicable.
*
* @return a unmodifiable list of file extensions.
*/
Iterable<String> getSupportedFileExtensions();
}

0 comments on commit 98e3ace

Please sign in to comment.