Skip to content

Commit

Permalink
Merge pull request #1127 from rbonifacio/master
Browse files Browse the repository at this point in the history
Source code refactoring.
  • Loading branch information
DavyLandman authored Oct 9, 2017
2 parents 4fbc0d6 + 157fac9 commit fb3976f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
14 changes: 7 additions & 7 deletions src/org/rascalmpl/interpreter/Evaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,14 @@ private IList parsePlainCommandLineArgs(String[] commandline) {
}

public Map<String, IValue> parseKeywordCommandLineArgs(IRascalMonitor monitor, String[] commandline, AbstractFunction func) {
Map<String, Type> expectedTypes = new HashMap<String,Type>();
Map<String, Type> expectedTypes = new HashMap<>();
Type kwTypes = func.getKeywordArgumentTypes(getCurrentEnvt());

for (String kwp : kwTypes.getFieldNames()) {
expectedTypes.put(kwp, kwTypes.getFieldType(kwp));
}

Map<String, IValue> params = new HashMap<String,IValue>();
Map<String, IValue> params = new HashMap<>();

for (int i = 0; i < commandline.length; i++) {
if (commandline[i].equals("-help")) {
Expand Down Expand Up @@ -707,7 +707,7 @@ private void initializeRecovery(IMap robust, int[][] lookaheads, IConstructor[]

for (IValue prod : robust) {
robustProds[i] = (IConstructor) prod;
List<Integer> chars = new LinkedList<Integer>();
List<Integer> chars = new LinkedList<>();
IList ranges = (IList) robust.get(prod);

for (IValue range : ranges) {
Expand Down Expand Up @@ -1263,8 +1263,8 @@ private void reloadModule(String name, ISourceLocation errorLocation, Set<String
* @return
*/
private Set<String> getImportingModules(Set<String> names) {
Set<String> found = new HashSet<String>();
LinkedList<String> todo = new LinkedList<String>(names);
Set<String> found = new HashSet<>();
LinkedList<String> todo = new LinkedList<>(names);

while (!todo.isEmpty()) {
String mod = todo.pop();
Expand All @@ -1278,8 +1278,8 @@ private Set<String> getImportingModules(Set<String> names) {
}

private Set<String> getExtendingModules(Set<String> names) {
Set<String> found = new HashSet<String>();
LinkedList<String> todo = new LinkedList<String>(names);
Set<String> found = new HashSet<>();
LinkedList<String> todo = new LinkedList<>(names);

while (!todo.isEmpty()) {
String mod = todo.pop();
Expand Down
4 changes: 2 additions & 2 deletions src/org/rascalmpl/interpreter/JavaToRascal.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public boolean boolValue(String command) {
}

private Object[] _listValue(IList q) {
ArrayList<Object> r = new ArrayList<Object>();
ArrayList<Object> r = new ArrayList<>();
for (IValue v : q) {
r.add(javaObject(v));
}
Expand Down Expand Up @@ -223,7 +223,7 @@ public boolean isProcedureInModule(String moduleName, String procedureName,
evaluator.doImport(null, moduleName);
ModuleEnvironment env = evaluator.getCurrentEnvt().getImport(
moduleName);
ArrayList<AbstractFunction> funcs = new ArrayList<AbstractFunction>();
ArrayList<AbstractFunction> funcs = new ArrayList<>();
Type typ = getType(env, procedureResultType);
if (typ == null)
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/org/rascalmpl/interpreter/env/GlobalEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private static void storeParser(HashMap<String, ParserTuple> store, String modul
}

public Set<String> getImportingModules(String mod) {
Set<String> result = new HashSet<String>();
Set<String> result = new HashSet<>();

for (ModuleEnvironment env : moduleEnvironment.values()) {
if (env.getImports().contains(mod)) {
Expand All @@ -213,8 +213,8 @@ public Set<String> getImportingModules(String mod) {
}

public Set<String> getExtendingModules(String mod) {
Set<String> result = new HashSet<String>();
List<String> todo = new LinkedList<String>();
Set<String> result = new HashSet<>();
List<String> todo = new LinkedList<>();
todo.add(mod);

while (!todo.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public IValue toIValue() {

public HashMap<String,IVarPattern> merge(HashMap<String,IVarPattern> left, List<IVarPattern> right){
if(left == null){
HashMap<String,IVarPattern> res = new HashMap<String,IVarPattern>();
HashMap<String,IVarPattern> res = new HashMap<>();
for(IVarPattern vpr: right){
res.put(vpr.name(), vpr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public boolean next(){

@Override
public List<IVarPattern> getVariables(){
List<IVarPattern> res = new LinkedList<IVarPattern>();
List<IVarPattern> res = new LinkedList<>();
for(String name : patternVars){
res.add(new RegExpVar(name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Type> bindings = new HashMap<Type,Type>();
Map<Type, Type> bindings = new HashMap<>();
bindings.putAll(ctx.getCurrentEnvt().getTypeBindings());
declaredType.match(subject.getType(), bindings);

Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/interpreter/result/NamedFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected boolean hasMemoization() {
}

protected Map<String, IValue> parseTags(FunctionDeclaration declaration) {
final Map<String, IValue> result = new HashMap<String, IValue>();
final Map<String, IValue> result = new HashMap<>();
Tags tags = declaration.getTags();
if (tags.hasTags()) {
for (Tag tag : tags.getTags()) {
Expand Down
16 changes: 8 additions & 8 deletions src/org/rascalmpl/interpreter/result/OverloadedFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private void addAll(List<AbstractFunction> container, List<AbstractFunction> can
Map<String, List<AbstractFunction>>[] constructors = new Map[10];
@SuppressWarnings("unchecked")
Map<IConstructor, List<AbstractFunction>>[] productions = new Map[10];
List<AbstractFunction> other = new LinkedList<AbstractFunction>();
List<AbstractFunction> other = new LinkedList<>();


for (AbstractFunction func : candidates) {
Expand Down Expand Up @@ -354,7 +354,7 @@ public IValue getValue() {
}

private static Type lub(List<AbstractFunction> candidates) {
Set<FunctionType> alternatives = new HashSet<FunctionType>();
Set<FunctionType> alternatives = new HashSet<>();
Iterator<AbstractFunction> iter = candidates.iterator();
if(!iter.hasNext()) {
return TF.voidType();
Expand Down Expand Up @@ -436,8 +436,8 @@ public OverloadedFunction join(OverloadedFunction other) {
if (other == null) {
return this;
}
List<AbstractFunction> joined = new ArrayList<AbstractFunction>(other.primaryCandidates.size() + primaryCandidates.size());
List<AbstractFunction> defJoined = new ArrayList<AbstractFunction>(other.defaultCandidates.size() + defaultCandidates.size());
List<AbstractFunction> joined = new ArrayList<>(other.primaryCandidates.size() + primaryCandidates.size());
List<AbstractFunction> defJoined = new ArrayList<>(other.defaultCandidates.size() + defaultCandidates.size());

joined.addAll(primaryCandidates);
defJoined.addAll(defaultCandidates);
Expand All @@ -458,9 +458,9 @@ public OverloadedFunction join(OverloadedFunction other) {
}

public OverloadedFunction add(AbstractFunction candidate) {
List<AbstractFunction> joined = new ArrayList<AbstractFunction>(primaryCandidates.size() + 1);
List<AbstractFunction> joined = new ArrayList<>(primaryCandidates.size() + 1);
joined.addAll(primaryCandidates);
List<AbstractFunction> defJoined = new ArrayList<AbstractFunction>(defaultCandidates.size() + 1);
List<AbstractFunction> defJoined = new ArrayList<>(defaultCandidates.size() + 1);
defJoined.addAll(defaultCandidates);

if (candidate.isDefault() && !defJoined.contains(candidate)) {
Expand Down Expand Up @@ -565,7 +565,7 @@ public ComposedFunctionResult composeFunction(ComposedFunctionResult that) {
}

public List<AbstractFunction> getFunctions(){
List<AbstractFunction> result = new LinkedList<AbstractFunction>();
List<AbstractFunction> result = new LinkedList<>();
for (AbstractFunction f : primaryCandidates) {
result.add(f);
}
Expand All @@ -578,7 +578,7 @@ public List<AbstractFunction> getFunctions(){
}

public List<AbstractFunction> getTests() {
List<AbstractFunction> result = new LinkedList<AbstractFunction>();
List<AbstractFunction> result = new LinkedList<>();
for (AbstractFunction f : getFunctions()) {
if (f.isTest()) {
result.add(f);
Expand Down
4 changes: 2 additions & 2 deletions src/org/rascalmpl/interpreter/types/FunctionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type,Type> bindings = new HashMap<Type,Type>();
Map<Type,Type> bindings = new HashMap<>();

if (!otherType.match(this, bindings)) {
return false;
Expand Down Expand Up @@ -456,7 +456,7 @@ public Type compose(Type right) {
if (right.isBottom()) {
return right;
}
Set<FunctionType> newAlternatives = new HashSet<FunctionType>();
Set<FunctionType> newAlternatives = new HashSet<>();

if(right instanceof FunctionType) {
if(TF.tupleType(((FunctionType) right).returnType).isSubtypeOf(this.argumentTypes)) {
Expand Down
10 changes: 5 additions & 5 deletions src/org/rascalmpl/interpreter/types/OverloadedFunctionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected Type lubWithOverloadedFunction(RascalType type) {

OverloadedFunctionType of = (OverloadedFunctionType) type;

Set<FunctionType> newAlternatives = new HashSet<FunctionType>();
Set<FunctionType> newAlternatives = new HashSet<>();

for(FunctionType f : getAlternatives()) {
for(FunctionType g : of.getAlternatives()) {
Expand All @@ -272,7 +272,7 @@ protected Type lubWithOverloadedFunction(RascalType type) {
protected Type lubWithFunction(RascalType type) {
FunctionType f = (FunctionType) type;

Set<FunctionType> newAlternatives = new HashSet<FunctionType>();
Set<FunctionType> newAlternatives = new HashSet<>();
newAlternatives.add(f);

return this.lubWithOverloadedFunction((RascalType)RTF.overloadedFunctionType(newAlternatives));
Expand All @@ -286,7 +286,7 @@ protected Type glbWithOverloadedFunction(RascalType type) {

OverloadedFunctionType of = (OverloadedFunctionType) type;

Set<FunctionType> newAlternatives = new HashSet<FunctionType>();
Set<FunctionType> newAlternatives = new HashSet<>();

if(getReturnType() == of.getReturnType()) {
newAlternatives.addAll(getAlternatives());
Expand All @@ -311,7 +311,7 @@ protected Type glbWithOverloadedFunction(RascalType type) {
protected Type glbWithFunction(RascalType type) {
FunctionType f = (FunctionType) type;

Set<FunctionType> newAlternatives = new HashSet<FunctionType>();
Set<FunctionType> newAlternatives = new HashSet<>();
newAlternatives.add(f);

return this.glbWithOverloadedFunction((RascalType)RTF.overloadedFunctionType(newAlternatives));
Expand Down Expand Up @@ -362,7 +362,7 @@ public Type compose(Type right) {
if (right.isBottom()) {
return right;
}
Set<FunctionType> newAlternatives = new HashSet<FunctionType>();
Set<FunctionType> newAlternatives = new HashSet<>();
if(right instanceof FunctionType) {
for(FunctionType ftype : this.alternatives) {
if(TF.tupleType(((FunctionType) right).getReturnType()).isSubtypeOf(ftype.getArgumentTypes())) {
Expand Down

0 comments on commit fb3976f

Please sign in to comment.