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 26 kB

11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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.HashMap;
  21. import java.util.List;
  22. import java.util.Locale;
  23. import java.util.Map;
  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. // stores RuntimeConfigurable as "RuntimeConfigurableWrapper"
  171. // in ret as side effect
  172. new RuntimeConfigurable(ret, "sequential"); //NOSONAR
  173. final int size = nestedSequential.getNested().size();
  174. for (int i = 0; i < size; ++i) {
  175. UnknownElement e =
  176. (UnknownElement) nestedSequential.getNested().get(i);
  177. ret.addChild(e);
  178. ret.getWrapper().addChild(e.getWrapper());
  179. }
  180. return ret;
  181. }
  182. /**
  183. * Gets this macro's attribute (and define?) list.
  184. *
  185. * @return the nested Attributes
  186. */
  187. public List<Attribute> getAttributes() {
  188. return attributes;
  189. }
  190. /**
  191. * Gets this macro's elements.
  192. *
  193. * @return the map nested elements, keyed by element name, with
  194. * {@link TemplateElement} values.
  195. */
  196. public Map<String, TemplateElement> getElements() {
  197. return elements;
  198. }
  199. /**
  200. * Check if a character is a valid character for an element or
  201. * attribute name.
  202. *
  203. * @param c the character to check
  204. * @return true if the character is a letter or digit or '.' or '-'
  205. * attribute name
  206. */
  207. public static boolean isValidNameCharacter(char c) {
  208. // ? is there an xml api for this ?
  209. return Character.isLetterOrDigit(c) || c == '.' || c == '-';
  210. }
  211. /**
  212. * Check if a string is a valid name for an element or attribute.
  213. *
  214. * @param name the string to check
  215. * @return true if the name consists of valid name characters
  216. */
  217. private static boolean isValidName(String name) {
  218. if (name.length() == 0) {
  219. return false;
  220. }
  221. for (int i = 0; i < name.length(); ++i) {
  222. if (!isValidNameCharacter(name.charAt(i))) {
  223. return false;
  224. }
  225. }
  226. return true;
  227. }
  228. /**
  229. * Add an attribute element.
  230. *
  231. * @param attribute an attribute nested element.
  232. */
  233. public void addConfiguredAttribute(Attribute attribute) {
  234. if (attribute.getName() == null) {
  235. throw new BuildException(
  236. "the attribute nested element needed a \"name\" attribute");
  237. }
  238. if (attribute.getName().equals(textName)) {
  239. throw new BuildException(
  240. "the name \"" + attribute.getName()
  241. + "\" has already been used by the text element");
  242. }
  243. final int size = attributes.size();
  244. for (int i = 0; i < size; ++i) {
  245. Attribute att = (Attribute) attributes.get(i);
  246. if (att.getName().equals(attribute.getName())) {
  247. throw new BuildException(
  248. "the name \"" + attribute.getName()
  249. + "\" has already been used in "
  250. + "another attribute element");
  251. }
  252. }
  253. attributes.add(attribute);
  254. }
  255. /**
  256. * Add an element element.
  257. *
  258. * @param element an element nested element.
  259. */
  260. public void addConfiguredElement(TemplateElement element) {
  261. if (element.getName() == null) {
  262. throw new BuildException(
  263. "the element nested element needed a \"name\" attribute");
  264. }
  265. if (elements.get(element.getName()) != null) {
  266. throw new BuildException(
  267. "the element " + element.getName()
  268. + " has already been specified");
  269. }
  270. if (hasImplicitElement
  271. || (element.isImplicit() && elements.size() != 0)) {
  272. throw new BuildException(
  273. "Only one element allowed when using implicit elements");
  274. }
  275. hasImplicitElement = element.isImplicit();
  276. elements.put(element.getName(), element);
  277. }
  278. /**
  279. * Create a new ant type based on the embedded tasks and types.
  280. */
  281. public void execute() {
  282. if (nestedSequential == null) {
  283. throw new BuildException("Missing sequential element");
  284. }
  285. if (name == null) {
  286. throw new BuildException("Name not specified");
  287. }
  288. name = ProjectHelper.genComponentName(getURI(), name);
  289. MyAntTypeDefinition def = new MyAntTypeDefinition(this);
  290. def.setName(name);
  291. def.setClass(MacroInstance.class);
  292. ComponentHelper helper = ComponentHelper.getComponentHelper(
  293. getProject());
  294. helper.addDataTypeDefinition(def);
  295. log("creating macro " + name, Project.MSG_VERBOSE);
  296. }
  297. /**
  298. * An attribute for the MacroDef task.
  299. *
  300. */
  301. public static class Attribute {
  302. private String name;
  303. private String defaultValue;
  304. private String description;
  305. private boolean doubleExpanding = true;
  306. /**
  307. * The name of the attribute.
  308. *
  309. * @param name the name of the attribute
  310. */
  311. public void setName(String name) {
  312. if (!isValidName(name)) {
  313. throw new BuildException(
  314. "Illegal name [" + name + "] for attribute");
  315. }
  316. this.name = name.toLowerCase(Locale.ENGLISH);
  317. }
  318. /**
  319. * @return the name of the attribute
  320. */
  321. public String getName() {
  322. return name;
  323. }
  324. /**
  325. * The default value to use if the parameter is not
  326. * used in the templated instance.
  327. *
  328. * @param defaultValue the default value
  329. */
  330. public void setDefault(String defaultValue) {
  331. this.defaultValue = defaultValue;
  332. }
  333. /**
  334. * @return the default value, null if not set
  335. */
  336. public String getDefault() {
  337. return defaultValue;
  338. }
  339. /**
  340. * @param desc Description of the element.
  341. * @since ant 1.6.1
  342. */
  343. public void setDescription(String desc) {
  344. description = desc;
  345. }
  346. /**
  347. * @return the description of the element, or <code>null</code> if
  348. * no description is available.
  349. * @since ant 1.6.1
  350. */
  351. public String getDescription() {
  352. return description;
  353. }
  354. /**
  355. * See {@link #isDoubleExpanding} for explanation.
  356. * @param doubleExpanding true to expand twice, false for just once
  357. * @since Ant 1.8.3
  358. */
  359. public void setDoubleExpanding(boolean doubleExpanding) {
  360. this.doubleExpanding = doubleExpanding;
  361. }
  362. /**
  363. * Determines whether {@link RuntimeConfigurable#maybeConfigure(Project, boolean)} will reevaluate this property.
  364. * For compatibility reasons (#52621) it will, though for most applications (#42046) it should not.
  365. * @return true if expanding twice (the default), false for just once
  366. * @since Ant 1.8.3
  367. */
  368. public boolean isDoubleExpanding() {
  369. return doubleExpanding;
  370. }
  371. /**
  372. * equality method
  373. *
  374. * @param obj an <code>Object</code> value
  375. * @return a <code>boolean</code> value
  376. */
  377. public boolean equals(Object obj) {
  378. if (obj == null) {
  379. return false;
  380. }
  381. if (obj.getClass() != getClass()) {
  382. return false;
  383. }
  384. Attribute other = (Attribute) obj;
  385. if (name == null) {
  386. if (other.name != null) {
  387. return false;
  388. }
  389. } else if (!name.equals(other.name)) {
  390. return false;
  391. }
  392. if (defaultValue == null) {
  393. if (other.defaultValue != null) {
  394. return false;
  395. }
  396. } else if (!defaultValue.equals(other.defaultValue)) {
  397. return false;
  398. }
  399. return true;
  400. }
  401. /**
  402. * @return a hash code value for this object.
  403. */
  404. public int hashCode() {
  405. return objectHashCode(defaultValue) + objectHashCode(name);
  406. }
  407. }
  408. /**
  409. * A nested text element for the MacroDef task.
  410. * @since ant 1.6.1
  411. */
  412. public static class Text {
  413. private String name;
  414. private boolean optional;
  415. private boolean trim;
  416. private String description;
  417. private String defaultString;
  418. /**
  419. * The name of the attribute.
  420. *
  421. * @param name the name of the attribute
  422. */
  423. public void setName(String name) {
  424. if (!isValidName(name)) {
  425. throw new BuildException(
  426. "Illegal name [" + name + "] for attribute");
  427. }
  428. this.name = name.toLowerCase(Locale.ENGLISH);
  429. }
  430. /**
  431. * @return the name of the attribute
  432. */
  433. public String getName() {
  434. return name;
  435. }
  436. /**
  437. * The optional attribute of the text element.
  438. *
  439. * @param optional if true this is optional
  440. */
  441. public void setOptional(boolean optional) {
  442. this.optional = optional;
  443. }
  444. /**
  445. * @return true if the text is optional
  446. */
  447. public boolean getOptional() {
  448. return optional;
  449. }
  450. /**
  451. * The trim attribute of the text element.
  452. *
  453. * @param trim if true this String.trim() is called on
  454. * the contents of the text element.
  455. */
  456. public void setTrim(boolean trim) {
  457. this.trim = trim;
  458. }
  459. /**
  460. * @return true if the text is trim
  461. */
  462. public boolean getTrim() {
  463. return trim;
  464. }
  465. /**
  466. * @param desc Description of the text.
  467. */
  468. public void setDescription(String desc) {
  469. description = desc;
  470. }
  471. /**
  472. * @return the description of the text, or <code>null</code> if
  473. * no description is available.
  474. */
  475. public String getDescription() {
  476. return description;
  477. }
  478. /**
  479. * @param defaultString default text for the string.
  480. */
  481. public void setDefault(String defaultString) {
  482. this.defaultString = defaultString;
  483. }
  484. /**
  485. * @return the default text if set, null otherwise.
  486. */
  487. public String getDefault() {
  488. return defaultString;
  489. }
  490. /**
  491. * equality method
  492. *
  493. * @param obj an <code>Object</code> value
  494. * @return a <code>boolean</code> value
  495. */
  496. public boolean equals(Object obj) {
  497. if (obj == null) {
  498. return false;
  499. }
  500. if (obj.getClass() != getClass()) {
  501. return false;
  502. }
  503. Text other = (Text) obj;
  504. return safeCompare(name, other.name)
  505. && optional == other.optional
  506. && trim == other.trim
  507. && safeCompare(defaultString, other.defaultString);
  508. }
  509. /**
  510. * @return a hash code value for this object.
  511. */
  512. public int hashCode() {
  513. return objectHashCode(name);
  514. }
  515. }
  516. private static boolean safeCompare(Object a, Object b) {
  517. return a == null ? b == null : a.equals(b);
  518. }
  519. /**
  520. * A nested element for the MacroDef task.
  521. */
  522. public static class TemplateElement {
  523. private String name;
  524. private String description;
  525. private boolean optional = false;
  526. private boolean implicit = false;
  527. /**
  528. * Sets the name of this element.
  529. *
  530. * @param name the name of the element
  531. */
  532. public void setName(String name) {
  533. if (!isValidName(name)) {
  534. throw new BuildException(
  535. "Illegal name [" + name + "] for macro element");
  536. }
  537. this.name = name.toLowerCase(Locale.ENGLISH);
  538. }
  539. /**
  540. * Gets the name of this element.
  541. *
  542. * @return the name of the element.
  543. */
  544. public String getName() {
  545. return name;
  546. }
  547. /**
  548. * Sets a textual description of this element,
  549. * for build documentation purposes only.
  550. *
  551. * @param desc Description of the element.
  552. * @since ant 1.6.1
  553. */
  554. public void setDescription(String desc) {
  555. description = desc;
  556. }
  557. /**
  558. * Gets the description of this element.
  559. *
  560. * @return the description of the element, or <code>null</code> if
  561. * no description is available.
  562. * @since ant 1.6.1
  563. */
  564. public String getDescription() {
  565. return description;
  566. }
  567. /**
  568. * Sets whether this element is optional.
  569. *
  570. * @param optional if true this element may be left out, default
  571. * is false.
  572. */
  573. public void setOptional(boolean optional) {
  574. this.optional = optional;
  575. }
  576. /**
  577. * Gets whether this element is optional.
  578. *
  579. * @return the optional attribute
  580. */
  581. public boolean isOptional() {
  582. return optional;
  583. }
  584. /**
  585. * Sets whether this element is implicit.
  586. *
  587. * @param implicit if true this element may be left out, default
  588. * is false.
  589. */
  590. public void setImplicit(boolean implicit) {
  591. this.implicit = implicit;
  592. }
  593. /**
  594. * Gets whether this element is implicit.
  595. *
  596. * @return the implicit attribute
  597. */
  598. public boolean isImplicit() {
  599. return implicit;
  600. }
  601. /**
  602. * equality method.
  603. *
  604. * @param obj an <code>Object</code> value
  605. * @return a <code>boolean</code> value
  606. */
  607. public boolean equals(Object obj) {
  608. if (obj == this) {
  609. return true;
  610. }
  611. if (obj == null || !obj.getClass().equals(getClass())) {
  612. return false;
  613. }
  614. TemplateElement t = (TemplateElement) obj;
  615. return
  616. (name == null ? t.name == null : name.equals(t.name))
  617. && optional == t.optional
  618. && implicit == t.implicit;
  619. }
  620. /**
  621. * @return a hash code value for this object.
  622. */
  623. public int hashCode() {
  624. return objectHashCode(name)
  625. + (optional ? 1 : 0) + (implicit ? 1 : 0);
  626. }
  627. } // END static class TemplateElement
  628. /**
  629. * same or similar equality method for macrodef, ignores project and
  630. * runtime info.
  631. *
  632. * @param obj an <code>Object</code> value
  633. * @param same if true test for sameness, otherwise just similar
  634. * @return a <code>boolean</code> value
  635. */
  636. private boolean sameOrSimilar(Object obj, boolean same) {
  637. if (obj == this) {
  638. return true;
  639. }
  640. if (obj == null) {
  641. return false;
  642. }
  643. if (!obj.getClass().equals(getClass())) {
  644. return false;
  645. }
  646. MacroDef other = (MacroDef) obj;
  647. if (name == null) {
  648. return other.name == null;
  649. }
  650. if (!name.equals(other.name)) {
  651. return false;
  652. }
  653. // Allow two macro definitions with the same location
  654. // to be treated as similar - bugzilla 31215
  655. if (other.getLocation() != null
  656. && other.getLocation().equals(getLocation())
  657. && !same) {
  658. return true;
  659. }
  660. if (text == null) {
  661. if (other.text != null) {
  662. return false;
  663. }
  664. } else {
  665. if (!text.equals(other.text)) {
  666. return false;
  667. }
  668. }
  669. if (getURI() == null || getURI().equals("")
  670. || getURI().equals(ProjectHelper.ANT_CORE_URI)) {
  671. if (!(other.getURI() == null || other.getURI().equals("")
  672. || other.getURI().equals(ProjectHelper.ANT_CORE_URI))) {
  673. return false;
  674. }
  675. } else {
  676. if (!getURI().equals(other.getURI())) {
  677. return false;
  678. }
  679. }
  680. if (!nestedSequential.similar(other.nestedSequential)) {
  681. return false;
  682. }
  683. if (!attributes.equals(other.attributes)) {
  684. return false;
  685. }
  686. if (!elements.equals(other.elements)) {
  687. return false;
  688. }
  689. return true;
  690. }
  691. /**
  692. * Similar method for this definition
  693. *
  694. * @param obj another definition
  695. * @return true if the definitions are similar
  696. */
  697. public boolean similar(Object obj) {
  698. return sameOrSimilar(obj, false);
  699. }
  700. /**
  701. * Equality method for this definition
  702. *
  703. * @param obj another definition
  704. * @return true if the definitions are the same
  705. */
  706. public boolean sameDefinition(Object obj) {
  707. return sameOrSimilar(obj, true);
  708. }
  709. /**
  710. * extends AntTypeDefinition, on create
  711. * of the object, the template macro definition
  712. * is given.
  713. */
  714. private static class MyAntTypeDefinition extends AntTypeDefinition {
  715. private MacroDef macroDef;
  716. /**
  717. * Creates a new <code>MyAntTypeDefinition</code> instance.
  718. *
  719. * @param macroDef a <code>MacroDef</code> value
  720. */
  721. public MyAntTypeDefinition(MacroDef macroDef) {
  722. this.macroDef = macroDef;
  723. }
  724. /**
  725. * Create an instance of the definition.
  726. * The instance may be wrapped in a proxy class.
  727. * @param project the current project
  728. * @return the created object
  729. */
  730. public Object create(Project project) {
  731. Object o = super.create(project);
  732. if (o == null) {
  733. return null;
  734. }
  735. ((MacroInstance) o).setMacroDef(macroDef);
  736. return o;
  737. }
  738. /**
  739. * Equality method for this definition
  740. *
  741. * @param other another definition
  742. * @param project the current project
  743. * @return true if the definitions are the same
  744. */
  745. public boolean sameDefinition(AntTypeDefinition other, Project project) {
  746. if (!super.sameDefinition(other, project)) {
  747. return false;
  748. }
  749. MyAntTypeDefinition otherDef = (MyAntTypeDefinition) other;
  750. return macroDef.sameDefinition(otherDef.macroDef);
  751. }
  752. /**
  753. * Similar method for this definition
  754. *
  755. * @param other another definition
  756. * @param project the current project
  757. * @return true if the definitions are the same
  758. */
  759. public boolean similarDefinition(
  760. AntTypeDefinition other, Project project) {
  761. if (!super.similarDefinition(other, project)) {
  762. return false;
  763. }
  764. MyAntTypeDefinition otherDef = (MyAntTypeDefinition) other;
  765. return macroDef.similar(otherDef.macroDef);
  766. }
  767. }
  768. private static int objectHashCode(Object o) {
  769. if (o == null) {
  770. return 0;
  771. } else {
  772. return o.hashCode();
  773. }
  774. }
  775. }