blob: f7af344e08c01149ff09662ea27f4ee00b6fa319 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/*
* Copyright (c) 1998-2002 PARC Inc. All rights reserved.
*
* Use and copying of this software and preparation of derivative works based
* upon this software are permitted. Any distribution of this software or
* derivative works must comply with all applicable United States export
* control laws.
*
* This software is made available AS IS, and PARC Inc. makes no
* warranty about the software, its performance or its conformity to any
* specification.
*/
package com.xerox.printing;
import java.awt.Point;
import java.io.IOException;
class ClassOne {
int i = 1 ; // 20 expect warning
}
class ClassError {
int i = 1 ; // 24 expect warning
}
class PrinterStream {}
class SubPrinterStream extends PrinterStream {
public void delegate() {
try {
throw new IOException("");
} catch (IOException e) {} // 33 expect error
}
}
class SubPoint extends Point {
Point create() { return new Point(); } // no error
Point another() { return new Point(); } // 39 expect error
}
/** @author Wes Isberg */
aspect CompileTime {
// article page 40 - warning
// START-SAMPLE declares-inoculated-nonSetterWrites Warn when setting non-public field
/** warn if setting non-public field outside a setter */
declare warning :
within(com.xerox.printing..*)
&& set(!public * *) && !withincode(* set*(..))
: "writing field outside setter" ;
// END-SAMPLE declares-inoculated-nonSetterWrites
// article page 41 - error
// START-SAMPLE declares-inoculated-validExceptionHandlingMethod Error when subclass method handles exception
declare error : handler(IOException+)
&& withincode(* PrinterStream+.delegate(..))
: "do not handle IOException in this method";
// END-SAMPLE declares-inoculated-validExceptionHandlingMethod
// START-SAMPLE declares-inoculated-validPointConstruction Error when factory not used
declare error : !withincode(Point+ SubPoint+.create(..))
&& within(com.xerox..*)
&& call(Point+.new(..))
: "use SubPoint.create() to create Point";
// END-SAMPLE declares-inoculated-validPointConstruction
}
|