branch develop updated (201ee14 -> 286c227)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository eugene. See https://gitlab.nuiton.org/nuiton/eugene.git from 201ee14 Remove old tag value and stereotypes api (See #4042) new 286c227 reintroduce old api for some extra cases but should improve this The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 286c227fb2ca02608ecaff69fc892ed350fd6509 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Oct 8 15:06:13 2016 +0200 reintroduce old api for some extra cases but should improve this Summary of changes: .../models/extension/tagvalue/TagValueUtil.java | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository eugene. See https://gitlab.nuiton.org/nuiton/eugene.git commit 286c227fb2ca02608ecaff69fc892ed350fd6509 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Oct 8 15:06:13 2016 +0200 reintroduce old api for some extra cases but should improve this --- .../models/extension/tagvalue/TagValueUtil.java | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/eugene/src/main/java/org/nuiton/eugene/models/extension/tagvalue/TagValueUtil.java b/eugene/src/main/java/org/nuiton/eugene/models/extension/tagvalue/TagValueUtil.java index ae45c99..6f09dbf 100644 --- a/eugene/src/main/java/org/nuiton/eugene/models/extension/tagvalue/TagValueUtil.java +++ b/eugene/src/main/java/org/nuiton/eugene/models/extension/tagvalue/TagValueUtil.java @@ -136,6 +136,46 @@ public class TagValueUtil { return tagName.getDefaultValue(); } + /** + * Seek for a tag value amoung elements given using these rules: + * <ul> + * <li>Look into {@code elements} and return the first not empty tag value found.</li> + * <li>If not found, Look into {@code elements} declaringElement (for each + * element that is a {@link ObjectModelElement} and return the first not empty tag + * value found.</li> + * <li>If not found return {@code defaultValue}</li> + * </ul> + * <strong>Note:</strong> Order of {@code elements} is important, better then to + * always starts from specialized to more general level (for example from attribute, + * to classifier or model). + * + * @param tagName tag name to find + * @param elements not null elements to test + * @return found tag value or {@code null} if not found + * @since 3.0 + */ + public static String findTagValue(String tagName,String defaultValue, WithTagValuesOrStereotypes... elements) { + String result = findDirectTagValue(tagName, elements); + + if (result != null) { + return result; + } + + for (WithTagValuesOrStereotypes element : elements) { + if (element instanceof ObjectModelElement) { + // try in declaring element + ObjectModelElement declaringElement = ((ObjectModelElement) element).getDeclaringElement(); + if (declaringElement != null) { + String value = findNotEmptyTagValue(tagName, declaringElement); + if (value != null) { + return value; + } + } + } + } + return defaultValue; + } + public static boolean findBooleanTagValue(TagValueMetadata tagName, WithTagValuesOrStereotypes... elements) { String value = findTagValue(tagName, elements); return value != null && "true".equalsIgnoreCase(value); @@ -189,6 +229,33 @@ public class TagValueUtil { return tagName.getDefaultValue(); } + /** + * Seek for a tag value amoung elements given using these rules: + * <ul> + * <li>Look into {@code elements} and return the first not empty tag value found.</li> + * <li>If not found return {@code defaultValue}</li> + * </ul> + * <strong>Note:</strong> Order of {@code elements} is important, better then to + * always starts from specialized to more general level (for example from attribute, + * to classifier or model). + * + * @param tagName tag name to find + * @param elements not null elements to test + * @return found tag value or {@code null} if not found + * @since 3.0 + */ + public static String findDirectTagValue(String tagName, WithTagValuesOrStereotypes... elements) { + + for (WithTagValuesOrStereotypes element : elements) { + String value = findNotEmptyTagValue(tagName, element); + if (value != null) { + return value; + } + } + + return null; + } + public static String findNotEmptyTagValue(TagValueMetadata tagName, WithTagValuesOrStereotypes element) { String value = null; @@ -206,6 +273,24 @@ public class TagValueUtil { } + public static String findNotEmptyTagValue(String tagName, WithTagValuesOrStereotypes element) { + + String value = null; + if (element != null) { + if (element instanceof ObjectModelPackage) { + value = findNotEmptyTagValue(tagName, (ObjectModelPackage) element); + } else { + value = element.getTagValue(tagName); + if (StringUtils.isEmpty(value)) { + value = null; + } + } + } + return value; + + } + + protected static String findNotEmptyTagValue(TagValueMetadata tagName, ObjectModelPackage element) { String value = element.getTagValue(tagName.getName()); @@ -219,6 +304,19 @@ public class TagValueUtil { } + protected static String findNotEmptyTagValue(String tagName, ObjectModelPackage element) { + + String value = element.getTagValue(tagName); + if (StringUtils.isEmpty(value)) { + value = null; + } + if (value == null && element.getParentPackage() != null) { + value = findNotEmptyTagValue(tagName, element.getParentPackage()); + } + return value; + + } + public static Matcher getStereotypeMatcher(String key) throws InvalidStereotypeSyntaxException { Matcher matcher = STEREOTYPE_PATTERN.matcher(key); if (!matcher.find()) { -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm