You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HelperInterfaceBinding.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.compiler.lookup;
  13. import java.util.ArrayList;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import org.aspectj.weaver.ResolvedMember;
  17. import org.aspectj.weaver.TypeX;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  20. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope;
  21. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
  22. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
  23. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
  24. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
  25. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
  26. public class HelperInterfaceBinding extends SourceTypeBinding {
  27. private TypeX typeX;
  28. SourceTypeBinding enclosingType;
  29. List methods = new ArrayList();
  30. public HelperInterfaceBinding(SourceTypeBinding enclosingType, TypeX typeX) {
  31. super();
  32. this.fPackage = enclosingType.fPackage;
  33. //this.fileName = scope.referenceCompilationUnit().getFileName();
  34. this.modifiers = AccPublic | AccInterface;
  35. this.sourceName = enclosingType.scope.referenceContext.name;
  36. this.enclosingType = enclosingType;
  37. this.typeX = typeX;
  38. this.typeVariables = NoTypeVariables;
  39. this.scope = enclosingType.scope;
  40. this.superInterfaces = new ReferenceBinding[0];
  41. }
  42. public HelperInterfaceBinding(
  43. char[][] compoundName,
  44. PackageBinding fPackage,
  45. ClassScope scope) {
  46. super(compoundName, fPackage, scope);
  47. }
  48. public char[] getFileName() {
  49. return enclosingType.getFileName();
  50. }
  51. public TypeX getTypeX() {
  52. return typeX;
  53. }
  54. public void addMethod(EclipseFactory world , ResolvedMember member) {
  55. MethodBinding binding = world.makeMethodBinding(member);
  56. this.methods.add(binding);
  57. }
  58. public FieldBinding[] fields() { return new FieldBinding[0]; }
  59. public MethodBinding[] methods() { return new MethodBinding[0]; }
  60. public char[] constantPoolName() {
  61. String sig = typeX.getSignature();
  62. return sig.substring(1, sig.length()-1).toCharArray();
  63. }
  64. public void generateClass(CompilationResult result, ClassFile enclosingClassFile) {
  65. ClassFile classFile = new ClassFile(this, enclosingClassFile, false);
  66. classFile.addFieldInfos();
  67. classFile.setForMethodInfos();
  68. for (Iterator i = methods.iterator(); i.hasNext(); ) {
  69. MethodBinding b = (MethodBinding)i.next();
  70. generateMethod(classFile, b);
  71. }
  72. classFile.addAttributes();
  73. result.record(this.constantPoolName(), classFile);
  74. }
  75. private void generateMethod(ClassFile classFile, MethodBinding binding) {
  76. classFile.generateMethodInfoHeader(binding);
  77. int methodAttributeOffset = classFile.contentsOffset;
  78. int attributeNumber = classFile.generateMethodInfoAttribute(binding);
  79. classFile.completeMethodInfo(methodAttributeOffset, attributeNumber);
  80. }
  81. public ReferenceBinding[] superInterfaces() {
  82. return new ReferenceBinding[0];
  83. }
  84. }