From 157fac9ac62bca5f0527a58e13a1575137714584 Mon Sep 17 00:00:00 2001 From: Rodrigo Bonifacio Date: Tue, 3 Oct 2017 19:13:17 -0300 Subject: [PATCH] Source code refactoring. Using the diamond operator instead of specifying the type parameters in the RHS of assignments. This simple transformation was built using Rascal-MPL. It is one of the transformations we implemented to evolve Java legacy systems towards the use of new constructs of the language. More details in our repository: https://github.com/refactoring-towards-language-evolution/rascal-Java8 It seems that worked with the build command mvn -Drascal.boot=--validating -B clean test --- src/org/rascalmpl/interpreter/Evaluator.java | 14 +++++++------- src/org/rascalmpl/interpreter/JavaToRascal.java | 4 ++-- .../interpreter/env/GlobalEnvironment.java | 6 +++--- .../matching/AbstractMatchingResult.java | 2 +- .../interpreter/matching/RegExpPatternValue.java | 2 +- .../matching/TypedVariablePattern.java | 2 +- .../interpreter/result/NamedFunction.java | 2 +- .../interpreter/result/OverloadedFunction.java | 16 ++++++++-------- .../interpreter/types/FunctionType.java | 4 ++-- .../types/OverloadedFunctionType.java | 10 +++++----- 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/org/rascalmpl/interpreter/Evaluator.java b/src/org/rascalmpl/interpreter/Evaluator.java index 53eb552746e..2f5c097c5af 100644 --- a/src/org/rascalmpl/interpreter/Evaluator.java +++ b/src/org/rascalmpl/interpreter/Evaluator.java @@ -552,14 +552,14 @@ private IList parsePlainCommandLineArgs(String[] commandline) { } public Map parseKeywordCommandLineArgs(IRascalMonitor monitor, String[] commandline, AbstractFunction func) { - Map expectedTypes = new HashMap(); + Map expectedTypes = new HashMap<>(); Type kwTypes = func.getKeywordArgumentTypes(getCurrentEnvt()); for (String kwp : kwTypes.getFieldNames()) { expectedTypes.put(kwp, kwTypes.getFieldType(kwp)); } - Map params = new HashMap(); + Map params = new HashMap<>(); for (int i = 0; i < commandline.length; i++) { if (commandline[i].equals("-help")) { @@ -707,7 +707,7 @@ private void initializeRecovery(IMap robust, int[][] lookaheads, IConstructor[] for (IValue prod : robust) { robustProds[i] = (IConstructor) prod; - List chars = new LinkedList(); + List chars = new LinkedList<>(); IList ranges = (IList) robust.get(prod); for (IValue range : ranges) { @@ -1263,8 +1263,8 @@ private void reloadModule(String name, ISourceLocation errorLocation, Set getImportingModules(Set names) { - Set found = new HashSet(); - LinkedList todo = new LinkedList(names); + Set found = new HashSet<>(); + LinkedList todo = new LinkedList<>(names); while (!todo.isEmpty()) { String mod = todo.pop(); @@ -1278,8 +1278,8 @@ private Set getImportingModules(Set names) { } private Set getExtendingModules(Set names) { - Set found = new HashSet(); - LinkedList todo = new LinkedList(names); + Set found = new HashSet<>(); + LinkedList todo = new LinkedList<>(names); while (!todo.isEmpty()) { String mod = todo.pop(); diff --git a/src/org/rascalmpl/interpreter/JavaToRascal.java b/src/org/rascalmpl/interpreter/JavaToRascal.java index 6f7f1a02f69..6d4d19064aa 100644 --- a/src/org/rascalmpl/interpreter/JavaToRascal.java +++ b/src/org/rascalmpl/interpreter/JavaToRascal.java @@ -134,7 +134,7 @@ public boolean boolValue(String command) { } private Object[] _listValue(IList q) { - ArrayList r = new ArrayList(); + ArrayList r = new ArrayList<>(); for (IValue v : q) { r.add(javaObject(v)); } @@ -223,7 +223,7 @@ public boolean isProcedureInModule(String moduleName, String procedureName, evaluator.doImport(null, moduleName); ModuleEnvironment env = evaluator.getCurrentEnvt().getImport( moduleName); - ArrayList funcs = new ArrayList(); + ArrayList funcs = new ArrayList<>(); Type typ = getType(env, procedureResultType); if (typ == null) return false; diff --git a/src/org/rascalmpl/interpreter/env/GlobalEnvironment.java b/src/org/rascalmpl/interpreter/env/GlobalEnvironment.java index 5757f54b7e2..0606bc49ba9 100644 --- a/src/org/rascalmpl/interpreter/env/GlobalEnvironment.java +++ b/src/org/rascalmpl/interpreter/env/GlobalEnvironment.java @@ -201,7 +201,7 @@ private static void storeParser(HashMap store, String modul } public Set getImportingModules(String mod) { - Set result = new HashSet(); + Set result = new HashSet<>(); for (ModuleEnvironment env : moduleEnvironment.values()) { if (env.getImports().contains(mod)) { @@ -213,8 +213,8 @@ public Set getImportingModules(String mod) { } public Set getExtendingModules(String mod) { - Set result = new HashSet(); - List todo = new LinkedList(); + Set result = new HashSet<>(); + List todo = new LinkedList<>(); todo.add(mod); while (!todo.isEmpty()) { diff --git a/src/org/rascalmpl/interpreter/matching/AbstractMatchingResult.java b/src/org/rascalmpl/interpreter/matching/AbstractMatchingResult.java index 426056a13cc..7b5dc390b27 100644 --- a/src/org/rascalmpl/interpreter/matching/AbstractMatchingResult.java +++ b/src/org/rascalmpl/interpreter/matching/AbstractMatchingResult.java @@ -89,7 +89,7 @@ public IValue toIValue() { public HashMap merge(HashMap left, List right){ if(left == null){ - HashMap res = new HashMap(); + HashMap res = new HashMap<>(); for(IVarPattern vpr: right){ res.put(vpr.name(), vpr); } diff --git a/src/org/rascalmpl/interpreter/matching/RegExpPatternValue.java b/src/org/rascalmpl/interpreter/matching/RegExpPatternValue.java index 1079e21763a..12d2193e075 100644 --- a/src/org/rascalmpl/interpreter/matching/RegExpPatternValue.java +++ b/src/org/rascalmpl/interpreter/matching/RegExpPatternValue.java @@ -174,7 +174,7 @@ public boolean next(){ @Override public List getVariables(){ - List res = new LinkedList(); + List res = new LinkedList<>(); for(String name : patternVars){ res.add(new RegExpVar(name)); } diff --git a/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java b/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java index ead3cd069b8..1938f63051f 100644 --- a/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java +++ b/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java @@ -92,7 +92,7 @@ public boolean next() { try { // type checking code for formal parameters; the static type of the actual should be a sub-type of the type of the formal - Map bindings = new HashMap(); + Map bindings = new HashMap<>(); bindings.putAll(ctx.getCurrentEnvt().getTypeBindings()); declaredType.match(subject.getType(), bindings); diff --git a/src/org/rascalmpl/interpreter/result/NamedFunction.java b/src/org/rascalmpl/interpreter/result/NamedFunction.java index 37c5b7e3f67..ce98544ecd7 100644 --- a/src/org/rascalmpl/interpreter/result/NamedFunction.java +++ b/src/org/rascalmpl/interpreter/result/NamedFunction.java @@ -180,7 +180,7 @@ protected boolean hasMemoization() { } protected Map parseTags(FunctionDeclaration declaration) { - final Map result = new HashMap(); + final Map result = new HashMap<>(); Tags tags = declaration.getTags(); if (tags.hasTags()) { for (Tag tag : tags.getTags()) { diff --git a/src/org/rascalmpl/interpreter/result/OverloadedFunction.java b/src/org/rascalmpl/interpreter/result/OverloadedFunction.java index 012d1222bbe..04dac59fd84 100644 --- a/src/org/rascalmpl/interpreter/result/OverloadedFunction.java +++ b/src/org/rascalmpl/interpreter/result/OverloadedFunction.java @@ -197,7 +197,7 @@ private void addAll(List container, List can Map>[] constructors = new Map[10]; @SuppressWarnings("unchecked") Map>[] productions = new Map[10]; - List other = new LinkedList(); + List other = new LinkedList<>(); for (AbstractFunction func : candidates) { @@ -354,7 +354,7 @@ public IValue getValue() { } private static Type lub(List candidates) { - Set alternatives = new HashSet(); + Set alternatives = new HashSet<>(); Iterator iter = candidates.iterator(); if(!iter.hasNext()) { return TF.voidType(); @@ -436,8 +436,8 @@ public OverloadedFunction join(OverloadedFunction other) { if (other == null) { return this; } - List joined = new ArrayList(other.primaryCandidates.size() + primaryCandidates.size()); - List defJoined = new ArrayList(other.defaultCandidates.size() + defaultCandidates.size()); + List joined = new ArrayList<>(other.primaryCandidates.size() + primaryCandidates.size()); + List defJoined = new ArrayList<>(other.defaultCandidates.size() + defaultCandidates.size()); joined.addAll(primaryCandidates); defJoined.addAll(defaultCandidates); @@ -458,9 +458,9 @@ public OverloadedFunction join(OverloadedFunction other) { } public OverloadedFunction add(AbstractFunction candidate) { - List joined = new ArrayList(primaryCandidates.size() + 1); + List joined = new ArrayList<>(primaryCandidates.size() + 1); joined.addAll(primaryCandidates); - List defJoined = new ArrayList(defaultCandidates.size() + 1); + List defJoined = new ArrayList<>(defaultCandidates.size() + 1); defJoined.addAll(defaultCandidates); if (candidate.isDefault() && !defJoined.contains(candidate)) { @@ -565,7 +565,7 @@ public ComposedFunctionResult composeFunction(ComposedFunctionResult that) { } public List getFunctions(){ - List result = new LinkedList(); + List result = new LinkedList<>(); for (AbstractFunction f : primaryCandidates) { result.add(f); } @@ -578,7 +578,7 @@ public List getFunctions(){ } public List getTests() { - List result = new LinkedList(); + List result = new LinkedList<>(); for (AbstractFunction f : getFunctions()) { if (f.isTest()) { result.add(f); diff --git a/src/org/rascalmpl/interpreter/types/FunctionType.java b/src/org/rascalmpl/interpreter/types/FunctionType.java index e507ed04d4b..1c7cf34cb29 100644 --- a/src/org/rascalmpl/interpreter/types/FunctionType.java +++ b/src/org/rascalmpl/interpreter/types/FunctionType.java @@ -273,7 +273,7 @@ public boolean isSubtypeOfFunction(RascalType other) { // because the argument types are co-variant. This would be weird since // instantiated functions are supposed to be substitutable for their generic // counter parts. So, we try to instantiate first, and then check again. - Map bindings = new HashMap(); + Map bindings = new HashMap<>(); if (!otherType.match(this, bindings)) { return false; @@ -456,7 +456,7 @@ public Type compose(Type right) { if (right.isBottom()) { return right; } - Set newAlternatives = new HashSet(); + Set newAlternatives = new HashSet<>(); if(right instanceof FunctionType) { if(TF.tupleType(((FunctionType) right).returnType).isSubtypeOf(this.argumentTypes)) { diff --git a/src/org/rascalmpl/interpreter/types/OverloadedFunctionType.java b/src/org/rascalmpl/interpreter/types/OverloadedFunctionType.java index 3afac8465d4..d3c3e2e3bdf 100644 --- a/src/org/rascalmpl/interpreter/types/OverloadedFunctionType.java +++ b/src/org/rascalmpl/interpreter/types/OverloadedFunctionType.java @@ -252,7 +252,7 @@ protected Type lubWithOverloadedFunction(RascalType type) { OverloadedFunctionType of = (OverloadedFunctionType) type; - Set newAlternatives = new HashSet(); + Set newAlternatives = new HashSet<>(); for(FunctionType f : getAlternatives()) { for(FunctionType g : of.getAlternatives()) { @@ -272,7 +272,7 @@ protected Type lubWithOverloadedFunction(RascalType type) { protected Type lubWithFunction(RascalType type) { FunctionType f = (FunctionType) type; - Set newAlternatives = new HashSet(); + Set newAlternatives = new HashSet<>(); newAlternatives.add(f); return this.lubWithOverloadedFunction((RascalType)RTF.overloadedFunctionType(newAlternatives)); @@ -286,7 +286,7 @@ protected Type glbWithOverloadedFunction(RascalType type) { OverloadedFunctionType of = (OverloadedFunctionType) type; - Set newAlternatives = new HashSet(); + Set newAlternatives = new HashSet<>(); if(getReturnType() == of.getReturnType()) { newAlternatives.addAll(getAlternatives()); @@ -311,7 +311,7 @@ protected Type glbWithOverloadedFunction(RascalType type) { protected Type glbWithFunction(RascalType type) { FunctionType f = (FunctionType) type; - Set newAlternatives = new HashSet(); + Set newAlternatives = new HashSet<>(); newAlternatives.add(f); return this.glbWithOverloadedFunction((RascalType)RTF.overloadedFunctionType(newAlternatives)); @@ -362,7 +362,7 @@ public Type compose(Type right) { if (right.isBottom()) { return right; } - Set newAlternatives = new HashSet(); + Set newAlternatives = new HashSet<>(); if(right instanceof FunctionType) { for(FunctionType ftype : this.alternatives) { if(TF.tupleType(((FunctionType) right).getReturnType()).isSubtypeOf(ftype.getArgumentTypes())) {