1

I want to ensure that all enums have a static method called findByAttribute.

I can select the method by

MATCH (enum:Enum) - [:DECLARES] -> (method:Method)
 WHERE method.static = true
 AND method.name = "findByAttribute"
RETURN enum.name, method.name

Now I want to inverse the condition of method selection. I tried NOT EXITS but that didn't work.

Tezra
  • 8,463
  • 3
  • 31
  • 68
Mark Hunt
  • 25
  • 5

2 Answers2

0

First, here are all the operators you can use, and how to use them

The easiest way is to use bubbles to group your logic. (This is probably the easiest to understand with one read through)

MATCH (enum:Enum) - [:DECLARES] -> (method:Method)
 WHERE NOT (method.static = true
 AND method.name = "findByAttribute")
RETURN enum.name, method.name

The next best thing is NOT (A and B)=NOT A OR NOT B

MATCH (enum:Enum) - [:DECLARES] -> (method:Method)
 WHERE NOT method.static = true
 OR NOT method.name = "findByAttribute"
RETURN enum.name, method.name

or using the inequality operator <> instead of inverting the Boolean

MATCH (enum:Enum) - [:DECLARES] -> (method:Method)
 WHERE method.static <> true
 OR method.name <> "findByAttribute"
RETURN enum.name, method.name

EXISTS is to merely check if a property is set, so doesn't really apply here because it can be set.


Assuming by inverse you meant "WHERE this method doesn't exist", you can NOT a pattern match (cut out method.name from return since there is no logical way to include it in this version of query)

MATCH (enum:Enum) 
 WHERE NOT (enum) - [:DECLARES] -> (:Method {static:true, name:"findByAttribute"})
RETURN enum.name
Tezra
  • 8,463
  • 3
  • 31
  • 68
0

Picking up the last query of the previous answer and correcting it a little bit:

MATCH
  (enum:Enum:Type) 
WHERE NOT
  (enum)-[:DECLARES]->(:Method {static:true, name:"findByAttribute"})
RETURN
  enum.fqn
Tezra
  • 8,463
  • 3
  • 31
  • 68
Dirk Mahler
  • 1,186
  • 1
  • 6
  • 7
  • Where did you get the "Type" label from? Was the only thing you actually changed the "method" var name syntax error? (Fixed in mine now that I noticed it) – Tezra Mar 27 '19 at 19:53
  • jQA makes heavy use of label combinations, e.g. a label "Type" (representing a Java type) can be qualified further by either "Class", "Interface", "Annotation" or "Enum". This qualification exists for all classes that have been part of the scann. Those that are referenced but not scanned (e.g. types from the JRE) are only labeled with "Type". – Dirk Mahler Mar 28 '19 at 17:52
  • Looking at the differences between the queries I added the "Type" label in the match clause ("Enum" can also appear in combination with "Value"), removed the duplicate "--" (wondering if this works) from the WHERE NOT clause and changed the RETURN clause to provide the fully qualified name of the enum type instead of just the simple class name (to be more expressive). – Dirk Mahler Mar 28 '19 at 17:55