Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.ast;
  13. import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
  14. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  15. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Clinit;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.codegen.BranchLabel;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.codegen.CodeStream;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel;
  20. import org.aspectj.org.eclipse.jdt.internal.compiler.codegen.Opcodes;
  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.LocalVariableBinding;
  24. import org.aspectj.weaver.AjcMemberMaker;
  25. public class AspectClinit extends Clinit {
  26. private boolean hasPre, hasPost;
  27. private FieldBinding initFailureField;
  28. public AspectClinit(Clinit old, CompilationResult compilationResult, boolean hasPre, boolean hasPost, FieldBinding initFailureField) {
  29. super(compilationResult);
  30. // CHECK do we need all the bits or just the needfreereturn bit?
  31. // if ((old.bits & ASTNode.NeedFreeReturn)!=0) this.bits |= ASTNode.NeedFreeReturn;
  32. this.bits = old.bits;
  33. this.sourceEnd = old.sourceEnd;
  34. this.sourceStart = old.sourceStart;
  35. this.declarationSourceEnd = old.declarationSourceEnd;
  36. this.declarationSourceStart = old.declarationSourceStart;
  37. this.hasPre = hasPre;
  38. this.hasPost = hasPost;
  39. this.initFailureField = initFailureField;
  40. }
  41. private ExceptionLabel handlerLabel;
  42. protected void generateSyntheticCode(
  43. ClassScope classScope,
  44. CodeStream codeStream)
  45. {
  46. if (initFailureField != null) {
  47. handlerLabel = new ExceptionLabel(codeStream, classScope.getJavaLangThrowable());
  48. handlerLabel.placeStart();
  49. }
  50. if (hasPre) {
  51. final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(classScope);
  52. codeStream.invoke(Opcodes.OPC_invokestatic,world.makeMethodBindingForCall(
  53. AjcMemberMaker.ajcPreClinitMethod(
  54. world.fromBinding(classScope.referenceContext.binding)
  55. )),null);
  56. }
  57. super.generateSyntheticCode(classScope, codeStream);
  58. }
  59. protected void generatePostSyntheticCode(
  60. ClassScope classScope,
  61. CodeStream codeStream)
  62. {
  63. super.generatePostSyntheticCode(classScope, codeStream);
  64. if (hasPost) {
  65. final EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(classScope);
  66. codeStream.invoke(Opcodes.OPC_invokestatic,world.makeMethodBindingForCall(
  67. AjcMemberMaker.ajcPostClinitMethod(
  68. world.fromBinding(classScope.referenceContext.binding)
  69. )),null);
  70. }
  71. if (initFailureField != null) {
  72. // Changes to this exception handling code may require changes to
  73. // BcelClassWeaver.isInitFailureHandler()
  74. handlerLabel.placeEnd();
  75. BranchLabel endLabel = new BranchLabel(codeStream);
  76. codeStream.goto_(endLabel);
  77. handlerLabel.place();
  78. codeStream.astore_0(); // Bug #52394
  79. // CHECK THIS...
  80. codeStream.addVariable(new LocalVariableBinding("caughtException".toCharArray(),initFailureField.type,ClassFileConstants.AccPrivate,false));
  81. codeStream.aload_0();
  82. codeStream.fieldAccess(Opcodes.OPC_putstatic, initFailureField, null);
  83. endLabel.place();
  84. }
  85. }
  86. }