Skip to content

Commit 4f90843

Browse files
committed
Update method accessors and dialog
1 parent 992adf5 commit 4f90843

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/data/MethodWrapper.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@ public MethodWrapper(Method method) {
6161
* @param methodName Name of method
6262
* @param parameters List of method's parameters
6363
* @param returnType Method's return type
64-
* @param className Method's fully qualified class name
6564
*/
66-
public MethodWrapper(String methodName, List<String> parameters, String returnType,
67-
String className) {
65+
public MethodWrapper(String methodName, List<String> parameters, String returnType) {
6866

6967
this.method = new Method(methodName, parameters, returnType);
7068
status = MethodStatus.NONE;
@@ -103,7 +101,7 @@ public String getMethodName(boolean fullyQualifiedName) {
103101
if (!fullyQualifiedName)
104102
return trimProperty(method.getClassName() + "." + method.getName());
105103
else
106-
return method.getClassName() + "." + method.getName();
104+
return method.getName();
107105
}
108106

109107
/**
@@ -179,10 +177,8 @@ public ArrayList<String> getCWEList() {
179177

180178
ArrayList<String> cweList = new ArrayList<String>();
181179

182-
for (Category category : method.getAllCategories()) {
183-
if (category.isCwe()) {
180+
for (Category category : method.getCwe()) {
184181
cweList.add(category.toString());
185-
}
186182
}
187183

188184
return cweList;
@@ -195,12 +191,12 @@ public ArrayList<String> getCWEList() {
195191
*/
196192
public ArrayList<String> getTypesList(boolean capitalize) {
197193

198-
ArrayList<String> typesList = new ArrayList<String>();
194+
ArrayList<String> typesList = new ArrayList<>();
199195

200-
for (Category category : method.getAllCategories()) {
201-
if (!category.isCwe() && !capitalize) {
196+
for (Category category : method.getSrm()) {
197+
if (!capitalize) {
202198
typesList.add(category.toString());
203-
} else if (!category.isCwe())
199+
} else
204200
typesList.add(Formatter.toTitleCase(category.toString()));
205201
}
206202

@@ -221,12 +217,12 @@ public Set<Category> getCategories() {
221217
*/
222218
public void setCategories(Set<Category> categories) {
223219

224-
Set<Category> cweCategories = null;
225-
Set<Category> srmCategories = null;
220+
Set<Category> cweCategories = new HashSet<>();
221+
Set<Category> srmCategories = new HashSet<>();
222+
226223
for(Category category: categories) {
227224
if (category.isCwe()) {
228225
cweCategories.add(category);
229-
} else if (category.isNone()) {
230226
} else {
231227
srmCategories.add(category);
232228
}
@@ -244,16 +240,16 @@ public String getUpdateOperation() {
244240
}
245241

246242
/**
247-
* Returns whether or not the method is a training method
248-
* @return Whether or not the method is a training method
243+
* Returns whether the method is a training method
244+
* @return Whether the method is a training method
249245
*/
250246
public boolean isTrainingMethod() {
251247
return isTrainingMethod;
252248
}
253249

254250
/**
255-
* Set whether or not the method is a training method
256-
* @param trainingMethod Whether or not the method is a training method
251+
* Set whether the method is a training method
252+
* @param trainingMethod Whether the method is a training method
257253
*/
258254
public void setTrainingMethod(boolean trainingMethod) {
259255
isTrainingMethod = trainingMethod;

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/ui/dialog/MethodDialog.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ public class MethodDialog extends DialogWrapper {
5353

5454
/**
5555
* Initializes dialog to show method properties
56-
* @param methods Method data that will be shown in dialog
57-
* @param signature Method Signature
58-
* @param project Active project
56+
*
57+
* @param methods Method data that will be shown in dialog
58+
* @param signature Method Signature
59+
* @param project Active project
5960
* @param categories List of all possible method categories
6061
*/
6162
public MethodDialog(HashMap<String, MethodWrapper> methods, String signature, Project project, Set<Category> categories) {
@@ -149,7 +150,7 @@ public void mouseClicked(MouseEvent e) {
149150
availableCategories.remove(selectedCategory);
150151

151152
selectedModel.addElement(selectedCategory);
152-
method.getCategories().add(selectedCategory);
153+
method.getMethod().addCategory(selectedCategory);
153154
methodTypes.setText(StringUtils.join(method.getTypesList(true), ", "));
154155
methodCwes.setText(StringUtils.join(method.getCWEList(), ", "));
155156
}
@@ -167,21 +168,21 @@ public void mouseClicked(MouseEvent e) {
167168
JList value = (JList) e.getSource();
168169
selectedCategory = (Category) value.getSelectedValue();
169170

170-
if (method.getTypesList(false).size() == 1 && !selectedCategory.isCwe()) {
171+
/*if (method.getTypesList(false).size() == 1 && !selectedCategory.isCwe()) {
171172
JBPopupFactory.getInstance()
172173
.createHtmlTextBalloonBuilder(resourceBundle.getString("Messages.Error.CategoryNotSelected"), MessageType.ERROR, null)
173174
.createBalloon()
174175
.show(JBPopupFactory.getInstance().guessBestPopupLocation((JComponent) selectedList), Balloon.Position.below);
175-
} else {
176+
} else {*/
176177

177-
selectedModel.removeElement(selectedCategory);
178-
method.getCategories().remove(selectedCategory);
179-
methodTypes.setText(StringUtils.join(method.getTypesList(true), ", "));
180-
methodCwes.setText(StringUtils.join(method.getCWEList(), ", "));
178+
selectedModel.removeElement(selectedCategory);
179+
method.getMethod().removeCategory(selectedCategory);
180+
methodTypes.setText(StringUtils.join(method.getTypesList(true), ", "));
181+
methodCwes.setText(StringUtils.join(method.getCWEList(), ", "));
181182

182-
availableModel.addElement(selectedCategory);
183-
availableCategories.add(selectedCategory);
184-
}
183+
availableModel.addElement(selectedCategory);
184+
availableCategories.add(selectedCategory);
185+
// }
185186
}
186187
}
187188
});
@@ -202,7 +203,8 @@ public void actionPerformed(ActionEvent e) {
202203

203204
/**
204205
* Loads method details in the dialog
205-
* @param signature Method signature
206+
*
207+
* @param signature Method signature
206208
* @param categories List of all possible method categories
207209
*/
208210
private void updateFields(String signature, Set<Category> categories) {
@@ -224,17 +226,14 @@ private void updateFields(String signature, Set<Category> categories) {
224226

225227
for (Category category : selectedCategories) {
226228

227-
if (availableCategories.contains(category)) {
228-
availableCategories.remove(category);
229-
}
229+
availableCategories.remove(category);
230230
}
231231

232232
selectedModel = addCategoriesToModel(selectedCategories, false);
233233
selectedList.setModel(selectedModel);
234234

235235
availableModel = addCategoriesToModel(availableCategories, false);
236236
availableList.setModel(availableModel);
237-
238237
}
239238

240239
@Override
@@ -250,6 +249,7 @@ public void doCancelAction() {
250249

251250
/**
252251
* Deep copy of method categories
252+
*
253253
* @param categories Method categories
254254
* @return New Set of method categories
255255
*/
@@ -303,7 +303,8 @@ protected void doOKAction() {
303303

304304
/**
305305
* Shows error message
306-
* @param message Message
306+
*
307+
* @param message Message
307308
* @param location Where on screen the message should be shown
308309
*/
309310
private void showErrorMessage(String message, JComponent location) {
@@ -321,8 +322,9 @@ protected JComponent createCenterPanel() {
321322

322323
/**
323324
* Add categories to the List model
325+
*
324326
* @param categories Method categories
325-
* @param showCwe Condition to show CWEs or not
327+
* @param showCwe Condition to show CWEs or not
326328
* @return return List Model for List
327329
*/
328330
private DefaultListModel<Category> addCategoriesToModel(Set<Category> categories, boolean showCwe) {

0 commit comments

Comments
 (0)