1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.method;
14 import org.simantics.databoard.Bindings;
15 import org.simantics.databoard.Datatypes;
16 import org.simantics.databoard.binding.Binding;
17 import org.simantics.databoard.type.Component;
18 import org.simantics.databoard.type.Datatype;
19 import org.simantics.databoard.type.UnionType;
22 public class MethodTypeDefinition implements Comparable<MethodTypeDefinition> {
24 public static Binding BINDING = Bindings.getBindingUnchecked( MethodTypeDefinition.class );
29 private transient int hash;
31 public MethodTypeDefinition(String name, MethodType type)
35 hash = name.hashCode() + type.hashCode()*7;
38 public String getName() {
42 public void setName(String name) {
44 hash = name.hashCode() + type.hashCode()*7;
47 public MethodType getType() {
52 public String toString() {
53 Datatype void_ = Datatypes.getDatatypeUnchecked(void.class);
54 StringBuilder sb = new StringBuilder();
56 Datatype res = type.getResponseType();
57 Datatype req = type.getRequestType();
58 UnionType err = (UnionType) type.getErrorType();
63 sb.append(req.toSingleLineString());
66 if (res.equals(void_))
69 sb.append(res.toSingleLineString());
71 if (err.getComponentCount()>0) {
72 sb.append(" throws ");
73 for (int i=0; i<err.getComponentCount(); i++) {
74 if (i>0) sb.append(", ");
75 Component c = err.getComponent(i);
77 sb.append( c.type.toSingleLineString() );
84 public int hashCode() {
89 public boolean equals(Object obj) {
90 if (obj instanceof MethodTypeDefinition==false) return false;
91 MethodTypeDefinition other = (MethodTypeDefinition) obj;
92 return other.name.equals(name) && other.type.equals(type);
96 public int compareTo(MethodTypeDefinition o) {
97 int c = name.compareTo( o.getName() );
99 c = type.compareTo( o.getType() );