@@ -201,46 +201,7 @@ public void computeFeatureVectorForToken(int i) {
201201
202202 int aligned = CAT_NO_ALIGNMENT ;
203203 if ( precedingNL >0 ) {
204- // at a newline, are we aligned with a prior sibling (in a list) etc...
205- if ( CollectFeatures .isAlignedWithFirstSiblingOfList (tokenToNodeMap , tokens , curToken ) ) {
206- aligned = CAT_ALIGN_WITH_LIST_FIRST_ELEMENT ;
207- }
208- else {
209- TerminalNode matchingLeftSymbol = getMatchingLeftSymbol (doc , node );
210- if ( matchingLeftSymbol !=null &&
211- matchingLeftSymbol .getSymbol ().getCharPositionInLine ()==curToken .getCharPositionInLine () ) {
212- aligned = CAT_ALIGN_WITH_PAIR ;
213- }
214- else {
215- ParserRuleContext parent = (ParserRuleContext )node .getParent ();
216- ParserRuleContext earliestRightAncestor = earliestAncestorEndingWithToken (parent , curToken );
217- Token earliestAncestorRightStart = null ;
218- if ( earliestRightAncestor !=null ) {
219- earliestAncestorRightStart = earliestRightAncestor .getStart ();
220- }
221- if ( earliestAncestorRightStart !=null &&
222- earliestAncestorRightStart !=curToken &&
223- earliestAncestorRightStart .getCharPositionInLine ()==curToken .getCharPositionInLine () )
224- {
225- aligned = CAT_ALIGN_WITH_ANCESTOR_FIRST_TOKEN ;
226- }
227- else {
228- Token earliestAncestorsParentStart = null ;
229- if ( earliestRightAncestor !=null && earliestRightAncestor .getParent ()!=null ) {
230- earliestAncestorsParentStart = earliestRightAncestor .getParent ().getStart ();
231- }
232- if ( earliestAncestorsParentStart !=null &&
233- earliestAncestorsParentStart !=curToken &&
234- earliestAncestorsParentStart .getCharPositionInLine ()==curToken .getCharPositionInLine () )
235- {
236- aligned = CAT_ALIGN_WITH_ANCESTORS_PARENT_FIRST_TOKEN ;
237- }
238- else if ( columnDelta >0 ) {
239- aligned = CAT_INDENT ; // indent standard amount
240- }
241- }
242- }
243- }
204+ aligned = getAlignmentCategory (node , curToken , columnDelta );
244205 }
245206
246207 int ws = 0 ;
@@ -258,6 +219,50 @@ else if ( columnDelta>0 ) {
258219 this .features .add (features );
259220 }
260221
222+ // at a newline, are we aligned with a prior sibling (in a list) etc...
223+ public int getAlignmentCategory (TerminalNode node , Token curToken , int columnDelta ) {
224+ int aligned = CAT_NO_ALIGNMENT ;
225+
226+ ParserRuleContext parent = (ParserRuleContext )node .getParent ();
227+ TerminalNode matchingLeftSymbol = getMatchingLeftSymbol (doc , node );
228+ ParserRuleContext earliestRightAncestor = earliestAncestorEndingWithToken (parent , curToken );
229+ Token earliestAncestorRightStart = null ;
230+ if ( earliestRightAncestor !=null ) {
231+ earliestAncestorRightStart = earliestRightAncestor .getStart ();
232+ }
233+ Token earliestAncestorsParentStart = null ;
234+ if ( earliestRightAncestor !=null && earliestRightAncestor .getParent ()!=null ) {
235+ earliestAncestorsParentStart = earliestRightAncestor .getParent ().getStart ();
236+ }
237+
238+ // at a newline, are we aligned with a prior sibling (in a list) etc...
239+ if ( CollectFeatures .isAlignedWithFirstSiblingOfList (tokenToNodeMap , tokens , curToken ) ) {
240+ aligned = CAT_ALIGN_WITH_LIST_FIRST_ELEMENT ;
241+ }
242+ else if ( matchingLeftSymbol !=null &&
243+ matchingLeftSymbol .getSymbol ().getCharPositionInLine ()==curToken .getCharPositionInLine () )
244+ {
245+ aligned = CAT_ALIGN_WITH_PAIR ;
246+ }
247+ else if ( earliestAncestorRightStart !=null &&
248+ earliestAncestorRightStart !=curToken &&
249+ earliestAncestorRightStart .getCharPositionInLine ()==curToken .getCharPositionInLine () )
250+ {
251+ aligned = CAT_ALIGN_WITH_ANCESTOR_FIRST_TOKEN ;
252+ }
253+ else if ( earliestAncestorsParentStart !=null &&
254+ earliestAncestorsParentStart !=curToken &&
255+ earliestAncestorsParentStart .getCharPositionInLine ()==curToken .getCharPositionInLine () )
256+ {
257+ aligned = CAT_ALIGN_WITH_ANCESTORS_PARENT_FIRST_TOKEN ;
258+ }
259+ else if ( columnDelta >0 ) {
260+ aligned = CAT_INDENT ; // indent standard amount
261+ }
262+
263+ return aligned ;
264+ }
265+
261266 public static int getPrecedingNL (CommonTokenStream tokens , int i ) {
262267 int precedingNL = 0 ;
263268 List <Token > wsTokensBeforeCurrentToken = tokens .getHiddenTokensToLeft (i );
0 commit comments