Skip to content

Commit

Permalink
Map Iteration In For Each Loop Check sevntu-checkstyle#195 Compilable…
Browse files Browse the repository at this point in the history
… UT input
  • Loading branch information
alexkravin committed Aug 29, 2014
1 parent 5a26697 commit 2f40da0
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public final void basicTest() throws Exception
mCheckConfig.addAttribute("proposeEntrySetUsage", "true");

final String[] expected = {
"22:13: " + getCheckMessage(MSG_KEY_ENTRYSET),
"45:13: " + getCheckMessage(MSG_KEY_VALUES),
"47:17: " + getCheckMessage(MSG_KEY_KEYSET),
"71:17: " + getCheckMessage(MSG_KEY_ENTRYSET),
"76:13: " + getCheckMessage(MSG_KEY_KEYSET),
"83:9: " + getCheckMessage(MSG_KEY_ENTRYSET),
"88:9: " + getCheckMessage(MSG_KEY_VALUES),
"106:9: " + getCheckMessage(MSG_KEY_ENTRYSET),
"116:9: " + getCheckMessage(MSG_KEY_VALUES),};
"23:13: " + getCheckMessage(MSG_KEY_ENTRYSET),
"46:13: " + getCheckMessage(MSG_KEY_VALUES),
"48:17: " + getCheckMessage(MSG_KEY_KEYSET),
"72:17: " + getCheckMessage(MSG_KEY_ENTRYSET),
"77:13: " + getCheckMessage(MSG_KEY_KEYSET),
"84:9: " + getCheckMessage(MSG_KEY_ENTRYSET),
"89:9: " + getCheckMessage(MSG_KEY_VALUES),
"107:9: " + getCheckMessage(MSG_KEY_ENTRYSET),
"117:9: " + getCheckMessage(MSG_KEY_VALUES),};

verify(mCheckConfig,
getPath("InputMapIterationInForEachLoop.java"), expected);
Expand All @@ -45,7 +45,7 @@ public final void importsWithoutFullPathTest() throws Exception
mCheckConfig.addAttribute("proposeEntrySetUsage", "true");

final String [] expected = {
"11:9: " + getCheckMessage(MSG_KEY_ENTRYSET),};
"12:9: " + getCheckMessage(MSG_KEY_ENTRYSET),};
verify(mCheckConfig,
getPath("InputMapIterationInForEachLoopImport.java"),
expected);
Expand All @@ -68,7 +68,7 @@ public final void skipIfConditionTest() throws Exception
supportedMapImplQualifiedNames);

final String [] expected = {
"12:9: " + getCheckMessage(MSG_KEY_ENTRYSET),
"14:9: " + getCheckMessage(MSG_KEY_ENTRYSET),
};

verify(mCheckConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.github.sevntu.checkstyle.checks.coding;
import java.util.Collection;
import java.util.Map;
import java.util.Iterator;
import java.util.Set;

public class MyMap<K, V> implements Iterable, Map
{


@Override
public Iterator iterator()
{
return null;
}
public static class Entry<K, V> {

public String getValue()
{
return null;
}

public char[] getKey()
{
return null;
}

}
@Override
public int size()
{
return 0;
}

@Override
public boolean isEmpty()
{
return false;
}

@Override
public boolean containsKey(Object key)
{
return false;
}

@Override
public boolean containsValue(Object value)
{
return false;
}

@Override
public Object get(Object key)
{
return null;
}

@Override
public Object put(Object key, Object value)
{
return null;
}

@Override
public Object remove(Object key)
{
return null;
}

@Override
public void putAll(Map m)
{

}

@Override
public void clear()
{

}

@Override
public Set keySet()
{
return null;
}

@Override
public Collection values()
{
return null;
}

@Override
public Set<MyMap.Entry<K, V>> entrySet()
{
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package com.github.sevntu.checkstyle.checks.coding;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
Expand All @@ -6,7 +7,7 @@
import java.util.Set;
import java.util.Map.Entry;

public class test {
public class InputMapIterationInForEachLoop {
Map<String, String> mMap = new HashMap<String, String>();
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import com.myTest.*;
package com.github.sevntu.checkstyle.checks.coding;
import com.github.sevntu.checkstyle.checks.coding.MyMap;
import java.util.*;

public class Test
public class InputMapIterationInForEachLoopImport
{
public static void main(String[] args)
{
Expand All @@ -13,9 +14,10 @@ public static void main(String[] args)
System.out.println(key + " --> " + map.get(key));
}

for (myMap.Entry<String, String> entry : myMap.entrySet())
for (MyMap.Entry<String, String> entry : myMap.entrySet())
{
System.out.println(entry.getValue() + " --> ");
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import com.myTest.*;
package com.github.sevntu.checkstyle.checks.coding;
import com.github.sevntu.checkstyle.checks.coding.MyMap;
import java.util.*;
import java.util.Map.Entry;

public class Test
public class InputMapIterationInForEachLoopSkipIf
{
public static void main(String[] args)
{
Expand Down Expand Up @@ -39,10 +41,10 @@ public static void main(String[] args)
}
}

for (myMap.Entry<String, String> entry : myMap.entrySet())
for (MyMap.Entry<String, String> entry : myMap.entrySet())
{
System.out.println(entry.getKey);
if (entry.getValue != "value") {
System.out.println(entry.getKey());
if (entry.getValue() != "value") {
System.out.println(entry.getValue() + " --> ");
}
}
Expand All @@ -51,8 +53,8 @@ public static void main(String[] args)

for (Entry<String, String> entry : tableToUpdater.entrySet()) {
String updater = entry.getValue();
if (updater instanceof DailyTableUpdater) {
updateManager.put(entry.getKey() + "-updater", updater);
if (updater instanceof Object) {
System.out.println(entry.getKey() + "-updater" + updater);
}
}
}
Expand Down

0 comments on commit 2f40da0

Please sign in to comment.