boolean (final PsiClass classToBind, final PsiClass newClass) { Lexer oldTextLexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST); Lexer newTextLexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST); String oldBuffer = classToBind.getText(); String newBuffer = newClass.getText(); oldTextLexer.start(oldBuffer); newTextLexer.start(newBuffer); while(true) { IElementType oldLexem = oldTextLexer.getTokenType(); IElementType newLexem = newTextLexer.getTokenType(); if (oldLexem == null || newLexem == null) { // must terminate at the same time return oldLexem == null && newLexem == null; } if (oldLexem != newLexem) { return false; } if (oldLexem != TokenType.WHITE_SPACE && oldLexem != JavaDocElementType.DOC_COMMENT) { int oldStart = oldTextLexer.getTokenStart(); int newStart = newTextLexer.getTokenStart(); int oldLength = oldTextLexer.getTokenEnd() - oldTextLexer.getTokenStart(); int newLength = newTextLexer.getTokenEnd() - newTextLexer.getTokenStart(); if (oldLength != newLength) { return false; } for(int i=0; i<oldLength; i++) { if (oldBuffer.charAt(oldStart+i) != newBuffer.charAt(newStart+i)) { return false; } } } oldTextLexer.advance(); newTextLexer.advance(); } }