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.

DeclareParentsImpl.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  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://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.internal.lang.reflect;
  13. import java.lang.reflect.Type;
  14. import org.aspectj.lang.reflect.AjType;
  15. import org.aspectj.lang.reflect.DeclareParents;
  16. import org.aspectj.lang.reflect.TypePattern;
  17. /**
  18. * @author colyer
  19. *
  20. */
  21. public class DeclareParentsImpl implements DeclareParents {
  22. private AjType<?> declaringType;
  23. private TypePattern targetTypesPattern;
  24. private Type[] parents;
  25. private String parentsString;
  26. private String firstMissingTypeName;
  27. private boolean isExtends;
  28. private boolean parentsError = false;
  29. // Parents arg is a comma-separate list of type names that needs to be turned into
  30. // AjTypes
  31. public DeclareParentsImpl(String targets, String parentsAsString, boolean isExtends, AjType<?> declaring)
  32. {
  33. this.targetTypesPattern = new TypePatternImpl(targets);
  34. this.isExtends = isExtends;
  35. this.declaringType = declaring;
  36. this.parentsString = parentsAsString;
  37. try {
  38. this.parents = StringToType.commaSeparatedListToTypeArray(parentsAsString, declaring.getJavaClass());
  39. } catch (ClassNotFoundException cnfEx) {
  40. this.parentsError = true;
  41. this.firstMissingTypeName = cnfEx.getMessage();
  42. }
  43. }
  44. public AjType getDeclaringType() {
  45. return this.declaringType;
  46. }
  47. public TypePattern getTargetTypesPattern() {
  48. return this.targetTypesPattern;
  49. }
  50. public boolean isExtends() {
  51. return this.isExtends;
  52. }
  53. public boolean isImplements() {
  54. return !this.isExtends;
  55. }
  56. public Type[] getParentTypes() throws ClassNotFoundException {
  57. if (parentsError) {
  58. throw new ClassNotFoundException(this.firstMissingTypeName);
  59. }
  60. return this.parents;
  61. }
  62. public String toString() {
  63. StringBuffer sb = new StringBuffer();
  64. sb.append("declare parents : ");
  65. sb.append(getTargetTypesPattern().asString());
  66. sb.append(isExtends() ? " extends " : " implements ");
  67. sb.append(this.parentsString);
  68. return sb.toString();
  69. }
  70. }