blob: 7b5aa8c86f0f66a230195644444eeb13dff58581 (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/* *******************************************************************
* Copyright (c) 2005 Contributors.
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
*
* Contributors:
* Adrian Colyer Initial implementation
* ******************************************************************/
package org.aspectj.internal.lang.reflect;
import java.lang.reflect.Type;
import org.aspectj.lang.reflect.AjType;
import org.aspectj.lang.reflect.DeclareParents;
import org.aspectj.lang.reflect.TypePattern;
/**
* @author colyer
*
*/
public class DeclareParentsImpl implements DeclareParents {
private AjType<?> declaringType;
private TypePattern targetTypesPattern;
private Type[] parents;
private String parentsString;
private String firstMissingTypeName;
private boolean isExtends;
private boolean parentsError = false;
// Parents arg is a comma-separate list of type names that needs to be turned into
// AjTypes
public DeclareParentsImpl(String targets, String parentsAsString, boolean isExtends, AjType<?> declaring)
{
this.targetTypesPattern = new TypePatternImpl(targets);
this.isExtends = isExtends;
this.declaringType = declaring;
this.parentsString = parentsAsString;
try {
this.parents = StringToType.commaSeparatedListToTypeArray(parentsAsString, declaring.getJavaClass());
} catch (ClassNotFoundException cnfEx) {
this.parentsError = true;
this.firstMissingTypeName = cnfEx.getMessage();
}
}
public AjType getDeclaringType() {
return this.declaringType;
}
public TypePattern getTargetTypesPattern() {
return this.targetTypesPattern;
}
public boolean isExtends() {
return this.isExtends;
}
public boolean isImplements() {
return !this.isExtends;
}
public Type[] getParentTypes() throws ClassNotFoundException {
if (parentsError) {
throw new ClassNotFoundException(this.firstMissingTypeName);
}
return this.parents;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("declare parents : ");
sb.append(getTargetTypesPattern().asString());
sb.append(isExtends() ? " extends " : " implements ");
sb.append(this.parentsString);
return sb.toString();
}
}
|