Skip to content

Commit

Permalink
Merge pull request #32 from ChristopheCVB/feat/connector
Browse files Browse the repository at this point in the history
feat: Action Data with stateId do not create Data constant
  • Loading branch information
ChristopheCVB authored Jul 24, 2021
2 parents f96d2c1 + 45f564e commit b1b0248
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ private Pair<JsonObject, TypeSpec.Builder> processAction(RoundEnvironment roundE
if (actionElement.equals(enclosingElement)) {
Pair<JsonObject, TypeSpec.Builder> actionDataResult = this.processActionData(roundEnv, pluginElement, plugin, categoryElement, category, actionElement, action, jsonAction, dataElement);
jsonActionData.add(actionDataResult.first);
actionTypeSpecBuilder.addType(actionDataResult.second.build());
if (actionDataResult.second != null) {
actionTypeSpecBuilder.addType(actionDataResult.second.build());
}
}
}
if (jsonActionData.size() > 0) {
Expand Down Expand Up @@ -420,7 +422,9 @@ private Pair<JsonObject, TypeSpec.Builder> processConnector(RoundEnvironment rou
if (connectorElement.equals(enclosingElement)) {
Pair<JsonObject, TypeSpec.Builder> connectorDataResult = this.processConnectorData(roundEnv, pluginElement, plugin, categoryElement, category, connectorElement, connector, jsonConnector, dataElement);
jsonConnectorData.add(connectorDataResult.first);
connectorTypeSpecBuilder.addType(connectorDataResult.second.build());
if (connectorDataResult.second != null) {
connectorTypeSpecBuilder.addType(connectorDataResult.second.build());
}
}
}
if (jsonConnectorData.size() > 0) {
Expand Down Expand Up @@ -580,6 +584,8 @@ private Pair<JsonObject, TypeSpec.Builder> processActionData(RoundEnvironment ro
return shortStateId.equals(data.stateId());
}).findFirst();
if (optionalStateElement.isPresent()) {
actionDataTypeSpecBuilder = null;

Element stateElement = optionalStateElement.get();
State state = stateElement.getAnnotation(State.class);
dataId.set(StateHelper.getStateId(pluginElement, categoryElement, category, stateElement, state));
Expand Down Expand Up @@ -678,7 +684,7 @@ private Pair<JsonObject, TypeSpec.Builder> processConnectorData(RoundEnvironment
this.messager.printMessage(Diagnostic.Kind.NOTE, "Process Connector Data: " + dataElement.getSimpleName());
Data data = dataElement.getAnnotation(Data.class);

TypeSpec.Builder actionDataTypeSpecBuilder = this.createConnectorDataTypeSpecBuilder(pluginElement, categoryElement, category, connectorElement, connector, dataElement, data);
TypeSpec.Builder connectorDataTypeSpecBuilder = this.createConnectorDataTypeSpecBuilder(pluginElement, categoryElement, category, connectorElement, connector, dataElement, data);

Element method = dataElement.getEnclosingElement();
String className = method.getEnclosingElement().getSimpleName() + "." + method.getSimpleName() + "(" + dataElement.getSimpleName() + ")";
Expand Down Expand Up @@ -718,6 +724,8 @@ private Pair<JsonObject, TypeSpec.Builder> processConnectorData(RoundEnvironment
return shortStateId.equals(data.stateId());
}).findFirst();
if (optionalStateElement.isPresent()) {
connectorDataTypeSpecBuilder = null;

Element stateElement = optionalStateElement.get();
State state = stateElement.getAnnotation(State.class);
dataId.set(StateHelper.getStateId(pluginElement, categoryElement, category, stateElement, state));
Expand Down Expand Up @@ -791,11 +799,11 @@ private Pair<JsonObject, TypeSpec.Builder> processConnectorData(RoundEnvironment
jsonData.addProperty(DataHelper.ID, dataId.get());
if (!connector.format().isEmpty()) {
// Replace wildcards
String rawFormat = jsonConnector.get(ActionHelper.FORMAT).getAsString();
jsonConnector.addProperty(ActionHelper.FORMAT, rawFormat.replace("{$" + (data.id().isEmpty() ? dataElement.getSimpleName().toString() : data.id()) + "$}", "{$" + dataId.get() + "$}"));
String rawFormat = jsonConnector.get(ConnectorHelper.FORMAT).getAsString();
jsonConnector.addProperty(ConnectorHelper.FORMAT, rawFormat.replace("{$" + (data.id().isEmpty() ? dataElement.getSimpleName().toString() : data.id()) + "$}", "{$" + dataId.get() + "$}"));
}

return Pair.create(jsonData, actionDataTypeSpecBuilder);
return Pair.create(jsonData, connectorDataTypeSpecBuilder);
}

/**
Expand Down

0 comments on commit b1b0248

Please sign in to comment.