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.

IfMethodDeclaration.java 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.ClassFile;
  15. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ReturnStatement;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser;
  20. import org.aspectj.weaver.Member;
  21. import org.aspectj.weaver.ResolvedMemberImpl;
  22. import org.aspectj.weaver.UnresolvedType;
  23. import org.aspectj.weaver.patterns.IfPointcut;
  24. import org.aspectj.weaver.patterns.PerClause;
  25. public class IfMethodDeclaration extends AjMethodDeclaration {
  26. IfPointcut ifPointcut;
  27. public IfMethodDeclaration(CompilationResult compilationResult, IfPointcut ifPointcut) {
  28. super(compilationResult);
  29. this.ifPointcut = ifPointcut;
  30. }
  31. public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
  32. // do nothing, we're already fully parsed
  33. }
  34. protected int generateInfoAttributes(ClassFile classFile) {
  35. return classFile.generateMethodInfoAttributes(binding, AstUtil.getAjSyntheticAttribute());
  36. }
  37. public void resolveStatements() {
  38. super.resolveStatements();
  39. if (binding != null) {
  40. ThisJoinPointVisitor tjp = new ThisJoinPointVisitor(this);
  41. ifPointcut.extraParameterFlags |= tjp.removeUnusedExtraArguments();
  42. // Check for FALSE or TRUE constant reference
  43. if (statements != null && statements.length == 1 && statements[0] instanceof ReturnStatement) {
  44. if (tjp.hasConstantReference) {
  45. if (tjp.constantReferenceValue == true) {
  46. ifPointcut.setAlways(true);
  47. } else {
  48. ifPointcut.setAlways(false);
  49. }
  50. return;
  51. }
  52. }
  53. // XXX this is where we should remove unavailable args if we're in a cflow
  54. EclipseFactory factory = EclipseFactory.fromScopeLookupEnvironment(scope);
  55. ifPointcut.testMethod = new ResolvedMemberImpl(Member.METHOD, factory.fromBinding(binding.declaringClass),
  56. this.modifiers, UnresolvedType.BOOLEAN, new String(this.selector),
  57. factory.fromBindings(this.binding.parameters));
  58. if (tjp.needsThisAspectInstance && scope.parent instanceof ClassScope) { // really should be
  59. ClassScope o = (ClassScope) scope.parent;
  60. if (o.referenceContext instanceof AspectDeclaration) { // really should be
  61. AspectDeclaration aspectDecl = (AspectDeclaration) o.referenceContext;
  62. if (aspectDecl.perClause != null && aspectDecl.perClause.getKind() != PerClause.SINGLETON) {
  63. scope.problemReporter()
  64. .signalError(sourceStart, sourceEnd,
  65. "thisAspectInstance can only be used inside an if() clause for singleton aspects (compiler limitation)");
  66. ignoreFurtherInvestigation = true;
  67. return;
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }