Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

BindingScope.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* *******************************************************************
  2. * Copyright (c) 2006-2008 Contributors
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * ******************************************************************/
  10. package org.aspectj.weaver;
  11. import org.aspectj.bridge.ISourceLocation;
  12. import org.aspectj.weaver.patterns.FormalBinding;
  13. import org.aspectj.weaver.patterns.SimpleScope;
  14. /**
  15. * BindingScope that knows the enclosingType, which is needed for pointcut reference resolution
  16. *
  17. * @author Alexandre Vasseur
  18. * @author Andy Clement
  19. */
  20. public class BindingScope extends SimpleScope {
  21. private final ResolvedType enclosingType;
  22. private final ISourceContext sourceContext;
  23. private boolean importsUpdated = false;
  24. public BindingScope(ResolvedType type, ISourceContext sourceContext, FormalBinding[] bindings) {
  25. super(type.getWorld(), bindings);
  26. this.enclosingType = type;
  27. this.sourceContext = sourceContext;
  28. }
  29. public ResolvedType getEnclosingType() {
  30. return enclosingType;
  31. }
  32. public ISourceLocation makeSourceLocation(IHasPosition location) {
  33. return sourceContext.makeSourceLocation(location);
  34. }
  35. public UnresolvedType lookupType(String name, IHasPosition location) {
  36. // bug 126560
  37. if (enclosingType != null && !importsUpdated) {
  38. // add the package we're in to the list of imported
  39. // prefixes so that we can find types in the same package
  40. String pkgName = enclosingType.getPackageName();
  41. if (pkgName != null && !pkgName.equals("")) {
  42. String[] existingImports = getImportedPrefixes();
  43. String pkgNameWithDot = pkgName.concat(".");
  44. boolean found = false;
  45. for (String existingImport : existingImports) {
  46. if (existingImport.equals(pkgNameWithDot)) {
  47. found = true;
  48. break;
  49. }
  50. }
  51. if (!found) {
  52. String[] newImports = new String[existingImports.length + 1];
  53. System.arraycopy(existingImports, 0, newImports, 0, existingImports.length);
  54. newImports[existingImports.length] = pkgNameWithDot;
  55. setImportedPrefixes(newImports);
  56. }
  57. }
  58. importsUpdated = true;
  59. }
  60. return super.lookupType(name, location);
  61. }
  62. }