Skip to content
Snippets Groups Projects
Commit 7fd9f5a9 authored by Tobias Ask's avatar Tobias Ask
Browse files

Use field for fxml class name used in annotation checks.

parent 0329f54e
No related branches found
No related tags found
1 merge request!5Resolve "Weak connection to controller class"
...@@ -44,6 +44,7 @@ public class JavaProjectGlossary extends Glossary implements IElementChangedList ...@@ -44,6 +44,7 @@ public class JavaProjectGlossary extends Glossary implements IElementChangedList
private String controllerClassName; private String controllerClassName;
private Map<String, List<String>> fxIds; private Map<String, List<String>> fxIds;
private List<String> eventHandlers; private List<String> eventHandlers;
private static final String FXML_ANNOTATION = FXML.class.getSimpleName();
public JavaProjectGlossary() { public JavaProjectGlossary() {
JavaCore.addElementChangedListener(this, ElementChangedEvent.POST_CHANGE); JavaCore.addElementChangedListener(this, ElementChangedEvent.POST_CHANGE);
...@@ -156,14 +157,13 @@ public class JavaProjectGlossary extends Glossary implements IElementChangedList ...@@ -156,14 +157,13 @@ public class JavaProjectGlossary extends Glossary implements IElementChangedList
} }
private boolean hasFxmlAnnotatedMembers(IType type) { private boolean hasFxmlAnnotatedMembers(IType type) {
String fxml = FXML.class.getSimpleName();
try { try {
List<IMethod> methods = new ArrayList<>(Arrays.asList(type.getMethods())); List<IMethod> methods = new ArrayList<>(Arrays.asList(type.getMethods()));
List<IField> fields = new ArrayList<>(Arrays.asList(type.getFields())); List<IField> fields = new ArrayList<>(Arrays.asList(type.getFields()));
boolean anyMethodsAnnotated = methods.stream().anyMatch(m -> boolean anyMethodsAnnotated = methods.stream().anyMatch(m ->
m.getAnnotation(fxml).exists()); m.getAnnotation(FXML_ANNOTATION).exists());
boolean anyFieldsAnnotated = fields.stream().anyMatch(f -> boolean anyFieldsAnnotated = fields.stream().anyMatch(f ->
f.getAnnotation(fxml).exists()); f.getAnnotation(FXML_ANNOTATION).exists());
return anyFieldsAnnotated || anyMethodsAnnotated; return anyFieldsAnnotated || anyMethodsAnnotated;
} catch (JavaModelException e) { } catch (JavaModelException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -217,9 +217,8 @@ public class JavaProjectGlossary extends Glossary implements IElementChangedList ...@@ -217,9 +217,8 @@ public class JavaProjectGlossary extends Glossary implements IElementChangedList
} }
private boolean isEventHandler(IMethod method) { private boolean isEventHandler(IMethod method) {
String fxml = FXML.class.getSimpleName();
try { try {
boolean isFxmlAnnotated = method.getAnnotation(fxml).exists(); boolean isFxmlAnnotated = method.getAnnotation(FXML_ANNOTATION).exists();
boolean returnsVoid = method.getReturnType().equals(Signature.SIG_VOID); boolean returnsVoid = method.getReturnType().equals(Signature.SIG_VOID);
if (isFxmlAnnotated && returnsVoid) { if (isFxmlAnnotated && returnsVoid) {
// valid ones are: // valid ones are:
...@@ -254,7 +253,7 @@ public class JavaProjectGlossary extends Glossary implements IElementChangedList ...@@ -254,7 +253,7 @@ public class JavaProjectGlossary extends Glossary implements IElementChangedList
IType type = controller.findPrimaryType(); IType type = controller.findPrimaryType();
try { try {
for (IField field : type.getFields()) { for (IField field : type.getFields()) {
if (field.getAnnotation("FXML").exists()) { if (field.getAnnotation(FXML_ANNOTATION).exists()) {
addToIds(ids, field); addToIds(ids, field);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment