-
Notifications
You must be signed in to change notification settings - Fork 7
/
HashSetValuesQuery.java
104 lines (94 loc) · 3.9 KB
/
HashSetValuesQuery.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
* Copyright (c) 2008, 2019 SAP AG, IBM Corporation and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP AG - initial API and implementation
* IBM Corporation - enhancements and fixes
* James Livingston - expose collection utils as API
*******************************************************************************/
package org.eclipse.mat.inspections.collections;
import org.eclipse.mat.SnapshotException;
import org.eclipse.mat.inspections.collectionextract.CollectionExtractionUtils;
import org.eclipse.mat.inspections.collectionextract.ExtractedMap;
import org.eclipse.mat.internal.Messages;
import org.eclipse.mat.internal.collectionextract.HashSetCollectionExtractor;
import org.eclipse.mat.query.IQuery;
import org.eclipse.mat.query.IResult;
import org.eclipse.mat.query.annotations.Argument;
import org.eclipse.mat.query.annotations.CommandName;
import org.eclipse.mat.query.annotations.HelpUrl;
import org.eclipse.mat.query.annotations.Icon;
import org.eclipse.mat.snapshot.ISnapshot;
import org.eclipse.mat.snapshot.extension.Subjects;
import org.eclipse.mat.snapshot.model.IObject;
import org.eclipse.mat.snapshot.query.ObjectListResult;
import org.eclipse.mat.util.IProgressListener;
@CommandName("hash_set_values")
@Icon("/META-INF/icons/hash_set.gif")
@HelpUrl("/org.eclipse.mat.ui.help/tasks/analyzingjavacollectionusage.html")
@Subjects({"java.util.AbstractSet",
"java.util.Collections$SynchronizedSet",
"java.util.Collections$UnmodifiableSet",
"java.util.Collections$CheckedSet",
"java.util.Collections$CheckedMap$CheckedEntrySet",
"java.util.Collections$SetFromMap",
"java.util.Properties$EntrySet",
"java.util.concurrent.ConcurrentHashMap$KeySetView",
"java.util.concurrent.ConcurrentHashMap$EntrySetView",
"java.util.ImmutableCollections$AbstractImmutableSet",
"java.util.ImmutableCollections$Set",
"java.beans.beancontext.BeanContextSupport",
})
public class HashSetValuesQuery implements IQuery
{
@Argument
public ISnapshot snapshot;
@Argument(flag = Argument.UNFLAGGED)
public IObject hashSet;
@Argument(isMandatory = false)
public String collection;
@Argument(isMandatory = false)
public String array_attribute;
@Argument(isMandatory = false)
public String key_attribute;
public IResult execute(IProgressListener listener) throws Exception
{
ExtractedMap extractor;
if (collection != null && hashSet.getClazz().doesExtend(collection))
{
if (array_attribute == null || key_attribute == null)
{
String msg = Messages.HashSetValuesQuery_ErrorMsg_MissingArgument;
throw new SnapshotException(msg);
}
extractor = new ExtractedMap(hashSet, new HashSetCollectionExtractor(array_attribute, key_attribute));
}
else
{
extractor = CollectionExtractionUtils.extractMap(hashSet);
if (extractor == null)
{
throw new IllegalArgumentException(hashSet.getTechnicalName());
}
}
// TODO: refactor out code with ExtractListValuesQuery
int[] result;
if (!extractor.hasSize())
{
result = new int[0];
}
else if (extractor.hasExtractableContents())
{
result = extractor.extractEntryIds();
}
else
{
throw new IllegalArgumentException(hashSet.getTechnicalName());
}
return new ObjectListResult.Outbound(snapshot, result);
}
}