Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] final variables

Here's how you can check that the final *member variables* do not contain lower case letters. There's a caveat: it doesn't work for String or primitive type constants, because Java requires them to be inlined. I also suggest specifying your package scope (e.g., "static final * com.acme..*+.*a*") to avoid matching things like System.out.

declare warning :
   get(static final * *a*) ||
   set(static final * *a*) ||
   get(static final * *b*) ||
   set(static final * *b*) ||
   ...
   get(static final * *z*) ||
   set(static final * *z*) :
   "Names of constants should not contain lower case letters.";


Paulo Merson




Paulo Alexandre Corigo Zenida wrote:

Good afternoon,

I am trying to enforce the naming convention in which one says that final "the names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.)" (in http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html#367).

	The source code I tried to enforce this is the following:

public class A {

	private final String RIGHT_NAME = "1";
			
	private final String wrong_name;
	
	private int x = 1;
	
	{
		final String x = "1";
		System.out.println(x);
	}
	
	public A() {
		wrong_name = "2";
		System.out.println(RIGHT_NAME + "," + wrong_name);
		System.out.println(x);
	}
}

public aspect EnforceFinalVariablesNamingConventionAspect {

	public pointcut x() :
		set(final * *.*) ||
		get(final * *.*);

	// it's capturing only gets, and all gets, final or not. Why?!
declare warning : x() : "Final variable";
}


	Am I doing something wrong or what I'm trying to do is not possible?

	Thanks in advance. Best regards,

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



Back to the top