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)) { Logger.getLogger(ServerTasksScanner.class.getName()).log(Level.WARNING, "Duplicated acceptor \"{0}\" on any protocol. Ignored.", aModuleName); tag.getParams().stream().forEach((String protocol) -> { if (acceptors.containsKey(protocol)) { Logger.getLogger(ServerTasksScanner.class.getName()).log(Level.WARNING, "Duplicated acceptor \"{0}\" on protocol \"{1}\". Ignored.", new Object[]{aModuleName, protocol}); 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()});
public void parseAnnotations() { for (String line : lines) { if (line.startsWith("@")) { //NOI18N // Split whith all whitespace characters String[] annotationTokens = line.split("[\\s,]+"); //NOI18N String annotationName = annotationTokens[0]; String annotationText = line.substring(annotationName.length()).trim(); tag = new Tag(annotationName, annotationText); tags.add(tag); } } }
public List<String> getParams() { if (params == null) { params = parseParams(); } return Collections.unmodifiableList(params); }
jsDoc.parseAnnotations(); for (JsDoc.Tag tag : jsDoc.getAnnotations()) { switch (tag.getName().toLowerCase()) { case JsDoc.Tag.ROLES_ALLOWED_TAG: aQuery.getReadRoles().addAll(tag.getParams()); if (aQuery.getWriteRoles().isEmpty()) { aQuery.getWriteRoles().addAll(tag.getParams()); aQuery.getReadRoles().addAll(tag.getParams()); break; case JsDoc.Tag.ROLES_ALLOWED_WRITE_TAG: aQuery.getWriteRoles().clear(); aQuery.getWriteRoles().addAll(tag.getParams()); break; case JsDoc.Tag.READONLY_TAG: case JsDoc.Tag.WRITABLE_TAG: Set<String> writables = new HashSet<>(); if (tag.getParams() != null) { tag.getParams().stream().forEach((writable) -> { if (writable != null) { writables.add(writable.toLowerCase());
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."); } }
@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); } }
public Tag getTag(String name) { return Tag.getTagWithName(tags, name); }
public boolean containsTag(String name) { return Tag.getTagWithName(tags, name) != null; }
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; }
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); }); } }); }
public boolean hasAnnotation(String anAnnotation) { return moduleAnnotations.stream().anyMatch((JsDoc.Tag aTag) -> { return aTag.getName().equalsIgnoreCase(anAnnotation); }); }