/** * 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; }
throw error("Invalid tag"); return parseTypeDesc().toArrayType(); return parseTypeDesc(); endPos = nextTerminator(); int dot = mStr.lastIndexOf('.', endPos); if (dot < mPos) { throw error("Invalid enumeration"); endPos = nextTerminator() + 1; break; throw error("Invalid type descriptor");
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); } }
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)); }
Annotation propAnn = dest.makeAnnotation(); propAnn.setType(propType); parseAnnotation(propAnn, propType); mv = dest.makeMemberValue(propAnn); } else if (propTag == TAG_CLASS) { mv = dest.makeMemberValue(parseTypeDesc()); } else { int endPos = nextTerminator(); String valueStr = mStr.substring(mPos, endPos); throw error("Invalid tag"); throw error("Invalid property value");
private int nextTerminator() { int index = mStr.indexOf(';', mPos); if (index < 0) { throw error("Missing terminator"); } return index; }
private char peekTag() { char tag = parseTag(); mPos--; return tag; }
Annotation propAnn = dest.makeAnnotation(); propAnn.setType(propType); parseAnnotation(propAnn, propType); mv = dest.makeMemberValue(propAnn); } else if (propTag == TAG_CLASS) { mv = dest.makeMemberValue(parseTypeDesc()); } else { int endPos = nextTerminator(); String valueStr = mStr.substring(mPos, endPos); throw error("Invalid tag"); throw error("Invalid property value");
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 char parseTag() { try { return mStr.charAt(mPos++); } catch (IndexOutOfBoundsException e) { throw error("Too short"); } }
private char peekTag() { char tag = parseTag(); mPos--; return tag; }
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; }
throw error("Invalid tag"); return parseTypeDesc().toArrayType(); return parseTypeDesc(); endPos = nextTerminator(); int dot = mStr.lastIndexOf('.', endPos); if (dot < mPos) { throw error("Invalid enumeration"); endPos = nextTerminator() + 1; break; throw error("Invalid type descriptor");
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 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; }