Create a field signature string for a specified variable.

@return the signature if field type is a type variable, else null.
336778
public String createFieldTypeSignature(VariableElement variable) {
    if (!hasGenericSignature(variable.asType())) {
      return null;
    }
    StringBuilder sb = new StringBuilder();
    genTypeSignature(variable.asType(), sb);
    return sb.toString();
  }
107192
private String createMethodSignature(Method method)
   {
      StringBuilder sb = new StringBuilder();
      sb.append("(");
      for (Class<?> type : method.getParameterTypes())
      {
         sb.append(getTypeString(type));
      }
      sb.append(")");
      Class<?> type = method.getReturnType();
      if (type.getName().equals("void"))
      {
         sb.append("V");
      }
      else
      {
         sb.append(getTypeString(type));
      }
      return sb.toString();
   }
1373420
public static IAtomContainer fromSignatureString(String signatureString, IChemObjectBuilder coBuilder) {
        ColoredTree tree = AtomSignature.parse(signatureString);
        MoleculeFromSignatureBuilder builder = new MoleculeFromSignatureBuilder(coBuilder);
        builder.makeFromColoredTree(tree);
        return builder.getAtomContainer();
    }
571655
private static String getSignature(TypeMirror type) {
        StringBuilder sbuf = new StringBuilder();
        type.accept(new SimpleTypeVisitor7<Void, StringBuilder>() {
            @Override
            protected Void defaultAction(TypeMirror e, StringBuilder stringBuilder) {
                return null;
            }

            @Override
            public Void visitPrimitive(PrimitiveType t, StringBuilder stringBuilder) {
                switch (t.getKind()) {
                    case BOOLEAN:
                        stringBuilder.append("Z");
                        break;
                    case BYTE:
                        stringBuilder.append("B");
                        break;
                    case CHAR:
                        stringBuilder.append("C");
                        break;
                    case DOUBLE:
                        stringBuilder.append("D");
                        break;
                    case FLOAT:
                        stringBuilder.append("F");
                        break;
                    case INT:
                        stringBuilder.append("I");
                        break;
                    case LONG:
                        stringBuilder.append("J");
                        break;
                    case SHORT:
                        stringBuilder.append("S");
                        break;
                    default:
                        break;
                }

                return null;
            }

            @Override
            public Void visitArray(ArrayType t, StringBuilder stringBuilder) {
                stringBuilder.append("[");
                t.getComponentType().accept(this, stringBuilder);
                return null;
            }

            @Override
            public Void visitDeclared(DeclaredType t, StringBuilder stringBuilder) {
                stringBuilder.append("L");
                stringBuilder.append(((TypeElement) t.asElement()).getQualifiedName().toString().replace('.', '/'));
                stringBuilder.append(";");

                return null;
            }

            @Override
            public Void visitExecutable(ExecutableType t, StringBuilder stringBuilder) {
                stringBuilder.append("(");
                for (TypeMirror p : t.getParameterTypes()) {
                    p.accept(this, stringBuilder);
                }
                stringBuilder.append(")");
                t.getReturnType().accept(this, stringBuilder);

                return null;
            }

            @Override
            public Void visitNoType(NoType t, StringBuilder stringBuilder) {
                if (t.getKind() == TypeKind.VOID) {
                    stringBuilder.append("V");
                }

                return null;
            }
        }, sbuf);

        return sbuf.toString();
    }
1106812
private TypeArgSignature getTypeArgSignature(Type type) {
		if (type instanceof WildcardType) {
			WildcardType wildcardType = (WildcardType) type;
			Type lowerBound = wildcardType.getLowerBounds().length == 0 ? null
					: wildcardType.getLowerBounds()[0];
			Type upperBound = wildcardType.getUpperBounds().length == 0 ? null
					: wildcardType.getUpperBounds()[0];

			if (lowerBound == null && Object.class.equals(upperBound)) {
				return new TypeArgSignature(
						TypeArgSignature.UNBOUNDED_WILDCARD,
						(FieldTypeSignature) getFullTypeSignature(upperBound));
			} else if (lowerBound == null && upperBound != null) {
				return new TypeArgSignature(
						TypeArgSignature.UPPERBOUND_WILDCARD,
						(FieldTypeSignature) getFullTypeSignature(upperBound));
			} else if (lowerBound != null) {
				return new TypeArgSignature(
						TypeArgSignature.LOWERBOUND_WILDCARD,
						(FieldTypeSignature) getFullTypeSignature(lowerBound));
			} else {
				throw new RuntimeException("Invalid type");
			}
		} else {
			return new TypeArgSignature(TypeArgSignature.NO_WILDCARD,
					(FieldTypeSignature) getFullTypeSignature(type));
		}
	}
543820
public static String createRootVariable(Path<?> path, int suffix) {
        String variable = path.accept(ToStringVisitor.DEFAULT, TEMPLATES);
        return variable + "_" + suffix;
    }
136609
@Nullable
	private FieldAnnotation getFieldAnnotation(final String fieldName) {
		JavaClass cls = getClassContext().getJavaClass();
		Field[] fields = cls.getFields();
		for (Field f : fields) {
			if (f.getName().equals(fieldName)) {
				return new FieldAnnotation(cls.getClassName(), fieldName, f.getSignature(), f.isStatic());
			}
		}
		return null; // shouldn't happen
	}
45575
public static String toLongString(final TypeVariable<?> var) {
        Validate.notNull(var, "var is null");
        final StringBuilder buf = new StringBuilder();
        final GenericDeclaration d = var.getGenericDeclaration();
        if (d instanceof Class<?>) {
            Class<?> c = (Class<?>) d;
            while (true) {
                if (c.getEnclosingClass() == null) {
                    buf.insert(0, c.getName());
                    break;
                }
                buf.insert(0, c.getSimpleName()).insert(0, '.');
                c = c.getEnclosingClass();
            }
        } else if (d instanceof Type) {// not possible as of now
            buf.append(toString((Type) d));
        } else {
            buf.append(d);
        }
        return buf.append(':').append(typeVariableToString(var)).toString();
    }
1281083
public Nullness getFieldInitializerNullness(TreePath fieldDeclPath, Context context) {
    Tree decl = fieldDeclPath.getLeaf();
    checkArgument(
        decl instanceof VariableTree && ((JCVariableDecl) decl).sym.getKind() == ElementKind.FIELD,
        "Leaf of fieldDeclPath must be a field declaration: %s",
        decl);

    ExpressionTree initializer = ((VariableTree) decl).getInitializer();
    if (initializer == null) {
      // An uninitialized field is null or 0 to start :)
      return ((JCVariableDecl) decl).type.isPrimitive() ? Nullness.NONNULL : Nullness.NULL;
    }
    TreePath initializerPath = TreePath.getPath(fieldDeclPath, initializer);
    ClassTree classTree = (ClassTree) fieldDeclPath.getParentPath().getLeaf();
    JavacProcessingEnvironment javacEnv = JavacProcessingEnvironment.instance(context);
    UnderlyingAST ast = new UnderlyingAST.CFGStatement(decl, classTree);
    ControlFlowGraph cfg =
        CFGBuilder.build(
            initializerPath,
            ast,
            /* assumeAssertionsEnabled */ false,
            /* assumeAssertionsDisabled */ false,
            javacEnv);
    try {
      nullnessPropagation
          .setContext(context)
          .setCompilationUnit(fieldDeclPath.getCompilationUnit());

      Analysis<Nullness, AccessPathStore<Nullness>, TrustingNullnessPropagation> analysis =
          new Analysis<>(nullnessPropagation, javacEnv);
      analysis.performAnalysis(cfg);
      return analysis.getValue(initializer);
    } finally {
      nullnessPropagation.setContext(null).setCompilationUnit(null);
    }
  }
366605
public String createNewVariableOnSolver(final String prefix) {
        final int index = this.name2idx.size() + 1;
        final String varName = prefix + "_" + index;
        this.name2idx.put(varName, index);
        this.idx2name.put(index, varName);
        return varName;
    }
490387
public static FieldInfo of(String name, TypeSignature typeSignature) {
        return new FieldInfo(name, FieldLocation.UNSPECIFIED, FieldRequirement.UNSPECIFIED, typeSignature,
                             ImmutableList.of(), null);
    }
1207970
@Override
    public boolean equalsIgnoringTypeParams(final TypeSignature other) {
        if (other instanceof TypeVariableSignature) {
            // Compare class type signature to type variable -- the logic for this
            // is implemented in TypeVariableSignature, and is not duplicated here
            return other.equalsIgnoringTypeParams(this);
        }
        if (!(other instanceof ClassRefTypeSignature)) {
            return false;
        }
        final ClassRefTypeSignature o = (ClassRefTypeSignature) other;
        if (o.suffixes.equals(this.suffixes)) {
            return o.className.equals(this.className);
        } else {
            return o.getFullyQualifiedClassName().equals(this.getFullyQualifiedClassName());
        }
    }
594657
private void genTypeSignature(TypeMirror type, StringBuilder sb) {
    switch (type.getKind()) {
      case BOOLEAN:
      case BYTE:
      case CHAR:
      case DOUBLE:
      case FLOAT:
      case INT:
      case LONG:
      case SHORT:
      case VOID:
        sb.append(TypeUtil.getBinaryName(type));
        break;
      case ARRAY:
        // ArrayTypeSignature ::= "[" TypSignature.
        sb.append('[');
        genTypeSignature(((ArrayType) type).getComponentType(), sb);
        break;
      case DECLARED:
        String typeName = elementUtil.getBinaryName(TypeUtil.asTypeElement(type));
        if (!TypeUtil.isStubType(typeName)) {
          // ClassTypeSignature ::= "L" {Ident "/"} Ident
          //   OptTypeArguments {"." Ident OptTypeArguments} ";".
          sb.append('L');
          sb.append(typeName.replace('.', '/'));
          genOptTypeArguments(((DeclaredType) type).getTypeArguments(), sb);
          sb.append(';');
        }
        break;
      case TYPEVAR:
        // TypeVariableSignature ::= "T" Ident ";".
        sb.append('T');
        sb.append(ElementUtil.getName(((TypeVariable) type).asElement()));
        sb.append(';');
        break;
      case WILDCARD:
        // TypeArgument ::= (["+" | "-"] FieldTypeSignature) | "*".
        TypeMirror upperBound = ((WildcardType) type).getExtendsBound();
        TypeMirror lowerBound = ((WildcardType) type).getSuperBound();
        if (upperBound != null) {
          sb.append('+');
          genTypeSignature(upperBound, sb);
        } else if (lowerBound != null) {
          sb.append('-');
          genTypeSignature(lowerBound, sb);
        } else {
          sb.append('*');
        }
        break;
      default:
        throw new AssertionError("Unexpected type kind: " + type.getKind());
    }
  }
38596
private void genClassSignature(TypeElement type, StringBuilder sb) {
    genOptFormalTypeParameters(type.getTypeParameters(), sb);
    // JDT returns null for an interface's superclass, but signatures expect Object.
    if (type.getKind().isInterface()) {
      sb.append(JAVA_OBJECT_SIGNATURE);
    } else {
      genTypeSignature(type.getSuperclass(), sb);
    }
    for (TypeMirror intrface : type.getInterfaces()) {
      genTypeSignature(intrface, sb);
    }
  }
1338533
public static String createTypeSignature(final String methodName, final Class<?>[] paramTypes) {
        final StringBuffer sb = new StringBuffer();
        sb.append(methodName);
        sb.append("(");
        for (int i = 0; i < paramTypes.length; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            sb.append(paramTypes[i].getSimpleName());
        }
        sb.append(")");
        return sb.toString();
    }
1106783
@SuppressWarnings( "unchecked" )
    private FieldMetadata processVariableDeclaration( SingleVariableDeclaration singleVariableDeclaration,
                                                      Type type ) {

        Variable variable;
        if (type.isPrimitiveType()) {
            FieldMetadata primitiveFieldMetadata = FieldMetadata.primitiveType(((PrimitiveType)type).getPrimitiveTypeCode().toString());
            variable = new Variable();
            variable.setName(JavaMetadataUtil.getName(singleVariableDeclaration.getName()));
            primitiveFieldMetadata.setName(variable.getName());

            primitiveFieldMetadata.getVariables().add(variable);
            for (IExtendedModifier extendedModifier : (List<IExtendedModifier>)singleVariableDeclaration.modifiers()) {
                if (extendedModifier.isAnnotation()) {
                    primitiveFieldMetadata.getAnnotations().add(createAnnotationMetadataFor((Annotation)extendedModifier));
                } else {
                    Modifier modifier = (Modifier)extendedModifier;
                    primitiveFieldMetadata.getModifiers().add(new ModifierMetadata(modifier.getKeyword().toString()));
                }
            }
            return primitiveFieldMetadata;
        }
        if (type.isSimpleType()) {
            SimpleType simpleType = (SimpleType)type;
            FieldMetadata simpleTypeFieldMetadata = FieldMetadata.simpleType(JavaMetadataUtil.getName(simpleType.getName()));
            variable = new Variable();
            variable.setName(JavaMetadataUtil.getName(singleVariableDeclaration.getName()));
            simpleTypeFieldMetadata.setName(variable.getName());
            simpleTypeFieldMetadata.getVariables().add(variable);
            for (IExtendedModifier simpleTypeExtendedModifier : (List<IExtendedModifier>)singleVariableDeclaration.modifiers()) {
                if (simpleTypeExtendedModifier.isAnnotation()) {
                    simpleTypeFieldMetadata.getAnnotations().add(createAnnotationMetadataFor((Annotation)simpleTypeExtendedModifier));
                } else {
                    Modifier modifier = (Modifier)simpleTypeExtendedModifier;
                    simpleTypeFieldMetadata.getModifiers().add(new ModifierMetadata(modifier.getKeyword().toString()));
                }
            }
            return simpleTypeFieldMetadata;
        }
        if (type.isParameterizedType()) {
            ParameterizedType parameterizedType = (ParameterizedType)type;
            FieldMetadata parameterizedTypeFieldMetadata = FieldMetadata.parametrizedType(getTypeName(parameterizedType));

            variable = new Variable();
            variable.setName(JavaMetadataUtil.getName(singleVariableDeclaration.getName()));
            parameterizedTypeFieldMetadata.setName(variable.getName());
            parameterizedTypeFieldMetadata.getVariables().add(variable);
            for (IExtendedModifier parameterizedExtendedModifier : (List<IExtendedModifier>)singleVariableDeclaration.modifiers()) {
                if (parameterizedExtendedModifier.isAnnotation()) {
                    parameterizedTypeFieldMetadata.getAnnotations().add(createAnnotationMetadataFor((Annotation)parameterizedExtendedModifier));
                } else {
                    Modifier modifier = (Modifier)parameterizedExtendedModifier;
                    parameterizedTypeFieldMetadata.getModifiers().add(new ModifierMetadata(modifier.getKeyword().toString()));
                }
            }
            return parameterizedTypeFieldMetadata;
        }
        if (type.isArrayType()) {
            ArrayType arrayType = (ArrayType)type;
            FieldMetadata arrayTypeFieldMetadata = FieldMetadata.arrayType(getTypeName(arrayType));

            variable = new Variable();
            variable.setName(JavaMetadataUtil.getName(singleVariableDeclaration.getName()));
            arrayTypeFieldMetadata.setName(variable.getName());
            arrayTypeFieldMetadata.getVariables().add(variable);

            for (IExtendedModifier arrayTypeExtendedModifier : (List<IExtendedModifier>)singleVariableDeclaration.modifiers()) {
                if (arrayTypeExtendedModifier.isAnnotation()) {
                    arrayTypeFieldMetadata.getAnnotations().add(createAnnotationMetadataFor((Annotation)arrayTypeExtendedModifier));
                } else {
                    Modifier modifier = (Modifier)arrayTypeExtendedModifier;
                    arrayTypeFieldMetadata.getModifiers().add(new ModifierMetadata(modifier.getKeyword().toString()));
                }
            }
            return arrayTypeFieldMetadata;
        }
        return null;
    }
713728
FieldDescriptor getFieldDescriptor(TypeCache.CachedType<?> cachedType, String signature) {
        FieldDescriptor fieldDescriptor = cachedType.getField(signature);
        if (fieldDescriptor == null) {
            fieldDescriptor = scannerContext.getStore().create(FieldDescriptor.class);
            fieldDescriptor.setSignature(signature);
            cachedType.addMember(signature, fieldDescriptor);
        }
        return fieldDescriptor;
    }