View | Details | Raw Unified | Return to bug 145047
Collapse All | Expand All

(-)src/org/aspectj/asm/IProgramElement.java (-3 / +4 lines)
Lines 116-127 Link Here
116
	public String toLabelString();
116
	public String toLabelString();
117
	public String toLabelString(boolean getFullyQualifiedArgTypes);
117
	public String toLabelString(boolean getFullyQualifiedArgTypes);
118
118
119
	public List getParameterTypes();
120
	public void setParameterTypes(List list);
121
122
	public List getParameterNames();
119
	public List getParameterNames();
123
	public void setParameterNames(List list);
120
	public void setParameterNames(List list);
124
	
121
	
122
	public List getParameterSignatures();
123
	public void setParameterSignatures(List list);
124
	public List getParameterTypes();
125
	
125
	/**
126
	/**
126
	 * The format of the string handle is not specified, but is stable across 
127
	 * The format of the string handle is not specified, but is stable across 
127
	 * compilation sessions.
128
	 * compilation sessions.
(-)src/org/aspectj/asm/internal/ProgramElement.java (-12 / +112 lines)
Lines 408-423 Link Here
408
		sb.append(name);
408
		sb.append(name);
409
		
409
		
410
		List ptypes = getParameterTypes();
410
		List ptypes = getParameterTypes();
411
		if (ptypes != null) {
411
		if (ptypes != null && (!ptypes.isEmpty() 
412
				|| this.kind.equals(IProgramElement.Kind.METHOD))
413
				|| this.kind.equals(IProgramElement.Kind.CONSTRUCTOR)
414
				|| this.kind.equals(IProgramElement.Kind.ADVICE)
415
				|| this.kind.equals(IProgramElement.Kind.POINTCUT)
416
				|| this.kind.equals(IProgramElement.Kind.INTER_TYPE_METHOD)
417
				|| this.kind.equals(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR)) {
412
			sb.append('('); 
418
			sb.append('('); 
413
			for (Iterator it = ptypes.iterator(); it.hasNext(); ) {
419
			for (Iterator it = ptypes.iterator(); it.hasNext(); ) {
414
				String arg = (String)it.next();
420
				char[] arg = (char[])it.next();
415
				if (getFullyQualifiedArgTypes) {
421
				if (getFullyQualifiedArgTypes) {
416
					sb.append(arg);
422
					sb.append(arg);
417
				} else {
423
				} else {
418
					int index = arg.lastIndexOf(".");
424
					int index = CharOperation.lastIndexOf('.',arg);
419
					if (index != -1) {
425
					if (index != -1) {
420
						sb.append(arg.substring(index + 1));
426
						sb.append(CharOperation.subarray(arg,index+1,arg.length));
421
					} else {
427
					} else {
422
						sb.append(arg);
428
						sb.append(arg);
423
					}
429
					}
Lines 503-519 Link Here
503
		//parameterNames = list; 
509
		//parameterNames = list; 
504
	}
510
	}
505
511
506
	public List getParameterTypes() { 
512
	public List getParameterTypes() {
507
		List parameterTypes = (List)kvpairs.get("parameterTypes");
513
		List l = getParameterSignatures();
508
		return parameterTypes; 
514
		if (l == null || l.isEmpty()) {
515
			return Collections.EMPTY_LIST;
516
		}
517
		List params = new ArrayList();
518
		for (Iterator iter = l.iterator(); iter.hasNext();) {
519
			params.add(createReadableName((char[]) iter.next()));
520
		}
521
		return params;
509
	}
522
	}
510
	public void setParameterTypes(List list) { 
523
	
511
		if (kvpairs==Collections.EMPTY_MAP) kvpairs = new HashMap();
524
	public List getParameterSignatures() {
512
		if (list==null || list.size()==0) kvpairs.put("parameterTypes",Collections.EMPTY_LIST);
525
		List parameters = (List)kvpairs.get("parameterSigs");
513
		else                               kvpairs.put("parameterTypes",list);
526
		return parameters;
514
//		parameterTypes = list; 
515
	}
527
	}
516
528
529
	public void setParameterSignatures(List list) {
530
		if (kvpairs==Collections.EMPTY_MAP) kvpairs = new HashMap();
531
		if (list==null || list.size()==0) kvpairs.put("parameterSigs",Collections.EMPTY_LIST);
532
		else kvpairs.put("parameterSigs",list);
533
	}
534
	
517
	public String getDetails() {
535
	public String getDetails() {
518
		String details = (String)kvpairs.get("details");
536
		String details = (String)kvpairs.get("details");
519
		return details; 
537
		return details; 
Lines 548-552 Link Here
548
	public ExtraInformation getExtraInfo() {
566
	public ExtraInformation getExtraInfo() {
549
		return (ExtraInformation)kvpairs.get("ExtraInformation");
567
		return (ExtraInformation)kvpairs.get("ExtraInformation");
550
	}
568
	}
569
570
	/**
571
	 * Creates a readable name from the given char array, for example, 
572
	 * given 'I' returns 'int'. Moreover, given 
573
	 * 'Ljava/lang/String;<Ljava/lang/String;>' returns
574
	 * 'java.lang.String<java.lang.String>'
575
	 */
576
	private char[] createReadableName(char[] c) {
577
		int lt = CharOperation.indexOf('<',c);
578
		int sc = CharOperation.indexOf(';',c);
579
		int gt = CharOperation.indexOf('>',c);
580
		
581
		int smallest = 0;
582
		if (lt == -1 && sc == -1 && gt == -1) {
583
			// we have something like 'Ljava/lang/String' or 'I'
584
			return getTypeName(c);
585
		} else if (lt != -1 && (sc == -1 || lt <= sc) && (gt == -1 || lt <= gt)) {
586
			// we have something like 'Ljava/lang/String<I'
587
			smallest = lt;
588
		} else if (sc != -1 && (lt == -1 || sc <= lt) && (gt == -1 || sc <= gt)) {
589
			// we have something like 'Ljava/lang/String;I'
590
			smallest = sc;
591
		} else {
592
			// we have something like '>;'
593
			smallest = gt;
594
		}
595
		char[] first = CharOperation.subarray(c,0,smallest);
596
		char[] second = CharOperation.subarray(c,smallest+1,c.length);
597
		if (smallest == 0 && first.length == 0 && c[0] == '>') {
598
			// c = {'>',';'} therefore we just want to return '>' to
599
			// close the generic signature
600
			return new char[]{'>'};
601
		} else if (first.length == 1 && second.length == 0) {
602
			return first;
603
		} else if (second.length == 0 || (second.length == 1 && second[0] == ';')){
604
			// we've reached the end of the array, therefore only care about
605
			// the first part
606
			return createReadableName(first);
607
		} else if (smallest == lt) {
608
			// if c = 'Ljava/lang/String;<I' then first = 'Ljava/Lang/String;' and
609
			// second = 'I'. Want to end up with 'Ljava.lang.String<I' and so add
610
			// the '<' back.
611
			char[] inclLT = CharOperation.concat(createReadableName(first),new char[]{'<'});
612
			return CharOperation.concat(inclLT,createReadableName(second));
613
		} else if (smallest == gt) {
614
			char[] inclLT = CharOperation.concat(createReadableName(first),new char[]{'>'});
615
			return CharOperation.concat(inclLT,createReadableName(second));			
616
		} else if (second.length != 2) {
617
			// if c = 'Ljava/lang/Sting;LMyClass' then first = 'Ljava/lang/String'
618
			// and second = 'LMyClass'. Want to end up with 'java.lang.String,MyClass
619
			// so want to add a ','. However, only want to do this if we're in the 
620
			// middle of a '<...>'
621
			char[] inclComma = CharOperation.concat(createReadableName(first),new char[]{','});
622
			return CharOperation.concat(inclComma,createReadableName(second));
623
		}
624
		return CharOperation.concat(createReadableName(first),createReadableName(second));
625
	}
626
	
627
	/**
628
	 * Given a char array, returns the type name for this. For example, given
629
	 * 'I' returns 'int' and given 'Ljava/lang/String' returns 'java.lang.String'
630
	 * Doesn't go any deaper so given 'Ljava/lang/String;<Ljava/lang/String;>' it
631
	 * returns 'java.lang.String;<Ljava.lang.String;>'. To create a fully readable
632
	 * name use createReadableName(char[])
633
	 */
634
	private char[] getTypeName(char[] c) {
635
		if (c.length == 0) {
636
			return c;
637
		} 
638
		SignatureType st = SignatureType.getSignatureTypeForChar(c[0]);
639
		if (st.isPrimitiveType()) {
640
			return st.getTypeName();
641
		} else if (st.isArray()) {
642
			return CharOperation.concat(
643
					getTypeName(CharOperation.subarray(c,1,c.length)),
644
					new char[]{'[',']'});
645
		} else {
646
			char[] type = CharOperation.subarray(c,1,c.length);
647
			CharOperation.replace(type,'/','.');
648
			return type;
649
		}
650
	}
551
}
651
}
552
652
(-)src/org/aspectj/asm/internal/CharOperation.java (+107 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2006 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: IBM Corporation - initial API and implementation 
9
 * 				 Helen Hawkins   - iniital version
10
 *******************************************************************/
11
package org.aspectj.asm.internal;
12
13
14
/**
15
 * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
16
 *
17
 */
18
public class CharOperation {
19
20
	/**
21
	 * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
22
	 */	
23
	public static final int indexOf(char toBeFound, char[] array) {
24
		for (int i = 0; i < array.length; i++)
25
			if (toBeFound == array[i])
26
				return i;
27
		return -1;
28
	}
29
	
30
	/**
31
	 * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
32
	 */	
33
	public static final char[] subarray(char[] array, int start, int end) {
34
		if (end == -1)
35
			end = array.length;
36
		if (start > end)
37
			return null;
38
		if (start < 0)
39
			return null;
40
		if (end > array.length)
41
			return null;
42
43
		char[] result = new char[end - start];
44
		System.arraycopy(array, start, result, 0, end - start);
45
		return result;
46
	}
47
	
48
	/**
49
	 * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
50
	 */	
51
	public static final void replace(
52
			char[] array,
53
			char toBeReplaced,
54
			char replacementChar) {
55
			if (toBeReplaced != replacementChar) {
56
				for (int i = 0, max = array.length; i < max; i++) {
57
					if (array[i] == toBeReplaced)
58
						array[i] = replacementChar;
59
				}
60
			}
61
		}
62
	
63
	/**
64
	 * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
65
	 */	
66
	public static final int lastIndexOf(char toBeFound, char[] array) {
67
		for (int i = array.length; --i >= 0;)
68
			if (toBeFound == array[i])
69
				return i;
70
		return -1;
71
	}
72
	
73
	/**
74
	 * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
75
	 */	
76
	public static final char[] concat(char[] first, char[] second) {
77
		if (first == null)
78
			return second;
79
		if (second == null)
80
			return first;
81
82
		int length1 = first.length;
83
		int length2 = second.length;
84
		char[] result = new char[length1 + length2];
85
		System.arraycopy(first, 0, result, 0, length1);
86
		System.arraycopy(second, 0, result, length1, length2);
87
		return result;
88
	}
89
90
	/**
91
	 * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation
92
	 */	
93
	public static final boolean equals(char[] first, char[] second) {
94
		if (first == second)
95
			return true;
96
		if (first == null || second == null)
97
			return false;
98
		if (first.length != second.length)
99
			return false;
100
101
		for (int i = first.length; --i >= 0;)
102
			if (first[i] != second[i])
103
				return false;
104
		return true;
105
	}
106
	
107
}
(-)src/org/aspectj/asm/internal/SignatureType.java (+128 lines)
Added Link Here
1
/********************************************************************
2
 * Copyright (c) 2006 Contributors. All rights reserved. 
3
 * This program and the accompanying materials are made available 
4
 * under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution and is available at 
6
 * http://eclipse.org/legal/epl-v10.html 
7
 *  
8
 * Contributors: IBM Corporation - initial API and implementation 
9
 * 				 Helen Hawkins   - iniital version
10
 *******************************************************************/
11
package org.aspectj.asm.internal;
12
13
public class SignatureType {
14
	
15
	private static final char C_BOOLEAN 	= 'Z';
16
	private static final char C_BYTE 		= 'B';
17
	private static final char C_CHAR 		= 'C';
18
	private static final char C_DOUBLE 		= 'D';
19
	private static final char C_FLOAT 		= 'F';
20
	private static final char C_INT 		= 'I';
21
	private static final char C_LONG		= 'J';
22
	private static final char C_SHORT		= 'S';
23
	private static final char C_ARRAY		= '[';
24
	private static final char C_RESOLVED	= 'L';
25
	private static final char C_UNRESOLVED	= 'Q';
26
	
27
	public static final SignatureType BOOLEAN = new SignatureType(C_BOOLEAN);
28
	public static final SignatureType BYTE = new SignatureType(C_BYTE);
29
	public static final SignatureType CHAR = new SignatureType(C_CHAR);
30
	public static final SignatureType DOUBLE = new SignatureType(C_DOUBLE);
31
	public static final SignatureType FLOAT = new SignatureType(C_FLOAT);
32
	public static final SignatureType INT = new SignatureType(C_INT);
33
	public static final SignatureType LONG = new SignatureType(C_LONG);
34
	public static final SignatureType SHORT = new SignatureType(C_SHORT);
35
	public static final SignatureType ARRAY = new SignatureType(C_ARRAY);
36
	public static final SignatureType RESOLVED = new SignatureType(C_RESOLVED);
37
	public static final SignatureType UNRESOLVED = new SignatureType(C_UNRESOLVED);
38
	public static final SignatureType ERROR = new SignatureType('E');
39
40
	private static final char[] c_boolean = new char[]{'b','o','o','l','e','a','n'};
41
	private static final char[] c_byte = new char[]{'b','y','t','e'};
42
	private static final char[] c_char = new char[]{'c','h','a','r'};
43
	private static final char[] c_double = new char[]{'d','o','u','b','l','e'};
44
	private static final char[] c_float = new char[]{'f','l','o','a','t'};
45
	private static final char[] c_int = new char[]{'i','n','t'};
46
	private static final char[] c_long = new char[]{'l','o','n','g'};
47
	private static final char[] c_short = new char[]{'s','h','o','r','t'};
48
	
49
	public static final SignatureType[] ALL = {
50
		BOOLEAN,BYTE,CHAR,DOUBLE,FLOAT,INT,LONG,SHORT,ARRAY,RESOLVED,UNRESOLVED
51
	};
52
	
53
	final char name;
54
	
55
	private SignatureType(char name) {
56
		this.name = name;
57
	}
58
	
59
	public char getName() {
60
		return name;
61
	}
62
	
63
	public static SignatureType getSignatureTypeForChar(char charType) {
64
		for (int i = 0; i < ALL.length; i++) {
65
			if (ALL[i].getName() == charType) return ALL[i];	
66
		}
67
		return ERROR;
68
	}
69
	
70
	public static char getTypeForCharName(char[] charName) {
71
		if (CharOperation.equals(charName,c_boolean)) {
72
			return C_BOOLEAN;
73
		} else if (CharOperation.equals(charName,c_byte)) {
74
			return C_BYTE;
75
		} else if (CharOperation.equals(charName,c_char)) {
76
			return C_CHAR;
77
		} else if (CharOperation.equals(charName,c_double)) {
78
			return C_DOUBLE;
79
		} else if (CharOperation.equals(charName,c_float)) {
80
			return C_FLOAT;
81
		} else if (CharOperation.equals(charName,c_int)) {
82
			return C_INT;
83
		} else if (CharOperation.equals(charName,c_long)) {
84
			return C_LONG;
85
		} else if (CharOperation.equals(charName,c_short)) {
86
			return C_SHORT;
87
		} else {
88
			return C_UNRESOLVED;
89
		}
90
	}
91
	
92
	public char[] getTypeName() {
93
		if (this.equals(BOOLEAN)) {
94
			return c_boolean;
95
		} else if (this.equals(BYTE)) {
96
			return c_byte;
97
		} else if (this.equals(CHAR)) {
98
			return c_char;
99
		} else if (this.equals(DOUBLE)) {
100
			return c_double;
101
		} else if (this.equals(FLOAT)) {
102
			return c_float;
103
		} else if (this.equals(INT)) {
104
			return c_int;
105
		} else if (this.equals(LONG)) {
106
			return c_long;
107
		} else if (this.equals(SHORT)) {
108
			return c_short;
109
		} 
110
		return new char[0];
111
	}
112
	
113
	public boolean isArray() {
114
		return this == ARRAY;
115
	}
116
	
117
	public boolean isPrimitiveType() {
118
		return this == BOOLEAN
119
		|| this == BYTE
120
		|| this == CHAR
121
		|| this == DOUBLE
122
		|| this == FLOAT
123
		|| this == INT
124
		|| this == LONG
125
		|| this == SHORT;
126
	}
127
128
}

Return to bug 145047