]> source.dussan.org Git - aspectj.git/blob
a9c4bd532aebca2e910fc0d269a5c2e06e45e619
[aspectj.git] /
1 /* *******************************************************************
2  * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
3  * All rights reserved. 
4  * This program and the accompanying materials are made available 
5  * under the terms of the Eclipse Public License v1.0 
6  * which accompanies this distribution and is available at 
7  * http://www.eclipse.org/legal/epl-v10.html 
8  *  
9  * Contributors: 
10  *     PARC     initial implementation 
11  * ******************************************************************/
12 package org.aspectj.ajdt.internal.compiler.lookup;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
18 import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
19 import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
20 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Binding;
21 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope;
22 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
23 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
24 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
25 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
26 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
27 import org.aspectj.weaver.ResolvedMember;
28 import org.aspectj.weaver.UnresolvedType;
29
30 public class HelperInterfaceBinding extends SourceTypeBinding {
31         private UnresolvedType typeX;
32         SourceTypeBinding enclosingType;
33         List<MethodBinding> methods = new ArrayList<MethodBinding>();
34
35         public HelperInterfaceBinding(SourceTypeBinding enclosingType, UnresolvedType typeX) {
36                 super();
37                 this.fPackage = enclosingType.fPackage;
38                 // this.fileName = scope.referenceCompilationUnit().getFileName();
39                 this.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccInterface
40                                 | ClassFileConstants.AccAbstract;
41                 this.sourceName = enclosingType.scope.referenceContext.name;
42                 this.enclosingType = enclosingType;
43                 this.typeX = typeX;
44                 this.typeVariables = Binding.NO_TYPE_VARIABLES;
45                 this.scope = enclosingType.scope;
46                 this.superInterfaces = new ReferenceBinding[0];
47         }
48
49         public HelperInterfaceBinding(char[][] compoundName, PackageBinding fPackage, ClassScope scope) {
50                 super(compoundName, fPackage, scope);
51         }
52
53         public char[] getFileName() {
54                 return enclosingType.getFileName();
55         }
56
57         public UnresolvedType getTypeX() {
58                 return typeX;
59         }
60
61         public void addMethod(EclipseFactory world, ResolvedMember member) {
62                 MethodBinding binding = world.makeMethodBinding(member);
63                 this.methods.add(binding);
64         }
65
66         public FieldBinding[] fields() {
67                 return new FieldBinding[0];
68         }
69
70         public MethodBinding[] methods() {
71                 return new MethodBinding[0];
72         }
73
74         public char[] constantPoolName() {
75                 String sig = typeX.getSignature();
76                 return sig.substring(1, sig.length() - 1).toCharArray();
77         }
78
79         public void generateClass(CompilationResult result, ClassFile enclosingClassFile) {
80                 ClassFile classFile = new ClassFile(this);
81                 classFile.initialize(this, enclosingClassFile, false);
82 //              classFile.recordInnerClasses(this);
83                 // classFile.addFieldInfos();
84                 classFile.contents[classFile.contentsOffset++] = (byte) 0;
85                 classFile.contents[classFile.contentsOffset++] = (byte) 0;
86                 classFile.setForMethodInfos();
87                 for (MethodBinding b: methods) {
88                         generateMethod(classFile, b);
89                 }
90                 classFile.addAttributes();
91                 result.record(this.constantPoolName(), classFile);
92         }
93
94         private void generateMethod(ClassFile classFile, MethodBinding binding) {
95                 classFile.generateMethodInfoHeader(binding);
96                 int methodAttributeOffset = classFile.contentsOffset;
97                 int attributeNumber = classFile.generateMethodInfoAttributes(binding);
98                 classFile.completeMethodInfo(binding, methodAttributeOffset, attributeNumber);
99         }
100
101         public ReferenceBinding[] superInterfaces() {
102                 return new ReferenceBinding[0];
103         }
104
105 }