visitor-pattern

How to find whether a member variable is used in a method using code in eclipse jdt?

拜拜、爱过 提交于 2019-12-13 21:16:29
问题 I have to find all the methods in a class that use a particular member variable. (like "References" in eclipse but I want to implement using code...)I use AST visitor pattern that visits FieldDeclaration to get the name and type of all the member variables. I also use visitor pattern that visits MethodDeclaration nodes to get the content of each method using getBody(). Now I have the field variable name, type and member method details. I thought I can use a string search on the content of

Is there any kind of “line visitor” in Eclipse JDT Java Parser? If there is not, does someone knows a good workaround?

女生的网名这么多〃 提交于 2019-12-13 14:05:56
问题 I wanna visit the nodes in an AST from a Java file and extract some information related to these nodes. But, I wanna pass by the AST guided by the lines in the source code file. I know there is information about the lines associated with each node, but the problem is that the default way to access the nodes is through specific visitors. So: 1. to avoid redundant visits to the nodes, 2. do not generates overhead while trying to enumerate all the possible node types (or visitors), and 3. to

Select method based on field in class

空扰寡人 提交于 2019-12-13 14:05:03
问题 So I have a class that contains a String-field: public class A { private String type = ... public String getType(){ return this.type; } public void setType(String type){ this.type = type; } } I also have a list of all possible types, there are twelve and possibly more in the future. Now I want to write a method that gets an object of class A and calls a specific method depending on which "type" is in the class. Is there a smarter solution than writing 12 (or more) if-statements? Normally I

What's the difference between using the Visitor pattern and a separate class?

倖福魔咒の 提交于 2019-12-13 04:30:53
问题 I would like to know what is the difference between the Visitor pattern and using a static method to execute code in separation. Let's take a look at an example where I might call the Visitor pattern: new AnalyticsVisitor.accept(myClass); and this when called in from myClass for example, would move the work into a visitor to execute. It would even garbage collect faster if it's memory intensive. Now lets take a look at using a simple method to achieve more or less the same thing: new

Gather info from xhtml in java: parser + visitor?

余生颓废 提交于 2019-12-12 02:28:32
问题 I have to write a piece of code that loads a remote web page, search for the links, visit those pages and gather some info from certain tags... How would you do this? Is the visitor pattern of any help here? If so, how could I use it? Thanks 回答1: Some comments/suggestions Not sure if the visitor patter is a good fit over here. A typical scenario for the visitor pattern is when the operation algorithm differs depending on the object on which the algorithm is applied. The crude way to solve

How to do unit testing of Visitors in Jsqlparser?

徘徊边缘 提交于 2019-12-12 00:49:05
问题 I have implemented the Visitors of JSqlparser to parse SQL queries. The code is working absolutely fine. I am not sure how to do unit testing for those visitors. For example I have the following sql statement: Select a.a1, a.a2 from foo as a To parse it I have implemented StatementVisitor interface and my code goes like this: public class StmntVisitorImpl implements StatementVisitor { @Override public void visit(Select select) { LOG.debug("Begin Select visit : "+select.toString());

Use visitor pattern to handle else if

Deadly 提交于 2019-12-11 19:04:12
问题 I wonder if there is any way to handle a simple condition with the visitor pattern or not? For instance, if we have the below code, how can we apply the visitor pattern to it? public class Elseif { private int total; public int Condition(int x) { if(x==1) { total = 100; } else if(x==2) { total = 200; } return total; } } in other words how you want to write the overload for IVisitor interface ? public interface IVisitor { int Visitor(int x); } 回答1: The Visitor Pattern is for distinguishing

How can I use the boost visitor concept with a class containing state variables?

偶尔善良 提交于 2019-12-11 09:29:56
问题 I'm attempting to use boost::static_visitor to implement actions on a boost::variant type that affect the state of some variable. My approach was to contain all of the state variables in my command visitor class, but it seems this is not possible. Here is my code example: #include <string> #include <sstream> #include <vector> #include <boost/variant.hpp> #include <boost/foreach.hpp> struct TypeA { int varA; int varB; }; struct TypeB { std::string varA; std::string varB; }; typedef boost:

Visitor Pattern: Traversing tree elements in client or visitor

别说谁变了你拦得住时间么 提交于 2019-12-11 09:13:19
问题 Good morning stackoverflow, I'm currently implemeting a visitor pattern on something like an AST. Now my question is, how do I iterate through the elements ? I think its somewhat more logical to just return the object to the visitor and let the visitor traverse from there on. Because you're keeping up flexibility , when you would like to traverse the object in different ways. On the other side one could say, the visitor shouldn't concern about the structure of the object. So in case the

Visitor class holding large shared state: best way to implement reference semantics?

依然范特西╮ 提交于 2019-12-10 16:15:31
问题 This question is loosely based on the Boost.Graph library (BGL) that uses a Visitor-like pattern to customize recursive (search) algorithms. The BGL passes visitor objects by value (in analogy with the STL function objects) and the documentation states Since the visitor parameter is passed by value, if your visitor contains state then any changes to the state during the algorithm will be made to a copy of the visitor object, not the visitor object passed in. Therefore you may want the visitor