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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. import java.util.ArrayList;
  14. import java.util.List;
  15. import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Binding;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope;
  20. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
  21. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
  22. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
  23. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
  24. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
  25. import org.aspectj.weaver.ResolvedMember;
  26. import org.aspectj.weaver.UnresolvedType;
  27. public class HelperInterfaceBinding extends SourceTypeBinding {
  28. private UnresolvedType typeX;
  29. SourceTypeBinding enclosingType;
  30. List<MethodBinding> methods = new ArrayList<>();
  31. public HelperInterfaceBinding(SourceTypeBinding enclosingType, UnresolvedType typeX) {
  32. super();
  33. this.fPackage = enclosingType.fPackage;
  34. // this.fileName = scope.referenceCompilationUnit().getFileName();
  35. this.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccInterface
  36. | ClassFileConstants.AccAbstract;
  37. this.sourceName = enclosingType.scope.referenceContext.name;
  38. this.enclosingType = enclosingType;
  39. this.typeX = typeX;
  40. this.typeVariables = Binding.NO_TYPE_VARIABLES;
  41. this.scope = enclosingType.scope;
  42. this.superInterfaces = new ReferenceBinding[0];
  43. }
  44. public HelperInterfaceBinding(char[][] compoundName, PackageBinding fPackage, ClassScope scope) {
  45. super(compoundName, fPackage, scope);
  46. }
  47. public char[] getFileName() {
  48. return enclosingType.getFileName();
  49. }
  50. public UnresolvedType getTypeX() {
  51. return typeX;
  52. }
  53. public void addMethod(EclipseFactory world, ResolvedMember member) {
  54. MethodBinding binding = world.makeMethodBinding(member);
  55. this.methods.add(binding);
  56. }
  57. public FieldBinding[] fields() {
  58. return new FieldBinding[0];
  59. }
  60. public MethodBinding[] methods() {
  61. return new MethodBinding[0];
  62. }
  63. public char[] constantPoolName() {
  64. String sig = typeX.getSignature();
  65. return sig.substring(1, sig.length() - 1).toCharArray();
  66. }
  67. public void generateClass(CompilationResult result, ClassFile enclosingClassFile) {
  68. ClassFile classFile = new ClassFile(this);
  69. classFile.initialize(this, enclosingClassFile, false);
  70. // classFile.recordInnerClasses(this);
  71. // classFile.addFieldInfos();
  72. classFile.contents[classFile.contentsOffset++] = (byte) 0;
  73. classFile.contents[classFile.contentsOffset++] = (byte) 0;
  74. classFile.setForMethodInfos();
  75. for (MethodBinding b: methods) {
  76. generateMethod(classFile, b);
  77. }
  78. classFile.addAttributes();
  79. result.record(this.constantPoolName(), classFile);
  80. }
  81. private void generateMethod(ClassFile classFile, MethodBinding binding) {
  82. classFile.generateMethodInfoHeader(binding);
  83. int methodAttributeOffset = classFile.contentsOffset;
  84. int attributeNumber = classFile.generateMethodInfoAttributes(binding);
  85. classFile.completeMethodInfo(binding, methodAttributeOffset, attributeNumber);
  86. }
  87. public ReferenceBinding[] superInterfaces() {
  88. return new ReferenceBinding[0];
  89. }
  90. }