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 com.thoughtworks.qdox.model.JavaParameter;
23  import org.codehaus.mojo.jaxb2.shared.Validate;
24  
25  import java.util.List;
26  
27  /**
28   * Comparable path structure to locate a particular method within compilation unit.
29   *
30   * @author <a href="mailto:lj@jguru.se">Lennart J&ouml;relid</a>, jGuru Europe AB
31   * @since 2.0
32   */
33  public class MethodLocation extends FieldLocation {
34  
35      /**
36       * Signature for a method without any parameters.
37       */
38      public static final String NO_PARAMETERS = "()";
39  
40      /**
41       * Separator for a method's parameters.
42       */
43      public static final String PARAMETER_SEPARATOR = ",";
44  
45      // Internal state
46      private String parameters = NO_PARAMETERS;
47  
48      public MethodLocation(final String packageName,
49                            final String className,
50                            final String memberName,
51                            final List<JavaParameter> parameters) {
52  
53          super(packageName, className, memberName);
54  
55          // Check sanity
56          Validate.notNull(parameters, "parameters");
57  
58          // Stringify the parameter types
59          if (parameters.size() > 0) {
60              final StringBuilder builder = new StringBuilder();
61  
62              for (JavaParameter current : parameters) {
63                  builder.append(current.getType().getFullyQualifiedName()).append(PARAMETER_SEPARATOR);
64              }
65              this.parameters = "(" + builder.substring(0, builder.lastIndexOf(PARAMETER_SEPARATOR)) + ")";
66          }
67      }
68  
69      /**
70       * {@inheritDoc}
71       */
72      @Override
73      public String toString() {
74          return super.toString() + parameters;
75      }
76  
77      /**
78       * {@inheritDoc}
79       */
80      @Override
81      public int hashCode() {
82          return this.toString().hashCode();
83      }
84  
85      /**
86       * @return The parameters, concatenated into a String.
87       */
88      public String getParametersAsString() {
89          return parameters;
90      }
91  
92      /**
93       * @return True if this MethodLocation has no parameters.
94       */
95      public boolean hasNoParameters() {
96          return NO_PARAMETERS.equals(parameters);
97      }
98  }