Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Can I "generate" with aspectJ

You can use inter-type declarations as follows:

public class info {
  public String firstName;
}


public aspect InfoProperties {

  public String info.getFirstName() {}

  public void info.setFirstName(String fName) { firstName = fName; } 
 
}

You can't make the public field in "info" suddenly become private, but you 
could use a declare warning to achieve a similar effect. To the 
InfoProperties aspect add the following:

declare warning ; set(* info.firstName) && !within(InfoProperties)
  : "Only update firstName via the setter method.";

-- Adrian
Adrian_Colyer@xxxxxxxxxx



Ťavoda Pavel <Pavel.Tavoda@xxxxxxxxxx> 
Sent by: aspectj-dev-admin@xxxxxxxxxxx
25/05/2004 08:19
Please respond to
aspectj-dev


To
<aspectj-dev@xxxxxxxxxxx>
cc

Subject
[aspectj-dev] Can I "generate" with aspectJ






I would like to generate some methods inside java class. For example: 
SRC: 
public class info { 
        public String firstName; 
} 
After weaving: 
public class info { 
        private String firstName; 
        public String getFirstName() { 
        } 
        public void setFirstName(String pName) { 
                firstName=pName; 
        } 
} 
Is something like this feasible with AspectJ? 
TNX 
Pavel Tavoda 



Back to the top