Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: RES: [aspectj-users] Declare error

The problem with this solution is that it will flag any non-default
constructor. Thus the implementation of BadA below should be ok (it has a
default constructor) but is incorrectly flagged by aspect C.

I don't think this can be done at compile time with the current compiler. The problem is that declare warning/error flags individual offensive join point. The error you are attempting to detect is the lack of a join point
(default constructor) in a set of join points (constructors of a given
class). I think Ron's solution is the best so far.

Cheers,
Nick


public class Andre {
    public static void main(String[] args) {}

    static class A {}
    static class GoodA extends A { GoodA() {} }
    static class BadA extends A {
        BadA(String s) {}
        BadA(){}//whoops! This should be OK!
    }
    static class WhoCares1 { WhoCares1() {} }
    static class WhoCares2 { WhoCares2(String s) {} }

    static aspect C {
      pointcut p():
        execution(A+.new(..)) &&  !execution(A+.new());
      declare error: p() : "boooo!";
    }
}

On Mar 29, 2004, at 1:47 PM, Jeffrey Palm wrote:

André Dantas Rocha wrote:

Hi Jitesh,
The problem is that I would like to do this in compile time, using errors or
warnings... Andre
-----Mensagem original-----
De: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx]
Em nome de JITESH KALYANI Shivanand
Enviada em: sexta-feira, 26 de março de 2004 16:41
Para: aspectj-users@xxxxxxxxxxx
Assunto: RE: [aspectj-users] Declare error
HI,
I have tried small example. We can have poincut to constructor and check if it is default constructor OR prameterised constructor. If it is prameterised
constructor, throw error. See if this u want.
class constructorTest  {	
	int a = 0;
	public static void main(String[] args) 	{
constructorTest obj1 = new constructorTest(); constructorTest obj2 = new constructorTest(10);
		System.out.println("Program Over!");
	}
	
	public constructorTest() {
		System.out.println("Executing Default Constructor");
	}
	
	public constructorTest(int a) {
		this.a = a;
		System.out.println("Executing parameterised Constructor : a
= "+a);
	}
}
aspect testaspect
{
	pointcut myConstructor() : within(constructorTest) &&
execution(constructorTest+.new(..));
	 before (): myConstructor() {
		 Object[] args = thisJoinPoint.getArgs();
        		if(args.length == 0) {
			System.out.println("Default Constructor");
		}else {
			System.out.println("Parameterised Constructor");
			//throw error.
		}
	}
}
Jitesh
----------
From:
aspectj-users-admin@xxxxxxxxxxx[SMTP:aspectj-users-admin@xxxxxxxxxxx] on
behalf of André Dantas Rocha[SMTP:ad-rocha@xxxxxxxxxx]
Reply To: 	aspectj-users@xxxxxxxxxxx
Sent: 	Friday, March 26, 2004 5:17 PM
To: 	aspectj-users@xxxxxxxxxxx
Subject: 	RES: [aspectj-users] Declare error

I don't know how to....

 _____

De: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx] Em nome de Nicholas Lesiecki Enviada em: sexta-feira, 26 de março de 2004 01:51
Para: aspectj-users@xxxxxxxxxxx
Assunto: Re: [aspectj-users] Declare error


Possibly. Can you write an attempt at doing this and submit it to the
list?
Nick
On Mar 25, 2004, at 12:53 PM, André Dantas Rocha wrote:



Hi,
I would like to declare an error if any subtype of ClassA do not have a
default constructor.
Is it possible?
Thanks



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users

Try this:

public class Andre {

  public static void main(String[] args) {}

  static class A {}
  static class GoodA extends A { GoodA() {} }
  static class BadA extends A { BadA(String s) {} }
  static class WhoCares1 { WhoCares1() {} }
  static class WhoCares2 { WhoCares2(String s) {} }

  static aspect C {
    pointcut p():
      execution(A+.new(..)) &&  !execution(A+.new());
    declare error: p() : "boooo!";
  }
}

Jeff

--
Jeffrey Palm --> http://www.ccs.neu.edu/home/jpalm
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top