private int nextTerminator() { int index = mStr.indexOf(';', mPos); if (index < 0) { throw error("Missing terminator"); } return index; }
private char parseTag() { try { return mStr.charAt(mPos++); } catch (IndexOutOfBoundsException e) { throw error("Too short"); } }
private String parseName() { int index = mStr.indexOf('=', mPos); if (index < 0) { throw error("Incomplete assignment"); } String name = mStr.substring(mPos, index); mPos = index + 1; return name; }
private Annotation.MemberValue parseArray(Annotation dest, char compTag, TypeDesc compType) { List<Annotation.MemberValue> mvList = new ArrayList<Annotation.MemberValue>(); while (true) { try { if (mStr.charAt(mPos) == ';') { mPos++; break; } } catch (IndexOutOfBoundsException e) { error("Missing terminator"); } mvList.add(parseProperty(dest, compTag, compType)); } Annotation.MemberValue[] mvArray = new Annotation.MemberValue[mvList.size()]; return dest.makeMemberValue(mvList.toArray(mvArray)); }
private void parseAnnotation(Annotation dest, TypeDesc annType) { while (true) { try { if (mStr.charAt(mPos) == ';') { mPos++; break; } } catch (IndexOutOfBoundsException e) { error("Missing terminator"); } if (mPos >= mStr.length()) { break; } String propName = parseName(); char propTag = peekTag(); Annotation.MemberValue mv; if (propTag == TAG_ARRAY) { mPos++; mv = parseArray(dest, peekTag(), parseTypeDesc()); } else { mv = parseProperty(dest, propTag, parseTypeDesc()); } dest.putMemberValue(propName, mv); } }
/** * Parses the given annotation, returning the root annotation that received * the results. * * @param rootAnnotation root annotation * @return root annotation * @throws IllegalArgumentExcecption if annotation is malformed */ public Annotation parse(Annotation rootAnnotation) { mPos = 0; if (parseTag() != TAG_ANNOTATION) { throw error("Malformed"); } TypeDesc rootAnnotationType = parseTypeDesc(); if (rootAnnotation == null) { rootAnnotation = buildRootAnnotation(rootAnnotationType); } else if (!rootAnnotationType.equals(rootAnnotation.getType())) { throw new IllegalArgumentException ("Annotation type of \"" + rootAnnotationType + "\" does not match expected type of \"" + rootAnnotation.getType()); } parseAnnotation(rootAnnotation, rootAnnotationType); return rootAnnotation; }
private int nextTerminator() { int index = mStr.indexOf(';', mPos); if (index < 0) { throw error("Missing terminator"); } return index; }
private char parseTag() { try { return mStr.charAt(mPos++); } catch (IndexOutOfBoundsException e) { throw error("Too short"); } }
private String parseName() { int index = mStr.indexOf('=', mPos); if (index < 0) { throw error("Incomplete assignment"); } String name = mStr.substring(mPos, index); mPos = index + 1; return name; }
private Annotation.MemberValue parseArray(Annotation dest, char compTag, TypeDesc compType) { List<Annotation.MemberValue> mvList = new ArrayList<Annotation.MemberValue>(); while (true) { try { if (mStr.charAt(mPos) == ';') { mPos++; break; } } catch (IndexOutOfBoundsException e) { error("Missing terminator"); } mvList.add(parseProperty(dest, compTag, compType)); } Annotation.MemberValue[] mvArray = new Annotation.MemberValue[mvList.size()]; return dest.makeMemberValue(mvList.toArray(mvArray)); }
private void parseAnnotation(Annotation dest, TypeDesc annType) { while (true) { try { if (mStr.charAt(mPos) == ';') { mPos++; break; } } catch (IndexOutOfBoundsException e) { error("Missing terminator"); } if (mPos >= mStr.length()) { break; } String propName = parseName(); char propTag = peekTag(); Annotation.MemberValue mv; if (propTag == TAG_ARRAY) { mPos++; mv = parseArray(dest, peekTag(), parseTypeDesc()); } else { mv = parseProperty(dest, propTag, parseTypeDesc()); } dest.putMemberValue(propName, mv); } }
/** * Parses the given annotation, returning the root annotation that received * the results. * * @param rootAnnotation root annotation * @return root annotation * @throws IllegalArgumentExcecption if annotation is malformed */ public Annotation parse(Annotation rootAnnotation) { mPos = 0; if (parseTag() != TAG_ANNOTATION) { throw error("Malformed"); } TypeDesc rootAnnotationType = parseTypeDesc(); if (rootAnnotation == null) { rootAnnotation = buildRootAnnotation(rootAnnotationType); } else if (!rootAnnotationType.equals(rootAnnotation.getType())) { throw new IllegalArgumentException ("Annotation type of \"" + rootAnnotationType + "\" does not match expected type of \"" + rootAnnotation.getType()); } parseAnnotation(rootAnnotation, rootAnnotationType); return rootAnnotation; }