1 /* *******************************************************************
2 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
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
10 * PARC initial implementation
11 * ******************************************************************/
12 package org.aspectj.ajdt.internal.compiler.lookup;
14 import java.util.ArrayList;
15 import java.util.List;
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;
30 public class HelperInterfaceBinding extends SourceTypeBinding {
31 private UnresolvedType typeX;
32 SourceTypeBinding enclosingType;
33 List<MethodBinding> methods = new ArrayList<MethodBinding>();
35 public HelperInterfaceBinding(SourceTypeBinding enclosingType, UnresolvedType typeX) {
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;
44 this.typeVariables = Binding.NO_TYPE_VARIABLES;
45 this.scope = enclosingType.scope;
46 this.superInterfaces = new ReferenceBinding[0];
49 public HelperInterfaceBinding(char[][] compoundName, PackageBinding fPackage, ClassScope scope) {
50 super(compoundName, fPackage, scope);
53 public char[] getFileName() {
54 return enclosingType.getFileName();
57 public UnresolvedType getTypeX() {
61 public void addMethod(EclipseFactory world, ResolvedMember member) {
62 MethodBinding binding = world.makeMethodBinding(member);
63 this.methods.add(binding);
66 public FieldBinding[] fields() {
67 return new FieldBinding[0];
70 public MethodBinding[] methods() {
71 return new MethodBinding[0];
74 public char[] constantPoolName() {
75 String sig = typeX.getSignature();
76 return sig.substring(1, sig.length() - 1).toCharArray();
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);
90 classFile.addAttributes();
91 result.record(this.constantPoolName(), classFile);
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);
101 public ReferenceBinding[] superInterfaces() {
102 return new ReferenceBinding[0];