langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/pubapi/PubMethod.java
author alundblad
Tue, 09 Jun 2015 15:57:45 +0200
changeset 31115 8d8e98052d5d
child 34752 9c262a013456
permissions -rw-r--r--
8054717: SJavac should track changes in the public apis of classpath classes! Summary: Added functionality for tracking changes in public APIs of classpath classes. Reviewed-by: jlahoda, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
     1
/*
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
     4
 *
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    10
 *
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    15
 * accompanied this code).
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    16
 *
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    20
 *
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    23
 * questions.
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    24
 */
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    25
package com.sun.tools.sjavac.pubapi;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    26
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    27
import java.io.Serializable;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    28
import java.util.List;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    29
import java.util.Set;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    30
import java.util.stream.Collectors;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    31
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    32
import javax.lang.model.element.Modifier;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    33
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    34
public class PubMethod implements Serializable {
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    35
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    36
    private static final long serialVersionUID = -7813050194553446243L;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    37
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    38
    Set<Modifier> modifiers;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    39
    List<PubApiTypeParam> typeParams;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    40
    TypeDesc returnType;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    41
    String identifier;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    42
    List<TypeDesc> paramTypes;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    43
    List<TypeDesc> throwDecls;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    44
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    45
    public PubMethod(Set<Modifier> modifiers,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    46
                     List<PubApiTypeParam> typeParams,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    47
                     TypeDesc returnType,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    48
                     String identifier,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    49
                     List<TypeDesc> paramTypes,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    50
                     List<TypeDesc> throwDecls) {
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    51
        this.modifiers = modifiers;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    52
        this.typeParams = typeParams;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    53
        this.returnType = returnType;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    54
        this.identifier = identifier;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    55
        this.paramTypes = paramTypes;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    56
        this.throwDecls = throwDecls;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    57
    }
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    58
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    59
    // We need to include return type and type parameters to be sure to have
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    60
    // different values for different methods. (A method can be overloaded with
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    61
    // the only difference being the upper bound of the return type.)
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    62
    public String asSignatureString() {
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    63
        StringBuilder sb = new StringBuilder();
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    64
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    65
        // <A extends String, Serializable, B extends List>
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    66
        if (typeParams.size() > 0) {
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    67
            sb.append(typeParams.stream()
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    68
                                .map(PubApiTypeParam::asString)
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    69
                                .collect(Collectors.joining(",", "<", "> ")));
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    70
        }
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    71
        sb.append(TypeDesc.encodeAsString(returnType));
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    72
        sb.append(" ");
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    73
        sb.append(identifier);
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    74
        sb.append("(");
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    75
        sb.append(paramTypes.stream()
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    76
                            .map(TypeDesc::encodeAsString)
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    77
                            .collect(Collectors.joining(",")));
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    78
        sb.append(")");
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    79
        return sb.toString();
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    80
    }
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    81
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    82
    @Override
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    83
    public boolean equals(Object obj) {
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    84
        if (getClass() != obj.getClass())
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    85
            return false;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    86
        PubMethod other = (PubMethod) obj;
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    87
        return modifiers.equals(other.modifiers)
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    88
            && typeParams.equals(other.typeParams)
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    89
            && returnType.equals(other.returnType)
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    90
            && identifier.equals(other.identifier)
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    91
            && paramTypes.equals(other.paramTypes)
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    92
            && throwDecls.equals(other.throwDecls);
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    93
    }
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    94
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    95
    @Override
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    96
    public int hashCode() {
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    97
        return modifiers.hashCode()
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    98
             ^ typeParams.hashCode()
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
    99
             ^ returnType.hashCode()
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   100
             ^ identifier.hashCode()
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   101
             ^ paramTypes.hashCode()
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   102
             ^ throwDecls.hashCode();
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   103
    }
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   104
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   105
    public String toString() {
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   106
        return String.format("%s[modifiers: %s, typeParams: %s, retType: %s, identifier: %s, params: %s, throws: %s]",
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   107
                             getClass().getSimpleName(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   108
                             modifiers,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   109
                             typeParams,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   110
                             returnType,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   111
                             identifier,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   112
                             paramTypes,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   113
                             throwDecls);
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   114
    }
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
diff changeset
   115
}