Skip to content

Commit

Permalink
Merge pull request #63 from tcerny/seproj_ulm_2020
Browse files Browse the repository at this point in the history
AST datastructure with Simple Parser for Text File Lines and JSON import/export
  • Loading branch information
pmbittner authored Mar 24, 2021
2 parents e00ae09 + 954c6c6 commit fca14c2
Show file tree
Hide file tree
Showing 44 changed files with 1,016 additions and 89 deletions.
3 changes: 2 additions & 1 deletion de.tubs.variantsync.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
<groupId>de.tubs.variantsync</groupId>
<artifactId>de.tubs.variantsync</artifactId>
<version>0.0.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>de.tubs.variantsync.core</artifactId>
<packaging>eclipse-plugin</packaging>

<groupId>de.tubs.variantsync.core</groupId>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ public void listenForActiveClass() {
}

public static void addNature(IProject project) {
final VariantSyncProgressMonitor progressMonitor = new VariantSyncProgressMonitor("Adding VariantSync nature to " + project.getName());
final VariantSyncProgressMonitor progressMonitor = new VariantSyncProgressMonitor(String.format("Adding VariantSync nature to %s", project.getName()));
try {
final IProjectDescription description = project.getDescription();
final String[] natures = description.getNatureIds();

// the natures array is copied to a newNatures array, in which the variant NATURE_ID is added as first element
final String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 1, natures.length);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ProjectNotFoundException(Type type, String message) {

@Override
public String toString() {
return "A " + (type == Type.CONFIGURATION ? "configuration project" : "variant") + " does not exist in the workspace. " + getMessage();
return String.format("A %s does not exist in the workspace. %s", (type == Type.CONFIGURATION ? "configuration project" : "variant"), getMessage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private List<IFeatureProject> findConfigurationProjects() {
for (final IFeatureProject project : CorePlugin.getFeatureProjects()) {
// System.out.print(" project " + project.getProjectName());
if (project.getComposerID().equals("de.tubs.variantsync.core.composer")) {
LogOperations.logInfo("Found configuration project with name: " + project.getProjectName());
LogOperations.logInfo(String.format("Found configuration project with name: %s", project.getProjectName()));
projects.add(project);
// System.out.println(" is variant composing");
} else {
Expand All @@ -126,7 +126,7 @@ private void findVariants(ConfigurationProject configurationProject) {
} else {
try {
final IMarker m = file.createMarker("de.tubs.variantsync.marker.error");
m.setAttribute(IMarker.MESSAGE, "Project " + projectName + " is missing in the workspace");
m.setAttribute(IMarker.MESSAGE, String.format("Project %s is missing in the workspace", projectName));
m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
m.setAttribute(IMarker.LINE_NUMBER, 0);
Expand Down Expand Up @@ -176,9 +176,9 @@ public ConfigurationProject getActiveConfigurationProject() {
public void propertyChange(FeatureIDEEvent event) {
switch (event.getEventType()) {
case FEATURE_ADD:
LogOperations.logInfo("Feature added: " + event);
LogOperations.logInfo(String.format("Feature added: %s", event));
case MODEL_DATA_SAVED:
LogOperations.logInfo("Model Event" + event);
LogOperations.logInfo(String.format("Model Event %s", event));
if (event.getSource() instanceof IFeatureModel) {
final IFeatureModel model = (IFeatureModel) event.getSource();
final List<String> featureExpressions = getActiveConfigurationProject().getFeatureContextManager().getContextsAsStrings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ConfigurationProject extends AManager implements ISaveableManager {
private List<IProject> projects = new ArrayList<>();

public IFeatureProject getFeatureProject() {
if(configurationProject != null && configurationProject.getProject().exists()) {
if ((configurationProject != null) && configurationProject.getProject().exists()) {
return configurationProject;
}

Expand Down Expand Up @@ -85,8 +85,8 @@ public Configuration getConfigurationForVariant(IProject project) {
final IFile configPath = (IFile) EclipseFileSystem.getResource(confPath);
final String configFileName = configPath.getName();
final String configName = configFileName.substring(0, configFileName.lastIndexOf('.'));
System.out.println("[ConfigurationProject.getConfigurationForVariant] Check name equality Project(" + project.getName() + ") with Config("
+ configName + ")");
System.out.println(String.format("[ConfigurationProject.getConfigurationForVariant] Check name equality Project(%s) with Config(%s)",
project.getName(), configName));
if (configName.equals(project.getName())) {
final ConfigurationManager configurationManager = ConfigurationManager.getInstance(Paths.get(configPath.getRawLocationURI()));
if (configurationManager != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public FeatureContext(String name, FeatureColor highlighter) {
}

public boolean isComposed() {
// if the name contains one of the operators "or", "and" or "not" in its middle, the FeatureContext is supposed to be composed
return name.matches(".*(or|and|not).*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class CodeMappingFormat extends AXMLFormat<List<SourceFile>> {
private static final String MAPPINGS = "Mappings";
private static final String SOURCEFILE = "SourceFile";
private static final String CODEMAPPINGS = "CodeMapping";
private static final Pattern CONTENT_REGEX = Pattern.compile("\\A\\s*(<[?]xml\\s.*[?]>\\s*)?<" + MAPPINGS + "[\\s>]");

private static final Pattern CONTENT_REGEX = XMLFormatHelper.createContentRegex(MAPPINGS);

public static final String FILENAME = ".mapping.xml";

Expand Down Expand Up @@ -108,5 +109,4 @@ public boolean supportsContent(CharSequence content) {
public String getName() {
return "CodeMapping";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class FeatureContextFormat extends AXMLFormat<List<FeatureContext>> {
private static final String ID = "FeatureContexts";
private static final String FEATURE_CONTEXTS = "contexts";
private static final String FEATURE_CONTEXT = "context";
private static final Pattern CONTENT_REGEX = Pattern.compile("\\A\\s*(<[?]xml\\s.*[?]>\\s*)?<" + FEATURE_CONTEXTS + "[\\s>]");

private static final Pattern CONTENT_REGEX = XMLFormatHelper.createContentRegex(FEATURE_CONTEXTS);

public static final String FILENAME = ".contexts.xml";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class PatchFormat extends AXMLFormat<List<IPatch<?>>> {
private static final String PATCHES = "Patches";
private static final String PATCH = "Patch";
private static final String DELTA = "Delta";
private static final Pattern CONTENT_REGEX = Pattern.compile("\\A\\s*(<[?]xml\\s.*[?]>\\s*)?<" + PATCHES + "[\\s>]");

private static final Pattern CONTENT_REGEX = XMLFormatHelper.createContentRegex(PATCHES);

public static final String FILENAME = ".patches.xml";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.tubs.variantsync.core.managers.persistence;

import java.util.regex.Pattern;

public class XMLFormatHelper {

// the xml pattern should start with an optional standard xml-starting line (e.g. <?xml charSequenceOfArbitraryLength?>)
// followed by an xml tag starting with the content string
public static Pattern createContentRegex(String content) {
return Pattern.compile("\\A\\s*(<[?]xml\\s.*[?]>\\s*)?<" + content + "[\\s>]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
}

private IProject createJavaProjectWithVariantNature(String projectName) {
final VariantSyncProgressMonitor progressMonitor = new VariantSyncProgressMonitor("Create Project " + projectName);
final VariantSyncProgressMonitor progressMonitor = new VariantSyncProgressMonitor(String.format("Create Project %s", projectName));
// create project
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IProject project = root.getProject(projectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean isEmpty() {

@Override
public String toString() {
return "APatch [deltas=" + deltas + "]";
return String.format("APatch [deltas= %s ]", deltas);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public IDeltaFactory getExtension(String id) throws NoSuchExtensionException {
return extension;
}
}
StringBuilder errorMsg = new StringBuilder("No extension found for ID ").append(id);
throw new NoSuchExtensionException(errorMsg.toString());
final String errorMsg = String.format("No extension found for ID %s", id);
throw new NoSuchExtensionException(errorMsg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,29 @@ public DefaultDelta(IFile res, long timestamp, String factoryId) {

@Override
public String getOriginalAsString() {
String ret = String.valueOf(original.getPosition());
ret = ret + ":;:";
StringBuilder ret = new StringBuilder(String.valueOf(original.getPosition()));
ret.append(":;:");

for (final String line : original.getLines()) {
ret = ret + line + "#:#";
ret.append(line);
ret.append("#:#");
}
ret = ret.substring(0, ret.lastIndexOf("#:#"));
ret = ret + ":;:";
ret = new StringBuilder(ret.substring(0, ret.lastIndexOf("#:#")));
ret.append(":;:");

for (final String bLine : original.getBefore()) {
ret = ret + bLine + "#:#";
ret.append(bLine);
ret.append("#:#");
}
ret = ret.substring(0, ret.lastIndexOf("#:#"));
ret = ret + ":;:";
ret = new StringBuilder(ret.substring(0, ret.lastIndexOf("#:#")));
ret.append(":;:");

for (final String aLine : original.getAfter()) {
ret = ret + aLine + "#:#";
ret.append(aLine);
ret.append("#:#");
}
ret = ret.substring(0, ret.lastIndexOf("#:#"));

return ret;
return ret.substring(0, ret.lastIndexOf("#:#"));
}

@Override
Expand All @@ -58,33 +60,36 @@ public void setOriginalFromString(String original) {

@Override
public String getRevisedAsString() {
String ret = String.valueOf(revised.getPosition());
ret = ret + ":;:";
StringBuilder ret = new StringBuilder(String.valueOf(revised.getPosition()));
ret.append(":;:");

for (final String line : revised.getLines()) {
ret = ret + line + "#:#";
ret.append(line);
ret.append("#:#");
}
if (!revised.getLines().isEmpty()) {
ret = ret.substring(0, ret.lastIndexOf("#:#"));
ret = new StringBuilder(ret.substring(0, ret.lastIndexOf("#:#")));
}
ret = ret + ":;:";
ret.append(":;:");

for (final String bLine : revised.getBefore()) {
ret = ret + bLine + "#:#";
ret.append(bLine);
ret.append("#:#");
}
if (!revised.getBefore().isEmpty()) {
ret = ret.substring(0, ret.lastIndexOf("#:#"));
ret = new StringBuilder(ret.substring(0, ret.lastIndexOf("#:#")));
}
ret = ret + ":;:";
ret.append(":;:");

for (final String aLine : revised.getAfter()) {
ret = ret + aLine + "#:#";
ret.append(aLine);
ret.append("#:#");
}
if (!revised.getAfter().isEmpty()) {
ret = ret.substring(0, ret.lastIndexOf("#:#"));
ret = new StringBuilder(ret.substring(0, ret.lastIndexOf("#:#")));
}

return ret;
return ret.toString();
}

@Override
Expand All @@ -101,7 +106,7 @@ public void setRevisedFromString(String revised) {

@Override
public String getRepresentation() {
return "--- (" + original.getPosition() + ") " + original.getLines() + "\n" + "+++ (" + revised.getPosition() + ") " + revised.getLines();
return String.format("--- (%s) %s%n+++ (%s) %s", original.getPosition(), original.getLines(), revised.getPosition(), revised.getLines());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static IDeltaFactory<?> getInstance() {

@Override
public String toString() {
return "DefaultDeltaFactory [getId()=" + getId() + ", getName()=" + getName() + "]";
return String.format("DefaultDeltaFactory [getId()=%s, getName()=%s]", getId(), getName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public List<IVariantSyncMarker> getMarkersForDeltas(IFile file, List<IDelta<Chun
final List<IVariantSyncMarker> variantSyncMarkers = new ArrayList<>();
for (final IDelta<Chunk<String>> delta : deltas) {
final Chunk revised = delta.getRevised();
// For the display of markers, the utilities.MarkerUtils.setMarker-method uses Editor/Document-information provided by IDocument.
// IDocument is 0-based (so the first line is line 0 in IDocument), which means that every line number has to be reduced by 1
final IVariantSyncMarker variantSyncMarker = new AMarkerInformation(revised.getPosition() - 1, revised.getLines().size() - 1, true);
variantSyncMarker.setContext(delta.getContext());
variantSyncMarkers.add(variantSyncMarker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IFile applyDelta(IFile file, IPatch<?> patch) {
final IDeltaFactory<?> factory = DeltaFactoryManager.getFactoryById(delta.getFactoryId());
newFile = factory.applyDelta(newFile, delta);
} catch (final NoSuchExtensionException e) {
LogOperations.logError("Could not find extension with id: " + delta.getFactoryId(), e);
LogOperations.logError(String.format("Could not find extension with id: %s", delta.getFactoryId()), e);
}
}
return newFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MyDiffNode extends DiffNode {

@Override
public String toString() {
return "MyDiffNode [fDirty=" + fDirty + ", fLastId=" + fLastId + ", fLastName=" + fLastName + "]";
return String.format("MyDiffNode [fDirty=%s, fLastId=%s, fLastName=%s]", fDirty, fLastId, fLastName);
}

private boolean fDirty = false;
Expand Down Expand Up @@ -99,7 +99,7 @@ public String getName() {
fLastName = super.getName();
}
if (fDirty) {
return '<' + fLastName + '>';
return String.format("<%s>", fLastName);
}
return fLastName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Deprecated
public class DeltaCompareViewer extends Wizard {

public static final String ID = VariantSyncPlugin.PLUGIN_ID + ".views.synchronization.compare";
public static final String ID = String.format("%s.views.synchronization.compare", VariantSyncPlugin.PLUGIN_ID);
private final DeltaCompareViewerPage page;
private final IFile file;
private final IDelta<?> delta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public void createControl(Composite parent) {
}

public List<String> getSourceCode() {
return Arrays.asList(sourceViewer.getDocument().get().split("\n"));
return Arrays.asList(sourceViewer.getDocument().get().split(String.format("%n")));
}

private String getStringFromList(List<String> entries) {
String str = "";
for (final String el : entries) {
str += el + "\n";
str += String.format("%s%n", el);
}
return str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static long addMarker(IResource res, int posStart, int posEnd, FeatureCo
IMarker marker = null;
if (res.exists()) {
marker = res.createMarker(getMarker(featureContext.highlighter));
marker.setAttribute(IMarker.MESSAGE, "Feature: " + featureContext.name);
marker.setAttribute(IMarker.MESSAGE, String.format("Feature: %s", featureContext.name));
marker.setAttribute(IMarker.CHAR_START, posStart);
marker.setAttribute(IMarker.CHAR_END, posEnd);
return marker.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class PerspectiveFactory implements IPerspectiveFactory {

public static final String ID = VariantSyncPlugin.PLUGIN_ID + ".perspective";
public static final String ID = String.format("%s.perspective", VariantSyncPlugin.PLUGIN_ID);

@Override
public void createInitialLayout(IPageLayout layout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public String toString() {
if (root != null) {
int i = 0;
TreeNode currentNode = root;
String ret = root.toString() + "\n";
String ret = String.format("%s%n", root.toString());
while ((currentNode == null) && (i < currentNode.getNumberOfChildren())) {
currentNode = currentNode.getChildAt(i);
ret = ret + currentNode.toString() + "\n";
ret += String.format("%s%n", currentNode.toString());
i++;
}
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public Object getNewValue() {

@Override
public String toString() {
return "VariantSyncEvent [source=" + source + ", eventType=" + eventType + ", oldValue=" + oldValue + ", newValue=" + newValue + "]";
return String.format("VariantSyncEvent [source=%s, eventType=%s, oldValue=%s, newValue=%s]", source, eventType, oldValue, newValue);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
try {
MarkerUtils.cleanResource(currentFile);
} catch (final CoreException e) {
LogOperations.logError("Cannot clear all markers from: " + currentFile.getFullPath(), e);
LogOperations.logError(String.format("Cannot clear all markers from: %s", currentFile.getFullPath()), e);
}

final ConfigurationProject configurationProject = VariantSyncPlugin.getActiveConfigurationProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
public class FeatureContextManager extends Wizard {

public static final String ID = VariantSyncPlugin.PLUGIN_ID + ".views.featurecontexts.manage";
public static final String ID = String.format("%s.views.featurecontexts.manage", VariantSyncPlugin.PLUGIN_ID);

private final List<FeatureContext> expressions;

Expand Down
Loading

0 comments on commit fca14c2

Please sign in to comment.