diff --git a/RegExpSupport/src/org/intellij/lang/regexp/_RegExLexer.java b/RegExpSupport/src/org/intellij/lang/regexp/_RegExLexer.java index b789ad5a697e..89ccdee550b8 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/_RegExLexer.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/_RegExLexer.java @@ -14,8 +14,6 @@ * limitations under the License. */ -/* The following code was generated by JFlex 1.4.1 on 23.09.09 18:11 */ - /* It's an automatically generated code. Do not modify it. */ package org.intellij.lang.regexp; @@ -30,8 +28,8 @@ import com.intellij.psi.StringEscapesTokenTypes; /** * This class is a scanner generated by * JFlex 1.4.1 - * on 23.09.09 18:11 from the specification file - * C:/JetBrains/IDEA/svnPlugins/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex + * on 04.11.09 17:54 from the specification file + * RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex */ class _RegExLexer implements FlexLexer { /** initial size of the lookahead buffer */ @@ -51,12 +49,12 @@ class _RegExLexer implements FlexLexer { * Translates characters to character classes */ private static final String ZZ_CMAP_PACKED = - "\10\0\2\50\1\13\1\0\1\50\1\57\22\0\1\60\1\54\1\0"+ - "\1\56\1\15\1\0\1\47\1\0\1\4\1\5\1\17\1\20\1\46"+ - "\1\42\1\3\1\0\1\2\7\41\2\1\1\51\1\0\1\55\1\53"+ - "\1\52\1\16\1\0\1\24\1\24\1\30\1\27\1\36\1\34\1\25"+ + "\10\0\2\51\1\13\1\0\1\51\1\60\22\0\1\44\1\55\1\0"+ + "\1\57\1\15\1\0\1\50\1\0\1\4\1\5\1\17\1\20\1\47"+ + "\1\42\1\3\1\0\1\2\7\41\2\1\1\52\1\0\1\56\1\54"+ + "\1\53\1\16\1\0\1\24\1\24\1\30\1\27\1\36\1\34\1\25"+ "\1\43\1\32\6\43\1\33\1\35\1\43\1\26\3\43\1\26\1\26"+ - "\1\43\1\25\1\10\1\12\1\11\1\14\1\44\1\0\1\23\1\24"+ + "\1\43\1\25\1\10\1\12\1\11\1\14\1\45\1\0\1\23\1\24"+ "\1\31\1\27\1\23\1\23\2\43\1\32\4\43\1\22\1\43\1\33"+ "\1\43\1\22\1\26\1\22\1\40\1\43\1\26\1\37\1\43\1\25"+ "\1\6\1\21\1\7\54\0\1\43\12\0\1\43\4\0\1\43\5\0"+ @@ -65,43 +63,43 @@ class _RegExLexer implements FlexLexer { "\1\43\1\0\24\43\1\0\54\43\1\0\46\43\1\0\5\43\4\0"+ "\202\43\10\0\105\43\1\0\46\43\2\0\2\43\6\0\20\43\41\0"+ "\46\43\2\0\1\43\7\0\47\43\110\0\33\43\5\0\3\43\56\0"+ - "\32\43\5\0\13\43\25\0\12\45\4\0\2\43\1\0\143\43\1\0"+ - "\1\43\17\0\2\43\7\0\2\43\12\45\3\43\2\0\1\43\20\0"+ + "\32\43\5\0\13\43\25\0\12\46\4\0\2\43\1\0\143\43\1\0"+ + "\1\43\17\0\2\43\7\0\2\43\12\46\3\43\2\0\1\43\20\0"+ "\1\43\1\0\36\43\35\0\3\43\60\0\46\43\13\0\1\43\u0152\0"+ - "\66\43\3\0\1\43\22\0\1\43\7\0\12\43\4\0\12\45\25\0"+ + "\66\43\3\0\1\43\22\0\1\43\7\0\12\43\4\0\12\46\25\0"+ "\10\43\2\0\2\43\2\0\26\43\1\0\7\43\1\0\1\43\3\0"+ - "\4\43\3\0\1\43\36\0\2\43\1\0\3\43\4\0\12\45\2\43"+ + "\4\43\3\0\1\43\36\0\2\43\1\0\3\43\4\0\12\46\2\43"+ "\23\0\6\43\4\0\2\43\2\0\26\43\1\0\7\43\1\0\2\43"+ - "\1\0\2\43\1\0\2\43\37\0\4\43\1\0\1\43\7\0\12\45"+ + "\1\0\2\43\1\0\2\43\37\0\4\43\1\0\1\43\7\0\12\46"+ "\2\0\3\43\20\0\11\43\1\0\3\43\1\0\26\43\1\0\7\43"+ "\1\0\2\43\1\0\5\43\3\0\1\43\22\0\1\43\17\0\2\43"+ - "\4\0\12\45\25\0\10\43\2\0\2\43\2\0\26\43\1\0\7\43"+ + "\4\0\12\46\25\0\10\43\2\0\2\43\2\0\26\43\1\0\7\43"+ "\1\0\2\43\1\0\5\43\3\0\1\43\36\0\2\43\1\0\3\43"+ - "\4\0\12\45\1\0\1\43\21\0\1\43\1\0\6\43\3\0\3\43"+ + "\4\0\12\46\1\0\1\43\21\0\1\43\1\0\6\43\3\0\3\43"+ "\1\0\4\43\3\0\2\43\1\0\1\43\1\0\2\43\3\0\2\43"+ - "\3\0\3\43\3\0\10\43\1\0\3\43\55\0\11\45\25\0\10\43"+ + "\3\0\3\43\3\0\10\43\1\0\3\43\55\0\11\46\25\0\10\43"+ "\1\0\3\43\1\0\27\43\1\0\12\43\1\0\5\43\46\0\2\43"+ - "\4\0\12\45\25\0\10\43\1\0\3\43\1\0\27\43\1\0\12\43"+ - "\1\0\5\43\3\0\1\43\40\0\1\43\1\0\2\43\4\0\12\45"+ + "\4\0\12\46\25\0\10\43\1\0\3\43\1\0\27\43\1\0\12\43"+ + "\1\0\5\43\3\0\1\43\40\0\1\43\1\0\2\43\4\0\12\46"+ "\25\0\10\43\1\0\3\43\1\0\27\43\1\0\20\43\46\0\2\43"+ - "\4\0\12\45\25\0\22\43\3\0\30\43\1\0\11\43\1\0\1\43"+ - "\2\0\7\43\72\0\60\43\1\0\2\43\14\0\7\43\11\0\12\45"+ + "\4\0\12\46\25\0\22\43\3\0\30\43\1\0\11\43\1\0\1\43"+ + "\2\0\7\43\72\0\60\43\1\0\2\43\14\0\7\43\11\0\12\46"+ "\47\0\2\43\1\0\1\43\2\0\2\43\1\0\1\43\2\0\1\43"+ "\6\0\4\43\1\0\7\43\1\0\3\43\1\0\1\43\1\0\1\43"+ "\2\0\2\43\1\0\4\43\1\0\2\43\11\0\1\43\2\0\5\43"+ - "\1\0\1\43\11\0\12\45\2\0\2\43\42\0\1\43\37\0\12\45"+ + "\1\0\1\43\11\0\12\46\2\0\2\43\42\0\1\43\37\0\12\46"+ "\26\0\10\43\1\0\42\43\35\0\4\43\164\0\42\43\1\0\5\43"+ - "\1\0\2\43\25\0\12\45\6\0\6\43\112\0\46\43\12\0\51\43"+ + "\1\0\2\43\25\0\12\46\6\0\6\43\112\0\46\43\12\0\51\43"+ "\7\0\132\43\5\0\104\43\5\0\122\43\6\0\7\43\1\0\77\43"+ "\1\0\1\43\1\0\4\43\2\0\7\43\1\0\1\43\1\0\4\43"+ "\2\0\47\43\1\0\1\43\1\0\4\43\2\0\37\43\1\0\1\43"+ "\1\0\4\43\2\0\7\43\1\0\1\43\1\0\4\43\2\0\7\43"+ "\1\0\7\43\1\0\27\43\1\0\37\43\1\0\1\43\1\0\4\43"+ - "\2\0\7\43\1\0\47\43\1\0\23\43\16\0\11\45\56\0\125\43"+ + "\2\0\7\43\1\0\47\43\1\0\23\43\16\0\11\46\56\0\125\43"+ "\14\0\u026c\43\2\0\10\43\12\0\32\43\5\0\113\43\25\0\15\43"+ "\1\0\4\43\16\0\22\43\16\0\22\43\16\0\15\43\1\0\3\43"+ - "\17\0\64\43\43\0\1\43\4\0\1\43\3\0\12\45\46\0\12\45"+ - "\6\0\130\43\10\0\51\43\127\0\35\43\51\0\12\45\36\43\2\0"+ + "\17\0\64\43\43\0\1\43\4\0\1\43\3\0\12\46\46\0\12\46"+ + "\6\0\130\43\10\0\51\43\127\0\35\43\51\0\12\46\36\43\2\0"+ "\5\43\u038b\0\154\43\224\0\234\43\4\0\132\43\6\0\26\43\2\0"+ "\6\43\2\0\46\43\2\0\6\43\2\0\10\43\1\0\1\43\1\0"+ "\1\43\1\0\1\43\1\0\37\43\2\0\65\43\1\0\7\43\1\0"+ @@ -116,7 +114,7 @@ class _RegExLexer implements FlexLexer { "\7\43\14\0\5\43\5\0\1\43\1\0\12\43\1\0\15\43\1\0"+ "\5\43\1\0\1\43\1\0\2\43\1\0\2\43\1\0\154\43\41\0"+ "\u016b\43\22\0\100\43\2\0\66\43\50\0\14\43\164\0\5\43\1\0"+ - "\207\43\23\0\12\45\7\0\32\43\6\0\32\43\13\0\131\43\3\0"+ + "\207\43\23\0\12\46\7\0\32\43\6\0\32\43\13\0\131\43\3\0"+ "\6\43\2\0\6\43\2\0\6\43\2\0\3\43\43\0"; /** @@ -136,13 +134,13 @@ class _RegExLexer implements FlexLexer { "\1\27\1\30\1\31\1\32\1\33\1\34\1\3\1\35"+ "\1\36\1\35\1\37\1\40\1\1\1\41\1\42\1\2"+ "\1\43\1\44\1\45\1\46\1\47\1\50\1\51\1\52"+ - "\1\53\2\54\1\55\1\11\1\56\1\57\1\60\1\61"+ - "\1\62\1\63\1\64\1\65\2\0\1\66\1\67\2\57"+ - "\2\60\1\70\1\71\1\0\1\66\1\57\1\72\2\60"+ - "\1\73\1\66\3\60\1\74"; + "\1\53\1\54\2\55\1\56\1\11\1\57\1\60\1\61"+ + "\1\62\1\63\1\64\1\65\1\66\2\0\1\67\1\70"+ + "\2\60\2\61\1\71\1\72\1\0\1\67\1\60\1\73"+ + "\2\61\1\74\1\67\3\61\1\75"; private static int [] zzUnpackAction() { - int [] result = new int[88]; + int [] result = new int[89]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; @@ -173,14 +171,15 @@ class _RegExLexer implements FlexLexer { "\0\u0188\0\u024c\0\u0188\0\u027d\0\u0188\0\u02ae\0\u0188\0\u0188"+ "\0\u0188\0\u0188\0\u0188\0\u02df\0\u0188\0\u0188\0\u01ea\0\u0188"+ "\0\u0188\0\u0310\0\u0341\0\u0188\0\u0188\0\u0372\0\u0188\0\u0188"+ - "\0\u03a3\0\u03d4\0\u0188\0\u0188\0\u0188\0\u0188\0\u0188\0\u0405"+ - "\0\u0188\0\u0188\0\u0188\0\u0436\0\u0467\0\u0188\0\u0188\0\u0188"+ - "\0\u0188\0\u0188\0\u0498\0\u04c9\0\u04fa\0\u0188\0\u052b\0\u055c"+ - "\0\u058d\0\u05be\0\u0188\0\u0188\0\u05ef\0\u0620\0\u0188\0\u0188"+ - "\0\u0651\0\u0682\0\u0188\0\u0188\0\u06b3\0\u06e4\0\u0188\0\u0188"; + "\0\u03a3\0\u03d4\0\u0188\0\u0188\0\u0188\0\u0188\0\u0188\0\u0188"+ + "\0\u0405\0\u0188\0\u0188\0\u0188\0\u0436\0\u0467\0\u0188\0\u0188"+ + "\0\u0188\0\u0188\0\u0188\0\u0498\0\u04c9\0\u04fa\0\u0188\0\u052b"+ + "\0\u055c\0\u058d\0\u05be\0\u0188\0\u0188\0\u05ef\0\u0620\0\u0188"+ + "\0\u0188\0\u0651\0\u0682\0\u0188\0\u0188\0\u06b3\0\u06e4\0\u0188"+ + "\0\u0188"; private static int [] zzUnpackRowMap() { - int [] result = new int[88]; + int [] result = new int[89]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; @@ -205,36 +204,37 @@ class _RegExLexer implements FlexLexer { private static final String ZZ_TRANS_PACKED_0 = "\3\11\1\12\1\13\1\14\1\15\1\11\1\16\1\11"+ "\1\17\1\20\1\21\1\22\1\23\1\24\1\25\1\26"+ - "\20\11\1\27\5\11\1\20\5\11\1\30\1\20\1\31"+ - "\12\11\1\32\1\0\45\11\1\33\2\34\4\33\1\35"+ - "\12\33\17\36\1\34\1\33\1\36\1\33\1\34\1\37"+ - "\12\33\11\40\1\41\1\40\1\0\45\40\6\11\1\15"+ - "\1\11\1\16\1\42\1\17\1\43\1\21\25\11\1\27"+ - "\4\11\1\44\1\43\6\11\1\43\1\11\6\45\1\46"+ + "\20\11\1\27\1\11\1\30\4\11\1\20\5\11\1\31"+ + "\1\20\12\11\1\32\1\0\45\11\1\33\2\34\4\33"+ + "\1\35\12\33\17\36\1\34\1\33\1\36\2\33\1\34"+ + "\1\37\11\33\11\40\1\41\1\40\1\0\45\40\6\11"+ + "\1\15\1\11\1\16\1\42\1\17\1\43\1\21\25\11"+ + "\1\27\5\11\1\44\1\43\6\11\1\43\6\45\1\46"+ "\1\45\1\47\1\45\1\17\46\45\5\50\1\51\14\50"+ - "\17\52\1\50\1\53\1\52\5\50\1\54\7\50\13\10"+ - "\1\55\43\10\1\55\1\10\77\0\1\56\53\0\1\57"+ - "\47\0\1\60\1\61\1\62\4\63\1\60\1\63\1\60"+ - "\1\63\1\60\6\63\2\64\2\65\2\66\1\67\1\70"+ - "\1\67\1\71\1\72\1\73\1\72\1\74\1\75\1\61"+ - "\1\63\1\72\15\60\36\0\1\76\23\0\2\34\36\0"+ - "\1\34\3\0\1\34\14\0\2\36\17\0\20\36\1\0"+ - "\3\36\62\0\1\77\33\0\17\52\2\0\1\52\37\0"+ - "\17\53\2\0\1\53\66\0\2\100\1\101\1\102\1\103"+ - "\1\104\3\0\2\61\36\0\1\61\21\0\1\105\36\0"+ - "\1\105\17\0\61\106\1\107\2\110\20\107\2\110\2\107"+ - "\3\110\2\107\1\110\1\107\1\110\2\107\1\110\17\107"+ - "\1\111\2\112\20\111\2\112\2\111\3\112\2\111\1\112"+ - "\1\111\1\112\2\111\1\112\17\111\53\0\1\113\1\114"+ - "\4\0\5\115\1\0\53\115\2\0\1\116\36\0\1\116"+ - "\17\0\62\117\2\120\20\117\2\120\2\117\3\120\2\117"+ - "\1\120\1\117\1\120\2\117\1\120\17\117\62\121\2\122"+ - "\20\121\2\122\2\121\3\122\2\121\1\122\1\121\1\122"+ - "\2\121\1\122\17\121\5\115\1\123\53\115\2\0\1\124"+ - "\36\0\1\124\17\0\62\125\2\126\20\125\2\126\2\125"+ - "\3\126\2\125\1\126\1\125\1\126\2\125\1\126\17\125"+ - "\62\127\2\130\20\127\2\130\2\127\3\130\2\127\1\130"+ - "\1\127\1\130\2\127\1\130\17\127"; + "\17\52\1\50\1\53\1\52\6\50\1\54\6\50\13\10"+ + "\1\55\44\10\1\55\77\0\1\56\53\0\1\57\47\0"+ + "\1\60\1\61\1\62\4\63\1\60\1\63\1\60\1\63"+ + "\1\64\6\63\2\65\2\66\2\67\1\70\1\71\1\70"+ + "\1\72\1\73\1\74\1\73\1\75\1\76\1\61\1\63"+ + "\1\73\1\64\4\60\1\64\6\60\1\64\36\0\1\77"+ + "\23\0\2\34\36\0\1\34\4\0\1\34\13\0\2\36"+ + "\17\0\20\36\1\0\1\36\1\0\2\36\62\0\1\100"+ + "\32\0\17\52\2\0\1\52\37\0\17\53\2\0\1\53"+ + "\67\0\2\101\1\102\1\103\1\104\1\105\2\0\2\61"+ + "\36\0\1\61\21\0\1\106\36\0\1\106\17\0\61\107"+ + "\1\110\2\111\20\110\2\111\2\110\3\111\2\110\1\111"+ + "\1\110\1\111\2\110\1\111\17\110\1\112\2\113\20\112"+ + "\2\113\2\112\3\113\2\112\1\113\1\112\1\113\2\112"+ + "\1\113\17\112\54\0\1\114\1\115\3\0\5\116\1\0"+ + "\53\116\2\0\1\117\36\0\1\117\17\0\62\120\2\121"+ + "\20\120\2\121\2\120\3\121\2\120\1\121\1\120\1\121"+ + "\2\120\1\121\17\120\62\122\2\123\20\122\2\123\2\122"+ + "\3\123\2\122\1\123\1\122\1\123\2\122\1\123\17\122"+ + "\5\116\1\124\53\116\2\0\1\125\36\0\1\125\17\0"+ + "\62\126\2\127\20\126\2\127\2\126\3\127\2\126\1\127"+ + "\1\126\1\127\2\126\1\127\17\126\62\130\2\131\20\130"+ + "\2\131\2\130\3\131\2\130\1\131\1\130\1\131\2\130"+ + "\1\131\17\130"; private static int [] zzUnpackTrans() { int [] result = new int[1813]; @@ -281,12 +281,12 @@ class _RegExLexer implements FlexLexer { "\6\0\2\1\2\11\1\1\2\11\1\3\1\1\12\11"+ "\1\1\1\11\1\1\1\11\1\1\5\11\1\1\2\11"+ "\1\3\2\11\2\1\2\11\1\1\1\15\1\11\2\1"+ - "\5\11\1\1\3\11\2\1\5\11\2\0\1\1\1\11"+ + "\6\11\1\1\3\11\2\1\5\11\2\0\1\1\1\11"+ "\4\1\2\11\1\0\1\1\2\11\2\1\2\11\2\1"+ "\2\11"; private static int [] zzUnpackAttribute() { - int [] result = new int[88]; + int [] result = new int[89]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; @@ -431,14 +431,7 @@ class _RegExLexer implements FlexLexer { // For Demetra compatibility public void reset(CharSequence buffer, int initialState){ - zzBuffer = buffer; - zzBufferArray = null; - zzCurrentPos = zzMarkedPos = zzStartRead = 0; - zzPushbackPos = 0; - zzAtEOF = false; - zzAtBOL = true; - zzEndRead = buffer.length(); - yybegin(initialState); + reset(buffer, 0, buffer.length(), initialState); } /** @@ -650,243 +643,247 @@ class _RegExLexer implements FlexLexer { case 7: { if (yystate() != CLASS2) yypushstate(EMBRACED); return RegExpTT.LBRACE; } - case 61: break; + case 62: break; case 6: { return RegExpTT.GROUP_END; } - case 62: break; + case 63: break; case 36: { yypushstate(CLASS1); return RegExpTT.CLASS_BEGIN; } - case 63: break; + case 64: break; case 14: { return RegExpTT.STAR; } - case 64: break; + case 65: break; case 40: { return RegExpTT.ESC_CHARACTER; } - case 65: break; + case 66: break; case 28: { return commentMode ? com.intellij.psi.TokenType.WHITE_SPACE : RegExpTT.ESC_CHARACTER; } - case 66: break; + case 67: break; + case 41: + { return commentMode ? RegExpTT.CHARACTER : RegExpTT.REDUNDANT_ESCAPE; + } + case 68: break; case 37: { return RegExpTT.REDUNDANT_ESCAPE; } - case 67: break; + case 69: break; case 24: { return RegExpTT.COMMA; } - case 68: break; - case 56: + case 70: break; + case 57: { return RegExpTT.POS_LOOKBEHIND; } - case 69: break; + case 71: break; case 39: { return RegExpTT.BAD_OCT_VALUE; } - case 70: break; + case 72: break; case 10: { return commentMode ? com.intellij.psi.TokenType.WHITE_SPACE : RegExpTT.CTRL_CHARACTER; } - case 71: break; + case 73: break; case 30: { yypopstate(); yypushstate(EMBRACED); return RegExpTT.LBRACE; } - case 72: break; - case 48: + case 74: break; + case 49: { return StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN; } - case 73: break; - case 57: + case 75: break; + case 58: { return RegExpTT.NEG_LOOKBEHIND; } - case 74: break; - case 60: + case 76: break; + case 61: { return RegExpTT.UNICODE_CHAR; } - case 75: break; - case 55: + case 77: break; + case 56: { if (xmlSchemaMode) { yypushback(1); return RegExpTT.CHAR_CLASS; } else return RegExpTT.CTRL; } - case 76: break; + case 78: break; case 35: { yybegin(OPTIONS); return RegExpTT.SET_OPTIONS; } - case 77: break; + case 79: break; case 12: { return RegExpTT.DOLLAR; } - case 78: break; - case 49: + case 80: break; + case 50: { yypopstate(); return RegExpTT.QUOTE_END; } - case 79: break; - case 52: + case 81: break; + case 53: { return RegExpTT.POS_LOOKAHEAD; } - case 80: break; + case 82: break; case 22: { yypopstate(); return RegExpTT.RBRACE; } - case 81: break; + case 83: break; case 3: { return RegExpTT.CHARACTER; } - case 82: break; - case 53: + case 84: break; + case 54: { return RegExpTT.NEG_LOOKAHEAD; } - case 83: break; - case 41: + case 85: break; + case 42: { return RegExpTT.ESC_CTRL_CHARACTER; } - case 84: break; + case 86: break; case 23: { return RegExpTT.NAME; } - case 85: break; - case 50: + case 87: break; + case 51: { return RegExpTT.ANDAND; } - case 86: break; + case 88: break; case 13: { return RegExpTT.QUEST; } - case 87: break; - case 43: + case 89: break; + case 44: { return RegExpTT.CHAR_CLASS; } - case 88: break; + case 90: break; case 17: { return RegExpTT.MINUS; } - case 89: break; - case 59: + case 91: break; + case 60: { return RegExpTT.COMMENT; } - case 90: break; + case 92: break; case 38: { return yystate() != CLASS2 ? RegExpTT.BACKREF : RegExpTT.ESC_CHARACTER; } - case 91: break; + case 93: break; case 16: { return RegExpTT.UNION; } - case 92: break; - case 44: + case 94: break; + case 45: { if (xmlSchemaMode) return RegExpTT.CHAR_CLASS; else return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; } - case 93: break; - case 54: + case 95: break; + case 55: { return RegExpTT.OCT_CHAR; } - case 94: break; + case 96: break; case 4: { return RegExpTT.DOT; } - case 95: break; + case 97: break; case 32: { yybegin(YYINITIAL); return RegExpTT.GROUP_END; } - case 96: break; + case 98: break; case 21: { return RegExpTT.NUMBER; } - case 97: break; - case 45: + case 99: break; + case 46: { yypushstate(PROP); return RegExpTT.PROPERTY; } - case 98: break; - case 19: + case 100: break; + case 18: { return commentMode ? com.intellij.psi.TokenType.WHITE_SPACE : RegExpTT.CHARACTER; } - case 99: break; + case 101: break; case 33: { handleOptions(); return RegExpTT.OPTIONS_OFF; } - case 100: break; + case 102: break; case 34: { yybegin(YYINITIAL); return RegExpTT.COLON; } - case 101: break; + case 103: break; case 25: { assert false : yytext(); } - case 102: break; + case 104: break; case 27: { yypopstate(); return RegExpTT.CLASS_END; } - case 103: break; + case 105: break; case 11: { return RegExpTT.CARET; } - case 104: break; + case 106: break; case 1: { handleOptions(); return RegExpTT.OPTIONS_ON; } - case 105: break; + case 107: break; case 29: { yypopstate(); yypushback(1); } - case 106: break; - case 42: + case 108: break; + case 43: { return yystate() != CLASS2 ? RegExpTT.BOUNDARY : RegExpTT.ESC_CHARACTER; } - case 107: break; - case 18: + case 109: break; + case 19: { if (commentMode) { yypushstate(COMMENT); return RegExpTT.COMMENT; } else return RegExpTT.CHARACTER; } - case 108: break; - case 58: + case 110: break; + case 59: { return RegExpTT.HEX_CHAR; } - case 109: break; + case 111: break; case 20: { return RegExpTT.BAD_CHARACTER; } - case 110: break; + case 112: break; case 5: { return RegExpTT.GROUP_BEGIN; } - case 111: break; + case 113: break; case 8: { yypushstate(CLASS2); return RegExpTT.CLASS_BEGIN; } - case 112: break; - case 51: + case 114: break; + case 52: { return RegExpTT.NON_CAPT_GROUP; } - case 113: break; + case 115: break; case 9: { return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; } - case 114: break; - case 47: + case 116: break; + case 48: { return RegExpTT.BAD_HEX_VALUE; } - case 115: break; + case 117: break; case 2: { yypopstate(); return RegExpTT.COMMENT; } - case 116: break; - case 46: + case 118: break; + case 47: { yypushstate(QUOTED); return RegExpTT.QUOTE_BEGIN; } - case 117: break; + case 119: break; case 26: { yybegin(CLASS2); return RegExpTT.CHARACTER; } - case 118: break; + case 120: break; case 15: { return RegExpTT.PLUS; } - case 119: break; + case 121: break; case 31: { yybegin(YYINITIAL); return RegExpTT.BAD_CHARACTER; } - case 120: break; + case 122: break; default: if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; diff --git a/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex b/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex index d2784722c228..dcd94c284ed0 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex +++ b/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex @@ -138,6 +138,7 @@ HEX_CHAR=[0-9a-fA-F] {ESCAPE} {CONTROL} { return RegExpTT.ESC_CTRL_CHARACTER; } {ESCAPE} [:letter:] { return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; } +{ESCAPE} [\n\b\t\r\f ] { return commentMode ? RegExpTT.CHARACTER : RegExpTT.REDUNDANT_ESCAPE; } {ESCAPE} {ANY} { return RegExpTT.REDUNDANT_ESCAPE; } {ESCAPE} { return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; } diff --git a/RegExpSupport/testData/RETest.xml b/RegExpSupport/testData/RETest.xml index 7578aebfabb8..e0c7c3163d86 100644 --- a/RegExpSupport/testData/RETest.xml +++ b/RegExpSupport/testData/RETest.xml @@ -979,4 +979,15 @@ OK + + + + (?x)a\ b\ c + OK + + + \ b]]> + OK + + diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactImpl.java index 90b10646826d..77564966808f 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactImpl.java @@ -16,11 +16,9 @@ package com.intellij.packaging.impl.artifacts; import com.intellij.openapi.util.UserDataHolderBase; -import com.intellij.packaging.artifacts.ArtifactProperties; -import com.intellij.packaging.artifacts.ArtifactPropertiesProvider; -import com.intellij.packaging.artifacts.ArtifactType; -import com.intellij.packaging.artifacts.ModifiableArtifact; +import com.intellij.packaging.artifacts.*; import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.util.EventDispatcher; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NonNls; @@ -37,16 +35,23 @@ public class ArtifactImpl extends UserDataHolderBase implements ModifiableArtifa private String myName; private boolean myBuildOnMake; private String myOutputPath; + private final EventDispatcher myDispatcher; private ArtifactType myArtifactType; private Map> myProperties; public ArtifactImpl(@NotNull String name, @NotNull ArtifactType artifactType, boolean buildOnMake, @NotNull CompositePackagingElement rootElement, String outputPath) { + this(name, artifactType, buildOnMake, rootElement, outputPath, null); + } + public ArtifactImpl(@NotNull String name, @NotNull ArtifactType artifactType, boolean buildOnMake, @NotNull CompositePackagingElement rootElement, + String outputPath, + EventDispatcher dispatcher) { myName = name; myArtifactType = artifactType; myBuildOnMake = buildOnMake; myRootElement = rootElement; myOutputPath = outputPath; + myDispatcher = dispatcher; myProperties = new HashMap>(); resetProperties(); } @@ -86,8 +91,8 @@ public class ArtifactImpl extends UserDataHolderBase implements ModifiableArtifa return Collections.unmodifiableCollection(myProperties.keySet()); } - public ArtifactImpl createCopy() { - final ArtifactImpl artifact = new ArtifactImpl(myName, myArtifactType, myBuildOnMake, myRootElement, myOutputPath); + public ArtifactImpl createCopy(EventDispatcher dispatcher) { + final ArtifactImpl artifact = new ArtifactImpl(myName, myArtifactType, myBuildOnMake, myRootElement, myOutputPath, dispatcher); for (Map.Entry> entry : myProperties.entrySet()) { final ArtifactProperties newProperties = artifact.myProperties.get(entry.getKey()); //noinspection unchecked @@ -97,7 +102,11 @@ public class ArtifactImpl extends UserDataHolderBase implements ModifiableArtifa } public void setName(@NotNull String name) { + String oldName = myName; myName = name; + if (myDispatcher != null) { + myDispatcher.getMulticaster().artifactChanged(this, oldName); + } } @NonNls @Override diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java index bb89c9db80db..7ccbe70ec50f 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java @@ -52,7 +52,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo @NonNls public static final String COMPONENT_NAME = "ArtifactManager"; @NonNls public static final String PACKAGING_ELEMENT_NAME = "element"; @NonNls public static final String TYPE_ID_ATTRIBUTE = "id"; - private final ArtifactManagerModel myModel = new ArtifactManagerModel(); + private final ArtifactManagerModel myModel; private final Project myProject; private final DefaultPackagingElementResolvingContext myResolvingContext; private boolean myInsideCommit = false; @@ -67,6 +67,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo public ArtifactManagerImpl(Project project, VirtualFileManager virtualFileManager) { myProject = project; + myModel = new ArtifactManagerModel(); myResolvingContext = new DefaultPackagingElementResolvingContext(myProject); virtualFileManager.addVirtualFileListener(new ArtifactVirtualFileListener(myProject, this), myProject); } @@ -85,6 +86,11 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo return myModel.getArtifactByOriginal(artifact); } + @NotNull + public Artifact getOriginalArtifact(@NotNull Artifact artifact) { + return myModel.getOriginalArtifact(artifact); + } + public Collection getArtifactsByType(@NotNull ArtifactType type) { return myModel.getArtifactsByType(type); } @@ -183,8 +189,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo } if (myLoaded) { - final ArtifactModelImpl model = new ArtifactModelImpl(this); - model.addArtifacts(artifacts); + final ArtifactModelImpl model = new ArtifactModelImpl(this, artifacts); doCommit(model); } else { @@ -258,10 +263,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo @Override public ModifiableArtifactModel createModifiableModel() { - ((ArtifactPointerManagerImpl)ArtifactPointerManager.getInstance(myProject)).updateAllPointers(); - final ArtifactModelImpl model = new ArtifactModelImpl(this); - model.addArtifacts(getArtifactsList()); - return model; + return new ArtifactModelImpl(this, getArtifactsList()); } @Override diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelBase.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelBase.java index a3db26ee4d86..ee67d33edb5e 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelBase.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelBase.java @@ -55,6 +55,11 @@ public abstract class ArtifactModelBase implements ArtifactModel { return artifact; } + @NotNull + public Artifact getOriginalArtifact(@NotNull Artifact artifact) { + return artifact; + } + public Collection getArtifactsByType(@NotNull ArtifactType type) { final List result = new ArrayList(); for (Artifact artifact : getArtifacts()) { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java index bd4583e8073e..2617aaf973b0 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java @@ -36,16 +36,15 @@ public class ArtifactModelImpl extends ArtifactModelBase implements ModifiableAr private final Map myModifiable2Original = new HashMap(); private final EventDispatcher myDispatcher = EventDispatcher.create(ArtifactListener.class); - public ArtifactModelImpl(ArtifactManagerImpl artifactManager) { + public ArtifactModelImpl(ArtifactManagerImpl artifactManager, List originalArtifacts) { myArtifactManager = artifactManager; - myOriginalArtifacts = new ArrayList(); - } - - public void addArtifacts(List artifacts) { - for (ArtifactImpl artifact : artifacts) { - myOriginalArtifacts.add(artifact); - } - artifactsChanged(); + myOriginalArtifacts = new ArrayList(originalArtifacts); + addListener(new ArtifactAdapter() { + @Override + public void artifactChanged(@NotNull Artifact artifact, @NotNull String oldName) { + artifactsChanged(); + } + }); } protected List getArtifactsList() { @@ -70,7 +69,7 @@ public class ArtifactModelImpl extends ArtifactModelBase implements ModifiableAr @NotNull public ModifiableArtifact addArtifact(@NotNull String name, @NotNull ArtifactType artifactType, CompositePackagingElement rootElement) { final String outputPath = ArtifactUtil.getDefaultArtifactOutputPath(name, myArtifactManager.getProject()); - final ArtifactImpl artifact = new ArtifactImpl(generateUniqueName(name), artifactType, false, rootElement, outputPath); + final ArtifactImpl artifact = new ArtifactImpl(generateUniqueName(name), artifactType, false, rootElement, outputPath, myDispatcher); myOriginalArtifacts.add(artifact); myArtifact2ModifiableCopy.put(artifact, artifact); myModifiable2Original.put(artifact, artifact); @@ -123,7 +122,8 @@ public class ArtifactModelImpl extends ArtifactModelBase implements ModifiableAr ArtifactImpl modifiableCopy = myArtifact2ModifiableCopy.get(artifactImpl); if (modifiableCopy == null) { - modifiableCopy = artifactImpl.createCopy(); + modifiableCopy = artifactImpl.createCopy(myDispatcher); + myDispatcher.getMulticaster().artifactChanged(modifiableCopy, artifact.getName()); myArtifact2ModifiableCopy.put(artifactImpl, modifiableCopy); myModifiable2Original.put(modifiableCopy, artifactImpl); artifactsChanged(); @@ -131,7 +131,8 @@ public class ArtifactModelImpl extends ArtifactModelBase implements ModifiableAr return modifiableCopy; } - public Artifact getOriginalArtifact(Artifact artifact) { + @NotNull + public Artifact getOriginalArtifact(@NotNull Artifact artifact) { final ArtifactImpl original = myModifiable2Original.get(artifact); return original != null ? original : artifact; } @@ -151,6 +152,16 @@ public class ArtifactModelImpl extends ArtifactModelBase implements ModifiableAr myArtifactManager.commit(this); } + public void dispose() { + List artifacts = new ArrayList(); + for (ArtifactImpl artifact : myModifiable2Original.keySet()) { + if (myModifiable2Original.get(artifact).equals(artifact)) { + artifacts.add(artifact); + } + } + ((ArtifactPointerManagerImpl)ArtifactPointerManager.getInstance(myArtifactManager.getProject())).disposePointers(artifacts); + } + @Nullable public ArtifactImpl getModifiableCopy(Artifact artifact) { //noinspection SuspiciousMethodCalls diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactPointerImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactPointerImpl.java index 23aa58e44a95..c8b6b369fc98 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactPointerImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactPointerImpl.java @@ -15,9 +15,7 @@ */ package com.intellij.packaging.impl.artifacts; -import com.intellij.openapi.project.Project; import com.intellij.packaging.artifacts.Artifact; -import com.intellij.packaging.artifacts.ArtifactManager; import com.intellij.packaging.artifacts.ArtifactModel; import com.intellij.packaging.artifacts.ArtifactPointer; import org.jetbrains.annotations.NotNull; @@ -26,35 +24,42 @@ import org.jetbrains.annotations.NotNull; * @author nik */ public class ArtifactPointerImpl implements ArtifactPointer { - private final Project myProject; private String myName; private Artifact myArtifact; - public ArtifactPointerImpl(@NotNull Project project, @NotNull String name) { - myProject = project; + public ArtifactPointerImpl(@NotNull String name) { myName = name; } + public ArtifactPointerImpl(@NotNull Artifact artifact) { + myArtifact = artifact; + myName = artifact.getName(); + } + @NotNull - public String getName() { + public String getArtifactName() { return myName; } public Artifact getArtifact() { - if (myArtifact == null) { - myArtifact = findArtifact(ArtifactManager.getInstance(myProject)); - } return myArtifact; } - public Artifact findArtifact(@NotNull ArtifactModel artifactModel) { - if (myArtifact != null) { - final Artifact artifact = artifactModel.getArtifactByOriginal(myArtifact); - if (!artifact.equals(myArtifact)) { - return artifact; - } + @NotNull + public String getArtifactName(@NotNull ArtifactModel artifactModel) { + final Artifact artifact = getArtifact(); + if (artifact != null) { + return artifactModel.getArtifactByOriginal(artifact).getName(); } - return artifactModel.findArtifact(myName); + return myName; + } + + public Artifact findArtifact(@NotNull ArtifactModel artifactModel) { + final Artifact artifact = getArtifact(); + if (artifact != null) { + return artifactModel.getArtifactByOriginal(artifact); + } + return null; } void setArtifact(Artifact artifact) { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactPointerManagerImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactPointerManagerImpl.java index 4d19897f7438..92401f8a24ef 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactPointerManagerImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactPointerManagerImpl.java @@ -20,72 +20,98 @@ import com.intellij.packaging.artifacts.*; import org.jetbrains.annotations.NotNull; import java.util.HashMap; +import java.util.List; import java.util.Map; /** * @author nik */ public class ArtifactPointerManagerImpl extends ArtifactPointerManager { + private final Map myUnresolvedPointers = new HashMap(); + private final Map myPointers = new HashMap(); private final Project myProject; - private final Map myPointers = new HashMap(); public ArtifactPointerManagerImpl(Project project) { myProject = project; - myProject.getMessageBus().connect().subscribe(ArtifactManager.TOPIC, new ArtifactAdapter() { + project.getMessageBus().connect().subscribe(ArtifactManager.TOPIC, new ArtifactAdapter() { @Override public void artifactRemoved(@NotNull Artifact artifact) { - final ArtifactPointerImpl pointer = myPointers.get(artifact.getName()); - if (pointer != null) { - pointer.setArtifact(null); - } + disposePointer(artifact); } @Override public void artifactAdded(@NotNull Artifact artifact) { - final ArtifactPointerImpl artifactPointer = myPointers.get(artifact.getName()); - if (artifactPointer != null) { - artifactPointer.setArtifact(artifact); + final ArtifactPointerImpl pointer = myPointers.get(artifact); + if (pointer != null) { + pointer.setName(artifact.getName()); + } + + final ArtifactPointerImpl unresolved = myUnresolvedPointers.remove(artifact.getName()); + if (unresolved != null) { + unresolved.setArtifact(artifact); + if (pointer == null) { + myPointers.put(artifact, unresolved); + } } } @Override public void artifactChanged(@NotNull Artifact artifact, @NotNull String oldName) { - final ArtifactPointerImpl pointer = myPointers.get(oldName); + final ArtifactPointerImpl pointer = myPointers.get(artifact); if (pointer != null) { - pointer.setArtifact(artifact); - final String newName = artifact.getName(); - if (!newName.equals(oldName)) { - pointer.setName(newName); - myPointers.remove(oldName); - myPointers.put(newName, pointer); + pointer.setName(artifact.getName()); + } + + final ArtifactPointerImpl unresolved = myUnresolvedPointers.remove(artifact.getName()); + if (unresolved != null) { + unresolved.setArtifact(artifact); + if (pointer == null) { + myPointers.put(artifact, unresolved); } } } }); } - public void updateAllPointers() { - for (ArtifactPointerImpl pointer : myPointers.values()) { - pointer.getArtifact(); + private void disposePointer(Artifact artifact) { + final ArtifactPointerImpl pointer = myPointers.remove(artifact); + if (pointer != null) { + pointer.setArtifact(null); + myUnresolvedPointers.put(pointer.getArtifactName(), pointer); } } - public ArtifactPointer create(@NotNull String name) { - ArtifactPointerImpl pointer = myPointers.get(name); + public ArtifactPointer createPointer(@NotNull String name) { + final Artifact artifact = ArtifactManager.getInstance(myProject).findArtifact(name); + if (artifact != null) { + return createPointer(artifact); + } + + ArtifactPointerImpl pointer = myUnresolvedPointers.get(name); if (pointer == null) { - pointer = new ArtifactPointerImpl(myProject, name); - myPointers.put(name, pointer); + pointer = new ArtifactPointerImpl(name); + myUnresolvedPointers.put(name, pointer); } return pointer; } - public ArtifactPointer create(@NotNull Artifact artifact) { - final String name = artifact.getName(); - ArtifactPointerImpl pointer = myPointers.get(name); + public ArtifactPointer createPointer(@NotNull Artifact artifact) { + ArtifactPointerImpl pointer = myPointers.get(artifact); if (pointer == null) { - pointer = new ArtifactPointerImpl(myProject, name); - myPointers.put(artifact.getName(), pointer); + pointer = new ArtifactPointerImpl(artifact); + myPointers.put(artifact, pointer); } return pointer; } + + @Override + public ArtifactPointer createPointer(@NotNull Artifact artifact, @NotNull ArtifactModel artifactModel) { + return createPointer(artifactModel.getOriginalArtifact(artifact)); + } + + public void disposePointers(List artifacts) { + for (Artifact artifact : artifacts) { + disposePointer(artifact); + } + } } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java index 021c9772d3f2..8addfc9c57e0 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java @@ -58,7 +58,7 @@ public class ArtifactElementType extends ComplexPackagingElementType artifacts = context.chooseArtifacts(getAvailableArtifacts(context, artifact), CompilerBundle.message("dialog.title.choose.artifacts")); final List elements = new ArrayList(); for (Artifact selected : artifacts) { - elements.add(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).create(selected.getName()))); + elements.add(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(selected, context.getArtifactModel()))); } return elements; } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactPackagingElement.java index 5995a48e5444..4207fbbfde5f 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactPackagingElement.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactPackagingElement.java @@ -18,19 +18,16 @@ package com.intellij.packaging.impl.elements; import com.intellij.compiler.ant.BuildProperties; import com.intellij.compiler.ant.Generator; import com.intellij.openapi.project.Project; -import com.intellij.packaging.artifacts.Artifact; -import com.intellij.packaging.artifacts.ArtifactType; -import com.intellij.packaging.artifacts.ArtifactPointer; -import com.intellij.packaging.artifacts.ArtifactPointerManager; +import com.intellij.packaging.artifacts.*; import com.intellij.packaging.elements.*; import com.intellij.packaging.impl.ui.ArtifactElementPresentation; import com.intellij.packaging.impl.ui.DelegatedPackagingElementPresentation; -import com.intellij.packaging.ui.PackagingElementPresentation; import com.intellij.packaging.ui.ArtifactEditorContext; +import com.intellij.packaging.ui.PackagingElementPresentation; import com.intellij.util.xmlb.annotations.Attribute; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NonNls; import java.util.ArrayList; import java.util.Collections; @@ -107,14 +104,14 @@ public class ArtifactPackagingElement extends ComplexPackagingElement createArtifactElement(@NotNull Artifact artifact, @NotNull Project project) { - return new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).create(artifact)); + return new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(artifact)); } @NotNull @@ -204,6 +205,12 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { return elements; } + @NotNull + @Override + public PackagingElement createArtifactElement(@NotNull ArtifactPointer artifactPointer, @NotNull Project project) { + return new ArtifactPackagingElement(project, artifactPointer); + } + @NotNull @Override public PackagingElement createLibraryFiles(@NotNull String libraryName, @NotNull String level, String moduleName) { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/run/ArtifactChooser.java b/java/compiler/impl/src/com/intellij/packaging/impl/run/ArtifactChooser.java index 6040b2d44727..b2ef063f94ae 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/run/ArtifactChooser.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/run/ArtifactChooser.java @@ -32,7 +32,7 @@ import java.util.List; public class ArtifactChooser extends ElementsChooser { private static final Comparator ARTIFACT_COMPARATOR = new Comparator() { public int compare(ArtifactPointer o1, ArtifactPointer o2) { - return o1.getName().compareToIgnoreCase(o2.getName()); + return o1.getArtifactName().compareToIgnoreCase(o2.getArtifactName()); } }; private static final ElementProperties INVALID_ARTIFACT_PROPERTIES = new ElementProperties() { @@ -57,7 +57,7 @@ public class ArtifactChooser extends ElementsChooser { @Override protected String getItemText(@NotNull ArtifactPointer value) { - return value.getName(); + return value.getArtifactName(); } @Override diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRun.java b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRun.java index d16dfac6052f..f9f8c8bcad13 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRun.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRun.java @@ -72,7 +72,7 @@ public class BuildArtifactsBeforeRun implements BeforeRunTaskProvider pointers = new THashSet(); for (Artifact artifact : artifacts) { - pointers.add(ArtifactPointerManager.getInstance(myProject).create(artifact)); + pointers.add(ArtifactPointerManager.getInstance(myProject).createPointer(artifact)); } pointers.addAll(task.getArtifactPointers()); ArtifactChooser chooser = new ArtifactChooser(new ArrayList(pointers)); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTask.java b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTask.java index 3411b1066c8a..65a1d8d36be6 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTask.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTask.java @@ -46,7 +46,7 @@ public class BuildArtifactsBeforeRunTask extends BeforeRunTask { final List children = element.getChildren(ARTIFACT_ELEMENT); final ArtifactPointerManager pointerManager = ArtifactPointerManager.getInstance(myProject); for (Element child : children) { - myArtifactPointers.add(pointerManager.create(child.getAttributeValue(NAME_ATTRIBUTE))); + myArtifactPointers.add(pointerManager.createPointer(child.getAttributeValue(NAME_ATTRIBUTE))); } } @@ -54,7 +54,7 @@ public class BuildArtifactsBeforeRunTask extends BeforeRunTask { public void writeExternal(Element element) { super.writeExternal(element); for (ArtifactPointer pointer : myArtifactPointers) { - element.addContent(new Element(ARTIFACT_ELEMENT).setAttribute(NAME_ATTRIBUTE, pointer.getName())); + element.addContent(new Element(ARTIFACT_ELEMENT).setAttribute(NAME_ATTRIBUTE, pointer.getArtifactName())); } } @@ -74,14 +74,14 @@ public class BuildArtifactsBeforeRunTask extends BeforeRunTask { } public void addArtifact(Artifact artifact) { - final ArtifactPointer pointer = ArtifactPointerManager.getInstance(myProject).create(artifact); + final ArtifactPointer pointer = ArtifactPointerManager.getInstance(myProject).createPointer(artifact); if (!myArtifactPointers.contains(pointer)) { myArtifactPointers.add(pointer); } } public void removeArtifact(Artifact artifact) { - myArtifactPointers.remove(ArtifactPointerManager.getInstance(myProject).create(artifact)); + myArtifactPointers.remove(ArtifactPointerManager.getInstance(myProject).createPointer(artifact)); } public boolean equals(Object o) { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/ArtifactElementPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ArtifactElementPresentation.java index 2daa2a0b324a..a9dabbf9f02d 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/ArtifactElementPresentation.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ArtifactElementPresentation.java @@ -24,43 +24,51 @@ import com.intellij.packaging.ui.PackagingElementWeights; import com.intellij.packaging.ui.TreeNodePresentation; import com.intellij.ui.SimpleTextAttributes; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author nik */ public class ArtifactElementPresentation extends TreeNodePresentation { - private final Artifact myArtifact; + private final ArtifactPointer myArtifactPointer; private final ArtifactEditorContext myContext; - private final String myName; public ArtifactElementPresentation(ArtifactPointer artifactPointer, ArtifactEditorContext context) { - myName = artifactPointer != null ? artifactPointer.getName() : ""; - myArtifact = artifactPointer != null ? artifactPointer.findArtifact(context.getArtifactModel()) : null; + myArtifactPointer = artifactPointer; myContext = context; } public String getPresentableName() { - return myName; + return myArtifactPointer != null ? myArtifactPointer.getArtifactName(myContext.getArtifactModel()) : ""; } @Override public boolean canNavigateToSource() { - return myArtifact != null; + return findArtifact() != null; } @Override public Object getSourceObject() { - return myArtifact; + return myArtifactPointer; } @Override public void navigateToSource() { - myContext.selectArtifact(myArtifact); + final Artifact artifact = findArtifact(); + if (artifact != null) { + myContext.selectArtifact(artifact); + } } public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { - presentationData.setIcons(myArtifact != null ? myArtifact.getArtifactType().getIcon() : PlainArtifactType.ARTIFACT_ICON); - presentationData.addText(myName, myArtifact != null ? mainAttributes : SimpleTextAttributes.ERROR_ATTRIBUTES); + final Artifact artifact = findArtifact(); + presentationData.setIcons(artifact != null ? artifact.getArtifactType().getIcon() : PlainArtifactType.ARTIFACT_ICON); + presentationData.addText(getPresentableName(), artifact != null ? mainAttributes : SimpleTextAttributes.ERROR_ATTRIBUTES); + } + + @Nullable + private Artifact findArtifact() { + return myArtifactPointer != null ? myArtifactPointer.findArtifact(myContext.getArtifactModel()) : null; } @Override diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactModel.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactModel.java index 4c339a000d72..1a11ecbb4c67 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactModel.java +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactModel.java @@ -33,5 +33,8 @@ public interface ArtifactModel { @NotNull Artifact getArtifactByOriginal(@NotNull Artifact artifact); + @NotNull + Artifact getOriginalArtifact(@NotNull Artifact artifact); + Collection getArtifactsByType(@NotNull ArtifactType type); } diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactPointer.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactPointer.java index 78908d8d8815..ee1ed1c5390f 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactPointer.java +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactPointer.java @@ -24,11 +24,14 @@ import org.jetbrains.annotations.NotNull; public interface ArtifactPointer { @NotNull - String getName(); + String getArtifactName(); @Nullable Artifact getArtifact(); + @NotNull + String getArtifactName(@NotNull ArtifactModel artifactModel); + @Nullable Artifact findArtifact(@NotNull ArtifactModel artifactModel); diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactPointerManager.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactPointerManager.java index f6927e12dc28..c5f32f480c43 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactPointerManager.java +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactPointerManager.java @@ -27,7 +27,9 @@ public abstract class ArtifactPointerManager { return ServiceManager.getService(project, ArtifactPointerManager.class); } - public abstract ArtifactPointer create(@NotNull String name); + public abstract ArtifactPointer createPointer(@NotNull String name); - public abstract ArtifactPointer create(@NotNull Artifact artifact); + public abstract ArtifactPointer createPointer(@NotNull Artifact artifact); + + public abstract ArtifactPointer createPointer(@NotNull Artifact artifact, @NotNull ArtifactModel artifactModel); } diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ModifiableArtifactModel.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ModifiableArtifactModel.java index 50d16dad85c6..5e6172f8e6c2 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ModifiableArtifactModel.java +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ModifiableArtifactModel.java @@ -35,10 +35,17 @@ public interface ModifiableArtifactModel extends ArtifactModel { @NotNull ModifiableArtifact getOrCreateModifiableArtifact(@NotNull Artifact artifact); + @Nullable + Artifact getModifiableCopy(Artifact artifact); + + void addListener(@NotNull ArtifactListener listener); + + void removeListener(@NotNull ArtifactListener listener); + + boolean isModified(); void commit(); - @Nullable - Artifact getModifiableCopy(Artifact artifact); + void dispose(); } diff --git a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java index 179477db3faa..7401a31d0e55 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java +++ b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java @@ -20,6 +20,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.project.Project; import com.intellij.packaging.artifacts.Artifact; +import com.intellij.packaging.artifacts.ArtifactPointer; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -53,6 +54,9 @@ public abstract class PackagingElementFactory { @NotNull public abstract List> createLibraryElements(@NotNull Library library); + @NotNull + public abstract PackagingElement createArtifactElement(@NotNull ArtifactPointer artifactPointer, @NotNull Project project); + @NotNull public abstract PackagingElement createArtifactElement(@NotNull Artifact artifact, @NotNull Project project); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java index 6f3ade014cf3..fe32672e4699 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java @@ -22,7 +22,6 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigur import com.intellij.openapi.util.Disposer; import com.intellij.packaging.artifacts.*; import com.intellij.packaging.elements.CompositePackagingElement; -import com.intellij.packaging.impl.artifacts.ArtifactModelImpl; import com.intellij.packaging.impl.artifacts.ArtifactUtil; import com.intellij.packaging.ui.ManifestFileConfiguration; import org.jetbrains.annotations.NotNull; @@ -69,7 +68,7 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon @NotNull public Artifact getOriginalArtifact(@NotNull Artifact artifact) { if (myModifiableModel != null) { - return ((ArtifactModelImpl)myModifiableModel).getOriginalArtifact(artifact); + return myModifiableModel.getOriginalArtifact(artifact); } return artifact; } @@ -108,7 +107,7 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon artifact = getOriginalArtifact(artifact); ArtifactEditorImpl artifactEditor = myArtifactEditors.get(artifact); if (artifactEditor == null) { - final ArtifactEditorSettings settings = myEditorSettings.get(ArtifactPointerManager.getInstance(myProject).create(artifact)); + final ArtifactEditorSettings settings = myEditorSettings.get(ArtifactPointerManager.getInstance(myProject).createPointer(artifact, getArtifactModel())); artifactEditor = new ArtifactEditorImpl(this, artifact, settings != null ? settings : myDefaultSettings); myArtifactEditors.put(artifact, artifactEditor); } @@ -124,7 +123,7 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon public ModifiableArtifactModel getModifiableArtifactModel() { if (myModifiableModel == null) { myModifiableModel = ArtifactManager.getInstance(myProject).createModifiableModel(); - ((ArtifactModelImpl)myModifiableModel).addListener(myModifiableModelListener); + myModifiableModel.addListener(myModifiableModelListener); } return myModifiableModel; } @@ -168,12 +167,15 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon Disposer.dispose(editor); } myArtifactEditors.clear(); + if (myModifiableModel != null) { + myModifiableModel.dispose(); + } } public void saveEditorSettings() { myEditorSettings.clear(); for (ArtifactEditorImpl artifactEditor : myArtifactEditors.values()) { - final ArtifactPointer pointer = ArtifactPointerManager.getInstance(myProject).create(artifactEditor.getArtifact()); + final ArtifactPointer pointer = ArtifactPointerManager.getInstance(myProject).createPointer(artifactEditor.getArtifact(), getArtifactModel()); myEditorSettings.put(pointer, artifactEditor.createSettings()); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactAction.java index bc96b49d0686..f3cb59b7db44 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/ExtractArtifactAction.java @@ -16,7 +16,6 @@ package com.intellij.openapi.roots.ui.configuration.artifacts.actions; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx; @@ -71,7 +70,7 @@ public class ExtractArtifactAction extends LayoutTreeActionBase { for (PackagingElement element : selectedElements) { parent.removeChild(element); } - parent.addOrFindChild(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).create(artifact))); + parent.addOrFindChild(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(artifact, myArtifactEditor.getContext().getArtifactModel()))); } }); treeComponent.rebuildTree(); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ArtifactSourceItem.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ArtifactSourceItem.java index b393f4785910..e56a47bc42c4 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ArtifactSourceItem.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ArtifactSourceItem.java @@ -15,15 +15,19 @@ */ package com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems; +import com.intellij.openapi.project.Project; import com.intellij.packaging.artifacts.Artifact; -import com.intellij.packaging.artifacts.ArtifactPointerManager; import com.intellij.packaging.artifacts.ArtifactPointer; +import com.intellij.packaging.artifacts.ArtifactPointerManager; import com.intellij.packaging.elements.PackagingElement; import com.intellij.packaging.elements.PackagingElementFactory; import com.intellij.packaging.elements.PackagingElementOutputKind; import com.intellij.packaging.impl.artifacts.JarArtifactType; import com.intellij.packaging.impl.ui.ArtifactElementPresentation; -import com.intellij.packaging.ui.*; +import com.intellij.packaging.ui.ArtifactEditorContext; +import com.intellij.packaging.ui.PackagingSourceItem; +import com.intellij.packaging.ui.SourceItemPresentation; +import com.intellij.packaging.ui.SourceItemWeights; import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -40,7 +44,7 @@ public class ArtifactSourceItem extends PackagingSourceItem { } public SourceItemPresentation createPresentation(@NotNull ArtifactEditorContext context) { - final ArtifactPointer pointer = ArtifactPointerManager.getInstance(context.getProject()).create(myArtifact); + final ArtifactPointer pointer = ArtifactPointerManager.getInstance(context.getProject()).createPointer(myArtifact, context.getArtifactModel()); return new DelegatedSourceItemPresentation(new ArtifactElementPresentation(pointer, context)) { @Override public int getWeight() { @@ -51,7 +55,9 @@ public class ArtifactSourceItem extends PackagingSourceItem { @NotNull public List> createElements(@NotNull ArtifactEditorContext context) { - return Collections.singletonList(PackagingElementFactory.getInstance().createArtifactElement(myArtifact, context.getProject())); + final Project project = context.getProject(); + final ArtifactPointer pointer = ArtifactPointerManager.getInstance(project).createPointer(myArtifact, context.getArtifactModel()); + return Collections.singletonList(PackagingElementFactory.getInstance().createArtifactElement(pointer, project)); } public boolean equals(Object obj) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 88ca6d57f87d..a9b2b9bd3ae3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -687,7 +687,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } @Override public void visitReferenceElement(PsiJavaCodeReferenceElement ref) { - JavaResolveResult result = null; + JavaResolveResult result; try { result = ref.advancedResolve(true); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateLocalVarFromInstanceofAction.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateLocalVarFromInstanceofAction.java index 13e84b26958c..14f04687e1c4 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateLocalVarFromInstanceofAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateLocalVarFromInstanceofAction.java @@ -143,7 +143,7 @@ public class CreateLocalVarFromInstanceofAction extends BaseIntentionAction { private static boolean atSameLine(final PsiExpression condition, final Editor editor) { int line = editor.getCaretModel().getLogicalPosition().line; - return editor.offsetToLogicalPosition(condition.getTextOffset()).line == line; + return editor.getDocument().getLineNumber(condition.getTextOffset()) == line; } public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) { diff --git a/java/java-impl/src/com/intellij/psi/impl/source/PsiTypeElementImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/PsiTypeElementImpl.java index 4e4e1ca854c3..9312cd73248f 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/PsiTypeElementImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/PsiTypeElementImpl.java @@ -19,12 +19,14 @@ import com.intellij.codeInsight.daemon.impl.analysis.AnnotationsHighlightUtil; import com.intellij.lang.ASTNode; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.source.tree.*; import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtil; import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import com.intellij.util.PatchedSoftReference; @@ -132,7 +134,7 @@ public class PsiTypeElementImpl extends CompositePsiElement implements PsiTypeEl PsiType type = cached == null ? null : cached.get(); if (type != null) return type; try { - String combinedAnnos = StringUtil.join(getApplicableAnnotations(), ANNOTATION_TEXT, " "); + String combinedAnnos = getCombinedAnnosText(); String text = combinedAnnos.length() == 0 ? getText().trim() : combinedAnnos + " " + getText().trim(); type = JavaPsiFacade.getInstance(getProject()).getElementFactory().createTypeFromText(text, context); myCachedDetachedType = new PatchedSoftReference(type); @@ -143,6 +145,13 @@ public class PsiTypeElementImpl extends CompositePsiElement implements PsiTypeEl return type; } + @NotNull + private String getCombinedAnnosText() { + boolean typeAnnotationsSupported = PsiUtil.getLanguageLevel(this).isAtLeast(LanguageLevel.JDK_1_7); + if (!typeAnnotationsSupported) return ""; + return StringUtil.join(getApplicableAnnotations(), ANNOTATION_TEXT, " "); + } + private static final Function ANNOTATION_TEXT = new Function() { public String fun(PsiAnnotation psiAnnotation) { return psiAnnotation.getText(); diff --git a/java/java-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java b/java/java-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java index 383341ad1453..ff5fdaa291f9 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java @@ -102,7 +102,8 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi if ("java.lang".equals(packageName)) return true; // class from my package imported implicitly - PsiFile file = myPlace == null ? null : myPlace.getContainingFile(); + PsiFile file = myPlace == null ? null : FileContextUtil.getContextFile(myPlace); + return file instanceof PsiJavaFile && ((PsiJavaFile)file).getPackageName().equals(packageName); } diff --git a/platform/lang-api/src/com/intellij/refactoring/util/CommonRefactoringUtil.java b/platform/lang-api/src/com/intellij/refactoring/util/CommonRefactoringUtil.java index b44b5373ae18..e111afca04cd 100644 --- a/platform/lang-api/src/com/intellij/refactoring/util/CommonRefactoringUtil.java +++ b/platform/lang-api/src/com/intellij/refactoring/util/CommonRefactoringUtil.java @@ -106,8 +106,6 @@ public class CommonRefactoringUtil { boolean seenNonWritablePsiFilesWithoutVirtualFile = false; for (PsiElement element : elements) { - if (element.isWritable()) continue; - if (element instanceof PsiDirectory) { PsiDirectory dir = (PsiDirectory)element; final VirtualFile vFile = dir.getVirtualFile(); @@ -140,13 +138,11 @@ public class CommonRefactoringUtil { } } else { - if (!directory.isWritable()) { - if (virtualFile.getFileSystem() instanceof JarFileSystem) { - failed.add(virtualFile); - } - else { - readonly.add(virtualFile); - } + if (virtualFile.getFileSystem() instanceof JarFileSystem) { + failed.add(virtualFile); + } + else { + readonly.add(virtualFile); } } } @@ -162,7 +158,7 @@ public class CommonRefactoringUtil { if (file == null) { seenNonWritablePsiFilesWithoutVirtualFile = true; } - else if (!file.isWritable()) { + else { final VirtualFile vFile = file.getVirtualFile(); if (vFile != null) { readonly.add(vFile); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapAction.java b/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapAction.java index f06e46664384..0ca3ec755404 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapAction.java @@ -24,6 +24,7 @@ import com.intellij.psi.*; public class UnwrapAction extends BaseCodeInsightAction{ public UnwrapAction() { + super(true); setEnabledInModalContext(true); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/QuickFixAction.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/QuickFixAction.java index 769e7f3ece85..b6cd42dadcc0 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/QuickFixAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/QuickFixAction.java @@ -224,8 +224,8 @@ public class QuickFixAction extends AnAction { Set readOnlyFiles = new THashSet(); for (RefElement refElement : refElements) { PsiElement psiElement = refElement.getElement(); - if (psiElement == null) continue; - if (!psiElement.isWritable()) readOnlyFiles.add(psiElement.getContainingFile().getVirtualFile()); + if (psiElement == null || psiElement.getContainingFile() == null) continue; + readOnlyFiles.add(psiElement.getContainingFile().getVirtualFile()); } return readOnlyFiles; } diff --git a/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java b/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java index 691326a8710c..e1a5463e4977 100644 --- a/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java +++ b/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java @@ -56,6 +56,7 @@ public class FileListPasteProvider implements PasteProvider { catch (IOException e) { return; } + if (fileList == null) return; List elements = new ArrayList(); for (File file : fileList) { final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); diff --git a/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInTarget.java b/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInTarget.java index 01a97e47e887..dde21573fcf6 100644 --- a/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInTarget.java +++ b/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInTarget.java @@ -27,9 +27,9 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowId; import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.openapi.wm.ex.ToolWindowEx; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtilBase; import org.jetbrains.annotations.NotNull; @@ -61,7 +61,7 @@ public abstract class ProjectViewSelectInTarget extends SelectInTargetPsiWrapper final ProjectView projectView = ProjectView.getInstance(project); ToolWindowManager windowManager=ToolWindowManager.getInstance(project); - final ToolWindowEx projectViewToolWindow = (ToolWindowEx) windowManager.getToolWindow(ToolWindowId.PROJECT_VIEW); + final ToolWindow projectViewToolWindow = windowManager.getToolWindow(ToolWindowId.PROJECT_VIEW); final Runnable runnable = new Runnable() { public void run() { if (requestFocus) { diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java index 68da08839eed..adf7c33ace82 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java @@ -172,27 +172,24 @@ public class ProjectViewDirectoryHelper { return psiDirectory.getChildren(); } - Set directoriesOnTheWayToContentRoots = new THashSet(); + PsiManager manager = psiDirectory.getManager(); + Set directoriesOnTheWayToContentRoots = new THashSet(); for (VirtualFile root : getTopLevelRoots()) { VirtualFile current = root; while (current != null) { VirtualFile parent = current.getParent(); if (parent == dir) { - directoriesOnTheWayToContentRoots.add(current); + final PsiDirectory psi = manager.findDirectory(current); + if (psi != null) { + directoriesOnTheWayToContentRoots.add(psi); + } } current = parent; } } - PsiManager manager = psiDirectory.getManager(); - PsiElement[] answer = new PsiElement[directoriesOnTheWayToContentRoots.size()]; - int i = 0; - for (VirtualFile directory : directoriesOnTheWayToContentRoots) { - answer[i++] = manager.findDirectory(directory); - } - - return answer; + return directoriesOnTheWayToContentRoots.toArray(new PsiElement[directoriesOnTheWayToContentRoots.size()]); } // used only for non-flatten packages mode diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/FileContextUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/FileContextUtil.java index 18563570d9af..a5da52c6d624 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/FileContextUtil.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/FileContextUtil.java @@ -23,6 +23,7 @@ import com.intellij.openapi.util.Key; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.SmartPsiElementPointer; +import org.jetbrains.annotations.NotNull; public class FileContextUtil { public static final Key INJECTED_IN_ELEMENT = Key.create("injectedIn"); @@ -32,7 +33,7 @@ public class FileContextUtil { return pointer == null ? null : pointer.getElement(); } - public static PsiFile getContextFile(PsiElement element){ + public static PsiFile getContextFile(@NotNull PsiElement element){ if (!element.isValid()) return null; PsiFile file = element.getContainingFile(); if (file == null) return null; diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java index 50fc6d81de72..8f238179f52e 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java @@ -1540,7 +1540,7 @@ public class AbstractTreeUi { public List getLoadedChildrenFor(Object element) { List result = new ArrayList(); - DefaultMutableTreeNode node = (DefaultMutableTreeNode)findNodeByElement(element); + DefaultMutableTreeNode node = (DefaultMutableTreeNode)getNodeForElement(element, false); if (node != null) { for (int i = 0; i < node.getChildCount(); i++) { TreeNode each = node.getChildAt(i); @@ -1772,6 +1772,8 @@ public class AbstractTreeUi { } private void processNodeActionsIfReady(final DefaultMutableTreeNode node) { + assertIsDispatchThread(); + if (isNodeBeingBuilt(node)) return; final Object o = node.getUserObject(); diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/UpdaterTreeState.java b/platform/platform-api/src/com/intellij/ide/util/treeView/UpdaterTreeState.java index a7453f085c9c..3998c8c42386 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/UpdaterTreeState.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/UpdaterTreeState.java @@ -127,9 +127,8 @@ public class UpdaterTreeState { public void addAll(final UpdaterTreeState state) { myToExpand.putAll(state.myToExpand); - final Iterator toSelect = state.myToSelect.keySet().iterator(); - while (toSelect.hasNext()) { - Object each = toSelect.next(); + Object[] toSelect = state.getToSelect(); + for (Object each : toSelect) { if (!myAdjustedSelection.containsKey(each)) { myToSelect.put(each, each); } diff --git a/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java b/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java index eb0f4003af36..4af5395f6b23 100644 --- a/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java +++ b/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java @@ -281,6 +281,7 @@ public class Tree extends JTree implements Autoscroll, TestableUi { } } + if (last == null) continue; Rectangle lastBounds = getPathBounds(getPath(last)); if (firstBounds == null || lastBounds == null) continue; diff --git a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateSession.java b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateSession.java index 7ec05b47749b..ee14c0946e64 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateSession.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateSession.java @@ -28,7 +28,7 @@ import gnu.trove.THashSet; import java.util.*; public class CacheUpdateSession { - private static final Logger LOG = Logger.getInstance("#com.intellij.ide.startup.SyncSession"); + private static final Logger LOG = Logger.getInstance("#" + CacheUpdateSession.class.getName()); private static final Key FILED_TO_INDEX = Key.create(CacheUpdateSession.class.getSimpleName() + ".FAILED_TO_INDEX"); private final Collection myFilesToUpdate; private final List>> myUpdatersWithFiles = diff --git a/platform/platform-impl/src/com/intellij/openapi/project/DumbModeIndicator.java b/platform/platform-impl/src/com/intellij/openapi/project/DumbModeIndicator.java index a56a5e8a2a58..22c5a027652a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/DumbModeIndicator.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/DumbModeIndicator.java @@ -39,8 +39,8 @@ public class DumbModeIndicator extends AbstractProjectComponent { myAlarm.addRequest(new Runnable() { public void run() { myHandler = DumbService.getInstance(myProject).showDumbModeNotification( - "Updating indexes...
" + - "Some of advanced features (refactorings, navigation, etc.) are not available."); + "Updating indices...
" + + "Some of advanced features (refactorings, usage search ) are temporarily unavailable"); } }, 1000); } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java index 67cf6a2999fa..3bc319642e01 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java @@ -17,21 +17,22 @@ package com.intellij.openapi.project; import com.intellij.ide.IdeBundle; import com.intellij.ide.caches.CacheUpdater; +import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationNamesInfo; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.*; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.popup.BalloonHandler; +import com.intellij.openapi.util.Ref; import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.ex.StatusBarEx; -import com.intellij.util.concurrency.Semaphore; import com.intellij.util.containers.Queue; import com.intellij.util.messages.MessageBus; import org.jetbrains.annotations.NotNull; +import javax.swing.*; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import java.lang.reflect.InvocationHandler; @@ -40,19 +41,18 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Collection; -import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; public class DumbServiceImpl extends DumbService { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.project.DumbServiceImpl"); - private final AtomicBoolean myDumb = new AtomicBoolean(); + private volatile boolean myDumb = false; private final DumbModeListener myPublisher; - private final LinkedBlockingQueue myUpdatesQueue = new LinkedBlockingQueue(); + private final Queue myUpdatesQueue = new Queue(5); private final Queue myRunWhenSmartQueue = new Queue(5); private final Project myProject; - + @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass"}) public static DumbServiceImpl getInstance(@NotNull Project project) { return (DumbServiceImpl)DumbService.getInstance(project); } @@ -60,8 +60,6 @@ public class DumbServiceImpl extends DumbService { public DumbServiceImpl(Project project, MessageBus bus) { myProject = project; myPublisher = bus.syncPublisher(DUMB_MODE); - - new CacheUpdateProcessor().start(); } @Override @@ -70,12 +68,11 @@ public class DumbServiceImpl extends DumbService { } public boolean isDumb() { - return myDumb.get(); + return myDumb; } @Override public void runWhenSmart(Runnable runnable) { - // todo: run is swing thread if (!isDumb()) { runnable.run(); } @@ -88,49 +85,56 @@ public class DumbServiceImpl extends DumbService { public void queueCacheUpdate(Collection updaters) { // prevent concurrent modifications - final Collection updatersCopy = new ArrayList(updaters); - CacheUpdateRunner runner = new CacheUpdateRunner(myProject, updatersCopy); + final CacheUpdateRunner runner = new CacheUpdateRunner(myProject, new ArrayList(updaters)); - if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) { - EmptyProgressIndicator i = new EmptyProgressIndicator(); - runner.queryNeededFiles(i); - runner.processFiles(i, false); - runner.updatingDone(); - return; - } - - ProgressIndicator indicator = new EmptyProgressIndicator(); - - if (ApplicationManager.getApplication().isDispatchThread() && !isDumb()) { - int size = runner.queryNeededFiles(indicator); - if (size < 10) { + final Application application = ApplicationManager.getApplication(); + if (application.isDispatchThread() && !myDumb && application.isWriteAccessAllowed()) { + ProgressIndicator indicator = new EmptyProgressIndicator(); + final int size = runner.queryNeededFiles(indicator); + if (size < 50) { + // if not that many files found, process them on the spot, avoiding entering dumb mode if (size > 0) { runner.processFiles(indicator, false); } runner.updatingDone(); return; } - - updateStarted(); } - try { - myUpdatesQueue.put(runner); - } - catch (InterruptedException e) { - throw new RuntimeException(e); - } + + final IndexUpdateRunnable updateRunnable = new IndexUpdateRunnable(runner); + + invokeOnEDT(new DumbAwareRunnable() { + public void run() { + if (myProject.isDisposed()) { + return; + } + // ok to test and set the flag like this, because the change is always done from dispatch thread + final boolean wasDumb = myDumb; + if (!wasDumb) { + myDumb = true; + myPublisher.enteredDumbMode(); + + updateRunnable.run(); + } + else { + myUpdatesQueue.addLast(updateRunnable); + } + } + }); } - private void updateStarted() { - ApplicationManager.getApplication().assertIsDispatchThread(); - myDumb.set(true); - myPublisher.enteredDumbMode(); + private static void invokeOnEDT(DumbAwareRunnable runnable) { + if (ApplicationManager.getApplication().isDispatchThread()) { + runnable.run(); + } + else { + SwingUtilities.invokeLater(runnable); + } } private void updateFinished() { - ApplicationManager.getApplication().assertIsDispatchThread(); - myDumb.set(false); + myDumb = false; myPublisher.exitDumbMode(); while (true) { final Runnable runnable; @@ -140,6 +144,9 @@ public class DumbServiceImpl extends DumbService { } runnable = myRunWhenSmartQueue.pullFirst(); } + if (myProject.isDisposed()) { + return; + } runnable.run(); } } @@ -163,151 +170,116 @@ public class DumbServiceImpl extends DumbService { return statusBar.notifyProgressByBalloon(MessageType.WARNING, message, null, listener); } - private class CacheUpdateProcessor implements Runnable { - private int myProcessedItems; - private int myTotalItems; - private int myCurrentUpdateTotal; + private static final Ref NULL_ACTION = new Ref(null); + + private class IndexUpdateRunnable implements Runnable { + private final CacheUpdateRunner myAction; + private double myProcessedItems; + private volatile int myTotalItems; + private double myCurrentBaseTotal; - public void start() { - new Thread(this).start(); + public IndexUpdateRunnable(CacheUpdateRunner action) { + myAction = action; + myTotalItems = 0; + myCurrentBaseTotal = 0; } public void run() { - while (true) { - CacheUpdateRunner runner = null; - while (runner == null) { - if (myProject.isDisposed()) return; - try { - runner = myUpdatesQueue.poll(500, TimeUnit.MILLISECONDS); - } - catch (InterruptedException e) { - LOG.info(e); - return; - } - } - if (myProject.isDisposed()) return; + if (myProject.isDisposed()) { + return; + } - final Semaphore sema = new Semaphore(); - sema.down(); + ProgressManager.getInstance().run(new Task.Backgroundable(myProject, IdeBundle.message("progress.indexing"), false) { - final CacheUpdateRunner finalRunner = runner; - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - new Task.Backgroundable(myProject, IdeBundle.message("progress.indexing"), false) { - @Override - public void run(@NotNull final ProgressIndicator indicator) { + private final ArrayBlockingQueue> myActionQueue = new ArrayBlockingQueue>(1); + + @Override + public void run(@NotNull final ProgressIndicator indicator) { + final ProgressIndicator proxy = + (ProgressIndicator)Proxy.newProxyInstance(indicator.getClass().getClassLoader(), new Class[]{ProgressIndicator.class}, new InvocationHandler() { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if ("setFraction".equals(method.getName())) { + final double fraction = (Double)args[0]; + args[0] = new Double((myProcessedItems + fraction * myCurrentBaseTotal) / myTotalItems); + } try { - notifyStartedIfNotInDumbMode(); - try { - processPendingUpdates(finalRunner, createIndicatorProxy(indicator)); - } - finally { - notifyFinishedIfQueueEmpty(); - } + return method.invoke(indicator, args); } - catch (Throwable e) { - if (!(e instanceof ProcessCanceledException)) { - LOG.error(e); + catch (InvocationTargetException e) { + final Throwable cause = e.getCause(); + if (cause instanceof ProcessCanceledException) { + throw cause; } - } - finally { - sema.up(); + throw e; } } - - }.queue(); - } - }); - - sema.waitFor(); - } - } - - private void notifyStartedIfNotInDumbMode() { - ApplicationManager.getApplication().invokeAndWait(new Runnable() { - public void run() { - if (myProject.isDisposed()) return; - if (!isDumb()) { - updateStarted(); - myProcessedItems = 0; - myTotalItems = 0; - myCurrentUpdateTotal = 0; - } + }); + runAction(proxy, myAction); } - }, ModalityState.defaultModalityState()); - } - private void notifyFinishedIfQueueEmpty() { - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - if (myProject.isDisposed()) return; - if (myUpdatesQueue.isEmpty()) updateFinished(); + private void runAction(ProgressIndicator indicator, CacheUpdateRunner updateRunner) { + do { + int count = 0; + try { + indicator.setIndeterminate(true); + indicator.setText(IdeBundle.message("progress.indexing.scanning")); + count = updateRunner.queryNeededFiles(indicator); + + myCurrentBaseTotal = count; + myTotalItems += count; + + indicator.setIndeterminate(false); + indicator.setText(IdeBundle.message("progress.indexing.updaing")); + updateRunner.processFiles(indicator, true); + } + finally { + updateRunner.updatingDone(); + myProcessedItems += count; + invokeOnEDT(new DumbAwareRunnable() { + public void run() { + if (myUpdatesQueue.isEmpty()) { + // really terminate the tesk + myActionQueue.offer(NULL_ACTION); + updateFinished(); + } + else { + //run next dumb action + final IndexUpdateRunnable nextUpdateRunnable = myUpdatesQueue.pullFirst(); + // run next action under already existing progress indicator + if (!myActionQueue.offer(new Ref(nextUpdateRunnable.myAction))) { + LOG.assertTrue(false, "Action queue rejected next updateRunnable!"); + nextUpdateRunnable.run(); + } + } + } + }); + + // try to obtain the next action or terminate if no actions left + try { + Ref ref; + do { + ref = myActionQueue.poll(500, TimeUnit.MILLISECONDS); + updateRunner = ref != null? ref.get() : null; + if (myProject.isDisposed()) { + // just terminate the progress task + break; + } + } + while (ref == null); + } + catch (InterruptedException ignored) { + LOG.info(ignored); + break; + } + } + } + while (updateRunner != null); + // make it impossible to add actions to the queue anymore + myActionQueue.offer(NULL_ACTION); } + }); } - - private void processPendingUpdates(CacheUpdateRunner runner, ProgressIndicator indicator) { - while (true) { - if (myProject.isDisposed()) break; - - queryNeededFiles(runner, indicator); - processFiles(runner, indicator); - updatingDone(runner); - - try { - if (myProject.isDisposed()) break; - runner = myUpdatesQueue.poll(100, TimeUnit.MILLISECONDS); - if (runner == null) return; - } - catch (InterruptedException e) { - LOG.info(e); - break; - } - } - } - - private void queryNeededFiles(CacheUpdateRunner runner, ProgressIndicator indicator) { - indicator.setIndeterminate(true); - indicator.setText(IdeBundle.message("progress.indexing.scanning")); - myCurrentUpdateTotal = runner.queryNeededFiles(indicator); - myTotalItems += myCurrentUpdateTotal; - } - - private void processFiles(CacheUpdateRunner runner, ProgressIndicator indicator) { - long before = System.currentTimeMillis(); - indicator.setIndeterminate(false); - indicator.setText(IdeBundle.message("progress.indexing.updaing")); - runner.processFiles(indicator, true); - - long after = System.currentTimeMillis(); - } - - private void updatingDone(CacheUpdateRunner runner) { - runner.updatingDone(); - myProcessedItems += myCurrentUpdateTotal; - } - - private ProgressIndicator createIndicatorProxy(final ProgressIndicator indicator) { - return (ProgressIndicator)Proxy - .newProxyInstance(indicator.getClass().getClassLoader(), new Class[]{ProgressIndicator.class}, new InvocationHandler() { - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if ("setFraction".equals(method.getName())) { - double fraction = (Double)args[0]; - args[0] = new Double((myProcessedItems + fraction * myCurrentUpdateTotal) / myTotalItems); - } - - try { - return method.invoke(indicator, args); - } - catch (InvocationTargetException e) { - final Throwable cause = e.getCause(); - if (cause instanceof ProcessCanceledException) { - throw cause; - } - throw e; - } - } - }); - } } + } diff --git a/platform/testFramework/testSrc/com/intellij/codeInsight/unwrap/UnwrapTestCase.java b/platform/testFramework/testSrc/com/intellij/codeInsight/unwrap/UnwrapTestCase.java new file mode 100644 index 000000000000..554506348a56 --- /dev/null +++ b/platform/testFramework/testSrc/com/intellij/codeInsight/unwrap/UnwrapTestCase.java @@ -0,0 +1,77 @@ +package com.intellij.codeInsight.unwrap; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiFile; +import com.intellij.testFramework.LightPlatformCodeInsightTestCase; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public abstract class UnwrapTestCase extends LightPlatformCodeInsightTestCase { + protected void assertUnwrapped(String codeBefore, String expectedCodeAfter) throws Exception { + assertUnwrapped(codeBefore, expectedCodeAfter, 0); + } + + protected void assertUnwrapped(String codeBefore, String expectedCodeAfter, final int option) throws Exception { + configureCode(codeBefore); + + UnwrapHandler h = new UnwrapHandler() { + @Override + protected void selectOption(List options, Editor editor, PsiFile file) { + if (options.isEmpty()) return; + options.get(option).actionPerformed(null); + } + }; + + h.invoke(getProject(), getEditor(), getFile()); + + checkResultByText(createCode(expectedCodeAfter)); + } + + protected void assertOptions(String code, String... expectedOptions) throws IOException { + configureCode(code); + + final List actualOptions = new ArrayList(); + + UnwrapHandler h = new UnwrapHandler() { + @Override + protected void selectOption(List options, Editor editor, PsiFile file) { + for (AnAction each : options) { + actualOptions.add(each.getTemplatePresentation().getText()); + } + } + }; + + h.invoke(getProject(), getEditor(), getFile()); + + assertEquals(Arrays.asList(expectedOptions), actualOptions); + } + + protected void configureCode(final String codeBefore) throws IOException { + configureFromFileText(getFileNameToCreate(), createCode(codeBefore)); + } + + protected String getFileNameToCreate() { + return "A.java"; + } + + protected String createCode(String codeBefore) { + return "public class A {\n" + + " void foo() {\n" + + indentTwice(codeBefore) + + " }\n" + + "}"; + } + + protected String indentTwice(String code) { + String result = ""; + for (String line : StringUtil.tokenize(code, "\n")) { + result += " " + line + "\n"; + } + return result; + } +} \ No newline at end of file diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index d17e316f345e..5a196ff2aa7c 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -1238,7 +1238,7 @@ public class StringUtil { return result.toString(); } - private static String replace(final String text, final String[] from, final String[] to) { + public static String replace(final String text, final String[] from, final String[] to) { final StringBuilder result = new StringBuilder(text.length()); replace: for (int i = 0; i < text.length(); i++) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/UtilityClassWithoutPrivateConstructorInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/UtilityClassWithoutPrivateConstructorInspection.java index e91772642bb0..1388f8378686 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/UtilityClassWithoutPrivateConstructorInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/UtilityClassWithoutPrivateConstructorInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2008 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2009 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.searches.ClassInheritorsSearch; +import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.util.IncorrectOperationException; import com.intellij.util.Query; import com.siyeh.HardcodedMethodConstants; @@ -67,10 +68,28 @@ public class UtilityClassWithoutPrivateConstructorInspection @Override protected InspectionGadgetsFix buildFix(Object... infos) { final PsiClass aClass = (PsiClass)infos[0]; - if (hasNullArgConstructor(aClass)) { - return new MakeConstructorPrivateFix(); - } else { + final PsiMethod constructor = getNullArgConstructor(aClass); + if (constructor == null) { + final Query query = + ReferencesSearch.search(aClass, aClass.getUseScope()); + for (PsiReference reference : query) { + final PsiElement element = reference.getElement(); + final PsiElement parent = element.getParent(); + if (parent instanceof PsiNewExpression) { + return null; + } + } return new CreateEmptyPrivateConstructor(); + } else { + final Query query = + ReferencesSearch.search(constructor, + constructor.getUseScope()); + final PsiReference reference = query.findFirst(); + if (reference == null) { + return new MakeConstructorPrivateFix(); + } else { + return null; + } } } @@ -91,14 +110,14 @@ public class UtilityClassWithoutPrivateConstructorInspection if (aClass == null) { return; } - final PsiManager psiManager = PsiManager.getInstance(project); - final PsiElementFactory factory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory(); + final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); + final PsiElementFactory factory = psiFacade.getElementFactory(); final PsiMethod constructor = factory.createConstructor(); final PsiModifierList modifierList = constructor.getModifierList(); modifierList.setModifierProperty(PsiModifier.PRIVATE, true); aClass.add(constructor); final CodeStyleManager styleManager = - psiManager.getCodeStyleManager(); + CodeStyleManager.getInstance(project); styleManager.reformat(constructor); } } @@ -220,14 +239,15 @@ public class UtilityClassWithoutPrivateConstructorInspection } } - static boolean hasNullArgConstructor(PsiClass aClass) { + @Nullable + static PsiMethod getNullArgConstructor(PsiClass aClass) { final PsiMethod[] constructors = aClass.getConstructors(); for (final PsiMethod constructor : constructors) { final PsiParameterList params = constructor.getParameterList(); if (params.getParametersCount() == 0) { - return true; + return constructor; } } - return false; + return null; } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java index ea0d3cf76fdb..ac709e306eb3 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2009 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.psiutils.ComparisonUtils; +import com.siyeh.ig.psiutils.ExpressionUtils; import org.jetbrains.annotations.NotNull; public class ConstantOnLHSOfComparisonInspection extends BaseInspection { @@ -68,16 +69,20 @@ public class ConstantOnLHSOfComparisonInspection extends BaseInspection { final PsiBinaryExpression expression = (PsiBinaryExpression) descriptor.getPsiElement(); final PsiExpression rhs = expression.getROperand(); - final PsiExpression lhs = expression.getLOperand(); + if (rhs == null) { + return; + } final PsiJavaToken sign = expression.getOperationSign(); - final String flippedSign = + final String flippedComparison = ComparisonUtils.getFlippedComparison(sign); - assert rhs != null; + if (flippedComparison == null) { + return; + } + final PsiExpression lhs = expression.getLOperand(); final String rhsText = rhs.getText(); final String lhsText = lhs.getText(); replaceExpression(expression, - rhsText + ' ' + flippedSign + ' ' + lhsText); - + rhsText + ' ' + flippedComparison + ' ' + lhsText); } } @@ -87,7 +92,7 @@ public class ConstantOnLHSOfComparisonInspection extends BaseInspection { @Override public void visitBinaryExpression( @NotNull PsiBinaryExpression expression) { super.visitBinaryExpression(expression); - if(!(expression.getROperand() != null)) { + if (!(expression.getROperand() != null)) { return; } if (!ComparisonUtils.isComparison(expression)) { @@ -95,11 +100,16 @@ public class ConstantOnLHSOfComparisonInspection extends BaseInspection { } final PsiExpression lhs = expression.getLOperand(); final PsiExpression rhs = expression.getROperand(); - if (!PsiUtil.isConstantExpression(lhs) - || PsiUtil.isConstantExpression(rhs)) { + if (!isConstantExpression(lhs) + || isConstantExpression(rhs)) { return; } registerError(expression); } + + private boolean isConstantExpression(PsiExpression expression) { + return ExpressionUtils.isNullLiteral(expression) || + PsiUtil.isConstantExpression(expression); + } } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java index b4bb9758cb0e..f5a18b238cfd 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java @@ -27,6 +27,7 @@ import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.psiutils.ComparisonUtils; +import com.siyeh.ig.psiutils.ExpressionUtils; import org.jetbrains.annotations.NotNull; public class ConstantOnRHSOfComparisonInspection extends BaseInspection { @@ -71,14 +72,14 @@ public class ConstantOnRHSOfComparisonInspection extends BaseInspection { if (rhs == null) { return; } - final PsiExpression lhs = expression.getLOperand(); final PsiJavaToken sign = expression.getOperationSign(); - final String rhsText = rhs.getText(); final String flippedComparison = ComparisonUtils.getFlippedComparison(sign); if (flippedComparison == null) { return; } + final PsiExpression lhs = expression.getLOperand(); + final String rhsText = rhs.getText(); final String lhsText = lhs.getText(); replaceExpression(expression, rhsText + ' ' + flippedComparison + ' ' + lhsText); @@ -99,11 +100,15 @@ public class ConstantOnRHSOfComparisonInspection extends BaseInspection { } final PsiExpression lhs = expression.getLOperand(); final PsiExpression rhs = expression.getROperand(); - if (!PsiUtil.isConstantExpression(rhs) || - PsiUtil.isConstantExpression(lhs)) { + if (!isConstantExpression(rhs) || isConstantExpression(lhs)) { return; } registerError(expression); } + + private boolean isConstantExpression(PsiExpression expression) { + return ExpressionUtils.isNullLiteral(expression) || + PsiUtil.isConstantExpression(expression); + } } } \ No newline at end of file diff --git a/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java b/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java index 0d050c2a7065..58f1c250a4b7 100644 --- a/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java +++ b/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java @@ -196,7 +196,11 @@ public class GitRootTracker implements VcsListener { * {@inheritDoc} */ public void directoryMappingChanged() { - scheduleRootsCheck(true); + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + scheduleRootsCheck(true); + } + }); } private void scheduleRootsCheck(final boolean rootsChanged) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/annotator/MavenDomAnnotator.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/annotator/MavenDomAnnotator.java index b452ea6c356c..e2788fcce131 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/annotator/MavenDomAnnotator.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/annotator/MavenDomAnnotator.java @@ -15,16 +15,75 @@ */ package org.jetbrains.idea.maven.dom.annotator; +import com.intellij.codeInspection.LocalQuickFix; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.lang.annotation.HighlightSeverity; +import com.intellij.openapi.fileEditor.OpenFileDescriptor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.ArrayUtil; import com.intellij.util.xml.DomElement; +import com.intellij.util.xml.DomUtil; import com.intellij.util.xml.highlighting.DomElementAnnotationHolder; import com.intellij.util.xml.highlighting.DomElementsAnnotator; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.idea.maven.dom.MavenDomBundle; +import org.jetbrains.idea.maven.dom.MavenDomUtil; +import org.jetbrains.idea.maven.dom.model.MavenDomParent; +import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel; +import org.jetbrains.idea.maven.project.MavenProject; +import org.jetbrains.idea.maven.project.MavenProjectProblem; public class MavenDomAnnotator implements DomElementsAnnotator { public void annotate(DomElement element, DomElementAnnotationHolder holder) { - //Project project = element.getManager().getProject(); - //MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project); - //if (element instanceof MavenDomProjectModel) { - // String groupId = ((MavenDomProjectModel)element).getGroupId().getValue(); - //} + if (element instanceof MavenDomProjectModel) { + addProblems(element, (MavenDomProjectModel)element, holder, + MavenProjectProblem.ProblemType.STRUCTURE, + MavenProjectProblem.ProblemType.SETTINGS_OR_PROFILES); + } + else if (element instanceof MavenDomParent) { + addProblems(element, DomUtil.getParentOfType(element, MavenDomProjectModel.class, true), holder, + MavenProjectProblem.ProblemType.PARENT); + } + } + + private void addProblems(DomElement element, MavenDomProjectModel model, DomElementAnnotationHolder holder, + MavenProjectProblem.ProblemType... types) { + MavenProject mavenProject = MavenDomUtil.findProject(model); + if (mavenProject != null) { + for (MavenProjectProblem each : mavenProject.getProblems()) { + MavenProjectProblem.ProblemType type = each.getType(); + if (!ArrayUtil.contains(type, types)) continue; + VirtualFile problemFile = each.findFile(); + + LocalQuickFix[] fixes = LocalQuickFix.EMPTY_ARRAY; + if (problemFile != null && mavenProject.getFile() != problemFile) { + fixes = new LocalQuickFix[]{new OpenProblemFileFix(problemFile)}; + } + holder.createProblem(element, HighlightSeverity.ERROR, each.getDescription(), fixes); + } + } + } + + private static class OpenProblemFileFix implements LocalQuickFix { + private final VirtualFile myFile; + + private OpenProblemFileFix(VirtualFile file) { + myFile = file; + } + + @NotNull + public String getName() { + return MavenDomBundle.message("fix.open.file", myFile.getName()); + } + + @NotNull + public String getFamilyName() { + return MavenDomBundle.message("inspection.group"); + } + + public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { + new OpenFileDescriptor(project, myFile).navigate(true); + } } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenDefaultModifiableModelsProvider.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenDefaultModifiableModelsProvider.java index 7e21c9e15cab..fb5bdd2bd40b 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenDefaultModifiableModelsProvider.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenDefaultModifiableModelsProvider.java @@ -133,6 +133,9 @@ public class MavenDefaultModifiableModelsProvider extends MavenBaseModifiableMod each.dispose(); } myModuleModel.dispose(); + if (myArtifactModel != null) { + myArtifactModel.dispose(); + } } }); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java index d9ed6836a471..9db61a13546f 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenIndicesManager.java @@ -15,7 +15,6 @@ */ package org.jetbrains.idea.maven.indices; -import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.application.Result; @@ -31,8 +30,6 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiManager; -import com.intellij.psi.impl.PsiModificationTrackerImpl; import gnu.trove.THashSet; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.catalog.ArchetypeCatalog; @@ -43,6 +40,7 @@ import org.jdom.Element; import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; +import org.jetbrains.idea.maven.utils.MavenRehighlighter; import org.jetbrains.idea.maven.embedder.MavenEmbedderFactory; import org.jetbrains.idea.maven.embedder.MavenEmbedderWrapper; import org.jetbrains.idea.maven.project.MavenGeneralSettings; @@ -310,16 +308,7 @@ public class MavenIndicesManager implements ApplicationComponent { private void scheduleRehighlightAllPoms(final Project projectOrNull) { if (projectOrNull == null) return; - MavenUtil.invokeLater(projectOrNull, new Runnable() { - public void run() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - public void run() { - ((PsiModificationTrackerImpl)PsiManager.getInstance(projectOrNull).getModificationTracker()).incCounter(); - DaemonCodeAnalyzer.getInstance(projectOrNull).restart(); - } - }); - } - }); + MavenRehighlighter.rehighlight(projectOrNull); } public synchronized Set getArchetypes() { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsStructure.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsStructure.java index 68e2831f5d8e..7564d7e58f3c 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsStructure.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsStructure.java @@ -303,7 +303,7 @@ public class MavenProjectsStructure extends SimpleTreeStructure { } public enum ErrorLevel { - NONE, WARNING, ERROR + NONE, ERROR } public abstract class CustomNode extends SimpleNode { @@ -443,8 +443,7 @@ public class MavenProjectsStructure extends SimpleTreeStructure { private SimpleTextAttributes prepareAttribs(SimpleTextAttributes from) { ErrorLevel level = getOverallErrorLevel(); - Color waveColor = level == ErrorLevel.NONE - ? null : (level == ErrorLevel.WARNING ? Color.GRAY : Color.RED); + Color waveColor = level == ErrorLevel.NONE ? null : Color.RED; int style = from.getStyle(); if (waveColor != null) style |= SimpleTextAttributes.STYLE_WAVED; return new SimpleTextAttributes(from.getBgColor(), @@ -629,19 +628,7 @@ public class MavenProjectsStructure extends SimpleTreeStructure { } private void updateErrorLevel() { - if (!myMavenProject.hasErrors()) { - setNodeErrorLevel(ErrorLevel.NONE); - return; - } - List problems = myMavenProject.getProblems(); - boolean isError = false; - for (MavenProjectProblem each : problems) { - if (each.isCritical()) { - isError = true; - break; - } - } - setNodeErrorLevel(isError ? ErrorLevel.ERROR : ErrorLevel.WARNING); + setNodeErrorLevel(myMavenProject.getProblems().isEmpty() ? ErrorLevel.NONE : ErrorLevel.ERROR); } @Override @@ -675,8 +662,7 @@ public class MavenProjectsStructure extends SimpleTreeStructure { desc.append(" "); desc.append(""); desc.append(""); - appendProblems(desc, true); - appendProblems(desc, false); + appendProblems(desc); if (getModulesErrorLevel() != ErrorLevel.NONE) { desc.append(""); @@ -698,8 +684,8 @@ public class MavenProjectsStructure extends SimpleTreeStructure { return result; } - private void appendProblems(StringBuilder desc, boolean critical) { - List problems = collectProblems(critical); + private void appendProblems(StringBuilder desc) { + List problems = myMavenProject.getProblems(); if (problems.isEmpty()) return; desc.append(""); @@ -709,8 +695,8 @@ public class MavenProjectsStructure extends SimpleTreeStructure { for (MavenProjectProblem each : problems) { desc.append(""); if (first) { - desc.append("" + MavenUtil.formatHtmlImage(critical ? ERROR_ICON_URL : WARNING_ICON_URL) + ""); - desc.append("" + (critical ? "Errors" : "Warnings") + ":"); + desc.append("" + MavenUtil.formatHtmlImage(ERROR_ICON_URL) + ""); + desc.append("Problems:"); first = false; } else { @@ -725,7 +711,7 @@ public class MavenProjectsStructure extends SimpleTreeStructure { } private String wrappedText(MavenProjectProblem each) { - String text = each.getDescription(); + String text = StringUtil.replace(each.getDescription(), new String[]{"<", ">"}, new String[]{"<", ">"}); StringBuffer result = new StringBuffer(); int count = 0; for (int i = 0; i < text.length(); i++) { @@ -742,14 +728,6 @@ public class MavenProjectsStructure extends SimpleTreeStructure { return result.toString(); } - private List collectProblems(boolean critical) { - List result = new ArrayList(); - for (MavenProjectProblem each : myMavenProject.getProblems()) { - if (critical == each.isCritical()) result.add(each); - } - return result; - } - public void updateGoals() { myLifecycleNode.updateGoals(); myPluginsNode.updateGoals(); @@ -1012,7 +990,7 @@ public class MavenProjectsStructure extends SimpleTreeStructure { else { setNameAndTooltip(myPluginInfo.getGoalPrefix(), null, myPlugin.getDisplayString()); } - setNodeErrorLevel(myPluginInfo == null ? ErrorLevel.WARNING : ErrorLevel.NONE); + setNodeErrorLevel(myPluginInfo == null ? ErrorLevel.ERROR : ErrorLevel.NONE); // there is no need to update goals since plugins do not change if (hadPluginInfo || myPluginInfo == null) return; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenId.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenId.java index c10690507b01..929bcf1e5220 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenId.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenId.java @@ -16,6 +16,7 @@ package org.jetbrains.idea.maven.project; import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Model; import java.io.Serializable; @@ -32,6 +33,10 @@ public class MavenId implements Serializable { this.myVersion = version; } + public MavenId(Model model) { + this(model.getGroupId(), model.getArtifactId(), model.getVersion()); + } + public MavenId(Artifact artifact) { this(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java index 8960ed7636eb..4060fabb74aa 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java @@ -101,7 +101,6 @@ public class MavenProject { if (updateLastReadStamp) newState.myLastReadStamp++; - newState.myValid = readerResult.isValid; newState.myActiveProfilesIds = readerResult.activeProfiles; newState.myReadingProblems = readerResult.readingProblems; newState.myLocalRepository = readerResult.localRepository; @@ -346,8 +345,8 @@ public class MavenProject { return MavenUtil.getProfilesXmlIoFile(myFile); } - public boolean hasErrors() { - return !myState.myValid; + public boolean hasReadingProblems() { + return !myState.myReadingProblems.isEmpty(); } public List getActiveProfilesIds() { @@ -441,7 +440,7 @@ public class MavenProject { getFile(), getActiveProfilesIds(), locator); - MavenProjectChanges changes = set(result, false, result.isValid, false); + MavenProjectChanges changes = set(result, false, result.readingProblems.isEmpty(), false); return Pair.create(changes, result.nativeMavenProject); } @@ -454,7 +453,7 @@ public class MavenProject { getFile(), getActiveProfilesIds(), console); - if (result == null || !result.isValid) return Pair.create(false, MavenProjectChanges.NONE); + if (result == null || !result.readingProblems.isEmpty()) return Pair.create(false, MavenProjectChanges.NONE); MavenProjectChanges changes = setFolders(result); return Pair.create(true, changes); } @@ -468,58 +467,62 @@ public class MavenProject { if (state.myProblemsCache == null) { synchronized (state) { if (state.myProblemsCache == null) { - state.myProblemsCache = collectProblems(state); + state.myProblemsCache = collectProblems(myFile, state); } } } return state.myProblemsCache; } - private static List collectProblems(State state) { + private static List collectProblems(VirtualFile file, State state) { List result = new ArrayList(); - validateParent(state, result); + validateParent(file, state, result); result.addAll(state.myReadingProblems); for (Map.Entry each : state.myModulesPathsAndNames.entrySet()) { if (LocalFileSystem.getInstance().findFileByPath(each.getKey()) == null) { - result.add(new MavenProjectProblem(ProjectBundle.message("maven.project.problem.missingModule", each.getValue()), false)); + result.add(createDependencyProblem(file, ProjectBundle.message("maven.project.problem.moduleNotFound", each.getValue()))); } } - validateDependencies(state, result); - validateExtensions(state, result); - validatePlugins(state, result); + validateDependencies(file, state, result); + validateExtensions(file, state, result); + validatePlugins(file, state, result); return result; } - private static void validateParent(State state, List result) { + private static void validateParent(VirtualFile file, State state, List result) { if (!isParentResolved(state)) { - result.add(new MavenProjectProblem(ProjectBundle.message("maven.project.problem.parentNotFound", state.myParentId), true)); + result.add(createDependencyProblem(file, ProjectBundle.message("maven.project.problem.parentNotFound", state.myParentId))); } } - private static void validateDependencies(State state, List result) { + private static void validateDependencies(VirtualFile file, State state, List result) { for (MavenArtifact each : getUnresolvedDependencies(state)) { - result.add(new MavenProjectProblem( - ProjectBundle.message("maven.project.problem.unresolvedDependency", each.getDisplayStringWithType()), false)); + result.add(createDependencyProblem(file, ProjectBundle.message("maven.project.problem.unresolvedDependency", + each.getDisplayStringWithType()))); } } - private static void validateExtensions(State state, List result) { + private static void validateExtensions(VirtualFile file, State state, List result) { for (MavenArtifact each : getUnresolvedExtensions(state)) { - result.add(new MavenProjectProblem( - ProjectBundle.message("maven.project.problem.unresolvedExtension", each.getDisplayStringSimple()), false)); + result.add(createDependencyProblem(file, ProjectBundle.message("maven.project.problem.unresolvedExtension", + each.getDisplayStringSimple()))); } } - private static void validatePlugins(State state, List result) { + private static void validatePlugins(VirtualFile file, State state, List result) { for (MavenPlugin each : getUnresolvedPlugins(state)) { - result.add(new MavenProjectProblem(ProjectBundle.message("maven.project.problem.unresolvedPlugin", each), false)); + result.add(createDependencyProblem(file, ProjectBundle.message("maven.project.problem.unresolvedPlugin", each))); } } + private static MavenProjectProblem createDependencyProblem(VirtualFile file, String description) { + return new MavenProjectProblem(file, description, MavenProjectProblem.ProblemType.DEPENDENCY); + } + private static boolean isParentResolved(State state) { return !state.myUnresolvedArtifactIds.contains(state.myParentId); } @@ -817,8 +820,6 @@ public class MavenProject { private static class State implements Cloneable, Serializable { long myLastReadStamp = 0; - boolean myValid; - MavenId myMavenId; MavenId myParentId; String myPackaging; @@ -851,7 +852,7 @@ public class MavenProject { List myRemoteRepositories; List myActiveProfilesIds; - List myReadingProblems; + Collection myReadingProblems; Set myUnresolvedArtifactIds; File myLocalRepository; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectProblem.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectProblem.java index 444de9d2e7ee..1c6636d9530b 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectProblem.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectProblem.java @@ -15,30 +15,67 @@ */ package org.jetbrains.idea.maven.project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; + import java.io.Serializable; public class MavenProjectProblem implements Serializable { + public enum ProblemType { + SYNTAX, STRUCTURE, DEPENDENCY, PARENT, SETTINGS_OR_PROFILES; + } + + private String myUrl; private String myDescription; - private boolean isCritical; + private ProblemType myType; protected MavenProjectProblem() { } - public MavenProjectProblem(String description, boolean critical) { + public MavenProjectProblem(VirtualFile file, String description, ProblemType type) { + myUrl = file.getUrl(); myDescription = description; - isCritical = critical; + myType = type; + } + + public String getUrl() { + return myUrl; } public String getDescription() { return myDescription; } - public boolean isCritical() { - return isCritical; + public ProblemType getType() { + return myType; + } + + public VirtualFile findFile() { + return VirtualFileManager.getInstance().findFileByUrl(myUrl); } @Override public String toString() { - return (isCritical ? "!!!" : "") + myDescription; + return myType + ":" + myDescription + ":" + myUrl; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MavenProjectProblem that = (MavenProjectProblem)o; + + if (!myDescription.equals(that.myDescription)) return false; + if (myType != that.myType) return false; + if (!myUrl.equals(that.myUrl)) return false; + + return true; + } + + public int hashCode() { + int result = myUrl.hashCode(); + result = 31 * result + myDescription.hashCode(); + result = 31 * result + myType.hashCode(); + return result; } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReader.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReader.java index a8fc06fde40e..e0289a658613 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReader.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReader.java @@ -17,7 +17,6 @@ package org.jetbrains.idea.maven.project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -57,17 +56,14 @@ import static com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces; public class MavenProjectReader { private static final String UNKNOWN = MavenId.UNKNOWN_VALUE; - private final Map myRawModelsAndValidityCache = new THashMap(); + private final Map myRawModelsAndProblemsCache = new THashMap(); public MavenProjectReaderResult readProject(MavenGeneralSettings generalSettings, VirtualFile file, List activeProfiles, MavenProjectReaderProjectLocator locator) { - Pair> readResult = doReadProjectModel(generalSettings, - file, - activeProfiles, - new THashSet(), - locator); + Pair> readResult = + doReadProjectModel(generalSettings, file, activeProfiles, new THashSet(), locator); File basedir = getBaseDir(file); Model model = expandProperties(readResult.first.model, basedir); @@ -76,63 +72,55 @@ public class MavenProjectReader { MavenProject mavenProject = new MavenProject(model); mavenProject.setFile(new File(file.getPath())); mavenProject.setActiveProfiles(readResult.second); - JBMavenProjectHelper.setSourceRoots(mavenProject, - Collections.singletonList(model.getBuild().getSourceDirectory()), + JBMavenProjectHelper.setSourceRoots(mavenProject, Collections.singletonList(model.getBuild().getSourceDirectory()), Collections.singletonList(model.getBuild().getTestSourceDirectory()), Collections.singletonList(model.getBuild().getScriptSourceDirectory())); - boolean isValid = readResult.first.validity; - List problems = new ArrayList(); - if (!isValid) { - problems.add(new MavenProjectProblem(ProjectBundle.message("maven.project.problem.syntaxError"), true)); - } - return new MavenProjectReaderResult(isValid, - activeProfiles, - problems, - Collections.EMPTY_SET, - generalSettings.getEffectiveLocalRepository(), - mavenProject); + return new MavenProjectReaderResult(activeProfiles, readResult.first.problems, Collections.EMPTY_SET, + generalSettings.getEffectiveLocalRepository(), mavenProject); } private File getBaseDir(VirtualFile file) { return new File(file.getParent().getPath()); } - private Pair> doReadProjectModel(MavenGeneralSettings generalSettings, + private Pair> doReadProjectModel(MavenGeneralSettings generalSettings, VirtualFile file, List activeProfiles, Set recursionGuard, MavenProjectReaderProjectLocator locator) { - ModelWithValidity modelWithValidity = myRawModelsAndValidityCache.get(file); + ModelWithProblems modelWithValidity = myRawModelsAndProblemsCache.get(file); if (modelWithValidity == null) { - modelWithValidity = doReadProjectModel(file, generalSettings); - myRawModelsAndValidityCache.put(file, modelWithValidity); + modelWithValidity = doReadProjectModel(file, generalSettings, false); + myRawModelsAndProblemsCache.put(file, modelWithValidity); } Model model = modelWithValidity.model; List activatedProfiles = applyProfiles(model, getBaseDir(file), activeProfiles); repairModelHeader(model); - if (!resolveInheritance(generalSettings, model, file, activeProfiles, recursionGuard, locator)) { - modelWithValidity.validity = false; // todo ????????? changing cached value - } + resolveInheritance(generalSettings, model, file, activeProfiles, + recursionGuard, locator, modelWithValidity.problems); // todo ????????? changing cached value repairModelBody(model); return Pair.create(modelWithValidity, activatedProfiles); } - private ModelWithValidity doReadProjectModel(VirtualFile file, MavenGeneralSettings generalSettings) { + private ModelWithProblems doReadProjectModel(VirtualFile file, MavenGeneralSettings generalSettings, boolean headerOnly) { Model result = new Model(); + LinkedHashSet problems = createProblemsList(); - Pair readXmlResult = readXml(file); - Element xmlProject = readXmlResult.first.getChild("project"); + Element xmlProject = readXml(file, problems, MavenProjectProblem.ProblemType.SYNTAX).getChild("project"); if (xmlProject == null) { - return new ModelWithValidity(result, false); + return new ModelWithProblems(result, problems); } result.setModelVersion(findChildValueByPath(xmlProject, "modelVersion")); result.setGroupId(findChildValueByPath(xmlProject, "groupId")); result.setArtifactId(findChildValueByPath(xmlProject, "artifactId")); result.setVersion(findChildValueByPath(xmlProject, "version")); + + if (headerOnly) return new ModelWithProblems(result, problems); + result.setPackaging(findChildValueByPath(xmlProject, "packaging")); result.setName(findChildValueByPath(xmlProject, "name")); @@ -150,18 +138,14 @@ public class MavenProjectReader { result.setParent(parent); } - result.setBuild(new Build()); readModelAndBuild(result, result.getBuild(), xmlProject); - Ref validity = new Ref(readXmlResult.second); - result.setProfiles(collectProfiles(generalSettings, file, xmlProject, validity)); - return new ModelWithValidity(result, validity.get()); + result.setProfiles(collectProfiles(generalSettings, file, xmlProject, problems)); + return new ModelWithProblems(result, problems); } - private void readModelAndBuild(ModelBase mavenModelBase, - BuildBase mavenBuildBase, - Element xmlModel) { + private void readModelAndBuild(ModelBase mavenModelBase, BuildBase mavenBuildBase, Element xmlModel) { mavenModelBase.setModules(findChildrenValuesByPath(xmlModel, "modules", "module")); collectProperties(findChildByPath(xmlModel, "properties"), mavenModelBase); @@ -199,15 +183,16 @@ public class MavenProjectReader { return result; } - private List collectProfiles(MavenGeneralSettings generalSettings, VirtualFile file, Element xmlProject, Ref validity) { + private List collectProfiles(MavenGeneralSettings generalSettings, + VirtualFile projectFile, + Element xmlProject, + Collection problems) { List result = new ArrayList(); collectProfiles(findChildrenByPath(xmlProject, "profiles", "profile"), result); - VirtualFile profilesFile = MavenUtil.findProfilesXmlFile(file); + VirtualFile profilesFile = MavenUtil.findProfilesXmlFile(projectFile); if (profilesFile != null) { - Pair readResult = readXml(profilesFile); - Element profilesFileElement = readResult.first; - if (!readResult.second) validity.set(false); + Element profilesFileElement = readXml(profilesFile, problems, MavenProjectProblem.ProblemType.SETTINGS_OR_PROFILES); Element rootElement = findChildByPath(profilesFileElement, "profiles"); if (rootElement == null) rootElement = findChildByPath(profilesFileElement, "profilesXml.profiles"); @@ -216,18 +201,18 @@ public class MavenProjectReader { } for (VirtualFile each : generalSettings.getEffectiveSettingsFiles()) { - collectProfilesFromSettingsFile(each, result, validity); + collectProfilesFromSettingsFile(each, result, problems); } return result; } - private void collectProfilesFromSettingsFile(VirtualFile settingsFile, List result, Ref validity) { + private void collectProfilesFromSettingsFile(VirtualFile settingsFile, + List result, + Collection problems) { if (settingsFile == null) return; - Pair readResult = readXml(settingsFile); - if (!readResult.second) validity.set(false); - - List xmlProfiles = findChildrenByPath(readResult.first, "settings.profiles", "profile"); + Element readResult = readXml(settingsFile, problems, MavenProjectProblem.ProblemType.SETTINGS_OR_PROFILES); + List xmlProfiles = findChildrenByPath(readResult, "settings.profiles", "profile"); collectProfiles(xmlProfiles, result); } @@ -322,9 +307,9 @@ public class MavenProjectReader { Profile eachExpandedProfile = expandedProfiles.get(i); // todo hook for IDEADEV-38717 - assert eachExpandedProfile != null : "expanded profile not found"; - assert Comparing.equal(eachExpandedProfile.getId(), eachRawProfile.getId()) : - "expected id: " + eachRawProfile.getId() + " was : " + eachExpandedProfile.getId(); + MavenLog.LOG.assertTrue(eachExpandedProfile != null, "expanded profile not found"); + MavenLog.LOG.assertTrue(Comparing.equal(eachExpandedProfile.getId(), eachRawProfile.getId()), + "expected id: " + eachRawProfile.getId() + " was : " + eachExpandedProfile.getId()); for (ProfileActivator eachActivator : getProfileActivators()) { try { @@ -360,12 +345,8 @@ public class MavenProjectReader { return new ProfileActivator[0]; } - return new ProfileActivator[]{ - new FileProfileActivator(), - sysPropertyActivator, - new JdkPrefixProfileActivator(), - new OperatingSystemProfileActivator() - }; + return new ProfileActivator[]{new FileProfileActivator(), sysPropertyActivator, new JdkPrefixProfileActivator(), + new OperatingSystemProfileActivator()}; } private void repairModelHeader(Model model) { @@ -410,26 +391,19 @@ public class MavenProjectReader { build.setFinalName("${project.artifactId}-${project.version}"); } - build.setSourceDirectory(isEmptyOrSpaces(build.getSourceDirectory()) - ? "src/main/java" - : build.getSourceDirectory()); - build.setTestSourceDirectory(isEmptyOrSpaces(build.getTestSourceDirectory()) - ? "src/test/java" - : build.getTestSourceDirectory()); - build.setScriptSourceDirectory(isEmptyOrSpaces(build.getScriptSourceDirectory()) - ? "src/main/scripts" - : build.getScriptSourceDirectory()); + build.setSourceDirectory(isEmptyOrSpaces(build.getSourceDirectory()) ? "src/main/java" : build.getSourceDirectory()); + build.setTestSourceDirectory(isEmptyOrSpaces(build.getTestSourceDirectory()) ? "src/test/java" : build.getTestSourceDirectory()); + build + .setScriptSourceDirectory(isEmptyOrSpaces(build.getScriptSourceDirectory()) ? "src/main/scripts" : build.getScriptSourceDirectory()); build.setResources(repairResources(build.getResources(), "src/main/resources")); build.setTestResources(repairResources(build.getTestResources(), "src/test/resources")); build.setDirectory(isEmptyOrSpaces(build.getDirectory()) ? "target" : build.getDirectory()); - build.setOutputDirectory(isEmptyOrSpaces(build.getOutputDirectory()) - ? "${project.build.directory}/classes" - : build.getOutputDirectory()); - build.setTestOutputDirectory(isEmptyOrSpaces(build.getTestOutputDirectory()) - ? "${project.build.directory}/test-classes" - : build.getTestOutputDirectory()); + build + .setOutputDirectory(isEmptyOrSpaces(build.getOutputDirectory()) ? "${project.build.directory}/classes" : build.getOutputDirectory()); + build.setTestOutputDirectory( + isEmptyOrSpaces(build.getTestOutputDirectory()) ? "${project.build.directory}/test-classes" : build.getTestOutputDirectory()); } private List repairResources(List resources, String defaultDir) { @@ -453,68 +427,71 @@ public class MavenProjectReader { return result; } - private boolean resolveInheritance(final MavenGeneralSettings generalSettings, - final Model model, - final VirtualFile file, - final List activeProfiles, - final Set recursionGuard, - final MavenProjectReaderProjectLocator locator) { - if (recursionGuard.contains(file)) return false; + private void resolveInheritance(final MavenGeneralSettings generalSettings, + final Model model, + final VirtualFile file, + final List activeProfiles, + final Set recursionGuard, + final MavenProjectReaderProjectLocator locator, + Collection problems) { + if (recursionGuard.contains(file)) { + problems.add(createProblem(file, ProjectBundle.message("maven.project.problem.recursiveInheritance"), + MavenProjectProblem.ProblemType.PARENT)); + return; + } recursionGuard.add(file); try { Parent parent = model.getParent(); final MavenParentDesc[] parentDesc = new MavenParentDesc[1]; if (parent != null) { - MavenId parentId = new MavenId(parent.getGroupId(), - parent.getArtifactId(), - parent.getVersion()); + MavenId parentId = new MavenId(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); if (parentId.equals(model.getGroupId(), model.getArtifactId(), model.getVersion())) { - // self-inheritance protection - return false; + problems.add(createProblem(file, ProjectBundle.message("maven.project.problem.selfInheritance"), + MavenProjectProblem.ProblemType.PARENT)); + return; } parentDesc[0] = new MavenParentDesc(parentId, parent.getRelativePath()); } - ModelWithValidity parentModelWithValidity = new MavenParentProjectFileProcessor() { - @Nullable - protected VirtualFile findManagedFile(@NotNull MavenId id) { - return locator.findProjectFile(id); - } - - @Override - @Nullable - protected ModelWithValidity processRelativeParent(VirtualFile parentFile) { - ModelWithValidity result = super.processRelativeParent(parentFile); - if (result == null) return null; - - MavenId parentId = parentDesc[0].getParentId(); - Model model = result.model; - if (!(parentId.equals(model.getGroupId(), model.getArtifactId(), model.getVersion()))) { - return null; + Pair parentModelWithProblems = + new MavenParentProjectFileProcessor>() { + @Nullable + protected VirtualFile findManagedFile(@NotNull MavenId id) { + return locator.findProjectFile(id); } - return result; - } - @Override - protected ModelWithValidity processSuperParent(VirtualFile parentFile) { - return null; // do not process superPom - } + @Override + @Nullable + protected Pair processRelativeParent(VirtualFile parentFile) { + Model parentModel = doReadProjectModel(parentFile, generalSettings, true).model; + MavenId parentId = parentDesc[0].getParentId(); + if (!parentId.equals(new MavenId(parentModel))) return null; - @Override - protected ModelWithValidity doProcessParent(VirtualFile parentFile) { - return doReadProjectModel(generalSettings, - parentFile, - activeProfiles, - recursionGuard, - locator).first; - } - }.process(generalSettings, file, parentDesc[0]); + return super.processRelativeParent(parentFile); + } - if (parentModelWithValidity == null) return true; // no parent or parent not found; + @Override + protected Pair processSuperParent(VirtualFile parentFile) { + return null; // do not process superPom + } - new DefaultModelInheritanceAssembler().assembleModelInheritance(model, parentModelWithValidity.model); - return parentModelWithValidity.validity; + @Override + protected Pair doProcessParent(VirtualFile parentFile) { + ModelWithProblems result = doReadProjectModel(generalSettings, parentFile, activeProfiles, recursionGuard, locator).first; + return Pair.create(parentFile, result); + } + }.process(generalSettings, file, parentDesc[0]); + + if (parentModelWithProblems == null) return; // no parent or parent not found; + if (!parentModelWithProblems.second.problems.isEmpty()) { + problems.add(createProblem(parentModelWithProblems.first, + ProjectBundle.message("maven.project.problem.parentHasProblems", + new MavenId(parentModelWithProblems.second.model)), + MavenProjectProblem.ProblemType.PARENT)); + } + + new DefaultModelInheritanceAssembler().assembleModelInheritance(model, parentModelWithProblems.second.model); } finally { recursionGuard.remove(file); @@ -548,14 +525,29 @@ public class MavenProjectReader { build.setScriptSourceDirectory(pathTranslator.alignToBaseDirectory(build.getScriptSourceDirectory(), basedir)); } + private MavenProjectProblem createStructureProblem(VirtualFile file, String description) { + return createProblem(file, description, MavenProjectProblem.ProblemType.STRUCTURE); + } + + private MavenProjectProblem createSyntaxProblem(VirtualFile file, MavenProjectProblem.ProblemType type) { + return createProblem(file, ProjectBundle.message("maven.project.problem.syntaxError", file.getName()), type); + } + + private MavenProjectProblem createProblem(VirtualFile file, String description, MavenProjectProblem.ProblemType type) { + return new MavenProjectProblem(file, description, type); + } + + private LinkedHashSet createProblemsList() { + return new LinkedHashSet(); + } + public MavenProjectReaderResult resolveProject(MavenGeneralSettings generalSettings, MavenEmbedderWrapper embedder, VirtualFile file, List activeProfiles, MavenProjectReaderProjectLocator locator) throws MavenProcessCanceledException { MavenProject mavenProject = null; - boolean isValid = true; - List problems = new ArrayList(); + Collection problems = createProblemsList(); Set unresolvedArtifactsIds = new THashSet(); try { @@ -574,39 +566,32 @@ public class MavenProjectReader { } if (message != null) { - problems.add(new MavenProjectProblem(message, true)); + problems.add(createStructureProblem(file, message)); } MavenLog.LOG.info(e); MavenLog.printInTests(e); // print exception since we need to know if something wrong with our logic } if (mavenProject == null) { - isValid = false; - if (problems.isEmpty()) { - problems.add(new MavenProjectProblem(ProjectBundle.message("maven.project.problem.syntaxError"), true)); + problems.add(createSyntaxProblem(file, MavenProjectProblem.ProblemType.SYNTAX)); } mavenProject = readProject(generalSettings, file, activeProfiles, locator).nativeMavenProject; } - return new MavenProjectReaderResult(isValid, - activeProfiles, - problems, - unresolvedArtifactsIds, - embedder.getLocalRepositoryFile(), - mavenProject); + return new MavenProjectReaderResult(activeProfiles, problems, unresolvedArtifactsIds, embedder.getLocalRepositoryFile(), mavenProject); } private Pair> doResolveProject(MavenEmbedderWrapper embedder, VirtualFile file, List profiles, - List problems) throws MavenProcessCanceledException { + Collection problems) throws MavenProcessCanceledException { MavenExecutionResult result = embedder.resolveProject(file, profiles); - validate(result, problems); + validate(file, result, problems); return Pair.create(result.getMavenProject(), result.getUnresolvedArtifactIds()); } - private boolean validate(MavenExecutionResult r, List problems) { + private boolean validate(VirtualFile file, MavenExecutionResult r, Collection problems) { for (Exception each : r.getExceptions()) { MavenLog.LOG.info(each); @@ -614,21 +599,19 @@ public class MavenProjectReader { ModelValidationResult modelValidationResult = ((InvalidProjectModelException)each).getValidationResult(); if (modelValidationResult != null) { for (Object eachValidationProblem : modelValidationResult.getMessages()) { - problems.add(new MavenProjectProblem((String)eachValidationProblem, true)); + problems.add(createStructureProblem(file, (String)eachValidationProblem)); } } else { - problems.add(new MavenProjectProblem(each.getCause().getMessage(), true)); + problems.add(createStructureProblem(file, each.getCause().getMessage())); } } else if (each instanceof ProjectBuildingException) { - String causeMessage = each.getCause() != null - ? each.getCause().getMessage() - : each.getMessage(); - problems.add(new MavenProjectProblem(causeMessage, true)); + String causeMessage = each.getCause() != null ? each.getCause().getMessage() : each.getMessage(); + problems.add(createStructureProblem(file, causeMessage)); } else { - problems.add(new MavenProjectProblem(each.getMessage(), true)); + problems.add(createStructureProblem(file, each.getMessage())); } } @@ -647,17 +630,13 @@ public class MavenProjectReader { MavenConsoleHelper.printExecutionExceptions(console, result); } - List problems = new ArrayList(); - if (!validate(result, problems)) return null; + Collection problems = createProblemsList(); + if (!validate(file, result, problems)) return null; MavenProject project = result.getMavenProject(); if (project == null) return null; - return new MavenProjectReaderResult(true, - profiles, - problems, - result.getUnresolvedArtifactIds(), - embedder.getLocalRepositoryFile(), + return new MavenProjectReaderResult(profiles, problems, result.getUnresolvedArtifactIds(), embedder.getLocalRepositoryFile(), project); } catch (MavenProcessCanceledException e) { @@ -670,7 +649,7 @@ public class MavenProjectReader { } } - private Pair readXml(VirtualFile file) { + private Element readXml(final VirtualFile file, final Collection problems, final MavenProjectProblem.ProblemType type) { final LinkedList stack = new LinkedList(); final Element root = new Element("root"); @@ -680,24 +659,16 @@ public class MavenProjectReader { } catch (IOException e) { MavenLog.LOG.warn("Cannot read the pom file: " + e); - return Pair.create(root, false); + problems.add(createProblem(file, e.getMessage(), type)); + return root; } - final boolean[] validity = new boolean[]{true}; - XmlBuilderDriver driver = new XmlBuilderDriver(text); XmlBuilder builder = new XmlBuilder() { - public void doctype(@Nullable CharSequence publicId, - @Nullable CharSequence systemId, - int startOffset, - int endOffset) { + public void doctype(@Nullable CharSequence publicId, @Nullable CharSequence systemId, int startOffset, int endOffset) { } - public ProcessingOrder startTag(CharSequence localName, - String namespace, - int startoffset, - int endoffset, - int headerEndOffset) { + public ProcessingOrder startTag(CharSequence localName, String namespace, int startoffset, int endoffset, int headerEndOffset) { String name = localName.toString(); if (StringUtil.isEmptyOrSpaces(name)) return ProcessingOrder.TAGS; @@ -738,12 +709,12 @@ public class MavenProjectReader { } public void error(String message, int startOffset, int endOffset) { - validity[0] = false; + problems.add(createSyntaxProblem(file, type)); } }; driver.build(builder); - return Pair.create(root, validity[0]); + return root; } private Element findChildByPath(Element element, String path) { @@ -790,13 +761,13 @@ public class MavenProjectReader { return result; } - private static class ModelWithValidity { + private static class ModelWithProblems { public Model model; - public boolean validity; + public Collection problems; - private ModelWithValidity(Model model, boolean validity) { + private ModelWithProblems(Model model, Collection problems) { this.model = model; - this.validity = validity; + this.problems = problems; } } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReaderResult.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReaderResult.java index 7bc148c9ef6d..1563e8d19fa9 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReaderResult.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReaderResult.java @@ -16,27 +16,24 @@ package org.jetbrains.idea.maven.project; import org.apache.maven.project.MavenProject; -import org.jetbrains.idea.maven.project.MavenId; import java.io.File; +import java.util.Collection; import java.util.List; import java.util.Set; public class MavenProjectReaderResult { - public boolean isValid; public List activeProfiles; - public List readingProblems; + public Collection readingProblems; public Set unresolvedArtifactIds; public File localRepository; public MavenProject nativeMavenProject; - public MavenProjectReaderResult(boolean valid, - List activeProfiles, - List readingProblems, + public MavenProjectReaderResult(List activeProfiles, + Collection readingProblems, Set unresolvedArtifactIds, File localRepository, MavenProject nativeMavenProject) { - isValid = valid; this.activeProfiles = activeProfiles; this.readingProblems = readingProblems; this.unresolvedArtifactIds = unresolvedArtifactIds; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java index c2123bd15039..ac2d361810fd 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java @@ -36,6 +36,7 @@ import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.problems.WolfTheProblemSolver; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.util.EventDispatcher; @@ -324,7 +325,7 @@ public class MavenProjectsManager extends SimpleProjectComponent implements Pers Iterator it = toResolve.iterator(); while (it.hasNext()) { MavenProject each = it.next(); - if (each.hasErrors()) it.remove(); + if (each.hasReadingProblems()) it.remove(); } if (haveChanges(toImport) || !deleted.isEmpty()) { @@ -362,7 +363,7 @@ public class MavenProjectsManager extends SimpleProjectComponent implements Pers } private boolean shouldScheduleProject(Pair projectWithChanges) { - return !projectWithChanges.first.hasErrors() && projectWithChanges.second.hasChanges(); + return !projectWithChanges.first.hasReadingProblems() && projectWithChanges.second.hasChanges(); } private void processMessage(Object message) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java new file mode 100644 index 000000000000..a659efb12e5b --- /dev/null +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.idea.maven.utils; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import org.jetbrains.idea.maven.dom.MavenDomUtil; + +public class MavenProblemFileHighlighter implements Condition { + private final Project myProject; + + public MavenProblemFileHighlighter(Project project) { + myProject = project; + } + + public boolean value(VirtualFile file) { + PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); + return psiFile != null && MavenDomUtil.isMavenFile(psiFile); + } +} diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenRehighlighter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenRehighlighter.java new file mode 100644 index 000000000000..f319b0cf4f8d --- /dev/null +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenRehighlighter.java @@ -0,0 +1,85 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.idea.maven.utils; + +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pair; +import com.intellij.psi.PsiManager; +import com.intellij.psi.impl.PsiModificationTrackerImpl; +import org.jetbrains.idea.maven.project.MavenProject; +import org.jetbrains.idea.maven.project.MavenProjectChanges; +import org.jetbrains.idea.maven.project.MavenProjectsManager; +import org.jetbrains.idea.maven.project.MavenProjectsTree; +import org.jetbrains.idea.maven.utils.MavenUtil; +import org.jetbrains.idea.maven.utils.SimpleProjectComponent; + +import java.util.List; + +public class MavenRehighlighter extends SimpleProjectComponent { + protected MavenRehighlighter(Project project) { + super(project); + } + + public void initComponent() { + MavenProjectsManager m = MavenProjectsManager.getInstance(myProject); + m.addManagerListener(new MavenProjectsManager.Listener() { + public void activated() { + rehighlight(myProject); + } + + public void scheduledImportsChanged() { + } + }); + m.addProjectsTreeListener(new MavenProjectsTree.ListenerAdapter() { + public void projectsUpdated(List> updated, List deleted, Object message) { + rehighlight(myProject); + } + + public void projectResolved(Pair projectWithChanges, + org.apache.maven.project.MavenProject nativeMavenProject, + Object message) { + rehighlight(myProject); + } + + public void pluginsResolved(MavenProject project) { + rehighlight(myProject); + } + + public void foldersResolved(Pair projectWithChanges, Object message) { + rehighlight(myProject); + } + + public void artifactsDownloaded(MavenProject project) { + rehighlight(myProject); + } + }); + } + + public static void rehighlight(final Project project) { + MavenUtil.invokeLater(project, new Runnable() { + public void run() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + ((PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker()).incCounter(); + DaemonCodeAnalyzer.getInstance(project).restart(); + } + }); + } + }); + } +} diff --git a/plugins/maven/src/main/resources/DomBundle.properties b/plugins/maven/src/main/resources/DomBundle.properties index 092a58d9b9af..d05b3c5fef93 100644 --- a/plugins/maven/src/main/resources/DomBundle.properties +++ b/plugins/maven/src/main/resources/DomBundle.properties @@ -4,4 +4,5 @@ fix.create.module=Create Module fix.create.module.with.parent=Create Module with Parent fix.update.indices=Update Maven Indices fix.parent.path=Fix relative path +fix.open.file=Open ''{0}'' intention.choose.file=Choose File diff --git a/plugins/maven/src/main/resources/META-INF/plugin.xml b/plugins/maven/src/main/resources/META-INF/plugin.xml index 38309d9df6ed..02897c9a24ba 100644 --- a/plugins/maven/src/main/resources/META-INF/plugin.xml +++ b/plugins/maven/src/main/resources/META-INF/plugin.xml @@ -34,6 +34,8 @@ + + @@ -120,6 +122,9 @@ org.jetbrains.idea.maven.utils.MavenImportNotifier + + org.jetbrains.idea.maven.utils.MavenRehighlighter + diff --git a/plugins/maven/src/main/resources/ProjectBundle.properties b/plugins/maven/src/main/resources/ProjectBundle.properties index d563458aeb77..1b43705f9190 100644 --- a/plugins/maven/src/main/resources/ProjectBundle.properties +++ b/plugins/maven/src/main/resources/ProjectBundle.properties @@ -65,12 +65,15 @@ maven.ignore.edit=Edit Ignored Files... maven.profile.activate=Activate maven.profile.deactivate=Deactivate -maven.project.problem.syntaxError=Pom file has syntax errors. -maven.project.problem.parentNotFound=Parent ''{0}'' not found. -maven.project.problem.missingModule=Missing module: ''{0}''. -maven.project.problem.unresolvedDependency=Unresolved dependency: ''{0}''. -maven.project.problem.unresolvedExtension=Unresolved build extension: ''{0}''. -maven.project.problem.unresolvedPlugin=Unresolved plugin: ''{0}''. +maven.project.problem.syntaxError=''{0}'' has syntax errors +maven.project.problem.recursiveInheritance=Recursive inheritance found +maven.project.problem.selfInheritance=Self-inheritance found +maven.project.problem.parentHasProblems=Parent ''{0}'' has problems +maven.project.problem.parentNotFound=Parent ''{0}'' not found +maven.project.problem.moduleNotFound=Module ''{0}'' not found +maven.project.problem.unresolvedDependency=Unresolved dependency: ''{0}'' +maven.project.problem.unresolvedExtension=Unresolved build extension: ''{0}'' +maven.project.problem.unresolvedPlugin=Unresolved plugin: ''{0}'' maven.tab.general=General diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java index f841899353a3..0b13a8d89153 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenImportingTestCase.java @@ -348,7 +348,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase { myProjectsManager.importProjects(); for (MavenProject each : myProjectsTree.getProjects()) { - if (each.hasErrors()) { + if (each.hasReadingProblems()) { System.out.println(each + " has problems: " + each.getProblems()); } } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomTestCase.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomTestCase.java index a758b1eb2575..4dc6ccd15164 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomTestCase.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomTestCase.java @@ -92,12 +92,17 @@ public abstract class MavenDomTestCase extends MavenImportingTestCase { return PsiManager.getInstance(myProject).findFile(f); } - private void configTest(VirtualFile f) throws IOException { + protected void configTest(VirtualFile f) throws IOException { if (Comparing.equal(myConfigTimestamps.get(f), f.getModificationStamp())) return; myCodeInsightFixture.configureFromExistingVirtualFile(f); myConfigTimestamps.put(f, f.getModificationStamp()); } + protected void type(VirtualFile f, char c) throws IOException { + configTest(f); + myCodeInsightFixture.type(c); + } + protected PsiReference getReferenceAtCaret(VirtualFile f) throws IOException { configTest(f); return findPsiFile(f).findReferenceAt(getEditorOffset(f)); diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenModelValidationTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenModelValidationTest.java index b569aae77fbc..b2b9350842a7 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenModelValidationTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenModelValidationTest.java @@ -91,4 +91,184 @@ public class MavenModelValidationTest extends MavenDomWithIndicesTestCase { "<version>"); checkHighlighting(); } + + public void testAddingSettingsXmlReadingProblemsToProjectTag() throws Exception { + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + ""); + updateSettingsXml("<<<"); + + myProjectsManager.forceUpdateAllProjectsOrFindAllAvailablePomFiles(); + waitForReadingCompletion(); + + VfsUtil.saveText(myProjectPom, + "<project>" + + " 4.0.0" + + " test" + + " project" + + " 1" + + ""); + checkHighlighting(); + } + + public void testAddingProfilesXmlReadingProblemsToProjectTag() throws Exception { + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + ""); + createProfilesXml("<<<"); + + myProjectsManager.forceUpdateAllProjectsOrFindAllAvailablePomFiles(); + waitForReadingCompletion(); + + VfsUtil.saveText(myProjectPom, + "<project>" + + " 4.0.0" + + " test" + + " project" + + " 1" + + ""); + checkHighlighting(); + } + + public void testAddingStructureReadingProblemsToParentTag() throws Exception { + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + " " + + " test" + + " project" + + " 1" + + " " + + ""); + myProjectsManager.forceUpdateAllProjectsOrFindAllAvailablePomFiles(); + waitForReadingCompletion(); + + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + " <parent>" + + " test" + + " project" + + " 1" + + " " + + ""); + checkHighlighting(); + } + + public void testAddingParentReadingProblemsToParentTag() throws Exception { + createModulePom("parent", + "test" + + "parent" + + "1" + + "<<<"); + + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + " " + + " test" + + " parent" + + " 1" + + " parent/pom.xml" + + " " + + ""); + myProjectsManager.forceUpdateAllProjectsOrFindAllAvailablePomFiles(); + waitForReadingCompletion(); + + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + " <parent>" + + " test" + + " parent" + + " 1" + + " parent/pom.xml" + + " " + + ""); + checkHighlighting(); + } + + public void testDoNotAddReadingSyntaxProblemsToProjectTag() throws Exception { + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + " <" + + ""); + myProjectsManager.forceUpdateAllProjectsOrFindAllAvailablePomFiles(); + waitForReadingCompletion(); + + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + " <" + + "</project>"); + checkHighlighting(); + } + + public void testDoNotAddDependencyAndModuleProblemsToProjectTag() throws Exception { + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + " " + + " foo" + + " " + + " " + + " " + + " xxx" + + " yyy" + + " xxx" + + " " + + " " + + ""); + myProjectsManager.forceUpdateAllProjectsOrFindAllAvailablePomFiles(); + waitForReadingCompletion(); + + VfsUtil.saveText(myProjectPom, + "" + + " 4.0.0" + + " test" + + " project" + + " 1" + + " " + + " foo" + + " " + + " " + + " " + + " xxx" + + " yyy" + + " xxx" + + " " + + " " + + ""); + checkHighlighting(); + } } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenParentCompletionAndResolutionTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenParentCompletionAndResolutionTest.java index 451d589b11a0..c07216cbeab0 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenParentCompletionAndResolutionTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenParentCompletionAndResolutionTest.java @@ -260,13 +260,17 @@ public class MavenParentCompletionAndResolutionTest extends MavenDomWithIndicesT public void testHighlightingUnknownValues() throws Throwable { importProject("test" + "project" + - "1" + + "1"); - "" + - " xxx" + - " xxx" + - " xxx" + - ""); + createProjectPom("test" + + "project" + + "1" + + + "" + + " xxx" + + " xxx" + + " xxx" + + ""); checkHighlighting(); } @@ -310,14 +314,18 @@ public class MavenParentCompletionAndResolutionTest extends MavenDomWithIndicesT public void testHighlightingInvalidRelativePath() throws Throwable { importProject("test" + "project" + - "1" + + "1"); - "" + - " junit" + - " junit" + - " 4.0" + - " parent/pom.xml" + - ""); + createProjectPom("test" + + "project" + + "1" + + + "" + + " junit" + + " junit" + + " 4.0" + + " parent/pom.xml" + + ""); checkHighlighting(); } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenTypingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenTypingTest.java index 8c61187f7546..ec69af152676 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenTypingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenTypingTest.java @@ -241,9 +241,7 @@ public class MavenTypingTest extends MavenDomTestCase { } private void assertTypeResultInRegularFile(VirtualFile f, char c, String expected) throws IOException { - myCodeInsightFixture.configureFromExistingVirtualFile(f); - myCodeInsightFixture.type(c); - + type(f, c); myCodeInsightFixture.checkResult(expected); } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/AddingDependencyTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/AddingDependencyTest.java similarity index 97% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/AddingDependencyTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/AddingDependencyTest.java index eaebec2a4eed..9ca0a037b7cc 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/AddingDependencyTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/AddingDependencyTest.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.util.io.ReadOnlyAttributeUtil; +import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.indices.MavenCustomRepositoryHelper; import org.jetbrains.idea.maven.project.MavenArtifact; import org.jetbrains.idea.maven.project.MavenId; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/ArchetypesTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArchetypesTest.java similarity index 96% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/ArchetypesTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArchetypesTest.java index 211f8fb552a5..795174854eaa 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/ArchetypesTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArchetypesTest.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.openapi.progress.EmptyProgressIndicator; import gnu.trove.THashMap; +import org.jetbrains.idea.maven.MavenTestCase; import org.jetbrains.idea.maven.execution.MavenExecutor; import org.jetbrains.idea.maven.execution.MavenExternalExecutor; import org.jetbrains.idea.maven.execution.MavenRunnerParameters; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/ArtifactsDownloadingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java similarity index 97% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/ArtifactsDownloadingTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java index ae3ded084790..dcf777d169b4 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/ArtifactsDownloadingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; +import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.indices.MavenCustomRepositoryHelper; import java.io.File; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/DependenciesImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java similarity index 99% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/DependenciesImportingTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java index cf37de561928..6a484519697d 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/DependenciesImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.*; @@ -23,6 +23,7 @@ import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.indices.MavenCustomRepositoryHelper; import org.jetbrains.idea.maven.project.MavenProject; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/DependenciesManagementTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesManagementTest.java similarity index 98% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/DependenciesManagementTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesManagementTest.java index 020b1f72b448..dd7d576b11e6 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/DependenciesManagementTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesManagementTest.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.idea.maven.MavenImportingTestCase; import java.io.File; import java.util.Arrays; @@ -128,7 +129,7 @@ public class DependenciesManagementTest extends MavenImportingTestCase { // maven doesn't expect imported pom to be in the reactor, // when it is fixed, let us know - assertTrue(myProjectsManager.findProject(project).hasErrors()); + assertTrue(myProjectsManager.findProject(project).hasReadingProblems()); assertModuleLibDeps("project"); // actually should be diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/FoldersImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/FoldersImportingTest.java similarity index 99% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/FoldersImportingTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/FoldersImportingTest.java index bf664815f57c..4921cbd83d1e 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/FoldersImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/FoldersImportingTest.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.openapi.roots.CompilerModuleExtension; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.importing.MavenDefaultModifiableModelsProvider; import org.jetbrains.idea.maven.importing.MavenRootModelAdapter; import org.jetbrains.idea.maven.indices.MavenCustomRepositoryHelper; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/GroovyImporterTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/GroovyImporterTest.java similarity index 99% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/GroovyImporterTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/GroovyImporterTest.java index e1fd98cb1e96..450aa150ff63 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/GroovyImporterTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/GroovyImporterTest.java @@ -2,10 +2,11 @@ * Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; +import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.importing.MavenDefaultModifiableModelsProvider; import org.jetbrains.idea.maven.importing.MavenRootModelAdapter; import org.jetbrains.plugins.groovy.config.GroovyConfigUtils; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/IgnoresImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/IgnoresImportingTest.java similarity index 97% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/IgnoresImportingTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/IgnoresImportingTest.java index 7acf2aaae505..16f51f1e36b5 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/IgnoresImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/IgnoresImportingTest.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.idea.maven.MavenImportingTestCase; import java.util.Collections; import java.util.concurrent.atomic.AtomicInteger; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/InvalidProjectImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/InvalidProjectImportingTest.java similarity index 93% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/InvalidProjectImportingTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/InvalidProjectImportingTest.java index 12ae0281ebad..5189db5dd78c 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/InvalidProjectImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/InvalidProjectImportingTest.java @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; +import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.indices.MavenCustomRepositoryHelper; import org.jetbrains.idea.maven.project.MavenProject; import org.jetbrains.idea.maven.project.MavenProjectProblem; @@ -28,7 +29,7 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { assertModules("project"); MavenProject root = getRootProjects().get(0); - assertProblems(root, "Pom file has syntax errors."); + assertProblems(root, "'pom.xml' has syntax errors"); } public void testUndefinedPropertyInHeader() throws Exception { @@ -55,7 +56,7 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { assertModules("project"); MavenProject root = getRootProjects().get(0); - assertProblems(root, "Parent 'test:parent:1' not found."); + assertProblems(root, "Parent 'test:parent:1' not found"); } public void testUnresolvedParentForInvalidProject() throws Exception { @@ -76,9 +77,9 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { MavenProject root = getRootProjects().get(0); assertProblems(root, - "Parent 'test:parent:1' not found.", + "Parent 'test:parent:1' not found", "Packaging 'jar' is invalid. Aggregator projects require 'pom' as packaging.", - "Missing module: 'foo'."); + "Module 'foo' not found"); } public void testMissingModules() throws Exception { @@ -94,7 +95,7 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { assertModules("project"); MavenProject root = getRootProjects().get(0); - assertProblems(root, "Missing module: 'foo'."); + assertProblems(root, "Module 'foo' not found"); } public void testInvalidProjectModel() throws Exception { @@ -137,8 +138,7 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { MavenProject root = getRootProjects().get(0); assertProblems(root); - assertProblems(getModules(root).get(0), - "Pom file has syntax errors."); + assertProblems(getModules(root).get(0), "'pom.xml' has syntax errors"); } public void testSeveratInvalidModulesAndWithSameName() throws Exception { @@ -316,10 +316,10 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { assertProblems(root); assertProblems(getModules(root).get(0), - "Unresolved dependency: 'xxx:xxx:jar:1'.", - "Unresolved dependency: 'yyy:yyy:jar:2'."); + "Unresolved dependency: 'xxx:xxx:jar:1'", + "Unresolved dependency: 'yyy:yyy:jar:2'"); assertProblems(getModules(root).get(1), - "Unresolved dependency: 'zzz:zzz:jar:3'."); + "Unresolved dependency: 'zzz:zzz:jar:3'"); } public void testUnresolvedPomTypeDependency() throws Exception { @@ -341,7 +341,7 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { assertModuleLibDeps("project"); MavenProject root = getRootProjects().get(0); - assertProblems(root, "Unresolved dependency: 'xxx:yyy:pom:4.0'."); + assertProblems(root, "Unresolved dependency: 'xxx:yyy:pom:4.0'"); } public void testDoesNotReportInterModuleDependenciesAsUnresolved() throws Exception { @@ -454,7 +454,7 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { ""); MavenProject root = getRootProjects().get(0); - assertProblems(root, "Unresolved build extension: 'xxx:yyy:1'."); + assertProblems(root, "Unresolved build extension: 'xxx:yyy:1'"); } public void testUnresolvedExtensionsAfterResolve() throws Exception { @@ -474,7 +474,7 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { resolveDependenciesAndImport(); MavenProject root = getRootProjects().get(0); - assertProblems(root, "Unresolved build extension: 'xxx:yyy:1'."); + assertProblems(root, "Unresolved build extension: 'xxx:yyy:1'"); } public void testDoesNotReportExtensionsThatWereNotTriedToBeResolved() throws Exception { @@ -575,10 +575,10 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { assertProblems(root); assertProblems(getModules(root).get(0), - "Unresolved build extension: 'xxx:xxx:1'."); + "Unresolved build extension: 'xxx:xxx:1'"); assertProblems(getModules(root).get(1), - "Unresolved build extension: 'yyy:yyy:1'.", - "Unresolved build extension: 'zzz:zzz:1'."); + "Unresolved build extension: 'yyy:yyy:1'", + "Unresolved build extension: 'zzz:zzz:1'"); } public void testUnresolvedPlugins() throws Exception { @@ -597,7 +597,7 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { ""); MavenProject root = getRootProjects().get(0); - assertProblems(root, "Unresolved plugin: 'xxx:yyy:1'."); + assertProblems(root, "Unresolved plugin: 'xxx:yyy:1'"); } public void testDoNotReportResolvedPlugins() throws Exception { @@ -641,7 +641,31 @@ public class InvalidProjectImportingTest extends MavenImportingTestCase { assertModules("project"); MavenProject root = getRootProjects().get(0); - assertProblems(root, "Unresolved plugin: 'xxx:yyy:1'."); + assertProblems(root, "Unresolved plugin: 'xxx:yyy:1'"); + } + + public void testInvalidSettingsXml() throws Exception { + updateSettingsXml("test" + + "project" + + "1"); + assertModules("project"); + + MavenProject root = getRootProjects().get(0); + assertProblems(root, "'settings.xml' has syntax errors"); + } + + public void testInvalidProfilesXml() throws Exception { + createProfilesXml("test" + + "project" + + "1"); + assertModules("project"); + + MavenProject root = getRootProjects().get(0); + assertProblems(root, "'profiles.xml' has syntax errors"); } private void assertProblems(MavenProject project, String... expectedProblems) { diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenPerformanceTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MavenPerformanceTest.java similarity index 96% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenPerformanceTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MavenPerformanceTest.java index 6a40d8c425db..e40f2b544b30 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenPerformanceTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MavenPerformanceTest.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.idea.Bombed; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.project.MavenProject; import java.util.Collections; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MiscImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MiscImportingTest.java similarity index 98% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/MiscImportingTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MiscImportingTest.java index 81b978999a3d..0a25977b2e1b 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MiscImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MiscImportingTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.ProjectTopics; import com.intellij.openapi.module.ModifiableModuleModel; @@ -21,6 +21,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.roots.ModuleRootEvent; import com.intellij.openapi.roots.ModuleRootListener; +import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.importing.MavenDefaultModifiableModelsProvider; import org.jetbrains.idea.maven.indices.MavenCustomRepositoryHelper; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/ReimportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ReimportingTest.java similarity index 98% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/ReimportingTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ReimportingTest.java index 5314c216340e..516c0373eb45 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/ReimportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ReimportingTest.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import org.jetbrains.idea.maven.MavenImportingTestCase; import java.util.concurrent.atomic.AtomicInteger; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/SnapshotDependenciesImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/SnapshotDependenciesImportingTest.java similarity index 99% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/SnapshotDependenciesImportingTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/SnapshotDependenciesImportingTest.java index 63f0738369d4..60d1f366b55b 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/SnapshotDependenciesImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/SnapshotDependenciesImportingTest.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.idea.maven.MavenImportingTestCase; import java.io.File; import java.io.IOException; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/StructureImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/StructureImportingTest.java similarity index 99% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/StructureImportingTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/StructureImportingTest.java index b1f53e45acb9..06398ef7097e 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/StructureImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/StructureImportingTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.compiler.impl.javaCompiler.javac.JavacSettings; import com.intellij.openapi.projectRoots.Sdk; @@ -21,6 +21,7 @@ import com.intellij.openapi.roots.LanguageLevelModuleExtension; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; +import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.project.MavenProject; import java.io.File; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/WorkingWithOpenProjectTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/WorkingWithOpenProjectTest.java similarity index 96% rename from plugins/maven/src/test/java/org/jetbrains/idea/maven/WorkingWithOpenProjectTest.java rename to plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/WorkingWithOpenProjectTest.java index 6c1a16f07e48..3c83c9e43ce4 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/WorkingWithOpenProjectTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/WorkingWithOpenProjectTest.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.idea.maven; +package org.jetbrains.idea.maven.importing; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.PsiTestUtil; +import org.jetbrains.idea.maven.MavenImportingTestCase; import java.io.File; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java index 69d7f012fd95..ddd09115d55a 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectReaderTest.java @@ -26,6 +26,7 @@ import org.jetbrains.idea.maven.embedder.MavenEmbedderFactory; import org.jetbrains.idea.maven.utils.MavenUtil; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -51,7 +52,7 @@ public class MavenProjectReaderTest extends MavenTestCase { "project" + "1"); - assertTrue(readProject(myProjectPom, new NullProjectLocator()).isValid); + assertProblems(readProject(myProjectPom, new NullProjectLocator())); createProjectPom("" + "" + @@ -61,7 +62,7 @@ public class MavenProjectReaderTest extends MavenTestCase { "1"); MavenProjectReaderResult result = readProject(myProjectPom, new NullProjectLocator()); - assertFalse(result.isValid); + assertProblems(result, "'pom.xml' has syntax errors"); org.apache.maven.project.MavenProject p = result.nativeMavenProject; assertEquals(new File(myProjectPom.getPath()), p.getFile()); @@ -85,7 +86,7 @@ public class MavenProjectReaderTest extends MavenTestCase { " 1" + ""); - assertFalse(readProject(module, new NullProjectLocator()).isValid); + assertProblems(readProject(module, new NullProjectLocator()), "Parent 'test:parent:1' has problems"); } public void testProjectWithAbsentParentXmlIsValid() throws Exception { @@ -94,7 +95,7 @@ public class MavenProjectReaderTest extends MavenTestCase { " parent" + " 1" + ""); - assertTrue(readProject(myProjectPom, new NullProjectLocator()).isValid); + assertProblems(readProject(myProjectPom, new NullProjectLocator())); } public void testProjectWithSelfParentIsInvalid() throws Exception { @@ -106,7 +107,7 @@ public class MavenProjectReaderTest extends MavenTestCase { "project" + "pom"); - assertFalse(readProject(myProjectPom, new NullProjectLocator()).isValid); + assertProblems(readProject(myProjectPom, new NullProjectLocator()), "Self-inheritance found"); } public void testInvalidProfilesXml() throws Exception { @@ -116,7 +117,7 @@ public class MavenProjectReaderTest extends MavenTestCase { createProfilesXml("foo"); MavenProjectReaderResult readResult = readProject(myProjectPom, new NullProjectLocator()); - assertFalse(readResult.isValid); + assertProblems(readResult, "'pom.xml' has syntax errors"); org.apache.maven.project.MavenProject p = readResult.nativeMavenProject; assertEquals(new File(myProjectPom.getPath()), p.getFile()); @@ -157,7 +158,7 @@ public class MavenProjectReaderTest extends MavenTestCase { "foo"); MavenProjectReaderResult readResult = readProject(myProjectPom, new NullProjectLocator()); - assertFalse(readResult.isValid); + assertProblems(readResult, "'pom.xml' has syntax errors"); org.apache.maven.project.MavenProject p = readResult.nativeMavenProject; assertEquals(new File(myProjectPom.getPath()), p.getFile()); @@ -431,7 +432,7 @@ public class MavenProjectReaderTest extends MavenTestCase { assertEquals("value12", p.getPackaging()); } - public void testHandlingRecursionProprietly() throws Exception { + public void testHandlingRecursiveProperties() throws Exception { createProjectPom("" + " ${prop2}" + " ${prop1}" + @@ -445,7 +446,7 @@ public class MavenProjectReaderTest extends MavenTestCase { assertEquals("${prop2}", p.getPackaging()); } - public void testHandlingRecursionProprietlyAndDoNotForgetCoClearRecursionGuard() throws Exception { + public void testHandlingRecursionProprielyAndDoNotForgetCoClearRecursionGuard() throws Exception { File repositoryPath = new File(myDir, "repository"); setRepositoryPath(repositoryPath.getPath()); @@ -477,7 +478,34 @@ public class MavenProjectReaderTest extends MavenTestCase { ""); MavenProjectReaderResult readResult = readProject(child, new NullProjectLocator()); - assertTrue(readResult.isValid); + assertProblems(readResult); + } + + public void testDoNotGoIntoRecursionWhenTryingToResolveParentInDefaultPath() throws Exception { + VirtualFile child = createModulePom("child", + "test" + + "child" + + "1" + + + "" + + " test" + + " parent" + + " 1" + + ""); + + createProjectPom("test" + + "subChild" + + "1" + + + "" + + " test" + + " child" + + " 1" + + " child/pom.xml" + + ""); + + MavenProjectReaderResult readResult = readProject(child, new NullProjectLocator()); + assertProblems(readResult); } public void testExpandingSystemAndEnvProperties() throws Exception { @@ -1098,7 +1126,7 @@ public class MavenProjectReaderTest extends MavenTestCase { private org.apache.maven.project.MavenProject readProject(VirtualFile file, String... profiles) { MavenProjectReaderResult readResult = readProject(file, new NullProjectLocator(), profiles); - assertTrue(readResult.isValid); + assertProblems(readResult); return readResult.nativeMavenProject; } @@ -1138,6 +1166,14 @@ public class MavenProjectReaderTest extends MavenTestCase { assertOrderedElementsAreEqual(resource.getExcludes(), excludes); } + private void assertProblems(MavenProjectReaderResult readerResult, String... expectedProblems) { + List actualProblems = new ArrayList(); + for (MavenProjectProblem each : readerResult.readingProblems) { + actualProblems.add(each.getDescription()); + } + assertOrderedElementsAreEqual(actualProblems, expectedProblems); + } + private static class NullProjectLocator implements MavenProjectReaderProjectLocator { public VirtualFile findProjectFile(MavenId coordinates) { return null; diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectsTreeReadingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectsTreeReadingTest.java index 2476698bd29b..bd6497cc9194 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectsTreeReadingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/project/MavenProjectsTreeReadingTest.java @@ -605,7 +605,7 @@ public class MavenProjectsTreeReadingTest extends MavenProjectsTreeTestCase { assertEquals("resolved: project ", listener.log); assertNotNull(nativeProject[0]); - assertTrue(project.hasErrors()); + assertTrue(project.hasReadingProblems()); } public void testDoNotUpdateChildAfterParentWasResolved() throws Exception { diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java b/plugins/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java index 791ba6c02194..600b1d77111a 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java @@ -19,6 +19,7 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; @@ -32,13 +33,17 @@ import com.intellij.spellchecker.state.StateLoader; import com.intellij.spellchecker.util.SPFileUtil; import com.intellij.spellchecker.util.Strings; import com.intellij.util.Consumer; +import com.sun.net.ssl.internal.ssl.SSLEngineImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.InputStream; import java.util.*; public class SpellCheckerManager { + private static final Logger LOG = Logger.getInstance("#com.intellij.spellchecker.SpellCheckerManager"); + private static final int MAX_SUGGESTIONS_THRESHOLD = 5; private static final int MAX_METRICS = 1; @@ -87,7 +92,13 @@ public class SpellCheckerManager { for (BundledDictionaryProvider provider : Extensions.getExtensions(BundledDictionaryProvider.EP_NAME)) { for (String dictionary : provider.getBundledDictionaries()) { if (this.settings == null || !this.settings.getBundledDisabledDictionariesPaths().contains(dictionary)) { - loaders.add(new StreamLoader(provider.getClass().getResourceAsStream(dictionary))); + final Class loaderClass = provider.getClass(); + final InputStream stream = loaderClass.getResourceAsStream(dictionary); + if (stream != null){ + loaders.add(new StreamLoader(stream)); + } else { + LOG.warn("Couldn't load dictionary '" + dictionary + "' for loader '" + loaderClass + "'"); + } } } }