void (@NotNull PsiField field) { boolean isSectionCommentsDetected = registerSectionComments(field); // There is a possible case that more than one field is declared for the same type like 'int i, j;'. // the case is handled in getFieldWithSiblings(). PsiElement fieldPrev = getPreviousNonWsComment(field.getPrevSibling(), 0); if (PsiUtil.isJavaToken(fieldPrev, JavaTokenType.COMMA)) { return; } // There is a possible case that fields which share the same type declaration are located on different document lines, e.g.: // int i1, // i2; // We want to consider only the first declaration then but need to expand its range to all affected lines (up to semicolon). TextRange range = isSectionCommentsDetected ? getElementRangeWithoutComments(field) : field.getTextRange(); PsiElement child = field.getLastChild(); boolean needSpecialProcessing = true; if (isSemicolon(child)) { needSpecialProcessing = false; } else if (child instanceof PsiComment) { // There is a possible field definition like below: // int f; // my comment. // The comment goes into field PSI here, that's why we need to handle it properly. PsiElement prev = getPreviousNonWsComment(child, range.getStartOffset()); needSpecialProcessing = prev != null && !isSemicolon(prev); } if (needSpecialProcessing) { for (PsiElement e = field.getNextSibling(); e != null; e = e.getNextSibling()) { if (e instanceof PsiWhiteSpace || e instanceof PsiComment) { // Skip white space and comment continue; } if (e instanceof PsiJavaToken) { if (((PsiJavaToken)e).getTokenType() == JavaTokenType.COMMA) { // Skip comma continue; } else { break; } } if (e instanceof PsiField) { PsiElement c = e.getLastChild(); if (c != null) { c = getPreviousNonWsComment(c, range.getStartOffset()); } // Stop if current field ends by a semicolon. if (c instanceof PsiErrorElement // Incomplete field without trailing semicolon || PsiUtil.isJavaToken(c, JavaTokenType.SEMICOLON)) { range = TextRange.create(range.getStartOffset(), expandToCommentIfPossible(c)); } else { continue; } } break; } } JavaElementArrangementEntry entry = createNewEntry(range, FIELD, field.getName()); if (entry == null) { return; } processEntry(entry, field, field.getInitializer()); myInfo.onFieldEntryCreated(field, entry); List<PsiField> referencedFields = new ArrayList<>(); for (PsiField adjacentField : getFieldWithSiblings(field)) { referencedFields.addAll(getReferencedFields(adjacentField)); } for (PsiField referencedField : referencedFields) { myInfo.registerFieldInitializationDependency(field, referencedField); } }