public JsDoc.Tag getAnnotation(String anAnnotation) { Optional<JsDoc.Tag> found = moduleAnnotations.stream().filter((JsDoc.Tag aTag) -> { return aTag.getName().equalsIgnoreCase(anAnnotation); }).findAny(); return found.isPresent() ? found.get() : null; }
public boolean hasAnnotation(String anAnnotation) { return moduleAnnotations.stream().anyMatch((JsDoc.Tag aTag) -> { return aTag.getName().equalsIgnoreCase(anAnnotation); }); }
@Override public void moduleScanned(String aModuleName, ScriptDocument.ModuleDocument aModuleDoc, File file) { try { List<JsDoc.Tag> annotations = aModuleDoc.getAnnotations(); if (annotations != null) { annotations.stream().forEach((JsDoc.Tag tag) -> { if (JsDoc.Tag.VALIDATOR_TAG.equalsIgnoreCase(tag.getName())) { validators.put(aModuleName, tag.getParams()); Logger.getLogger(ValidatorsScanner.class.getName()).log(Level.INFO, "Validator \"{0}\" on datasources {1} has been registered", new Object[]{aModuleName, tag.getParams().toString()}); } }); } } catch (Exception ex) { Logger.getLogger(ValidatorsScanner.class.getName()).log(Level.SEVERE, null, ex); } }
jsDoc.parseAnnotations(); for (JsDoc.Tag tag : jsDoc.getAnnotations()) { switch (tag.getName().toLowerCase()) { case JsDoc.Tag.ROLES_ALLOWED_TAG: aQuery.getReadRoles().addAll(tag.getParams());
if (annotations != null) { annotations.stream().forEach((JsDoc.Tag tag) -> { if (JsDoc.Tag.ACCEPTOR_TAG.equalsIgnoreCase(tag.getName()) || JsDoc.Tag.ACCEPTED_PROTOCOL_TAG.equalsIgnoreCase(tag.getName())) { if (tag.getParams() == null || tag.getParams().isEmpty()) { if (acceptors.containsKey(null)) { return JsDoc.Tag.RESIDENT_TAG.equalsIgnoreCase(tag.getName()); })) { residents.add(aModuleName); if (JsDoc.Tag.VALIDATOR_TAG.equalsIgnoreCase(tag.getName())) { validators.put(aModuleName, tag.getParams()); Logger.getLogger(ServerTasksScanner.class.getName()).log(Level.INFO, "Validator \"{0}\" on datasources {1} has been registered", new Object[]{aModuleName, tag.getParams().toString()});
Set<JsDoc.Tag> tags = tagsEntry.getValue(); tags.stream().forEach((JsDoc.Tag aTag) -> { if (GET_ANNOTATION.equalsIgnoreCase(aTag.getName())) { extractUri(rpcPoint, aTag, (String aUri) -> { gets.put(aUri, rpcPoint); }); if (PUT_ANNOTATION.equalsIgnoreCase(aTag.getName())) { extractUri(rpcPoint, aTag, (String aUri) -> { puts.put(aUri, rpcPoint); }); if (POST_ANNOTATION.equalsIgnoreCase(aTag.getName())) { extractUri(rpcPoint, aTag, (String aUri) -> { posts.put(aUri, rpcPoint); }); if (DELETE_ANNOTATION.equalsIgnoreCase(aTag.getName())) { extractUri(rpcPoint, aTag, (String aUri) -> { deletes.put(aUri, rpcPoint);
private void readPropertyRoles(String aPropertyName, String aJsDocBody) { if (aJsDocBody != null) { JsDoc jsDoc = new JsDoc(aJsDocBody); jsDoc.parseAnnotations(); jsDoc.getAnnotations().stream().forEach((JsDoc.Tag tag) -> { Set<JsDoc.Tag> tags = propertyAnnotations.get(aPropertyName); if (tags == null) { tags = new HashSet<>(); propertyAnnotations.put(aPropertyName, tags); } tags.add(tag); if (tag.getName().equalsIgnoreCase(JsDoc.Tag.ROLES_ALLOWED_TAG)) { Set<String> roles = propertyAllowedRoles.get(aPropertyName); if (roles == null) { roles = new HashSet<>(); } for (String role : tag.getParams()) { roles.add(role); } propertyAllowedRoles.put(aPropertyName, roles); } }); } } }
/** * Utility method for checking if a tag with some name is in the list. * * @param aTags Tags list * @param aTagName Tag's name * @return True if there is a tag with provided name */ public static Tag getTagWithName(List<Tag> aTags, String aTagName) { if (aTags != null) { for (Tag tag : aTags) { if (tag.getName().equals(aTagName)) { return tag; } } return null; } else { throw new NullPointerException("Tag list is null."); } }
private void extractUri(RPCPoint rpcPoint, JsDoc.Tag aTag, Consumer<String> withUri) { if (aTag.getParams() != null && !aTag.getParams().isEmpty()) { withUri.accept(aTag.getParams().get(0)); } else { Logger.getLogger(RestPointsScanner.class.getName()).log(Level.WARNING, "Annotation {0} in {1}.{2} missing uri parameter.", new Object[]{aTag.getName(), rpcPoint.getModuleName(), rpcPoint.getMethodName()}); } } }
void parseAnnotations(String commentText) { JsDoc jsDoc = new JsDoc(commentText); jsDoc.parseAnnotations(); jsDoc.getAnnotations().stream().forEach((JsDoc.Tag tag) -> { moduleAnnotations.add(tag); if (tag.getName().equalsIgnoreCase(JsDoc.Tag.ROLES_ALLOWED_TAG)) { tag.getParams().stream().forEach((role) -> { moduleAllowedRoles.add(role); }); } }); }