View Javadoc
1   package org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.location;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.codehaus.mojo.jaxb2.shared.Validate;
23  
24  /**
25   * Comparable path structure to locate a particular field within compilation unit.
26   *
27   * @author <a href="mailto:lj@jguru.se">Lennart J&ouml;relid</a>, jGuru Europe AB
28   * @since 2.0
29   */
30  public class FieldLocation extends ClassLocation {
31  
32      // Internal state
33      private String memberName;
34  
35      /**
36       * Creates a new FieldLocation with the supplied package, class and member names.
37       *
38       * @param packageName The name of the package for a class potentially holding JavaDoc. Cannot be {@code null}.
39       * @param className   The (simple) name of a class. Cannot be null or empty.
40       * @param memberName  The name of a (method or) field. Cannot be null or empty.
41       */
42      public FieldLocation(final String packageName,
43                           final String className,
44                           final String memberName) {
45  
46          // Delegate
47          super(packageName, className);
48  
49          // Check sanity
50          Validate.notEmpty(memberName, "memberName");
51  
52          // Assign internal state
53          this.memberName = memberName;
54      }
55  
56      /**
57       * Retrieves the name of the member (i.e. method or field), potentially holding JavaDoc.
58       *
59       * @return The name of the member (i.e. method or field), potentially holding JavaDoc.
60       * Never null or empty.
61       */
62      public String getMemberName() {
63          return memberName;
64      }
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      public String toString() {
71          return super.toString() + "#" + memberName;
72      }
73  
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      public int hashCode() {
79          return this.toString().hashCode();
80      }
81  }