X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fbinding%2Fclassfactory%2FSignatureVisitor.java;h=9aeaae595164061289151b2b20f1967b6e8f0c7d;hb=801fcbb85a8c63042fd9bb9775448dd962105dde;hp=6c001889760510a5fbf09ffbed2a784094ee7c06;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/classfactory/SignatureVisitor.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/classfactory/SignatureVisitor.java index 6c0018897..9aeaae595 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/classfactory/SignatureVisitor.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/classfactory/SignatureVisitor.java @@ -1,192 +1,192 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.databoard.binding.classfactory; - -import java.util.IdentityHashMap; - -import org.simantics.databoard.Datatypes; -import org.simantics.databoard.type.ArrayType; -import org.simantics.databoard.type.BooleanType; -import org.simantics.databoard.type.ByteType; -import org.simantics.databoard.type.Datatype; -import org.simantics.databoard.type.DoubleType; -import org.simantics.databoard.type.FloatType; -import org.simantics.databoard.type.IntegerType; -import org.simantics.databoard.type.LongType; -import org.simantics.databoard.type.MapType; -import org.simantics.databoard.type.OptionalType; -import org.simantics.databoard.type.RecordType; -import org.simantics.databoard.type.StringType; -import org.simantics.databoard.type.UnionType; -import org.simantics.databoard.type.VariantType; - -/** - * Signature Visitor builds a signature string from a datatype. - * The argument is StringBuilder. - * - * Signature is construtructed with the following notation. - * - * s StringType - * z BooleanType - * d DoubleType - * f FloatType - * i IntegerType - * b ByteType - * j LongType - * R Referable RecordType - * o* OptionalType, * denotes componentType - * a* ArrayType, * denotes componentType - * r**e RecordType, ** denotes fields - * u UnionType, * denotes components - * m** MapType, ** denotes keyType and valueType - * t Datatype - * - * For example, The signature of UUID.class is "rjje" - * - * @author toni.kalajainen - */ -public class SignatureVisitor implements Datatype.Visitor1 { - - public StringBuilder sb = new StringBuilder(); - public int hashcode = 0xbcbcbca; - public IdentityHashMap visited = new IdentityHashMap(); - - public static String toSignature(Datatype type) - { - SignatureVisitor sv = new SignatureVisitor(); - type.accept( sv, null ); - String sig = sv.sb.toString(); - return sig; - } - - @Override - public void visit(ArrayType b, Object obj) { - sb.append('a'); - b.componentType.accept(this, obj); - hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); - } - - @Override - public void visit(BooleanType b, Object obj) { - sb.append('z'); - hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); - } - - @Override - public void visit(DoubleType b, Object obj) { - sb.append('d'); - hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); - } - - @Override - public void visit(FloatType b, Object obj) { - sb.append('f'); - hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); - } - - @Override - public void visit(IntegerType b, Object obj) { - sb.append('i'); - hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); - } - - @Override - public void visit(ByteType b, Object obj) { - sb.append('b'); - hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); - } - - @Override - public void visit(LongType b, Object obj) { - sb.append('j'); - hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); - } - - @Override - public void visit(OptionalType b, Object obj) { - sb.append('o'); - b.componentType.accept(this, sb); - hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); - } - - @Override - public void visit(RecordType b, Object obj) { - if ( wasVisited(b) ) { - sb.append('R'); - return; - } - if ( b.isReferable() ) { - sb.append('R'); - return; - } - - sb.append('r'); - for (int i=0; i visited = new IdentityHashMap(); + + public static String toSignature(Datatype type) + { + SignatureVisitor sv = new SignatureVisitor(); + type.accept( sv, null ); + String sig = sv.sb.toString(); + return sig; + } + + @Override + public void visit(ArrayType b, Object obj) { + sb.append('a'); + b.componentType.accept(this, obj); + hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); + } + + @Override + public void visit(BooleanType b, Object obj) { + sb.append('z'); + hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); + } + + @Override + public void visit(DoubleType b, Object obj) { + sb.append('d'); + hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); + } + + @Override + public void visit(FloatType b, Object obj) { + sb.append('f'); + hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); + } + + @Override + public void visit(IntegerType b, Object obj) { + sb.append('i'); + hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); + } + + @Override + public void visit(ByteType b, Object obj) { + sb.append('b'); + hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); + } + + @Override + public void visit(LongType b, Object obj) { + sb.append('j'); + hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); + } + + @Override + public void visit(OptionalType b, Object obj) { + sb.append('o'); + b.componentType.accept(this, sb); + hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode(); + } + + @Override + public void visit(RecordType b, Object obj) { + if ( wasVisited(b) ) { + sb.append('R'); + return; + } + if ( b.isReferable() ) { + sb.append('R'); + return; + } + + sb.append('r'); + for (int i=0; i