Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ctf.core: Support field class alias in CTF2 Metadata
Allow field-class-alias fragments in root metadata node. Add new class FieldClass to be used instead of JsonObject. Create and register a FieldClassDeserializer that will accept a JSON Object as a field class or a JSON String as a field class alias and lookup a previously occurring field class alias with that name. Support a string as a field class alias in TypeAliasParser and lookup a previously occurring field class alias with that name in the Metadata root. [Added] Support field class alias in CTF2 Metadata Change-Id: I7a7cf52a1ce36ba726ba2ab568ed6e9b9cfc4803 Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/204823 Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
- Loading branch information
1 parent
01c87e9
commit 32f3220
Showing
5 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...ss.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/FieldClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Ericsson | ||
* | ||
* All rights reserved. This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 which | ||
* accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Tasse - Initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tracecompass.internal.ctf.core.event.metadata; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import org.eclipse.tracecompass.internal.ctf.core.event.types.ICTFMetadataNode; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.JsonPrimitive; | ||
|
||
/** | ||
* Class that stores a field class property, which can be a JSON object or a | ||
* string referring to a field class alias. | ||
*/ | ||
public class FieldClass { | ||
|
||
private final JsonObject fFieldClass; | ||
|
||
/** | ||
* Field class deserializer | ||
*/ | ||
public static class FieldClassDeserializer implements JsonDeserializer<FieldClass> { | ||
private final ICTFMetadataNode fRoot; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param root | ||
* the CTF metadata root node | ||
*/ | ||
public FieldClassDeserializer(ICTFMetadataNode root) { | ||
fRoot = root; | ||
} | ||
|
||
@Override | ||
public FieldClass deserialize(JsonElement jElement, Type typeOfT, JsonDeserializationContext context) | ||
throws JsonParseException { | ||
if (jElement.isJsonPrimitive()) { | ||
JsonPrimitive jPrimitive = jElement.getAsJsonPrimitive(); | ||
if (jPrimitive.isString()) { | ||
String fieldClassAlias = jPrimitive.getAsString(); | ||
for (ICTFMetadataNode node : fRoot.getChildren()) { | ||
if (node instanceof JsonFieldClassAliasMetadataNode) { | ||
JsonFieldClassAliasMetadataNode fieldClassAliasNode = (JsonFieldClassAliasMetadataNode) node; | ||
if (fieldClassAliasNode.getName().equals(fieldClassAlias)) { | ||
return new FieldClass(fieldClassAliasNode.getFieldClass()); | ||
} | ||
} | ||
} | ||
throw new JsonParseException("no previously occurring field class alias named '" + fieldClassAlias + '\''); //$NON-NLS-1$ | ||
} | ||
} else if (jElement.isJsonObject()) { | ||
JsonObject jObject = jElement.getAsJsonObject(); | ||
return new FieldClass(jObject); | ||
} | ||
throw new JsonParseException("field-class property is not a JSON object or JSON string"); //$NON-NLS-1$ | ||
} | ||
} | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param fieldClass | ||
* the field class JSON object | ||
*/ | ||
public FieldClass(JsonObject fieldClass) { | ||
fFieldClass = fieldClass; | ||
} | ||
|
||
/** | ||
* Get the field class as a JSON object | ||
* | ||
* @return the field class | ||
*/ | ||
public JsonObject getFieldClass() { | ||
return fFieldClass; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters