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

Method parseTokenWithSeparator

code/src/java/plugin/lsttokens/SabLst.java:62–166  ·  view source on GitHub ↗

This method sets the special abilities granted by this [object]. For efficiency, avoid calling this method except from I/O routines. @param context @param obj the CDOMbject that is to receive the new SpecialAbility @param aString String of special abilities delimited by pipes

(LoadContext context, CDOMObject obj, String aString)

Source from the content-addressed store, hash-verified

60 * String of special abilities delimited by pipes
61 */
62 @Override
63 protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String aString)
64 {
65 if (obj instanceof Ungranted)
66 {
67 return new ParseResult.Fail(
68 "Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName());
69 }
70 StringTokenizer tok = new StringTokenizer(aString, Constants.PIPE);
71
72 String firstToken = tok.nextToken();
73 if (looksLikeAPrerequisite(firstToken))
74 {
75 return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName());
76 }
77
78 boolean foundClear = false;
79
80 if (Constants.LST_DOT_CLEAR.equals(firstToken))
81 {
82 context.getObjectContext().removeList(obj, ListKey.SAB);
83 if (!tok.hasMoreTokens())
84 {
85 return ParseResult.SUCCESS;
86 }
87 firstToken = tok.nextToken();
88 foundClear = true;
89 }
90
91 if (looksLikeAPrerequisite(firstToken))
92 {
93 return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR in " + getTokenName());
94 }
95
96 if (Constants.LST_DOT_CLEAR.equals(firstToken))
97 {
98 return new ParseResult.Fail("SA tag confused by redundant '.CLEAR'" + aString);
99 }
100
101 SpecialAbility sa = new SpecialAbility(firstToken.intern());
102
103 if (!tok.hasMoreTokens())
104 {
105 sa.setName(firstToken.intern());
106 context.getObjectContext().addToList(obj, ListKey.SAB, sa);
107 return ParseResult.SUCCESS;
108 }
109
110 StringBuilder saName = new StringBuilder(aString.length());
111 saName.append(firstToken);
112
113 String token = tok.nextToken();
114 while (true)
115 {
116 if (Constants.LST_DOT_CLEAR.equals(token))
117 {
118 return new ParseResult.Fail("SA tag confused by '.CLEAR' as a " + "middle token: " + aString);
119 }

Callers

nothing calls this directly

Calls 14

getTokenNameMethod · 0.95
getSimpleNameMethod · 0.80
nextTokenMethod · 0.80
hasMoreTokensMethod · 0.80
getPrerequisiteMethod · 0.80
equalsMethod · 0.65
removeListMethod · 0.65
getObjectContextMethod · 0.65
setNameMethod · 0.65
addToListMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected