MCPcopy Create free account
hub / github.com/PCGen/pcgen / parseToken

Method parseToken

code/src/java/plugin/lsttokens/TemplateLst.java:61–152  ·  view source on GitHub ↗
(LoadContext context, CDOMObject cdo, String value)

Source from the content-addressed store, hash-verified

59 }
60
61 @Override
62 public ParseResult parseToken(LoadContext context, CDOMObject cdo, String value)
63 {
64 if (cdo instanceof Ungranted)
65 {
66 return new ParseResult.Fail(
67 "Cannot use " + getTokenName() + " on an Ungranted object type: " + cdo.getClass().getSimpleName());
68 }
69 ListKey<CDOMReference<PCTemplate>> lk;
70 String remaining;
71 boolean consolidate = false;
72 boolean specialLegal = false;
73 if (value.startsWith(Constants.LST_CHOOSE_COLON))
74 {
75 lk = ListKey.TEMPLATE_CHOOSE;
76 remaining = value.substring(Constants.LST_CHOOSE_COLON.length());
77 consolidate = true;
78 }
79 else if (value.startsWith(ADDCHOICE_COLON))
80 {
81 lk = ListKey.TEMPLATE_ADDCHOICE;
82 remaining = value.substring(ADDCHOICE_COLON.length());
83 }
84 else
85 {
86 lk = ListKey.TEMPLATE;
87 remaining = value;
88 specialLegal = true;
89 }
90 ParseResult pr = checkSeparatorsAndNonEmpty('|', remaining);
91 if (!pr.passed())
92 {
93 return pr;
94 }
95
96 StringTokenizer tok = new StringTokenizer(remaining, Constants.PIPE);
97
98 List<CDOMReference<PCTemplate>> list = new ArrayList<>();
99 List<CDOMReference<PCTemplate>> removelist = new ArrayList<>();
100 while (tok.hasMoreTokens())
101 {
102 String templKey = tok.nextToken();
103 if (specialLegal && templKey.endsWith(".REMOVE"))
104 {
105 removelist.add(context.getReferenceContext().getCDOMReference(PCTEMPLATE_CLASS,
106 templKey.substring(0, templKey.length() - 7)));
107 }
108 else if (specialLegal && templKey.equals(Constants.LST_PERCENT_LIST))
109 {
110 context.getObjectContext().addToList(cdo, ListKey.NEW_CHOOSE_ACTOR, this);
111 }
112 else
113 {
114 ReferenceManufacturer<PCTemplate> rm = context.getReferenceContext().getManufacturer(PCTEMPLATE_CLASS);
115 CDOMReference<PCTemplate> ref = TokenUtilities.getTypeOrPrimitive(rm, templKey);
116 if (ref == null)
117 {
118 // If we have an invalid template reference, regardless of type, log it

Callers

nothing calls this directly

Calls 15

getTokenNameMethod · 0.95
passedMethod · 0.95
getTypeOrPrimitiveMethod · 0.95
logMethod · 0.95
addReferenceMethod · 0.95
trimToSizeMethod · 0.95
getSimpleNameMethod · 0.80
hasMoreTokensMethod · 0.80
nextTokenMethod · 0.80
getCDOMReferenceMethod · 0.80
addMethod · 0.65

Tested by

no test coverage detected