You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MacroDef.java 25 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant.taskdefs;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.Locale;
  23. import java.util.HashMap;
  24. import org.apache.tools.ant.AntTypeDefinition;
  25. import org.apache.tools.ant.BuildException;
  26. import org.apache.tools.ant.ComponentHelper;
  27. import org.apache.tools.ant.Project;
  28. import org.apache.tools.ant.ProjectHelper;
  29. import org.apache.tools.ant.RuntimeConfigurable;
  30. import org.apache.tools.ant.Task;
  31. import org.apache.tools.ant.TaskContainer;
  32. import org.apache.tools.ant.UnknownElement;
  33. /**
  34. * Describe class <code>MacroDef</code> here.
  35. *
  36. * @since Ant 1.6
  37. */
  38. public class MacroDef extends AntlibDefinition {
  39. private NestedSequential nestedSequential;
  40. private String name;
  41. private boolean backTrace = true;
  42. private List<Attribute> attributes = new ArrayList<Attribute>();
  43. private Map<String, TemplateElement> elements = new HashMap<String, TemplateElement>();
  44. private String textName = null;
  45. private Text text = null;
  46. private boolean hasImplicitElement = false;
  47. /**
  48. * Name of the definition
  49. * @param name the name of the definition
  50. */
  51. public void setName(String name) {
  52. this.name = name;
  53. }
  54. /**
  55. * Add the text element.
  56. * @param text the nested text element to add
  57. * @since ant 1.6.1
  58. */
  59. public void addConfiguredText(Text text) {
  60. if (this.text != null) {
  61. throw new BuildException(
  62. "Only one nested text element allowed");
  63. }
  64. if (text.getName() == null) {
  65. throw new BuildException(
  66. "the text nested element needed a \"name\" attribute");
  67. }
  68. // Check if used by attributes
  69. for (Attribute attribute : attributes) {
  70. if (text.getName().equals(attribute.getName())) {
  71. throw new BuildException(
  72. "the name \"" + text.getName()
  73. + "\" is already used as an attribute");
  74. }
  75. }
  76. this.text = text;
  77. this.textName = text.getName();
  78. }
  79. /**
  80. * @return the nested text element
  81. * @since ant 1.6.1
  82. */
  83. public Text getText() {
  84. return text;
  85. }
  86. /**
  87. * Set the backTrace attribute.
  88. *
  89. * @param backTrace if true and the macro instance generates
  90. * an error, a backtrace of the location within
  91. * the macro and call to the macro will be output.
  92. * if false, only the location of the call to the
  93. * macro will be shown. Default is true.
  94. * @since ant 1.7
  95. */
  96. public void setBackTrace(boolean backTrace) {
  97. this.backTrace = backTrace;
  98. }
  99. /**
  100. * @return the backTrace attribute.
  101. * @since ant 1.7
  102. */
  103. public boolean getBackTrace() {
  104. return backTrace;
  105. }
  106. /**
  107. * This is the sequential nested element of the macrodef.
  108. *
  109. * @return a sequential element to be configured.
  110. */
  111. public NestedSequential createSequential() {
  112. if (this.nestedSequential != null) {
  113. throw new BuildException("Only one sequential allowed");
  114. }
  115. this.nestedSequential = new NestedSequential();
  116. return this.nestedSequential;
  117. }
  118. /**
  119. * The class corresponding to the sequential nested element.
  120. * This is a simple task container.
  121. */
  122. public static class NestedSequential implements TaskContainer {
  123. private List<Task> nested = new ArrayList<Task>();
  124. /**
  125. * Add a task or type to the container.
  126. *
  127. * @param task an unknown element.
  128. */
  129. public void addTask(Task task) {
  130. nested.add(task);
  131. }
  132. /**
  133. * @return the list of unknown elements
  134. */
  135. public List<Task> getNested() {
  136. return nested;
  137. }
  138. /**
  139. * A compare function to compare this with another
  140. * NestedSequential.
  141. * It calls similar on the nested unknown elements.
  142. *
  143. * @param other the nested sequential to compare with.
  144. * @return true if they are similar, false otherwise
  145. */
  146. public boolean similar(NestedSequential other) {
  147. final int size = nested.size();
  148. if (size != other.nested.size()) {
  149. return false;
  150. }
  151. for (int i = 0; i < size; ++i) {
  152. UnknownElement me = (UnknownElement) nested.get(i);
  153. UnknownElement o = (UnknownElement) other.nested.get(i);
  154. if (!me.similar(o)) {
  155. return false;
  156. }
  157. }
  158. return true;
  159. }
  160. }
  161. /**
  162. * Convert the nested sequential to an unknown element
  163. * @return the nested sequential as an unknown element.
  164. */
  165. public UnknownElement getNestedTask() {
  166. UnknownElement ret = new UnknownElement("sequential");
  167. ret.setTaskName("sequential");
  168. ret.setNamespace("");
  169. ret.setQName("sequential");
  170. new RuntimeConfigurable(ret, "sequential");
  171. final int size = nestedSequential.getNested().size();
  172. for (int i = 0; i < size; ++i) {
  173. UnknownElement e =
  174. (UnknownElement) nestedSequential.getNested().get(i);
  175. ret.addChild(e);
  176. ret.getWrapper().addChild(e.getWrapper());
  177. }
  178. return ret;
  179. }
  180. /**
  181. * Gets this macro's attribute (and define?) list.
  182. *
  183. * @return the nested Attributes
  184. */
  185. public List<Attribute> getAttributes() {
  186. return attributes;
  187. }
  188. /**
  189. * Gets this macro's elements.
  190. *
  191. * @return the map nested elements, keyed by element name, with
  192. * {@link TemplateElement} values.
  193. */
  194. public Map<String, TemplateElement> getElements() {
  195. return elements;
  196. }
  197. /**
  198. * Check if a character is a valid character for an element or
  199. * attribute name.
  200. *
  201. * @param c the character to check
  202. * @return true if the character is a letter or digit or '.' or '-'
  203. * attribute name
  204. */
  205. public static boolean isValidNameCharacter(char c) {
  206. // ? is there an xml api for this ?
  207. return Character.isLetterOrDigit(c) || c == '.' || c == '-';
  208. }
  209. /**
  210. * Check if a string is a valid name for an element or attribute.
  211. *
  212. * @param name the string to check
  213. * @return true if the name consists of valid name characters
  214. */
  215. private static boolean isValidName(String name) {
  216. if (name.length() == 0) {
  217. return false;
  218. }
  219. for (int i = 0; i < name.length(); ++i) {
  220. if (!isValidNameCharacter(name.charAt(i))) {
  221. return false;
  222. }
  223. }
  224. return true;
  225. }
  226. /**
  227. * Add an attribute element.
  228. *
  229. * @param attribute an attribute nested element.
  230. */
  231. public void addConfiguredAttribute(Attribute attribute) {
  232. if (attribute.getName() == null) {
  233. throw new BuildException(
  234. "the attribute nested element needed a \"name\" attribute");
  235. }
  236. if (attribute.getName().equals(textName)) {
  237. throw new BuildException(
  238. "the name \"" + attribute.getName()
  239. + "\" has already been used by the text element");
  240. }
  241. final int size = attributes.size();
  242. for (int i = 0; i < size; ++i) {
  243. Attribute att = (Attribute) attributes.get(i);
  244. if (att.getName().equals(attribute.getName())) {
  245. throw new BuildException(
  246. "the name \"" + attribute.getName()
  247. + "\" has already been used in "
  248. + "another attribute element");
  249. }
  250. }
  251. attributes.add(attribute);
  252. }
  253. /**
  254. * Add an element element.
  255. *
  256. * @param element an element nested element.
  257. */
  258. public void addConfiguredElement(TemplateElement element) {
  259. if (element.getName() == null) {
  260. throw new BuildException(
  261. "the element nested element needed a \"name\" attribute");
  262. }
  263. if (elements.get(element.getName()) != null) {
  264. throw new BuildException(
  265. "the element " + element.getName()
  266. + " has already been specified");
  267. }
  268. if (hasImplicitElement
  269. || (element.isImplicit() && elements.size() != 0)) {
  270. throw new BuildException(
  271. "Only one element allowed when using implicit elements");
  272. }
  273. hasImplicitElement = element.isImplicit();
  274. elements.put(element.getName(), element);
  275. }
  276. /**
  277. * Create a new ant type based on the embedded tasks and types.
  278. */
  279. public void execute() {
  280. if (nestedSequential == null) {
  281. throw new BuildException("Missing sequential element");
  282. }
  283. if (name == null) {
  284. throw new BuildException("Name not specified");
  285. }
  286. name = ProjectHelper.genComponentName(getURI(), name);
  287. MyAntTypeDefinition def = new MyAntTypeDefinition(this);
  288. def.setName(name);
  289. def.setClass(MacroInstance.class);
  290. ComponentHelper helper = ComponentHelper.getComponentHelper(
  291. getProject());
  292. helper.addDataTypeDefinition(def);
  293. log("creating macro " + name, Project.MSG_VERBOSE);
  294. }
  295. /**
  296. * An attribute for the MacroDef task.
  297. *
  298. */
  299. public static class Attribute {
  300. private String name;
  301. private String defaultValue;
  302. private String description;
  303. private boolean doubleExpanding = true;
  304. /**
  305. * The name of the attribute.
  306. *
  307. * @param name the name of the attribute
  308. */
  309. public void setName(String name) {
  310. if (!isValidName(name)) {
  311. throw new BuildException(
  312. "Illegal name [" + name + "] for attribute");
  313. }
  314. this.name = name.toLowerCase(Locale.ENGLISH);
  315. }
  316. /**
  317. * @return the name of the attribute
  318. */
  319. public String getName() {
  320. return name;
  321. }
  322. /**
  323. * The default value to use if the parameter is not
  324. * used in the templated instance.
  325. *
  326. * @param defaultValue the default value
  327. */
  328. public void setDefault(String defaultValue) {
  329. this.defaultValue = defaultValue;
  330. }
  331. /**
  332. * @return the default value, null if not set
  333. */
  334. public String getDefault() {
  335. return defaultValue;
  336. }
  337. /**
  338. * @param desc Description of the element.
  339. * @since ant 1.6.1
  340. */
  341. public void setDescription(String desc) {
  342. description = desc;
  343. }
  344. /**
  345. * @return the description of the element, or <code>null</code> if
  346. * no description is available.
  347. * @since ant 1.6.1
  348. */
  349. public String getDescription() {
  350. return description;
  351. }
  352. /**
  353. * See {@link #isDoubleExpanding} for explanation.
  354. * @param doubleExpanding true to expand twice, false for just once
  355. * @since Ant 1.8.3
  356. */
  357. public void setDoubleExpanding(boolean doubleExpanding) {
  358. this.doubleExpanding = doubleExpanding;
  359. }
  360. /**
  361. * Determines whether {@link RuntimeConfigurable#maybeConfigure(Project, boolean)} will reevaluate this property.
  362. * For compatibility reasons (#52621) it will, though for most applications (#42046) it should not.
  363. * @return true if expanding twice (the default), false for just once
  364. * @since Ant 1.8.3
  365. */
  366. public boolean isDoubleExpanding() {
  367. return doubleExpanding;
  368. }
  369. /**
  370. * equality method
  371. *
  372. * @param obj an <code>Object</code> value
  373. * @return a <code>boolean</code> value
  374. */
  375. public boolean equals(Object obj) {
  376. if (obj == null) {
  377. return false;
  378. }
  379. if (obj.getClass() != getClass()) {
  380. return false;
  381. }
  382. Attribute other = (Attribute) obj;
  383. if (name == null) {
  384. if (other.name != null) {
  385. return false;
  386. }
  387. } else if (!name.equals(other.name)) {
  388. return false;
  389. }
  390. if (defaultValue == null) {
  391. if (other.defaultValue != null) {
  392. return false;
  393. }
  394. } else if (!defaultValue.equals(other.defaultValue)) {
  395. return false;
  396. }
  397. return true;
  398. }
  399. /**
  400. * @return a hash code value for this object.
  401. */
  402. public int hashCode() {
  403. return objectHashCode(defaultValue) + objectHashCode(name);
  404. }
  405. }
  406. /**
  407. * A nested text element for the MacroDef task.
  408. * @since ant 1.6.1
  409. */
  410. public static class Text {
  411. private String name;
  412. private boolean optional;
  413. private boolean trim;
  414. private String description;
  415. private String defaultString;
  416. /**
  417. * The name of the attribute.
  418. *
  419. * @param name the name of the attribute
  420. */
  421. public void setName(String name) {
  422. if (!isValidName(name)) {
  423. throw new BuildException(
  424. "Illegal name [" + name + "] for attribute");
  425. }
  426. this.name = name.toLowerCase(Locale.ENGLISH);
  427. }
  428. /**
  429. * @return the name of the attribute
  430. */
  431. public String getName() {
  432. return name;
  433. }
  434. /**
  435. * The optional attribute of the text element.
  436. *
  437. * @param optional if true this is optional
  438. */
  439. public void setOptional(boolean optional) {
  440. this.optional = optional;
  441. }
  442. /**
  443. * @return true if the text is optional
  444. */
  445. public boolean getOptional() {
  446. return optional;
  447. }
  448. /**
  449. * The trim attribute of the text element.
  450. *
  451. * @param trim if true this String.trim() is called on
  452. * the contents of the text element.
  453. */
  454. public void setTrim(boolean trim) {
  455. this.trim = trim;
  456. }
  457. /**
  458. * @return true if the text is trim
  459. */
  460. public boolean getTrim() {
  461. return trim;
  462. }
  463. /**
  464. * @param desc Description of the text.
  465. */
  466. public void setDescription(String desc) {
  467. description = desc;
  468. }
  469. /**
  470. * @return the description of the text, or <code>null</code> if
  471. * no description is available.
  472. */
  473. public String getDescription() {
  474. return description;
  475. }
  476. /**
  477. * @param defaultString default text for the string.
  478. */
  479. public void setDefault(String defaultString) {
  480. this.defaultString = defaultString;
  481. }
  482. /**
  483. * @return the default text if set, null otherwise.
  484. */
  485. public String getDefault() {
  486. return defaultString;
  487. }
  488. /**
  489. * equality method
  490. *
  491. * @param obj an <code>Object</code> value
  492. * @return a <code>boolean</code> value
  493. */
  494. public boolean equals(Object obj) {
  495. if (obj == null) {
  496. return false;
  497. }
  498. if (obj.getClass() != getClass()) {
  499. return false;
  500. }
  501. Text other = (Text) obj;
  502. return safeCompare(name, other.name)
  503. && optional == other.optional
  504. && trim == other.trim
  505. && safeCompare(defaultString, other.defaultString);
  506. }
  507. /**
  508. * @return a hash code value for this object.
  509. */
  510. public int hashCode() {
  511. return objectHashCode(name);
  512. }
  513. }
  514. private static boolean safeCompare(Object a, Object b) {
  515. return a == null ? b == null : a.equals(b);
  516. }
  517. /**
  518. * A nested element for the MacroDef task.
  519. */
  520. public static class TemplateElement {
  521. private String name;
  522. private String description;
  523. private boolean optional = false;
  524. private boolean implicit = false;
  525. /**
  526. * Sets the name of this element.
  527. *
  528. * @param name the name of the element
  529. */
  530. public void setName(String name) {
  531. if (!isValidName(name)) {
  532. throw new BuildException(
  533. "Illegal name [" + name + "] for macro element");
  534. }
  535. this.name = name.toLowerCase(Locale.ENGLISH);
  536. }
  537. /**
  538. * Gets the name of this element.
  539. *
  540. * @return the name of the element.
  541. */
  542. public String getName() {
  543. return name;
  544. }
  545. /**
  546. * Sets a textual description of this element,
  547. * for build documentation purposes only.
  548. *
  549. * @param desc Description of the element.
  550. * @since ant 1.6.1
  551. */
  552. public void setDescription(String desc) {
  553. description = desc;
  554. }
  555. /**
  556. * Gets the description of this element.
  557. *
  558. * @return the description of the element, or <code>null</code> if
  559. * no description is available.
  560. * @since ant 1.6.1
  561. */
  562. public String getDescription() {
  563. return description;
  564. }
  565. /**
  566. * Sets whether this element is optional.
  567. *
  568. * @param optional if true this element may be left out, default
  569. * is false.
  570. */
  571. public void setOptional(boolean optional) {
  572. this.optional = optional;
  573. }
  574. /**
  575. * Gets whether this element is optional.
  576. *
  577. * @return the optional attribute
  578. */
  579. public boolean isOptional() {
  580. return optional;
  581. }
  582. /**
  583. * Sets whether this element is implicit.
  584. *
  585. * @param implicit if true this element may be left out, default
  586. * is false.
  587. */
  588. public void setImplicit(boolean implicit) {
  589. this.implicit = implicit;
  590. }
  591. /**
  592. * Gets whether this element is implicit.
  593. *
  594. * @return the implicit attribute
  595. */
  596. public boolean isImplicit() {
  597. return implicit;
  598. }
  599. /**
  600. * equality method.
  601. *
  602. * @param obj an <code>Object</code> value
  603. * @return a <code>boolean</code> value
  604. */
  605. public boolean equals(Object obj) {
  606. if (obj == this) {
  607. return true;
  608. }
  609. if (obj == null || !obj.getClass().equals(getClass())) {
  610. return false;
  611. }
  612. TemplateElement t = (TemplateElement) obj;
  613. return
  614. (name == null ? t.name == null : name.equals(t.name))
  615. && optional == t.optional
  616. && implicit == t.implicit;
  617. }
  618. /**
  619. * @return a hash code value for this object.
  620. */
  621. public int hashCode() {
  622. return objectHashCode(name)
  623. + (optional ? 1 : 0) + (implicit ? 1 : 0);
  624. }
  625. } // END static class TemplateElement
  626. /**
  627. * same or similar equality method for macrodef, ignores project and
  628. * runtime info.
  629. *
  630. * @param obj an <code>Object</code> value
  631. * @param same if true test for sameness, otherwise just similiar
  632. * @return a <code>boolean</code> value
  633. */
  634. private boolean sameOrSimilar(Object obj, boolean same) {
  635. if (obj == this) {
  636. return true;
  637. }
  638. if (obj == null) {
  639. return false;
  640. }
  641. if (!obj.getClass().equals(getClass())) {
  642. return false;
  643. }
  644. MacroDef other = (MacroDef) obj;
  645. if (name == null) {
  646. return other.name == null;
  647. }
  648. if (!name.equals(other.name)) {
  649. return false;
  650. }
  651. // Allow two macro definitions with the same location
  652. // to be treated as similar - bugzilla 31215
  653. if (other.getLocation() != null
  654. && other.getLocation().equals(getLocation())
  655. && !same) {
  656. return true;
  657. }
  658. if (text == null) {
  659. if (other.text != null) {
  660. return false;
  661. }
  662. } else {
  663. if (!text.equals(other.text)) {
  664. return false;
  665. }
  666. }
  667. if (getURI() == null || getURI().equals("")
  668. || getURI().equals(ProjectHelper.ANT_CORE_URI)) {
  669. if (!(other.getURI() == null || other.getURI().equals("")
  670. || other.getURI().equals(ProjectHelper.ANT_CORE_URI))) {
  671. return false;
  672. }
  673. } else {
  674. if (!getURI().equals(other.getURI())) {
  675. return false;
  676. }
  677. }
  678. if (!nestedSequential.similar(other.nestedSequential)) {
  679. return false;
  680. }
  681. if (!attributes.equals(other.attributes)) {
  682. return false;
  683. }
  684. if (!elements.equals(other.elements)) {
  685. return false;
  686. }
  687. return true;
  688. }
  689. /**
  690. * Similar method for this definition
  691. *
  692. * @param obj another definition
  693. * @return true if the definitions are similar
  694. */
  695. public boolean similar(Object obj) {
  696. return sameOrSimilar(obj, false);
  697. }
  698. /**
  699. * Equality method for this definition
  700. *
  701. * @param obj another definition
  702. * @return true if the definitions are the same
  703. */
  704. public boolean sameDefinition(Object obj) {
  705. return sameOrSimilar(obj, true);
  706. }
  707. /**
  708. * extends AntTypeDefinition, on create
  709. * of the object, the template macro definition
  710. * is given.
  711. */
  712. private static class MyAntTypeDefinition extends AntTypeDefinition {
  713. private MacroDef macroDef;
  714. /**
  715. * Creates a new <code>MyAntTypeDefinition</code> instance.
  716. *
  717. * @param macroDef a <code>MacroDef</code> value
  718. */
  719. public MyAntTypeDefinition(MacroDef macroDef) {
  720. this.macroDef = macroDef;
  721. }
  722. /**
  723. * Create an instance of the definition.
  724. * The instance may be wrapped in a proxy class.
  725. * @param project the current project
  726. * @return the created object
  727. */
  728. public Object create(Project project) {
  729. Object o = super.create(project);
  730. if (o == null) {
  731. return null;
  732. }
  733. ((MacroInstance) o).setMacroDef(macroDef);
  734. return o;
  735. }
  736. /**
  737. * Equality method for this definition
  738. *
  739. * @param other another definition
  740. * @param project the current project
  741. * @return true if the definitions are the same
  742. */
  743. public boolean sameDefinition(AntTypeDefinition other, Project project) {
  744. if (!super.sameDefinition(other, project)) {
  745. return false;
  746. }
  747. MyAntTypeDefinition otherDef = (MyAntTypeDefinition) other;
  748. return macroDef.sameDefinition(otherDef.macroDef);
  749. }
  750. /**
  751. * Similar method for this definition
  752. *
  753. * @param other another definition
  754. * @param project the current project
  755. * @return true if the definitions are the same
  756. */
  757. public boolean similarDefinition(
  758. AntTypeDefinition other, Project project) {
  759. if (!super.similarDefinition(other, project)) {
  760. return false;
  761. }
  762. MyAntTypeDefinition otherDef = (MyAntTypeDefinition) other;
  763. return macroDef.similar(otherDef.macroDef);
  764. }
  765. }
  766. private static int objectHashCode(Object o) {
  767. if (o == null) {
  768. return 0;
  769. } else {
  770. return o.hashCode();
  771. }
  772. }
  773. }