Skip to content

Commit

Permalink
Improvements to the auto-generator code
Browse files Browse the repository at this point in the history
  • Loading branch information
CesarCoelho committed Oct 4, 2024
1 parent 11efa40 commit a3b2cfd
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private SvgBaseWriter getSvgOutputFile(ServiceSummary service, Integer number,

if (splitOutSvg) {
try {
String filename = mainSvgFile.getClassName() + "_" + service.getService().getNumber() + "_" + number + "_" + name + "_" + phase;
String filename = mainSvgFile.getClassName() + "_" + service.getServiceNumber() + "_" + number + "_" + name + "_" + phase;
rv = new SvgWriter(mainSvgFile.getFolder(), filename, "svg", false);
mainSvgFile.addComment(filename, true);
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,10 @@ protected TypeReference getCompositeElementSuperType(TypeReference type) {
* @return the operation summary.
*/
protected ServiceSummary createOperationElementList(ServiceType service) {
boolean isComService = StdStrings.COM.equalsIgnoreCase(service.getName());
List<OperationSummary> operations = new LinkedList<>();

// only load operations if this is not the COM service
if (!isComService) {
if (!StdStrings.COM.equalsIgnoreCase(service.getName())) {
for (CapabilitySetType capabilitySet : service.getCapabilitySet()) {
for (OperationType op : capabilitySet.getSendIPOrSubmitIPOrRequestIP()) {
operations.add(extractOperationSummary(op, capabilitySet.getNumber()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static File createFolder(File parentFolder, String name) throws FileNotFo
* @return the converted string.
*/
public static String preCap(String str) {
if ((null != str) && (0 < str.length())) {
if ((str != null) && (str.length() > 0)) {
str = String.valueOf(str.charAt(0)).toUpperCase() + str.substring(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ public ServiceSummary(ServiceType service, List<OperationSummary> operations) {
*
* @return the service.
*/
@Deprecated
public ServiceType getService() {
return service;
}

/**
* Returns the service number.
*
* @return the service number.
*/
public int getServiceNumber() {
return service.getNumber();
}

/**
* Returns the operations of the service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,58 +396,16 @@ public String createAreaHelperClassInitialValue(String areaVar, short areaVersio
+ areaVar + "_AREA_VERSION, " + areaVar + "_AREA_ELEMENTS, " + areaVar + "_AREA_SERVICES)";
}

@Override
protected String getIntCallMethod() {
return "intValue";
}

@Override
protected String getOctetCallMethod() {
return "byteValue";
}

@Override
public String getRegisterMethodName() {
return "register";
}

@Override
public String getDeregisterMethodName() {
return "deregister";
}

@Override
public String getNullValue() {
return "null";
}

@Override
protected void addVectorAddStatement(LanguageWriter file, MethodWriter method,
String variable, String parameter) throws IOException {
method.addLine(variable + ".addElement(" + parameter + ")");
}

@Override
protected void addVectorRemoveStatement(LanguageWriter file, MethodWriter method,
String variable, String parameter) throws IOException {
method.addLine(variable + ".removeElement(" + parameter + ")");
}

@Override
protected String createStaticClassReference(String type) {
return type + ".class";
}

@Override
public String addressOf(String type) {
return type;
}

@Override
protected String createArraySize(boolean isActual, String type, String variable) {
return variable + ".length";
}

@Override
protected String malStringAsElement(LanguageWriter file) {
return createElementType(StdStrings.MAL, null, StdStrings.UNION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,18 +496,10 @@ protected void createServiceProviderClasses(File serviceFolder, AreaType area, S
createServiceProviderFolderComment(providerFolder, area, service);
createServiceProviderHandler(providerFolder, area, service, summary);
createServiceProviderSkeleton(providerFolder, area, service, summary, requiredPublishers);
//createServiceProviderDelegation(providerFolder, area, service, summary);
createServiceProviderInheritance(providerFolder, area, service, summary);
createServiceProviderInteractions(providerFolder, area, service, summary);
}

@Deprecated
private void createServiceProviderDelegation(File providerFolder, AreaType area,
ServiceType service, ServiceSummary summary) throws IOException {
logger.info(" > Creating provider delegate class: " + service.getName());
createServiceProviderSkeletonHandler(providerFolder, area, service, summary, true);
}

protected void createServiceProviderInheritance(File providerFolder, AreaType area,
ServiceType service, ServiceSummary summary) throws IOException {
logger.info(" > Creating provider inheritance class: " + service.getName());
Expand Down Expand Up @@ -1868,7 +1860,7 @@ public String checkForReservedWords(String arg) {
return (replacementWord != null) ? replacementWord : arg;
}

public String createConsumerPatternCall(OperationSummary op) {
public static String createConsumerPatternCall(OperationSummary op) {
switch (op.getPattern()) {
case SEND_OP:
return "send";
Expand Down Expand Up @@ -1930,7 +1922,7 @@ public List<CompositeField> createOperationArguments(GeneratorConfiguration conf
return new LinkedList<>();
}

List<CompositeField> rv = new LinkedList<>();
List<CompositeField> outputArgs = new LinkedList<>();

for (int i = 0; i < opArgs.size(); i++) {
TypeInfo ti = opArgs.get(i);
Expand All @@ -1956,10 +1948,10 @@ public List<CompositeField> createOperationArguments(GeneratorConfiguration conf
CompositeField argType = createCompositeElementsDetails(file, true,
argName, tir, true, true, cmt);

rv.add(argType);
outputArgs.add(argType);
}

return rv;
return outputArgs;
}

public String createOperationArgReturn(LanguageWriter file, MethodWriter method,
Expand Down Expand Up @@ -2002,7 +1994,12 @@ protected CompositeField createReturnType(LanguageWriter file, AreaType area,
}

String shortName = StubUtils.preCap(opName) + messageType;
String rt = getConfig().getAreaPackage(area.getName()) + area.getName().toLowerCase() + "." + service.getName().toLowerCase() + "." + getConfig().getBodyFolder() + "." + shortName;
String rt = getConfig().getAreaPackage(area.getName())
+ area.getName().toLowerCase() + "."
+ service.getName().toLowerCase() + "."
+ getConfig().getBodyFolder() + "."
+ shortName;

if (!multiReturnTypeMap.containsKey(rt)) {
multiReturnTypeMap.put(rt, new MultiReturnType(rt, area, service, shortName, returnTypes));
}
Expand Down Expand Up @@ -2113,28 +2110,12 @@ protected void createStructureFactoryFolderComment(File structureFolder, AreaTyp

protected abstract void createRequiredPublisher(String destinationFolderName, String fqPublisherName, RequiredPublisher op) throws IOException;

protected abstract void addVectorAddStatement(LanguageWriter file, MethodWriter method, String variable, String parameter) throws IOException;

protected abstract void addVectorRemoveStatement(LanguageWriter file, MethodWriter method, String variable, String parameter) throws IOException;

protected abstract String createStaticClassReference(String type);

public abstract String addressOf(String object);

protected abstract String createArraySize(boolean isActual, String type, String variable);

protected abstract String malStringAsElement(LanguageWriter file);

protected abstract String errorCodeAsReference(LanguageWriter file, String ref);

protected abstract String getIntCallMethod();

protected abstract String getOctetCallMethod();

public abstract String getRegisterMethodName();

public abstract String getDeregisterMethodName();

public abstract String getNullValue();

public abstract ClassWriter createClassFile(File folder, String className) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public void createServiceConsumerStub(File consumerFolder, AreaType area,
false, true, null, op.getName() + "Register",
StubUtils.concatenateArguments(subStr, serviceAdapterArg), throwsInteractionAndMALException, "Register method for the " + op.getName() + " PubSub interaction", null,
Arrays.asList(throwsInteractionException + " if there is a problem during the interaction as defined by the MAL specification.", throwsMALException + " if there is an implementation exception"));
method.addMethodWithDependencyStatement(consumerMethodCall + generator.getRegisterMethodName() + "(" + operationInstanceVar + ", subscription, adapter)", helperType, true);
method.addMethodWithDependencyStatement(consumerMethodCall + "register(" + operationInstanceVar + ", subscription, adapter)", helperType, true);
method.addMethodCloseStatement();

if (supportsAsync) {
Expand All @@ -628,7 +628,7 @@ public void createServiceConsumerStub(File consumerFolder, AreaType area,
StubUtils.concatenateArguments(subStr, serviceAdapterArg), throwsInteractionAndMALException,
"Asynchronous version of method " + op.getName() + "Register", "the MAL message sent to initiate the interaction",
Arrays.asList(throwsInteractionException + " if there is a problem during the interaction as defined by the MAL specification.", throwsMALException + " if there is an implementation exception"));
method.addLine("return " + consumerMethodCall + "async" + StubUtils.preCap(generator.getRegisterMethodName()) + "(" + operationInstanceVar + ", subscription, adapter)");
method.addLine("return " + consumerMethodCall + "asyncRegister(" + operationInstanceVar + ", subscription, adapter)");
method.addMethodCloseStatement();
}

Expand All @@ -637,7 +637,7 @@ public void createServiceConsumerStub(File consumerFolder, AreaType area,
Arrays.asList(idStr), throwsInteractionAndMALException,
"Deregister method for the " + op.getName() + " PubSub interaction", null,
Arrays.asList(throwsInteractionException + " if there is a problem during the interaction as defined by the MAL specification.", throwsMALException + " if there is an implementation exception"));
method.addLine(consumerMethodCall + generator.getDeregisterMethodName() + "(" + operationInstanceVar + ", identifierList)");
method.addLine(consumerMethodCall + "deregister(" + operationInstanceVar + ", identifierList)");
method.addMethodCloseStatement();

if (supportsAsync) {
Expand All @@ -647,7 +647,7 @@ public void createServiceConsumerStub(File consumerFolder, AreaType area,
throwsInteractionAndMALException, "Asynchronous version of method " + op.getName() + "Deregister",
"the MAL message sent to initiate the interaction",
Arrays.asList(throwsInteractionException + " if there is a problem during the interaction as defined by the MAL specification.", throwsMALException + " if there is an implementation exception"));
method.addLine("return " + consumerMethodCall + "async" + StubUtils.preCap(generator.getDeregisterMethodName()) + "(" + operationInstanceVar + ", identifierList, adapter)");
method.addLine("return " + consumerMethodCall + "asyncDeregister(" + operationInstanceVar + ", identifierList, adapter)");
method.addMethodCloseStatement();
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public JavaHelpers(GeneratorLangs generator) {
this.generator = generator;
}

public void createServiceHelperClass(File serviceFolder, AreaType area, ServiceType service, ServiceSummary summary) throws IOException {
public void createServiceHelperClass(File serviceFolder, AreaType area,
ServiceType service, ServiceSummary summary) throws IOException {
ClassWriter file = generator.createClassFile(serviceFolder, service.getName() + "Helper");

String serviceName = service.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import esa.mo.xsd.ExtendedServiceType;
import esa.mo.xsd.ModelObjectType;
import esa.mo.xsd.NamedElementReferenceWithCommentType;
import esa.mo.xsd.PubSubOperationType;
import esa.mo.xsd.ServiceType;
import esa.mo.xsd.SupportedFeatures;
import esa.mo.xsd.TypeReference;
Expand Down Expand Up @@ -185,7 +184,7 @@ public void createServiceInfoClass(File serviceFolder, AreaType area,
if (oType instanceof EnumerationType) {
text = clsName + ".fromOrdinal(0)";
}
*/
*/

String lclsName = generator.createElementType(area.getName(), service.getName(), typeName + "List");
elementInstantiations.add(text);
Expand Down

0 comments on commit a3b2cfd

Please sign in to comment.