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.

PatternNode.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 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. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.DataInputStream;
  14. import java.io.DataOutputStream;
  15. import java.io.IOException;
  16. import org.aspectj.bridge.ISourceLocation;
  17. import org.aspectj.weaver.CompressingDataOutputStream;
  18. import org.aspectj.weaver.IHasSourceLocation;
  19. import org.aspectj.weaver.ISourceContext;
  20. public abstract class PatternNode implements IHasSourceLocation {
  21. protected int start, end;
  22. protected ISourceContext sourceContext;
  23. public PatternNode() {
  24. super();
  25. start = end = -1;
  26. }
  27. public int getStart() {
  28. return start + (sourceContext != null ? sourceContext.getOffset() : 0);
  29. }
  30. public int getEnd() {
  31. return end + (sourceContext != null ? sourceContext.getOffset() : 0);
  32. }
  33. public ISourceContext getSourceContext() {
  34. return sourceContext;
  35. }
  36. public String getFileName() {
  37. return "unknown";
  38. }
  39. public void setLocation(ISourceContext sourceContext, int start, int end) {
  40. this.sourceContext = sourceContext;
  41. this.start = start;
  42. this.end = end;
  43. }
  44. public void copyLocationFrom(PatternNode other) {
  45. this.start = other.start;
  46. this.end = other.end;
  47. this.sourceContext = other.sourceContext;
  48. }
  49. public ISourceLocation getSourceLocation() {
  50. // System.out.println("get context: " + this + " is " + sourceContext);
  51. if (sourceContext == null) {
  52. // System.err.println("no context: " + this);
  53. return null;
  54. }
  55. return sourceContext.makeSourceLocation(this);
  56. }
  57. public abstract void write(CompressingDataOutputStream s) throws IOException;
  58. public void writeLocation(DataOutputStream s) throws IOException {
  59. s.writeInt(start);
  60. s.writeInt(end);
  61. }
  62. public void readLocation(ISourceContext context, DataInputStream s) throws IOException {
  63. start = s.readInt();
  64. end = s.readInt();
  65. this.sourceContext = context;
  66. }
  67. public abstract Object accept(PatternNodeVisitor visitor, Object data);
  68. public Object traverse(PatternNodeVisitor visitor, Object data) {
  69. return accept(visitor, data);
  70. }
  71. }