int (ASTNode parent, ASTNode child, CommonCodeStyleSettings settings) { IElementType nodeType = parent.getElementType(); if (nodeType == JavaElementType.METHOD) { return settings.METHOD_ANNOTATION_WRAP; } if (nodeType == JavaElementType.CLASS) { if (child.getElementType() == JavaTokenType.END_OF_LINE_COMMENT) { return CommonCodeStyleSettings.DO_NOT_WRAP; } // There is a possible case that current document state is invalid from language syntax point of view, e.g. the user starts // typing field definition and re-formatting is triggered by 'auto insert javadoc' processing. Example: // class Test { // @NotNull Object // } // Here '@NotNull' has a 'class' node as a parent but we want to use field annotation setting value. // Hence we check if subsequent parsed info is valid. for (ASTNode node = child.getTreeNext(); node != null; node = node.getTreeNext()) { if (node.getElementType() == TokenType.WHITE_SPACE || node instanceof PsiTypeElement) { continue; } if (node instanceof PsiErrorElement) { return settings.FIELD_ANNOTATION_WRAP; } } return settings.CLASS_ANNOTATION_WRAP; } if (nodeType == JavaElementType.FIELD) { return settings.FIELD_ANNOTATION_WRAP; } if (nodeType == JavaElementType.PARAMETER || nodeType == JavaElementType.RECEIVER_PARAMETER || nodeType == JavaElementType.RESOURCE_VARIABLE) { return settings.PARAMETER_ANNOTATION_WRAP; } if (nodeType == JavaElementType.LOCAL_VARIABLE) { return settings.VARIABLE_ANNOTATION_WRAP; } if (nodeType == JavaElementType.MODULE) { return settings.CLASS_ANNOTATION_WRAP; } return CommonCodeStyleSettings.DO_NOT_WRAP; }