From b33c13ea593b4b5a6890c51aa516f87726b9653c Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Fri, 22 Apr 2022 17:41:12 +0200 Subject: [PATCH] Use generics for another field in GenParser --- .../java/org/sablecc/sablecc/GenParser.java | 4 +- .../InternalTransformationsToGrammar.java | 48 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/sablecc/sablecc/GenParser.java b/src/main/java/org/sablecc/sablecc/GenParser.java index ace3408..c47721a 100644 --- a/src/main/java/org/sablecc/sablecc/GenParser.java +++ b/src/main/java/org/sablecc/sablecc/GenParser.java @@ -73,7 +73,7 @@ public class GenParser extends DepthFirstAdapter //This map contains Productions which were explicitely transformed in the grammar //Those transformations was specified by the grammar-writer. - private final Map<String, LinkedList> mapProductionTransformations = new HashMap<>(); + private final Map<String, List<PElem>> mapProductionTransformations = new HashMap<>(); private Map<String, Node> alts; @@ -128,7 +128,7 @@ public class GenParser extends DepthFirstAdapter if(node.getProdTransform() != null) { mapProductionTransformations.put("P"+ResolveIds.name(node.getId().getText()), - (LinkedList)node.getProdTransform().clone() ); + new LinkedList<>(node.getProdTransform()) ); } } } diff --git a/src/main/java/org/sablecc/sablecc/InternalTransformationsToGrammar.java b/src/main/java/org/sablecc/sablecc/InternalTransformationsToGrammar.java index eb66ba5..874d513 100644 --- a/src/main/java/org/sablecc/sablecc/InternalTransformationsToGrammar.java +++ b/src/main/java/org/sablecc/sablecc/InternalTransformationsToGrammar.java @@ -43,7 +43,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter private LinkedList listSimpleTermTransform; public final Map<Node, String> simpleTermTransform; - Map<String, LinkedList> mapProductionTransformations; + Map<String, List<PElem>> mapProductionTransformations; Map<Node, String> simpleTermOrsimpleListTermTypes; private Map<String, String> isElementIsAlist = new TreeMap<>(); @@ -54,7 +54,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ResolveTransformIds transformIds, LinkedList listSimpleTermTransform, Map<Node, String> simpleTermTransform, - Map<String, LinkedList> mapProductionTransformations, + Map<String, List<PElem>> mapProductionTransformations, Map<Node, String> simpleTermOrsimpleListTermTypes) { this.ids = ids; @@ -331,7 +331,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter if((count & (1 << elem)) != 0) { qMarkOrPlusElemType = ids.elemTypes.get(node); - LinkedList tmpProdTransform = mapProductionTransformations.get(qMarkOrPlusElemType); + List<PElem> tmpProdTransform = mapProductionTransformations.get(qMarkOrPlusElemType); if(!checkCreationOfXElem.contains("$" + elemName)) { @@ -383,7 +383,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter case PLUS: { qMarkOrPlusElemType = ids.elemTypes.get(node); - LinkedList tmpProdTransform = mapProductionTransformations.get(qMarkOrPlusElemType); + List<PElem> tmpProdTransform = mapProductionTransformations.get(qMarkOrPlusElemType); if(!checkCreationOfXElem.contains("$" + elemName)) { @@ -460,14 +460,14 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter */ public AProd createXelemProduction(final String name, final String elemTypeName, String XproductionName, - LinkedList nodeProdTransform) + List<PElem> nodeProdTransform) { final String rname = name.substring(1); - LinkedList listOfAltsXelem = new LinkedList(); + List<PAlt> listOfAltsXelem = new LinkedList<>(); if(nodeProdTransform != null) { - nodeProdTransform = (LinkedList)cloneList(nodeProdTransform); + nodeProdTransform = cloneList(nodeProdTransform); //Creation of the production transformation for Xelem //if the production transformation is introduced by the software @@ -476,7 +476,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter AElem elem = (AElem)nodeProdTransform.get(0); if(elem.getUnOp() == null && elem.getId().getText().equals(rname)) { - LinkedList elemsProdTransform = new LinkedList(); + List<PElem> elemsProdTransform = new LinkedList<>(); elemsProdTransform.add( new AElem( null, new AProductionSpecifier(), new TId(rname), new AStarUnOp() ) ); nodeProdTransform = elemsProdTransform; } @@ -486,14 +486,14 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter //That means elem is token type else { - LinkedList elemsProdTransform = new LinkedList(); + List<PElem> elemsProdTransform = new LinkedList<>(); elemsProdTransform.add( new AElem( null, new ATokenSpecifier(), new TId(rname), new AStarUnOp() ) ); nodeProdTransform = elemsProdTransform; } - final LinkedList listProdTransformationOfXelem = new LinkedList(); + final List<String> listProdTransformationOfXelem = new LinkedList<>(); - AElem []temp_listProdTransform = (AElem[])nodeProdTransform.toArray(new AElem[0]); + AElem []temp_listProdTransform = nodeProdTransform.toArray(new AElem[0]); for(int i=0; i<temp_listProdTransform.length; i++) { temp_listProdTransform[i].apply( new DepthFirstAdapter() @@ -517,9 +517,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter } //creation of the first AltTransform node - AElem[] prodTransformElems = (AElem[]) nodeProdTransform.toArray(new AElem[0]); + AElem[] prodTransformElems = nodeProdTransform.toArray(new AElem[0]); - final LinkedList listTerms_first = new LinkedList(); + final List<PTerm> listTerms_first = new LinkedList<>(); for(int i = 0; i < prodTransformElems.length; i++) { @@ -530,7 +530,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter { String tmpNodeName = ( (node.getElemName() == null) ? node.getId().getText() : node.getElemName().getText() ); - LinkedList listAListTerm_first = new LinkedList(); + List<PListTerm> listAListTerm_first = new LinkedList<>(); if(elemTypeName.startsWith("T")) { @@ -551,7 +551,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter AAltTransform aAltTransform = new AAltTransform(new TLBrace(), listTerms_first, new TRBrace()); //create the first list of elems of an alternative - LinkedList elems = new LinkedList(); + List<PElem> elems = new LinkedList<>(); AElem aElemFirstTobeAdded; //the elem is a token if(elemTypeName.startsWith("T")) @@ -570,9 +570,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter listOfAltsXelem.add(aParsedAlt); //create the second AltTransform node - prodTransformElems = (AElem[]) nodeProdTransform.toArray(new AElem[0]); + prodTransformElems = nodeProdTransform.toArray(new AElem[0]); - final LinkedList listTerms_second = new LinkedList(); + final List<PTerm> listTerms_second = new LinkedList<>(); for(int i = 0; i < prodTransformElems.length; i++) { @@ -584,7 +584,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter String tmpNodeName = ( (node.getElemName() == null) ? node.getId().getText() : node.getElemName().getText() ); - LinkedList listAListTerm_second = new LinkedList(); + List<PListTerm> listAListTerm_second = new LinkedList<>(); listAListTerm_second.add(new ASimpleListTerm(null, new TId(name), new TId(tmpNodeName)) ); @@ -609,7 +609,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter aAltTransform = new AAltTransform(new TLBrace(), listTerms_second, new TRBrace()); //creation of the second list of elems of an alternative :: two elems - elems = new LinkedList(); + elems = new LinkedList<>(); //first elem AElem aElemSecondTobeAdded = new AElem(null, new AProductionSpecifier(), new TId(name), null); @@ -637,13 +637,13 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter return prodToReturn; } - private List cloneList(List list) + @SuppressWarnings("unchecked") + private <T extends Node> List<T> cloneList(List<T> list) { - List clone = new LinkedList(); + List<T> clone = new LinkedList<>(); - for(Iterator i = list.iterator(); i.hasNext();) - { - clone.add(((Node) i.next()).clone()); + for (final T node : list) { + clone.add((T)node.clone()); } return clone; } -- GitLab