Skip to content

Add entry point to search the test items - #322

Merged
Sheng Chen (jdneo) merged 5 commits into
cs/test_runner_newfrom
cs/lazy-load
Sep 27, 2018
Merged

Sheng Chen (jdneo) merged 5 commits into
cs/test_runner_newfrom
cs/lazy-load

Conversation

@jdneo

Copy link
Copy Markdown
Member

No description provided.

private static Map<TestLevel, TestItemSearcher[]> initializeSearcherMap() {
final Map<TestLevel, TestItemSearcher[]> map = new HashMap<TestLevel, TestItemSearcher[]>();
map.put(TestLevel.FOLDER, new TestItemSearcher[] {new PackageSearcher()});
map.put(TestLevel.PACKAGE, new TestItemSearcher[] {new ClassSearcher() });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra white space here. Do you have related checkstyle rules for it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, but will consider adding more check rules in the future.

IProgressMonitor monitor) {
final List<TestItem> resultList = new ArrayList<>();
final TestItemSearcher[] searchers = searcherMap.get(parentType);
if (searchers != null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it feasible to use something like searcherMap.getOrDefault(parentType, []) to avoid the null check? The code would be more neat, but may consume more memory (for the default empty list)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep current implementation for now. Since generate a new empty array will also add more codes.


@SuppressWarnings("restriction")
public class TestSearchUtils {
private static final Map<TestLevel, TestItemSearcher[]> searcherMap = initializeSearcherMap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more simplier to use static block static { ... } to initialize searcherMap.

final IType parentClass = (IType) method.getParent();
if (!JUnitUtility.isAccessibleClass(parentClass) || Flags.isAbstract(parentClass.getFlags()) ||
parentClass.getFullyQualifiedName().equals(fullyQualifiedName)) {
!parentClass.getFullyQualifiedName().equals(fullyQualifiedName)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need neg?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the parent class of the method is not equal to fullyQualifiedName for searching. Then this method is not the child of the class we are searching

map.put(TestLevel.PACKAGE, new TestItemSearcher[] {new ClassSearcher()});
map.put(TestLevel.CLASS, new TestItemSearcher[] {new NestedClassSearcher(), new MethodSearcher()});
map.put(TestLevel.NESTED_CLASS, new TestItemSearcher[] {new NestedClassSearcher(), new MethodSearcher()});
return map;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put the hierarchy relationship in ts side? Let the java code just play as an utility role.

final SearchRequest request = gson.fromJson((String) arguments.get(0), SearchRequest.class);
final List<TestItem> resultList = searchTestItems(request.getLevel(),
request.getUri(), request.getFullName(), monitor);
if (request.isFetchAll()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetchAll is not necessary for tree view refresh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants