Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] class location question

There are some old classes (in default package) referenced by other classes across the system. If it is able to import default package (like prior to jdk1.3) then it would save time to reorganize the whole system. Indeed I agree to locate classes in the package appropriately is better; unfortunately sometimes not everything would work as we expect.

Thanks for you suggestion.

----- Original Message ----
From: Ron DiFrango <rdifrango@xxxxxxxxxxxxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Sent: Friday, 23 May, 2008 8:46:22 AM
Subject: Re: [aspectj-users] class location question

Why not place everything into packages instead of using the defaults?

Ron DiFrango

On May 22, 2008, at 6:12 PM, Neo Anderson wrote:

Sorry I post the wrong error message. The error message is as  the following lines:
adaptor/Adaptors.aj:9 [error] TemperatureSensor cannot be resolved to a type
public String TemperatureSensor.getStatus(){
              ^^^^^^^^^^^^^^^
adaptor/Adaptors.aj:14 [error] RadiationSensor cannot be resolved to a type
public String RadiationSensor.getStatus(){
              ^^^^^^^^^^^^^
adaptor/TemperatureSensor.java:3 [error] The type TemperatureSensor must implement the inherited abstract method StatusSensor.getStatus()
public class TemperatureSensor{
             ^^^^^^^^^^^^^^^^
adaptor/RadiationSensor.java:3 [error] The type RadiationSensor must implement the inherited abstract method StatusSensor.getStatus()
public class RadiationSensor{
             ^^^^^^^^^^^^^^

the source code of adaptor is as follow: Adaptor.aj
package adaptor;

public aspect Adaptors{
        declare parents:
                (TemperatureSensor || RadiationSensor) implements StatusSensor;
        public String TemperatureSensor.getStatus(){
                if(this.readTemperature()>120)
                        return "Dangerous!";
                return "OK!";
        }
        public String RadiationSensor.getStatus(){
                if(this.getRadiationLevel()>10)
                        return "Break down!";
                return "OK!";
        }
}

public class TemperatureSensor{
        public Double readTemperature(){
                return new Double(new java.util.Random().nextDouble());
        }
}

public class RadiationSensor{
    public Double getRadiationLevel(){
        return new Double(Math.random());
    }
}

These codes work when the sensor classes is located at another package such as sensor. Then the import statement in Adaptor.aj would work. But due to it is located at the top level (default location); the import statement, for instance, `import TemperatureSensor' won't work. 

I search on the google. Seemingly it is because of default package problem. JDK1.4+ no longer support default package import. So I use ajc -1.3 (ajc -1.3 TemperatureSensor.java RadiationSensor.java adaptor/Adaptors.aj adaptor/StatusSensor.java Test.java) instead; unfortunately those error still there.

How to solve this error?

Thanks for help,

----- Original Message ----
From: Simone Gianni <simoneg@xxxxxxxxxx>
Sent: Friday, 23 May, 2008 5:32:32 AM
Subject: Re: [aspectj-users] class location question

Hi Neo,
this is not aspectj related but java related. If you move a class from a
package to another (like from the "sensor" package to the default
package), you must change your imports in other classes accordingly,
otherwise they will still search the classes in the old package instead
of the new one. Remove those imports if they are in a class in the same
package, or at least remove the "sensor" part from them, since the
sensor package does not exist anymore.

Hope this helps,
Simone

Neo Anderson wrote:
I follow the tutorial (http://www.ibm.com/developerworks/library/j-aopwork5/) to practise design pattern. Whilst coding adaptor patterns, I encounter a problem. It is related to the path location.

The files sturcture in which code works fine looks as below:
sensor/TemperatureSensor.java
sensor/RadiationSensor.java
Test.java (where calls sensor classes)
adaptor/Adaptors.aj (adaptor pattern module)
adaptor/StatusSensor.java (sensor interface)

Everything resembles the tutorial and it works well. However, if I change the files structure to following:
TemperatureSensor.java
RadiationSensor.java
Test.java (where calls sensor classes)
adaptor/Adaptors.aj (adaptor pattern module)
adaptor/StatusSensor.java (sensor interface)

In this structure I move sensors classes to the default package (the same level as Test class)

Then when invoking ajc compiler it echos

[error] The import sensor cannot be resolved
import sensor.TemperatureSensor;
       ^^^^^
 [error] The import sensor cannot be resolved
import sensor.RadiationSensor;
       ^^^^^
 [error] TemperatureSensor cannot be resolved to a type
public String TemperatureSensor.getStatus(){
              ^^^^^^^^^^^^^^^
 [error] RadiationSensor cannot be resolved to a type
public String RadiationSensor.getStatus(){
              ^^^^^^^^^^^^^
 [error] The type TemperatureSensor must implement the inherited abstract method StatusSensor.getStatus()
public class TemperatureSensor{
             ^^^^^^^^^^^^^^^^
 [error] The type RadiationSensor must implement the inherited abstract method StatusSensor.getStatus()
public class RadiationSensor{
             ^^^^^^^^^^^^^^

What causes this error? or How should I compile the source in order to solve this error? 

Thank you very much,


      __________________________________________________________
Sent from Yahoo! Mail.
_______________________________________________
aspectj-users mailing list


_______________________________________________
aspectj-users mailing list



      __________________________________________________________
Sent from Yahoo! Mail.
_______________________________________________
aspectj-users mailing list



Sent from Yahoo! Mail.
A Smarter Email.

Back to the top