فهرست منبع

Refactoring to not break existing APIs but make them deprecated instead.

Thomas Kutz 9 سال پیش
والد
کامیت
92232b6d17

+ 31 - 13
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/ArtifactLocationProvider.java

@@ -31,6 +31,8 @@ public class ArtifactLocationProvider {
 		}
 	}
 	
+	public ArtifactLocationProvider() {}
+	
 	public ArtifactLocationProvider(ISCTFileSystemAccess sctFsa) {
 		this.sctFsa = sctFsa;
 	}
@@ -41,29 +43,45 @@ public class ArtifactLocationProvider {
 		generationArtifacts.add(new Artifact(artifactName, outputConfigName));
 	}
 
-	protected URI getURIForArtifcat(String artifactName) {
+	protected URI getURI(String artifactName) {
 		for (Artifact artifact : generationArtifacts) {
 			if (artifact.getName().equals(artifactName)) {
-				return sctFsa.getURI(artifact.getName(), artifact.getOutputName());
+				return getURI(artifact);
 			}
 		}
 		return null;
 	}
+
+	protected URI getURI(Artifact artifact) {
+		if (sctFsa != null) {
+			return sctFsa.getURI(artifact.getName(), artifact.getOutputName());
+		}
+		return null;
+	}
 	
-	public String computeRelativeForPath(String absolutePath, String baseArtifactName) {
-		URI baseTarget = getURIForArtifcat(baseArtifactName);
+	public String getRelativePath(String target, String baseArtifactName) {
+		URI baseUri = getURI(baseArtifactName);
+		if (baseUri == null) {
+			// throw new IllegalArgumentException("Artifact location for "+baseArtifactName+" not configured");
+			return target;
+		}
 		
-		IPath basePath = new Path(baseTarget.toFileString());
-		IPath absPath = new Path(absolutePath);
-		return absPath.makeRelativeTo(basePath).toOSString();
+		Path targetPath = new Path(target);
+		if (targetPath.isAbsolute()) {
+			return relativePath(target, baseUri.toFileString());
+		}
+		
+		URI absUri = getURI(target);
+		if (absUri != null) {
+			return relativePath(absUri.toFileString(), baseUri.toFileString());
+		}
+		// throw new IllegalArgumentException("Artifact location for "+target+" not configured");
+		return target;
 	}
 	
-	public String computeRelativeForName(String referencedArtifactName, String baseArtifactName) {
-		URI baseUri = getURIForArtifcat(baseArtifactName);
-		URI absUri = getURIForArtifcat(referencedArtifactName);
-		
-		IPath basePath = new Path(baseUri.toFileString());
-		IPath absPath = new Path(absUri.toFileString());
+	protected String relativePath(String absolute, String base) {
+		IPath basePath = new Path(base);
+		IPath absPath = new Path(absolute);
 		return absPath.makeRelativeTo(basePath).toOSString();
 	}
 }

+ 1 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CCodeGenerator.java

@@ -50,7 +50,7 @@ public class CCodeGenerator extends GenericJavaBasedGenerator {
 		if (debugFeatureHelper.isDumpSexec(entry)) {
 			dumpSexec(entry, flow);
 		}
-		delegate.generate(flow, entry, sctFsa);
+		delegate.generate(flow, entry, sctFsa.getIFileSystemAccess(), new ArtifactLocationProvider(sctFsa));
 	}
 
 	@Override

+ 17 - 19
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CGenerator.xtend

@@ -16,7 +16,6 @@ import org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator
 import org.yakindu.sct.model.sexec.ExecutionFlow
 import org.yakindu.sct.model.sgen.GeneratorEntry
 import org.yakindu.sct.model.sgraph.Statechart
-import org.yakindu.sct.generator.core.filesystem.ISCTFileSystemAccess
 
 /**
  * This is the C code generators main class. 
@@ -31,35 +30,34 @@ class CGenerator implements IExecutionFlowGenerator {
 	@Inject extension StatemachineRequiredHeader
 	@Inject extension Navigation
 	@Inject extension GenmodelEntries
-	
 	@Inject extension Naming
 	
+	/**
+	 * @Deprecated use {@link #generate(ExecutionFlow, GeneratorEntry, IFileSystemAccess, ArtifactLocationProvider)} instead
+	 */
+	@Deprecated
 	override generate(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-//		flow.generateTypesH(flow.sourceElement as Statechart, fsa, entry)
-//		flow.generateStatemachineHeader(flow.sourceElement as Statechart, fsa, entry)
-//		if (flow.timed || !flow.operations.empty || entry.tracingEnterState || entry.tracingExitState) {
-//			flow.generateStatemachineRequiredHeader(flow.sourceElement as Statechart, fsa, entry)
-//		}
-//		flow.generateStatemachineSource(flow.sourceElement as Statechart, fsa, entry)
+		generate(flow, entry, fsa, new ArtifactLocationProvider())
+	}
+	
+	def generate(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa, ArtifactLocationProvider locations) {
+		initArtifactLocations(flow, entry, locations)
+		
+		flow.generateTypesH(flow.sourceElement as Statechart, fsa, entry)
+		flow.generateStatemachineHeader(flow.sourceElement as Statechart, fsa, entry, locations)
+		if (flow.timed || !flow.operations.empty || entry.tracingEnterState || entry.tracingExitState) {
+			flow.generateStatemachineRequiredHeader(flow.sourceElement as Statechart, fsa, entry)
+		}
+		flow.generateStatemachineSource(flow.sourceElement as Statechart, fsa, entry)
 	}
 	
-	def generate(ExecutionFlow flow, GeneratorEntry entry, ISCTFileSystemAccess sctFsa) {
-		// initialize generation artifacts and their locations
-		val locations = new ArtifactLocationProvider(sctFsa)
+	def protected initArtifactLocations(ExecutionFlow flow, GeneratorEntry entry, ArtifactLocationProvider locations) {
 		locations.addArtifact(flow.typesModule.h, IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT)
 		locations.addArtifact(flow.module.h, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT)
 		locations.addArtifact(flow.module.c, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT)
 		if (flow.timed || !flow.operations.empty || entry.tracingEnterState || entry.tracingExitState) {
 			locations.addArtifact(flow.module.client.h, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT)
 		}
-
-		// perform generation
-		flow.generateTypesH(flow.sourceElement as Statechart, sctFsa.IFileSystemAccess, entry)
-		flow.generateStatemachineHeader(flow.sourceElement as Statechart, sctFsa.IFileSystemAccess, entry, locations)
-		if (flow.timed || !flow.operations.empty || entry.tracingEnterState || entry.tracingExitState) {
-			flow.generateStatemachineRequiredHeader(flow.sourceElement as Statechart, sctFsa.IFileSystemAccess, entry)
-		}
-		flow.generateStatemachineSource(flow.sourceElement as Statechart, sctFsa.IFileSystemAccess, entry)
 	}
 	
 }

+ 25 - 2
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineHeader.xtend

@@ -36,12 +36,27 @@ class StatemachineHeader {
 	@Inject extension ICodegenTypeSystemAccess
 	@Inject extension GenmodelEntries
 	@Inject extension INamingService
-
+	
+	/**
+	 * @Deprecated use {@link #generateStatemachineHeader(ExecutionFlow, Statechart, IFileSystemAccess, GeneratorEntry, ArtifactLocationProvider)} instead
+	 */
+	@Deprecated
+	def generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
+		generateStatemachineHeader(flow, sc, fsa, entry, new ArtifactLocationProvider())
+	}
 	
 	def generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry, ArtifactLocationProvider locations) {
 		flow.initializeNamingService
 		fsa.generateFile(flow.module.h, flow.generateStatemachineHeaderContents(entry, locations))
 	}
+	
+	/**
+	 * @Deprecated use {@link #generateStatemachineHeaderContents(ExecutionFlow, GeneratorEntry, ArtifactLocationProvider)} instead
+	 */
+	@Deprecated
+	def generateStatemachineHeaderContents(ExecutionFlow it, GeneratorEntry entry) {
+		generateStatemachineHeaderContents(it, entry, new ArtifactLocationProvider())
+	}
 
 	def generateStatemachineHeaderContents(ExecutionFlow it, GeneratorEntry entry, ArtifactLocationProvider locations) '''
 		«entry.licenseText»
@@ -110,8 +125,16 @@ class StatemachineHeader {
 		#endif /* «module.define»_H_ */
 	'''
 
+	/**
+	 * @Deprecated use {@link #includes(ExecutionFlow, ArtifactLocationProvider)} instead
+	 */
+	@Deprecated
+	def includes(ExecutionFlow it) {
+		includes(it, new ArtifactLocationProvider())
+	}
+
 	def includes(ExecutionFlow it, ArtifactLocationProvider locations) '''
-		#include "«locations.computeRelativeForName(typesModule.h, module.h)»"
+		#include "«locations.getRelativePath(typesModule.h, module.h)»"
 	'''
 	
 	def statesEnumDecl(ExecutionFlow it) '''