Skip to main content

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

Thanks for your help Jeffrey, but I would like to warning at the lack of the
default constructor, and I think it's not possible...

Andre

-----Mensagem original-----
De: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx]
Em nome de Jeffrey Palm
Enviada em: segunda-feira, 29 de março de 2004 17:47
Para: aspectj-users@xxxxxxxxxxx
Assunto: Re: RES: [aspectj-users] Declare error

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