public static JavaTypeName Parse(string dottedFullName) { var ret = new JavaTypeName(); foreach (var label in genericConstraintsLabels) { int gcidx = dottedFullName.IndexOf(label, StringComparison.Ordinal); int gcgidx = gcidx < 0 ? -1 : dottedFullName.IndexOf('<', 0, gcidx); int gccidx = gcidx < 0 ? -1 : dottedFullName.IndexOf(',', 0, gcidx); if (gcidx > 0 && gcgidx < 0 && gccidx < 0) { string args = dottedFullName.Substring(gcidx + label.Length).Trim(); ret.BoundsType = label; ret.GenericConstraints = ParseCommaSeparatedTypeNames(args).Select(s => Parse(s)).ToArray(); dottedFullName = dottedFullName.Substring(0, gcidx).Trim(); } } if (dottedFullName.EndsWith("...", StringComparison.Ordinal)) { ret.ArrayPart = "..."; dottedFullName = dottedFullName.Substring(0, dottedFullName.Length - 3); } while (dottedFullName.LastOrDefault() == ']') { int aidx = dottedFullName.LastIndexOf('['); ret.ArrayPart += dottedFullName.Substring(aidx); dottedFullName = dottedFullName.Substring(0, aidx); } int idx = dottedFullName.IndexOf('<'); int nextIndex = dottedFullName.Length; if (idx > 0) { int last = GetMatchingGenericCloser(dottedFullName, idx + 1); ret.GenericArguments = ParseCommaSeparatedTypeNames(dottedFullName.Substring(idx + 1, last - idx - 1)) .Select(s => JavaTypeName.Parse(s.Trim())) .ToArray(); nextIndex = last + 1; } // at this state, there is no way to distinguish package name from this name specification. ret.DottedName = idx < 0 ? dottedFullName : dottedFullName.Substring(0, idx); if (nextIndex < dottedFullName.Length) { if (dottedFullName [nextIndex] != '.') { throw new ArgumentException(nameof(dottedFullName)); } // the generic parent is parsed, but the rest is still there. var parent = ret; ret = Parse(dottedFullName.Substring(nextIndex + 1)); ret.GenericParent = parent; } return(ret); }
public void Resolve(JavaTypeCollection types, ICollection <JavaUnresolvableModel> unresolvables) { var jtn = JavaTypeName.Parse(GenericType); if (jtn.ArrayPart == "...") { IsParameterArray = true; } var type_parameters = DeclaringMethod.GetApplicableTypeParameters().ToArray(); try { TypeModel = types.ResolveTypeReference(GenericType, type_parameters); } catch (JavaTypeResolutionException) { unresolvables.Add(new JavaUnresolvableModel(this, Type, UnresolvableType.ParameterType)); return; } }
public JavaTypeReference ResolveTypeReference(string name, params JavaTypeParameter [] contextTypeParameters) => ResolveTypeReference(JavaTypeName.Parse(name), contextTypeParameters);