Skip to content

Commit

Permalink
+ TS printer for ForEachStmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Prud'hommeaux committed Nov 24, 2021
1 parent c2c035a commit de1cc05
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class HttpResourceAccessor implements ResourceAccessor {
return Collections.emptyList();
}
let containedInstances: Array<ManageableInstance> = new Array<>();
for (let containerTriple: Triple : containerTriples) {
for (const containerTriple of containerTriples) {
let containedInstance: ManageableInstance = this.getInstance(context, new URL(containerTriple.getObject().getURI()));
containedInstances.add(containedInstance);
}
Expand Down
4 changes: 2 additions & 2 deletions asTypescript/packages/client-http/src/HttpShapeTreeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ export class HttpShapeTreeClient implements ShapeTreeClient {
ret.maybeSet(HttpHeaders.LINK.getValue(), "<" + resourceTypeUrl + ">; rel=\"type\"");
}
if (focusNodes != null && !focusNodes.isEmpty()) {
for (let focusNode: URL : focusNodes) {
for (const focusNode of focusNodes) {
ret.maybeSet(HttpHeaders.LINK.getValue(), "<" + focusNode + ">; rel=\"" + LinkRelations.FOCUS_NODE.getValue() + "\"");
}
}
if (targetShapeTrees != null && !targetShapeTrees.isEmpty()) {
for (let targetShapeTree: URL : targetShapeTrees) {
for (const targetShapeTree of targetShapeTrees) {
ret.maybeSet(HttpHeaders.LINK.getValue(), "<" + targetShapeTree + ">; rel=\"" + LinkRelations.TARGET_SHAPETREE.getValue() + "\"");
}
}
Expand Down
12 changes: 6 additions & 6 deletions asTypescript/packages/core/src/ResourceAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ResourceAttributes {
// copy constructor
private copy(): ResourceAttributes {
let ret: ResourceAttributes = new ResourceAttributes();
for (let entry: Map.Entry<string, Array<string>> : this.myMapOfLists.entrySet()) {
for (const entry of this.myMapOfLists.entrySet()) {
ret.myMapOfLists.put(entry.getKey(), new Array<>(entry.getValue()));
}
return ret;
Expand All @@ -57,7 +57,7 @@ export class ResourceAttributes {
*/
public static parseLinkHeaders(headerValues: Array<string>): ResourceAttributes {
let linkHeaderMap: ResourceAttributes = new ResourceAttributes();
for (let headerValue: string : headerValues) {
for (const headerValue of headerValues) {
let matcher: Matcher = LINK_HEADER_PATTERN.matcher(headerValue);
// if (matcher.matches() && matcher.groupCount() >= 2) {
if (matcher.matches()) {
Expand Down Expand Up @@ -136,10 +136,10 @@ export class ResourceAttributes {
*/
public toList(...exclusions: string): string[] {
let ret: Array<string> = new Array<>();
for (let entry: Map.Entry<string, Array<string>> : this.myMapOfLists.entrySet()) {
for (const entry of this.myMapOfLists.entrySet()) {
let attr: string = entry.getKey();
if (!Arrays.stream(exclusions).anyMatch(s -> s === attr)) {
for (let value: string : entry.getValue()) {
for (const value of entry.getValue()) {
ret.add(attr);
ret.add(value);
}
Expand Down Expand Up @@ -179,8 +179,8 @@ export class ResourceAttributes {

public toString(): string {
let sb: StringBuilder = new StringBuilder();
for (let entry: Map.Entry<string, Array<string>> : this.myMapOfLists.entrySet()) {
for (let value: string : entry.getValue()) {
for (const entry of this.myMapOfLists.entrySet()) {
for (const value of entry.getValue()) {
if (sb.length() != 0) {
sb.append(",");
}
Expand Down
10 changes: 5 additions & 5 deletions asTypescript/packages/core/src/ShapeTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class ShapeTree {
let shapeLabel: Label = new Label(GlobalFactory.RDFFactory.createIRI(this.shape.toString()));
if (!focusNodeUrls.isEmpty()) {
// One or more focus nodes were provided for validation
for (let focusNodeUrl: URL : focusNodeUrls) {
for (const focusNodeUrl of focusNodeUrls) {
// Evaluate each provided focus node
let focusNode: IRI = GlobalFactory.RDFFactory.createIRI(focusNodeUrl.toString());
log.debug("Validating Shape Label = {}, Focus Node = {}", shapeLabel.toPrettyString(), focusNode.getIRIString());
Expand All @@ -138,7 +138,7 @@ export class ShapeTree {
} else {
// No focus nodes were provided for validation, so all subject nodes will be evaluated
let evaluateNodes: Array<Node> = GraphUtil.listSubjects(graph, Node.ANY, Node.ANY).toList();
for (let evaluateNode: Node : evaluateNodes) {
for (const evaluateNode of evaluateNodes) {
const focusUriString: string = evaluateNode.getURI();
let node: IRI = GlobalFactory.RDFFactory.createIRI(focusUriString);
validation.validate(node, shapeLabel);
Expand Down Expand Up @@ -182,7 +182,7 @@ export class ShapeTree {
// If one or more target shape trees have been supplied
if (!targetShapeTreeUrls.isEmpty()) {
// Test each supplied target shape tree
for (let targetShapeTreeUrl: URL : targetShapeTreeUrls) {
for (const targetShapeTreeUrl of targetShapeTreeUrls) {
// Check if it exists in st:contains
if (this.contains.contains(targetShapeTreeUrl)) {
let targetShapeTree: ShapeTree = ShapeTreeFactory.getShapeTree(targetShapeTreeUrl);
Expand All @@ -198,7 +198,7 @@ export class ShapeTree {
return new ValidationResult(false, null, "Failed to validate " + targetShapeTreeUrls);
} else {
// For each shape tree in st:contains
for (let containsShapeTreeUrl: URL : getPrioritizedContains()) {
for (const containsShapeTreeUrl of getPrioritizedContains()) {
let containsShapeTree: ShapeTree = ShapeTreeFactory.getShapeTree(containsShapeTreeUrl);
// Continue if the shape tree isn't gettable
if (containsShapeTree === null) {
Expand Down Expand Up @@ -259,7 +259,7 @@ export class ShapeTree {
}

private getReferencedShapeTreesListDepthFirst(currentReferencedShapeTrees: Array<ShapeTreeReference>, referencedShapeTrees: Array<ShapeTreeReference>): Array<ShapeTreeReference> /* throws ShapeTreeException */ {
for (let currentShapeTreeReference: ShapeTreeReference : currentReferencedShapeTrees) {
for (const currentShapeTreeReference of currentReferencedShapeTrees) {
referencedShapeTrees.add(currentShapeTreeReference);
let currentReferencedShapeTree: ShapeTree = ShapeTreeFactory.getShapeTree(currentShapeTreeReference.getReferenceUrl());
if (currentReferencedShapeTree != null) {
Expand Down
2 changes: 1 addition & 1 deletion asTypescript/packages/core/src/ShapeTreeAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class ShapeTreeAssignment {
throw new IllegalStateException("Incomplete shape tree assignment, Only " + assignmentTriples.size() + " attributes found");
}
// Lookup and assign each triple in the nested ShapeTreeAssignment
for (let assignmentTriple: Triple : assignmentTriples) {
for (const assignmentTriple of assignmentTriples) {
switch(assignmentTriple.getPredicate().getURI()) {
case RdfVocabulary.TYPE:
if (!assignmentTriple.getObject().isURI() || !assignmentTriple.getObject().getURI() === ShapeTreeVocabulary.SHAPETREE_ASSIGNMENT) {
Expand Down
8 changes: 4 additions & 4 deletions asTypescript/packages/core/src/ShapeTreeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ export class ShapeTreeFactory {
let shapeTree: ShapeTree = new ShapeTree(shapeTreeUrl, expectsType, label, shape, references, contains);
localShapeTreeCache.put(urlToUri(shapeTreeUrl), shapeTree);
// Recursively parse contained shape trees
for (let containedUrl: URL : contains) {
for (const containedUrl of contains) {
getShapeTree(containedUrl);
}
// Recursively parse referenced shape trees
for (let reference: ShapeTreeReference : references) {
for (const reference of references) {
getShapeTree(reference.getReferenceUrl());
}
return shapeTree;
Expand Down Expand Up @@ -106,7 +106,7 @@ export class ShapeTreeFactory {
let referencesProperty: Property = resourceModel.createProperty(ShapeTreeVocabulary.REFERENCES);
if (shapeTreeNode.hasProperty(referencesProperty)) {
let referenceStatements: Array<Statement> = shapeTreeNode.listProperties(referencesProperty).toList();
for (let referenceStatement: Statement : referenceStatements) {
for (const referenceStatement of referenceStatements) {
let referenceResource: Resource = referenceStatement.getObject().asResource();
const referencedShapeTreeUrlString: string = getStringValue(resourceModel, referenceResource, ShapeTreeVocabulary.REFERENCES_SHAPE_TREE);
const referencedShapeTreeUrl: URL;
Expand Down Expand Up @@ -189,7 +189,7 @@ export class ShapeTreeFactory {
let property: Property = model.createProperty(predicate);
if (resource.hasProperty(property)) {
let propertyStatements: Array<Statement> = resource.listProperties(property).toList();
for (let propertyStatement: Statement : propertyStatements) {
for (const propertyStatement of propertyStatements) {
let propertyNode: Node = propertyStatement.getObject().asNode();
if (propertyNode instanceof Node_URI) {
let contentUrl: URL = new URL(propertyNode.getURI());
Expand Down
14 changes: 7 additions & 7 deletions asTypescript/packages/core/src/ShapeTreeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ShapeTreeManager {
// <> a st:Manager
managerGraph.add(GraphHelper.newTriple(managerSubject, RDF.type.toString(), GraphHelper.knownUrl(ShapeTreeVocabulary.SHAPETREE_MANAGER)));
// For each assignment create a blank node and populate
for (let assignment: ShapeTreeAssignment : this.assignments) {
for (const assignment of this.assignments) {
// <> st:hasAssignment <assignment1>, <assignment2>
managerGraph.add(GraphHelper.newTriple(managerSubject, ShapeTreeVocabulary.HAS_ASSIGNMENT, assignment.getUrl()));
const subject: URI = urlToUri(assignment.getUrl());
Expand All @@ -84,7 +84,7 @@ export class ShapeTreeManager {
throw new ShapeTreeException(500, "Must provide a non-null assignment to an initialized List of assignments");
}
if (!this.assignments.isEmpty()) {
for (let existingAssignment: ShapeTreeAssignment : this.assignments) {
for (const existingAssignment of this.assignments) {
if (existingAssignment === assignment) {
throw new ShapeTreeException(422, "Identical shape tree assignment cannot be added to Shape Tree Manager: " + this.id);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ export class ShapeTreeManager {
* @return Minted URL for a new shape tree assignment
*/
public mintAssignmentUrl(proposedAssignmentUrl: URL): URL {
for (let assignment: ShapeTreeAssignment : this.assignments) {
for (const assignment of this.assignments) {
if (assignment.getUrl() === proposedAssignmentUrl) {
// If we somehow managed to randomly generate a location URL that already exists, generate another
return mintAssignmentUrl();
Expand All @@ -127,7 +127,7 @@ export class ShapeTreeManager {

public getContainingAssignments(): Array<ShapeTreeAssignment> /* throws ShapeTreeException */ {
let containingAssignments: Array<ShapeTreeAssignment> = new Array<>();
for (let assignment: ShapeTreeAssignment : this.assignments) {
for (const assignment of this.assignments) {
let shapeTree: ShapeTree = ShapeTreeFactory.getShapeTree(assignment.getShapeTree());
if (!shapeTree.getContains().isEmpty()) {
containingAssignments.add(assignment);
Expand Down Expand Up @@ -159,7 +159,7 @@ export class ShapeTreeManager {
const stAssignment: Node = NodeFactory.createURI(ShapeTreeVocabulary.HAS_ASSIGNMENT);
let assignmentNodes: Array<Triple> = managerGraph.find(s, stAssignment, Node.ANY).toList();
// For each st:hasAssignment node, extract a new ShapeTreeAssignment
for (let assignmentNode: Triple : assignmentNodes) {
for (const assignmentNode of assignmentNodes) {
let assignment: ShapeTreeAssignment = null;
try {
assignment = ShapeTreeAssignment.getFromGraph(new URL(assignmentNode.getObject().getURI()), managerGraph);
Expand All @@ -175,7 +175,7 @@ export class ShapeTreeManager {
if (this.assignments.isEmpty()) {
return null;
}
for (let assignment: ShapeTreeAssignment : this.assignments) {
for (const assignment of this.assignments) {
if (assignment.getShapeTree() === shapeTreeUrl) {
return assignment;
}
Expand All @@ -188,7 +188,7 @@ export class ShapeTreeManager {
if (this.getAssignments() === null || this.getAssignments().isEmpty()) {
return null;
}
for (let assignment: ShapeTreeAssignment : this.getAssignments()) {
for (const assignment of this.getAssignments()) {
if (rootAssignment.getUrl() === assignment.getRootAssignment()) {
return assignment;
}
Expand Down
6 changes: 3 additions & 3 deletions asTypescript/packages/core/src/ShapeTreeManagerDelta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ShapeTreeManagerDelta {
delta.updatedAssignments = updatedManager.getAssignments();
return delta;
}
for (let existingAssignment: ShapeTreeAssignment : existingManager.getAssignments()) {
for (const existingAssignment of existingManager.getAssignments()) {
// Assignments match, and are unchanged, so continue
if (updatedManager.getAssignments().contains(existingAssignment)) {
continue;
Expand All @@ -57,7 +57,7 @@ export class ShapeTreeManagerDelta {
// existing assignment isn't in the updated assignment, so remove
delta.removedAssignments.add(existingAssignment);
}
for (let updatedAssignment: ShapeTreeAssignment : updatedManager.getAssignments()) {
for (const updatedAssignment of updatedManager.getAssignments()) {
// Assignments match, and are unchanged, so continue
if (existingManager.getAssignments().contains(updatedAssignment)) {
continue;
Expand All @@ -73,7 +73,7 @@ export class ShapeTreeManagerDelta {
}

public static containsSameUrl(assignment: ShapeTreeAssignment, targetAssignments: Array<ShapeTreeAssignment>): ShapeTreeAssignment /* throws ShapeTreeException */ {
for (let targetAssignment: ShapeTreeAssignment : targetAssignments) {
for (const targetAssignment of targetAssignments) {
let assignmentUri: URI;
let targetAssignmentUri: URI;
try {
Expand Down
Loading

0 comments on commit de1cc05

Please sign in to comment.