Skip to content
Snippets Groups Projects
Commit b33c13ea authored by dgelessus's avatar dgelessus
Browse files

Use generics for another field in GenParser

parent bcded9ef
Branches
No related tags found
No related merge requests found
...@@ -73,7 +73,7 @@ public class GenParser extends DepthFirstAdapter ...@@ -73,7 +73,7 @@ public class GenParser extends DepthFirstAdapter
//This map contains Productions which were explicitely transformed in the grammar //This map contains Productions which were explicitely transformed in the grammar
//Those transformations was specified by the grammar-writer. //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; private Map<String, Node> alts;
...@@ -128,7 +128,7 @@ public class GenParser extends DepthFirstAdapter ...@@ -128,7 +128,7 @@ public class GenParser extends DepthFirstAdapter
if(node.getProdTransform() != null) if(node.getProdTransform() != null)
{ {
mapProductionTransformations.put("P"+ResolveIds.name(node.getId().getText()), mapProductionTransformations.put("P"+ResolveIds.name(node.getId().getText()),
(LinkedList)node.getProdTransform().clone() ); new LinkedList<>(node.getProdTransform()) );
} }
} }
} }
......
...@@ -43,7 +43,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -43,7 +43,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
private LinkedList listSimpleTermTransform; private LinkedList listSimpleTermTransform;
public final Map<Node, String> simpleTermTransform; public final Map<Node, String> simpleTermTransform;
Map<String, LinkedList> mapProductionTransformations; Map<String, List<PElem>> mapProductionTransformations;
Map<Node, String> simpleTermOrsimpleListTermTypes; Map<Node, String> simpleTermOrsimpleListTermTypes;
private Map<String, String> isElementIsAlist = new TreeMap<>(); private Map<String, String> isElementIsAlist = new TreeMap<>();
...@@ -54,7 +54,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -54,7 +54,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
ResolveTransformIds transformIds, ResolveTransformIds transformIds,
LinkedList listSimpleTermTransform, LinkedList listSimpleTermTransform,
Map<Node, String> simpleTermTransform, Map<Node, String> simpleTermTransform,
Map<String, LinkedList> mapProductionTransformations, Map<String, List<PElem>> mapProductionTransformations,
Map<Node, String> simpleTermOrsimpleListTermTypes) Map<Node, String> simpleTermOrsimpleListTermTypes)
{ {
this.ids = ids; this.ids = ids;
...@@ -331,7 +331,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -331,7 +331,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
if((count & (1 << elem)) != 0) if((count & (1 << elem)) != 0)
{ {
qMarkOrPlusElemType = ids.elemTypes.get(node); qMarkOrPlusElemType = ids.elemTypes.get(node);
LinkedList tmpProdTransform = mapProductionTransformations.get(qMarkOrPlusElemType); List<PElem> tmpProdTransform = mapProductionTransformations.get(qMarkOrPlusElemType);
if(!checkCreationOfXElem.contains("$" + elemName)) if(!checkCreationOfXElem.contains("$" + elemName))
{ {
...@@ -383,7 +383,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -383,7 +383,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
case PLUS: case PLUS:
{ {
qMarkOrPlusElemType = ids.elemTypes.get(node); qMarkOrPlusElemType = ids.elemTypes.get(node);
LinkedList tmpProdTransform = mapProductionTransformations.get(qMarkOrPlusElemType); List<PElem> tmpProdTransform = mapProductionTransformations.get(qMarkOrPlusElemType);
if(!checkCreationOfXElem.contains("$" + elemName)) if(!checkCreationOfXElem.contains("$" + elemName))
{ {
...@@ -460,14 +460,14 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -460,14 +460,14 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
*/ */
public AProd createXelemProduction(final String name, final String elemTypeName, public AProd createXelemProduction(final String name, final String elemTypeName,
String XproductionName, String XproductionName,
LinkedList nodeProdTransform) List<PElem> nodeProdTransform)
{ {
final String rname = name.substring(1); final String rname = name.substring(1);
LinkedList listOfAltsXelem = new LinkedList(); List<PAlt> listOfAltsXelem = new LinkedList<>();
if(nodeProdTransform != null) if(nodeProdTransform != null)
{ {
nodeProdTransform = (LinkedList)cloneList(nodeProdTransform); nodeProdTransform = cloneList(nodeProdTransform);
//Creation of the production transformation for Xelem //Creation of the production transformation for Xelem
//if the production transformation is introduced by the software //if the production transformation is introduced by the software
...@@ -476,7 +476,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -476,7 +476,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
AElem elem = (AElem)nodeProdTransform.get(0); AElem elem = (AElem)nodeProdTransform.get(0);
if(elem.getUnOp() == null && elem.getId().getText().equals(rname)) 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() ) ); elemsProdTransform.add( new AElem( null, new AProductionSpecifier(), new TId(rname), new AStarUnOp() ) );
nodeProdTransform = elemsProdTransform; nodeProdTransform = elemsProdTransform;
} }
...@@ -486,14 +486,14 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -486,14 +486,14 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
//That means elem is token type //That means elem is token type
else else
{ {
LinkedList elemsProdTransform = new LinkedList(); List<PElem> elemsProdTransform = new LinkedList<>();
elemsProdTransform.add( new AElem( null, new ATokenSpecifier(), new TId(rname), new AStarUnOp() ) ); elemsProdTransform.add( new AElem( null, new ATokenSpecifier(), new TId(rname), new AStarUnOp() ) );
nodeProdTransform = elemsProdTransform; 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++) for(int i=0; i<temp_listProdTransform.length; i++)
{ {
temp_listProdTransform[i].apply( new DepthFirstAdapter() temp_listProdTransform[i].apply( new DepthFirstAdapter()
...@@ -517,9 +517,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -517,9 +517,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
} }
//creation of the first AltTransform node //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++) for(int i = 0; i < prodTransformElems.length; i++)
{ {
...@@ -530,7 +530,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -530,7 +530,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
{ {
String tmpNodeName = ( (node.getElemName() == null) ? node.getId().getText() : String tmpNodeName = ( (node.getElemName() == null) ? node.getId().getText() :
node.getElemName().getText() ); node.getElemName().getText() );
LinkedList listAListTerm_first = new LinkedList(); List<PListTerm> listAListTerm_first = new LinkedList<>();
if(elemTypeName.startsWith("T")) if(elemTypeName.startsWith("T"))
{ {
...@@ -551,7 +551,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -551,7 +551,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
AAltTransform aAltTransform = new AAltTransform(new TLBrace(), listTerms_first, new TRBrace()); AAltTransform aAltTransform = new AAltTransform(new TLBrace(), listTerms_first, new TRBrace());
//create the first list of elems of an alternative //create the first list of elems of an alternative
LinkedList elems = new LinkedList(); List<PElem> elems = new LinkedList<>();
AElem aElemFirstTobeAdded; AElem aElemFirstTobeAdded;
//the elem is a token //the elem is a token
if(elemTypeName.startsWith("T")) if(elemTypeName.startsWith("T"))
...@@ -570,9 +570,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -570,9 +570,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
listOfAltsXelem.add(aParsedAlt); listOfAltsXelem.add(aParsedAlt);
//create the second AltTransform node //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++) for(int i = 0; i < prodTransformElems.length; i++)
{ {
...@@ -584,7 +584,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -584,7 +584,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
String tmpNodeName = ( (node.getElemName() == null) ? node.getId().getText() : String tmpNodeName = ( (node.getElemName() == null) ? node.getId().getText() :
node.getElemName().getText() ); node.getElemName().getText() );
LinkedList listAListTerm_second = new LinkedList(); List<PListTerm> listAListTerm_second = new LinkedList<>();
listAListTerm_second.add(new ASimpleListTerm(null, new TId(name), listAListTerm_second.add(new ASimpleListTerm(null, new TId(name),
new TId(tmpNodeName)) ); new TId(tmpNodeName)) );
...@@ -609,7 +609,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -609,7 +609,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
aAltTransform = new AAltTransform(new TLBrace(), listTerms_second, new TRBrace()); aAltTransform = new AAltTransform(new TLBrace(), listTerms_second, new TRBrace());
//creation of the second list of elems of an alternative :: two elems //creation of the second list of elems of an alternative :: two elems
elems = new LinkedList(); elems = new LinkedList<>();
//first elem //first elem
AElem aElemSecondTobeAdded = new AElem(null, new AProductionSpecifier(), new TId(name), null); AElem aElemSecondTobeAdded = new AElem(null, new AProductionSpecifier(), new TId(name), null);
...@@ -637,13 +637,13 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -637,13 +637,13 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
return prodToReturn; 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();) for (final T node : list) {
{ clone.add((T)node.clone());
clone.add(((Node) i.next()).clone());
} }
return clone; return clone;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment