diff options
Diffstat (limited to 'java/java-psi-impl/src/com')
51 files changed, 1930 insertions, 2461 deletions
diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/CoreJavaCodeInsightSettingsFacade.java b/java/java-psi-impl/src/com/intellij/codeInsight/CoreJavaCodeInsightSettingsFacade.java new file mode 100644 index 000000000000..59e51d86da1d --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/codeInsight/CoreJavaCodeInsightSettingsFacade.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2014 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 com.intellij.codeInsight; + +public class CoreJavaCodeInsightSettingsFacade extends JavaCodeInsightSettingsFacade { + @Override + public boolean isShowStaticAfterInstance() { + return false; + } +} diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java index b989c3054b06..552c7e2d9ff5 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java @@ -403,13 +403,16 @@ public class ExceptionUtil { final boolean includeSelfCalls) { final JavaResolveResult result = methodCall.resolveMethodGenerics(); final PsiMethod method = (PsiMethod)result.getElement(); + if (method == null) { + return Collections.emptyList(); + } final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class); if (!includeSelfCalls && method == containingMethod) { return Collections.emptyList(); } final PsiSubstitutor substitutor = result.getSubstitutor(); - if (method != null && !isArrayClone(method, methodCall) && methodCall instanceof PsiMethodCallExpression) { + if (!isArrayClone(method, methodCall) && methodCall instanceof PsiMethodCallExpression) { final PsiClassType[] thrownExceptions = method.getThrowsList().getReferencedTypes(); if (thrownExceptions.length > 0) { final PsiFile containingFile = (containingMethod == null ? methodCall : containingMethod).getContainingFile(); @@ -537,11 +540,11 @@ public class ExceptionUtil { } @NotNull - public static List<PsiClassType> getUnhandledExceptions(@Nullable PsiMethod method, - PsiElement element, - PsiElement topElement, - @NotNull PsiSubstitutor substitutor) { - if (method == null || isArrayClone(method, element)) { + public static List<PsiClassType> getUnhandledExceptions(@NotNull PsiMethod method, + PsiElement element, + PsiElement topElement, + @NotNull PsiSubstitutor substitutor) { + if (isArrayClone(method, element)) { return Collections.emptyList(); } final PsiClassType[] referencedTypes = method.getThrowsList().getReferencedTypes(); diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilderBase.java b/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilderBase.java index 550ffc26b062..7a296ff7630d 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilderBase.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilderBase.java @@ -29,6 +29,7 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PropertyUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; +import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.Function; import com.intellij.util.ObjectUtils; import com.intellij.util.text.CharArrayUtil; @@ -422,7 +423,7 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem } private boolean addToFold(List<FoldingDescriptor> list, PsiElement elementToFold, Document document, boolean allowOneLiners) { - LOG.assertTrue(elementToFold.isValid()); + PsiUtilCore.ensureValid(elementToFold); TextRange range = getRangeToFold(elementToFold); if (range == null) return false; return addFoldRegion(list, elementToFold, document, allowOneLiners, range); @@ -831,6 +832,10 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem @Override protected boolean isCustomFoldingRoot(ASTNode node) { IElementType nodeType = node.getElementType(); - return nodeType == JavaElementType.CLASS || nodeType == JavaElementType.CODE_BLOCK; + if (nodeType == JavaElementType.CLASS) { + ASTNode parent = node.getTreeParent(); + return parent == null || parent.getElementType() != JavaElementType.CLASS; + } + return nodeType == JavaElementType.CODE_BLOCK; } } diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java index a2f1dc9c0daa..7b154bd5383c 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -123,7 +123,7 @@ public class JavaDocInfoGenerator { elements = rawElements; } - return new Pair<PsiElement[], InheritDocProvider<PsiElement[]>>(elements, mapProvider(pair.second, dropFirst)); + return Pair.create(elements, mapProvider(pair.second, dropFirst)); } @Override @@ -250,6 +250,20 @@ public class JavaDocInfoGenerator { return true; } + public static String generateSignature(PsiElement element) { + StringBuilder buf = new StringBuilder(); + if (element instanceof PsiClass) { + if (generateClassSignature(buf, (PsiClass)element)) return null; + } + else if (element instanceof PsiField) { + generateFieldSignature(buf, (PsiField)element); + } + else if (element instanceof PsiMethod) { + generateMethodSignature(buf, (PsiMethod)element); + } + return buf.toString(); + } + @Nullable public String generateDocInfo(List<String> docURLs) { StringBuilder buffer = new StringBuilder(); @@ -293,6 +307,21 @@ public class JavaDocInfoGenerator { } buffer.append("<PRE>"); + if (generateClassSignature(buffer, aClass)) return; + buffer.append("</PRE>"); + //buffer.append("<br>"); + + PsiDocComment comment = getDocComment(aClass); + if (comment != null) { + generateCommonSection(buffer, comment); + generateTypeParametersSection(buffer, aClass); + } + + if (generatePrologueAndEpilogue) + generateEpilogue(buffer); + } + + private static boolean generateClassSignature(StringBuilder buffer, PsiClass aClass) { generateAnnotations(buffer, aClass); String modifiers = PsiFormatUtil.formatModifiers(aClass, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY); if (!modifiers.isEmpty()) { @@ -301,12 +330,12 @@ public class JavaDocInfoGenerator { } buffer.append(aClass.isInterface() ? LangBundle.message("java.terms.interface") : LangBundle.message("java.terms.class")); buffer.append(" "); - String refText = JavaDocUtil.getReferenceText(myProject, aClass); + String refText = JavaDocUtil.getReferenceText(aClass.getProject(), aClass); if (refText == null) { buffer.setLength(0); - return; + return true; } - String labelText = JavaDocUtil.getLabelText(myProject, manager, refText, aClass); + String labelText = JavaDocUtil.getLabelText(aClass.getProject(), aClass.getManager(), refText, aClass); buffer.append("<b>"); buffer.append(labelText); buffer.append("</b>"); @@ -350,17 +379,7 @@ public class JavaDocInfoGenerator { if (buffer.charAt(buffer.length() - 1) == '\n') { buffer.setLength(buffer.length() - 1); } - buffer.append("</PRE>"); - //buffer.append("<br>"); - - PsiDocComment comment = getDocComment(aClass); - if (comment != null) { - generateCommonSection(buffer, comment); - generateTypeParametersSection(buffer, aClass); - } - - if (generatePrologueAndEpilogue) - generateEpilogue(buffer); + return false; } private void generateTypeParametersSection(final StringBuilder buffer, final PsiClass aClass) { @@ -453,18 +472,7 @@ public class JavaDocInfoGenerator { } buffer.append("<PRE>"); - generateAnnotations(buffer, field); - String modifiers = PsiFormatUtil.formatModifiers(field, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY); - if (!modifiers.isEmpty()) { - buffer.append(modifiers); - buffer.append(" "); - } - generateType(buffer, field.getType(), field); - buffer.append(" "); - buffer.append("<b>"); - buffer.append(field.getName()); - appendInitializer(buffer, field); - buffer.append("</b>"); + generateFieldSignature(buffer, field); buffer.append("</PRE>"); //buffer.append("<br>"); @@ -479,6 +487,21 @@ public class JavaDocInfoGenerator { generateEpilogue(buffer); } + private static void generateFieldSignature(StringBuilder buffer, PsiField field) { + generateAnnotations(buffer, field); + String modifiers = PsiFormatUtil.formatModifiers(field, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY); + if (!modifiers.isEmpty()) { + buffer.append(modifiers); + buffer.append(" "); + } + generateType(buffer, field.getType(), field); + buffer.append(" "); + buffer.append("<b>"); + buffer.append(field.getName()); + appendInitializer(buffer, field); + buffer.append("</b>"); + } + public static void enumConstantOrdinal(StringBuilder buffer, PsiField field, PsiClass parentClass, final String newLine) { if (parentClass != null && field instanceof PsiEnumConstant) { final PsiField[] fields = parentClass.getFields(); @@ -778,6 +801,37 @@ public class JavaDocInfoGenerator { } buffer.append("<PRE>"); + generateMethodSignature(buffer, method); + + buffer.append("</PRE>"); + //buffer.append("<br>"); + + PsiDocComment comment = getMethodDocComment(method); + + generateMethodDescription(buffer, method, comment); + + generateSuperMethodsSection(buffer, method, false); + generateSuperMethodsSection(buffer, method, true); + + if (comment != null) { + generateDeprecatedSection(buffer, comment); + } + + generateParametersSection(buffer, method, comment); + generateTypeParametersSection(buffer, method); + generateReturnsSection(buffer, method, comment); + generateThrowsSection(buffer, method, comment); + + if (comment != null) { + generateSinceSection(buffer, comment); + generateSeeAlsoSection(buffer, comment); + } + + if (generatePrologueAndEpilogue) + generateEpilogue(buffer); + } + + private static void generateMethodSignature(StringBuilder buffer, PsiMethod method) { generateAnnotations(buffer, method); String modifiers = PsiFormatUtil.formatModifiers(method, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY); int indent = 0; @@ -846,33 +900,6 @@ public class JavaDocInfoGenerator { } } } - - buffer.append("</PRE>"); - //buffer.append("<br>"); - - PsiDocComment comment = getMethodDocComment(method); - - generateMethodDescription(buffer, method, comment); - - generateSuperMethodsSection(buffer, method, false); - generateSuperMethodsSection(buffer, method, true); - - if (comment != null) { - generateDeprecatedSection(buffer, comment); - } - - generateParametersSection(buffer, method, comment); - generateTypeParametersSection(buffer, method); - generateReturnsSection(buffer, method, comment); - generateThrowsSection(buffer, method, comment); - - if (comment != null) { - generateSinceSection(buffer, comment); - generateSeeAlsoSection(buffer, comment); - } - - if (generatePrologueAndEpilogue) - generateEpilogue(buffer); } @SuppressWarnings({"HardCodedStringLiteral"}) @@ -1481,7 +1508,7 @@ public class JavaDocInfoGenerator { String tagName = value.getText(); if (tagName != null && areWeakEqual(tagName, paramName)) { - parmTag = new Pair<PsiDocTag, InheritDocProvider<PsiDocTag>>(localTag, ourEmptyProvider); + parmTag = Pair.create(localTag, ourEmptyProvider); break; } } @@ -1498,7 +1525,7 @@ public class JavaDocInfoGenerator { try { final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory(); final PsiDocTag tag = elementFactory.createDocTagFromText("@exception " + paramName); - collectedTags.addLast(new Pair<PsiDocTag, InheritDocProvider<PsiDocTag>>(tag, ourEmptyProvider)); + collectedTags.addLast(Pair.create(tag, ourEmptyProvider)); } catch (IncorrectOperationException e) { LOG.error(e); diff --git a/java/java-psi-impl/src/com/intellij/core/CoreLanguageLevelProjectExtension.java b/java/java-psi-impl/src/com/intellij/core/CoreLanguageLevelProjectExtension.java index 07f42cd5c1b8..58956f32a406 100644 --- a/java/java-psi-impl/src/com/intellij/core/CoreLanguageLevelProjectExtension.java +++ b/java/java-psi-impl/src/com/intellij/core/CoreLanguageLevelProjectExtension.java @@ -37,6 +37,10 @@ public class CoreLanguageLevelProjectExtension extends LanguageLevelProjectExten } @Override + public void languageLevelsChanged() { + } + + @Override public void reloadProjectOnLanguageLevelChange(@NotNull LanguageLevel languageLevel, boolean forceReload) { } } diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.java b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.java deleted file mode 100644 index 1780cbeb9721..000000000000 --- a/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.java +++ /dev/null @@ -1,721 +0,0 @@ -/* - * Copyright 2000-2013 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. - */ - -/* The following code was generated by JFlex 1.4.3 on 05.06.13 19:07 */ - -/* It's an automatically generated code. Do not modify it. */ -package com.intellij.lang.java.lexer; - -import com.intellij.lexer.DocCommentTokenTypes; -import com.intellij.lexer.FlexLexer; -import com.intellij.psi.tree.IElementType; - -@SuppressWarnings("ALL") - -/** - * This class is a scanner generated by - * <a href="http://www.jflex.de/">JFlex</a> 1.4.3 - * on 05.06.13 19:07 from the specification file - * <tt>C:/Users/roman.shevchenko/Projects/IDEA/tools/lexer/../../community/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaDocLexer.flex</tt> - */ -class _JavaDocLexer implements FlexLexer { - /** initial size of the lookahead buffer */ - private static final int ZZ_BUFFERSIZE = 16384; - - /** lexical states */ - public static final int INLINE_TAG_NAME = 16; - public static final int PARAM_TAG_SPACE = 8; - public static final int COMMENT_DATA = 4; - public static final int DOC_TAG_VALUE = 10; - public static final int COMMENT_DATA_START = 2; - public static final int TAG_DOC_SPACE = 6; - public static final int YYINITIAL = 0; - public static final int DOC_TAG_VALUE_IN_PAREN = 12; - public static final int DOC_TAG_VALUE_IN_LTGT = 14; - - /** - * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l - * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l - * at the beginning of a line - * l is of the form l = 2*k, k a non negative integer - */ - private static final int ZZ_LEXSTATE[] = { - 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, - 8, 8 - }; - - /** - * Translates characters to character classes - */ - private static final String ZZ_CMAP_PACKED = - "\11\0\1\2\1\1\1\0\1\2\1\1\22\0\1\2\2\0\1\13"+ - "\1\4\3\0\1\11\1\12\1\7\1\0\1\14\1\5\1\3\1\6"+ - "\12\3\1\5\1\0\1\22\1\0\1\23\1\0\1\15\32\4\1\10"+ - "\1\0\1\10\1\0\1\4\1\0\1\17\13\4\1\21\2\4\1\16"+ - "\1\4\1\20\10\4\1\24\1\0\1\25\44\0\4\4\4\0\1\4"+ - "\12\0\1\4\4\0\1\4\5\0\27\4\1\0\37\4\1\0\u01ca\4"+ - "\4\0\14\4\16\0\5\4\7\0\1\4\1\0\1\4\201\0\5\4"+ - "\1\0\2\4\2\0\4\4\10\0\1\4\1\0\3\4\1\0\1\4"+ - "\1\0\24\4\1\0\123\4\1\0\213\4\10\0\236\4\11\0\46\4"+ - "\2\0\1\4\7\0\47\4\110\0\33\4\5\0\3\4\30\0\1\4"+ - "\24\0\53\4\43\0\2\4\1\0\143\4\1\0\1\4\17\0\2\4"+ - "\7\0\2\4\12\0\3\4\2\0\1\4\20\0\1\4\1\0\36\4"+ - "\35\0\131\4\13\0\1\4\30\0\41\4\11\0\2\4\4\0\1\4"+ - "\5\0\26\4\4\0\1\4\11\0\1\4\3\0\1\4\27\0\31\4"+ - "\253\0\66\4\3\0\1\4\22\0\1\4\7\0\12\4\17\0\7\4"+ - "\1\0\7\4\5\0\10\4\2\0\2\4\2\0\26\4\1\0\7\4"+ - "\1\0\1\4\3\0\4\4\3\0\1\4\20\0\1\4\15\0\2\4"+ - "\1\0\3\4\16\0\4\4\7\0\1\4\11\0\6\4\4\0\2\4"+ - "\2\0\26\4\1\0\7\4\1\0\2\4\1\0\2\4\1\0\2\4"+ - "\37\0\4\4\1\0\1\4\23\0\3\4\20\0\11\4\1\0\3\4"+ - "\1\0\26\4\1\0\7\4\1\0\2\4\1\0\5\4\3\0\1\4"+ - "\22\0\1\4\17\0\2\4\17\0\1\4\23\0\10\4\2\0\2\4"+ - "\2\0\26\4\1\0\7\4\1\0\2\4\1\0\5\4\3\0\1\4"+ - "\36\0\2\4\1\0\3\4\17\0\1\4\21\0\1\4\1\0\6\4"+ - "\3\0\3\4\1\0\4\4\3\0\2\4\1\0\1\4\1\0\2\4"+ - "\3\0\2\4\3\0\3\4\3\0\14\4\26\0\1\4\50\0\1\4"+ - "\13\0\10\4\1\0\3\4\1\0\27\4\1\0\12\4\1\0\5\4"+ - "\3\0\1\4\32\0\2\4\6\0\2\4\43\0\10\4\1\0\3\4"+ - "\1\0\27\4\1\0\12\4\1\0\5\4\3\0\1\4\40\0\1\4"+ - "\1\0\2\4\17\0\2\4\22\0\10\4\1\0\3\4\1\0\51\4"+ - "\2\0\1\4\20\0\1\4\21\0\2\4\30\0\6\4\5\0\22\4"+ - "\3\0\30\4\1\0\11\4\1\0\1\4\2\0\7\4\72\0\60\4"+ - "\1\0\2\4\13\0\10\4\72\0\2\4\1\0\1\4\2\0\2\4"+ - "\1\0\1\4\2\0\1\4\6\0\4\4\1\0\7\4\1\0\3\4"+ - "\1\0\1\4\1\0\1\4\2\0\2\4\1\0\4\4\1\0\2\4"+ - "\11\0\1\4\2\0\5\4\1\0\1\4\25\0\2\4\42\0\1\4"+ - "\77\0\10\4\1\0\44\4\33\0\5\4\163\0\53\4\24\0\1\4"+ - "\20\0\6\4\4\0\4\4\3\0\1\4\3\0\2\4\7\0\3\4"+ - "\4\0\15\4\14\0\1\4\21\0\46\4\12\0\53\4\1\0\1\4"+ - "\3\0\u0149\4\1\0\4\4\2\0\7\4\1\0\1\4\1\0\4\4"+ - "\2\0\51\4\1\0\4\4\2\0\41\4\1\0\4\4\2\0\7\4"+ - "\1\0\1\4\1\0\4\4\2\0\17\4\1\0\71\4\1\0\4\4"+ - "\2\0\103\4\45\0\20\4\20\0\125\4\14\0\u026c\4\2\0\21\4"+ - "\1\0\32\4\5\0\113\4\3\0\3\4\17\0\15\4\1\0\4\4"+ - "\16\0\22\4\16\0\22\4\16\0\15\4\1\0\3\4\17\0\64\4"+ - "\43\0\1\4\3\0\2\4\103\0\130\4\10\0\51\4\1\0\1\4"+ - "\5\0\106\4\12\0\35\4\63\0\36\4\2\0\5\4\13\0\54\4"+ - "\25\0\7\4\70\0\27\4\11\0\65\4\122\0\1\4\135\0\57\4"+ - "\21\0\7\4\67\0\36\4\15\0\2\4\20\0\46\4\32\0\44\4"+ - "\51\0\3\4\12\0\44\4\153\0\4\4\1\0\4\4\16\0\300\4"+ - "\100\0\u0116\4\2\0\6\4\2\0\46\4\2\0\6\4\2\0\10\4"+ - "\1\0\1\4\1\0\1\4\1\0\1\4\1\0\37\4\2\0\65\4"+ - "\1\0\7\4\1\0\1\4\3\0\3\4\1\0\7\4\3\0\4\4"+ - "\2\0\6\4\4\0\15\4\5\0\3\4\1\0\7\4\102\0\2\4"+ - "\23\0\1\4\34\0\1\4\15\0\1\4\20\0\15\4\3\0\32\4"+ - "\110\0\1\4\4\0\1\4\2\0\12\4\1\0\1\4\3\0\5\4"+ - "\6\0\1\4\1\0\1\4\1\0\1\4\1\0\4\4\1\0\13\4"+ - "\2\0\4\4\5\0\5\4\4\0\1\4\21\0\51\4\u0a77\0\57\4"+ - "\1\0\57\4\1\0\205\4\6\0\4\4\21\0\46\4\12\0\66\4"+ - "\11\0\1\4\20\0\27\4\11\0\7\4\1\0\7\4\1\0\7\4"+ - "\1\0\7\4\1\0\7\4\1\0\7\4\1\0\7\4\1\0\7\4"+ - "\120\0\1\4\u01d5\0\3\4\31\0\11\4\7\0\5\4\2\0\5\4"+ - "\4\0\126\4\6\0\3\4\1\0\132\4\1\0\4\4\5\0\51\4"+ - "\3\0\136\4\21\0\33\4\65\0\20\4\u0200\0\u19b6\4\112\0\u51cc\4"+ - "\64\0\u048d\4\103\0\56\4\2\0\u010d\4\3\0\20\4\12\0\2\4"+ - "\24\0\57\4\20\0\31\4\10\0\120\4\47\0\11\4\2\0\147\4"+ - "\2\0\4\4\1\0\2\4\16\0\12\4\120\0\10\4\1\0\3\4"+ - "\1\0\4\4\1\0\27\4\25\0\1\4\7\0\64\4\16\0\62\4"+ - "\76\0\6\4\3\0\1\4\16\0\34\4\12\0\27\4\31\0\35\4"+ - "\7\0\57\4\34\0\1\4\60\0\51\4\27\0\3\4\1\0\10\4"+ - "\24\0\27\4\3\0\1\4\5\0\60\4\1\0\1\4\3\0\2\4"+ - "\2\0\5\4\2\0\1\4\1\0\1\4\30\0\3\4\43\0\6\4"+ - "\2\0\6\4\2\0\6\4\11\0\7\4\1\0\7\4\221\0\43\4"+ - "\35\0\u2ba4\4\14\0\27\4\4\0\61\4\u2104\0\u012e\4\2\0\76\4"+ - "\2\0\152\4\46\0\7\4\14\0\5\4\5\0\1\4\1\0\12\4"+ - "\1\0\15\4\1\0\5\4\1\0\1\4\1\0\2\4\1\0\2\4"+ - "\1\0\154\4\41\0\u016b\4\22\0\100\4\2\0\66\4\50\0\15\4"+ - "\66\0\2\4\30\0\3\4\31\0\1\4\6\0\5\4\1\0\207\4"+ - "\7\0\1\4\34\0\32\4\4\0\1\4\1\0\32\4\13\0\131\4"+ - "\3\0\6\4\2\0\6\4\2\0\6\4\2\0\3\4\3\0\2\4"+ - "\3\0\2\4\31\0"; - - /** - * Translates characters to character classes - */ - private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); - - /** - * Translates DFA states to action switch labels. - */ - private static final int [] ZZ_ACTION = zzUnpackAction(); - - private static final String ZZ_ACTION_PACKED_0 = - "\11\0\3\1\1\2\1\3\2\2\1\4\1\5\1\6"+ - "\1\7\1\10\1\11\1\12\1\13\1\14\1\15\1\16"+ - "\1\17\1\12\1\20\1\1\1\0\1\21\1\0\2\22"+ - "\1\23\3\22\1\24"; - - private static int [] zzUnpackAction() { - int [] result = new int[41]; - int offset = 0; - offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackAction(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int count = packed.charAt(i++); - int value = packed.charAt(i++); - do result[j++] = value; while (--count > 0); - } - return j; - } - - - /** - * Translates a state to a row index in the transition table - */ - private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); - - private static final String ZZ_ROWMAP_PACKED_0 = - "\0\0\0\26\0\54\0\102\0\130\0\156\0\204\0\232"+ - "\0\260\0\306\0\334\0\362\0\306\0\u0108\0\362\0\u011e"+ - "\0\306\0\306\0\u0134\0\u014a\0\u0160\0\u0176\0\u018c\0\306"+ - "\0\306\0\306\0\306\0\306\0\u01a2\0\306\0\u011e\0\u01b8"+ - "\0\306\0\362\0\u01ce\0\u01e4\0\306\0\u01fa\0\u0210\0\u0226"+ - "\0\u01ce"; - - private static int [] zzUnpackRowMap() { - int [] result = new int[41]; - int offset = 0; - offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackRowMap(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int high = packed.charAt(i++) << 16; - result[j++] = high | packed.charAt(i++); - } - return j; - } - - /** - * The transition table of the DFA - */ - private static final int [] ZZ_TRANS = zzUnpackTrans(); - - private static final String ZZ_TRANS_PACKED_0 = - "\6\12\1\13\1\14\16\12\1\15\2\16\4\15\1\17"+ - "\5\15\1\20\6\15\1\21\1\22\1\15\1\16\1\23"+ - "\4\15\1\17\14\15\1\21\1\22\1\12\2\24\4\12"+ - "\1\14\15\12\1\22\1\12\2\25\4\12\1\14\16\12"+ - "\1\15\2\26\2\27\2\15\1\17\1\27\1\30\1\15"+ - "\1\31\1\32\1\15\4\27\1\33\2\15\1\22\1\12"+ - "\2\16\2\27\2\12\1\14\1\27\1\12\1\34\1\12"+ - "\1\32\1\12\4\27\10\12\1\35\2\12\1\14\6\12"+ - "\4\35\1\12\1\36\11\12\1\14\5\12\1\37\10\12"+ - "\35\0\1\40\24\0\1\41\1\42\17\0\2\16\27\0"+ - "\1\43\11\0\1\44\3\43\6\0\1\23\24\0\2\24"+ - "\24\0\2\25\24\0\2\26\26\0\2\27\3\0\1\27"+ - "\5\0\4\27\7\0\3\35\10\0\4\35\13\0\1\45"+ - "\21\0\3\43\10\0\4\43\7\0\3\43\10\0\1\43"+ - "\1\46\2\43\7\0\3\43\10\0\2\43\1\47\1\43"+ - "\7\0\3\43\10\0\1\43\1\50\2\43\7\0\3\43"+ - "\10\0\3\43\1\51\4\0"; - - private static int [] zzUnpackTrans() { - int [] result = new int[572]; - int offset = 0; - offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackTrans(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int count = packed.charAt(i++); - int value = packed.charAt(i++); - value--; - do result[j++] = value; while (--count > 0); - } - return j; - } - - - /* error codes */ - private static final int ZZ_UNKNOWN_ERROR = 0; - private static final int ZZ_NO_MATCH = 1; - private static final int ZZ_PUSHBACK_2BIG = 2; - private static final char[] EMPTY_BUFFER = new char[0]; - private static final int YYEOF = -1; - private static java.io.Reader zzReader = null; // Fake - - /* error messages for the codes above */ - private static final String ZZ_ERROR_MSG[] = { - "Unkown internal scanner error", - "Error: could not match input", - "Error: pushback value was too large" - }; - - /** - * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code> - */ - private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); - - private static final String ZZ_ATTRIBUTE_PACKED_0 = - "\11\0\1\11\2\1\1\11\3\1\2\11\5\1\5\11"+ - "\1\1\1\11\1\1\1\0\1\11\1\0\2\1\1\11"+ - "\4\1"; - - private static int [] zzUnpackAttribute() { - int [] result = new int[41]; - int offset = 0; - offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackAttribute(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int count = packed.charAt(i++); - int value = packed.charAt(i++); - do result[j++] = value; while (--count > 0); - } - return j; - } - - /** the current state of the DFA */ - private int zzState; - - /** the current lexical state */ - private int zzLexicalState = YYINITIAL; - - /** this buffer contains the current text to be matched and is - the source of the yytext() string */ - private CharSequence zzBuffer = ""; - - /** this buffer may contains the current text array to be matched when it is cheap to acquire it */ - private char[] zzBufferArray; - - /** the textposition at the last accepting state */ - private int zzMarkedPos; - - /** the textposition at the last state to be included in yytext */ - private int zzPushbackPos; - - /** the current text position in the buffer */ - private int zzCurrentPos; - - /** startRead marks the beginning of the yytext() string in the buffer */ - private int zzStartRead; - - /** endRead marks the last character in the buffer, that has been read - from input */ - private int zzEndRead; - - /** - * zzAtBOL == true <=> the scanner is currently at the beginning of a line - */ - private boolean zzAtBOL = true; - - /** zzAtEOF == true <=> the scanner is at the EOF */ - private boolean zzAtEOF; - - /** denotes if the user-EOF-code has already been executed */ - private boolean zzEOFDone; - - /* user code: */ - private boolean myJdk15Enabled; - private DocCommentTokenTypes myTokenTypes; - - public _JavaDocLexer(boolean isJdk15Enabled, DocCommentTokenTypes tokenTypes) { - this((java.io.Reader)null); - myJdk15Enabled = isJdk15Enabled; - myTokenTypes = tokenTypes; - } - - public boolean checkAhead(char c) { - if (zzMarkedPos >= zzBuffer.length()) return false; - return zzBuffer.charAt(zzMarkedPos) == c; - } - - public void goTo(int offset) { - zzCurrentPos = zzMarkedPos = zzStartRead = offset; - zzPushbackPos = 0; - zzAtEOF = offset < zzEndRead; - } - - - _JavaDocLexer(java.io.Reader in) { - this.zzReader = in; - } - - /** - * Creates a new scanner. - * There is also java.io.Reader version of this constructor. - * - * @param in the java.io.Inputstream to read input from. - */ - _JavaDocLexer(java.io.InputStream in) { - this(new java.io.InputStreamReader(in)); - } - - /** - * Unpacks the compressed character translation table. - * - * @param packed the packed character translation table - * @return the unpacked character translation table - */ - private static char [] zzUnpackCMap(String packed) { - char [] map = new char[0x10000]; - int i = 0; /* index in packed string */ - int j = 0; /* index in unpacked array */ - while (i < 1606) { - int count = packed.charAt(i++); - char value = packed.charAt(i++); - do map[j++] = value; while (--count > 0); - } - return map; - } - - public final int getTokenStart(){ - return zzStartRead; - } - - public final int getTokenEnd(){ - return getTokenStart() + yylength(); - } - - public void reset(CharSequence buffer, int start, int end,int initialState){ - zzBuffer = buffer; - zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer); - zzCurrentPos = zzMarkedPos = zzStartRead = start; - zzPushbackPos = 0; - zzAtEOF = false; - zzAtBOL = true; - zzEndRead = end; - yybegin(initialState); - } - - /** - * Refills the input buffer. - * - * @return <code>false</code>, iff there was new input. - * - * @exception java.io.IOException if any I/O-Error occurs - */ - private boolean zzRefill() throws java.io.IOException { - return true; - } - - - /** - * Returns the current lexical state. - */ - public final int yystate() { - return zzLexicalState; - } - - - /** - * Enters a new lexical state - * - * @param newState the new lexical state - */ - public final void yybegin(int newState) { - zzLexicalState = newState; - } - - - /** - * Returns the text matched by the current regular expression. - */ - public final CharSequence yytext() { - return zzBuffer.subSequence(zzStartRead, zzMarkedPos); - } - - - /** - * Returns the character at position <tt>pos</tt> from the - * matched text. - * - * It is equivalent to yytext().charAt(pos), but faster - * - * @param pos the position of the character to fetch. - * A value from 0 to yylength()-1. - * - * @return the character at position pos - */ - public final char yycharat(int pos) { - return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos); - } - - - /** - * Returns the length of the matched text region. - */ - public final int yylength() { - return zzMarkedPos-zzStartRead; - } - - - /** - * Reports an error that occured while scanning. - * - * In a wellformed scanner (no or only correct usage of - * yypushback(int) and a match-all fallback rule) this method - * will only be called with things that "Can't Possibly Happen". - * If this method is called, something is seriously wrong - * (e.g. a JFlex bug producing a faulty scanner etc.). - * - * Usual syntax/scanner level error handling should be done - * in error fallback rules. - * - * @param errorCode the code of the errormessage to display - */ - private void zzScanError(int errorCode) { - String message; - try { - message = ZZ_ERROR_MSG[errorCode]; - } - catch (ArrayIndexOutOfBoundsException e) { - message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; - } - - throw new Error(message); - } - - - /** - * Pushes the specified amount of characters back into the input stream. - * - * They will be read again by then next call of the scanning method - * - * @param number the number of characters to be read again. - * This number must not be greater than yylength()! - */ - public void yypushback(int number) { - if ( number > yylength() ) - zzScanError(ZZ_PUSHBACK_2BIG); - - zzMarkedPos -= number; - } - - - /** - * Contains user EOF-code, which will be executed exactly once, - * when the end of file is reached - */ - private void zzDoEOF() { - if (!zzEOFDone) { - zzEOFDone = true; - - } - } - - - /** - * Resumes scanning until the next regular expression is matched, - * the end of input is encountered or an I/O-Error occurs. - * - * @return the next token - * @exception java.io.IOException if any I/O-Error occurs - */ - public IElementType advance() throws java.io.IOException { - int zzInput; - int zzAction; - - // cached fields: - int zzCurrentPosL; - int zzMarkedPosL; - int zzEndReadL = zzEndRead; - CharSequence zzBufferL = zzBuffer; - char[] zzBufferArrayL = zzBufferArray; - char [] zzCMapL = ZZ_CMAP; - - int [] zzTransL = ZZ_TRANS; - int [] zzRowMapL = ZZ_ROWMAP; - int [] zzAttrL = ZZ_ATTRIBUTE; - - while (true) { - zzMarkedPosL = zzMarkedPos; - - zzAction = -1; - - zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; - - zzState = ZZ_LEXSTATE[zzLexicalState]; - - - zzForAction: { - while (true) { - - if (zzCurrentPosL < zzEndReadL) - zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); - else if (zzAtEOF) { - zzInput = YYEOF; - break zzForAction; - } - else { - // store back cached positions - zzCurrentPos = zzCurrentPosL; - zzMarkedPos = zzMarkedPosL; - boolean eof = zzRefill(); - // get translated positions and possibly new buffer - zzCurrentPosL = zzCurrentPos; - zzMarkedPosL = zzMarkedPos; - zzBufferL = zzBuffer; - zzEndReadL = zzEndRead; - if (eof) { - zzInput = YYEOF; - break zzForAction; - } - else { - zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); - } - } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; - if (zzNext == -1) break zzForAction; - zzState = zzNext; - - int zzAttributes = zzAttrL[zzState]; - if ( (zzAttributes & 1) == 1 ) { - zzAction = zzState; - zzMarkedPosL = zzCurrentPosL; - if ( (zzAttributes & 8) == 8 ) break zzForAction; - } - - } - } - - // store back cached position - zzMarkedPos = zzMarkedPosL; - - switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { - case 12: - { return myTokenTypes.tagValueSharp(); - } - case 21: break; - case 16: - { yybegin(COMMENT_DATA); return myTokenTypes.tagValueGT(); - } - case 22: break; - case 3: - { return myTokenTypes.space(); - } - case 23: break; - case 6: - { return myTokenTypes.commentData(); - } - case 24: break; - case 5: - { yybegin(COMMENT_DATA); return myTokenTypes.inlineTagEnd(); - } - case 25: break; - case 19: - { yybegin(COMMENT_DATA_START); return myTokenTypes.commentStart(); - } - case 26: break; - case 7: - { if (checkAhead('<') || checkAhead('\"')) yybegin(COMMENT_DATA); - else if (checkAhead('\u007b') ) yybegin(COMMENT_DATA); // lbrace - there's a error in JLex when typing lbrace directly - else yybegin(DOC_TAG_VALUE); - return myTokenTypes.space(); - } - case 27: break; - case 8: - { yybegin(DOC_TAG_VALUE); return myTokenTypes.space(); - } - case 28: break; - case 10: - { return myTokenTypes.tagValueToken(); - } - case 29: break; - case 18: - { yybegin(TAG_DOC_SPACE); return myTokenTypes.tagName(); - } - case 30: break; - case 9: - { yybegin(COMMENT_DATA); return myTokenTypes.space(); - } - case 31: break; - case 20: - { yybegin(PARAM_TAG_SPACE); return myTokenTypes.tagName(); - } - case 32: break; - case 1: - { return myTokenTypes.badCharacter(); - } - case 33: break; - case 15: - { yybegin(DOC_TAG_VALUE); return myTokenTypes.tagValueRParen(); - } - case 34: break; - case 11: - { yybegin(DOC_TAG_VALUE_IN_PAREN); return myTokenTypes.tagValueLParen(); - } - case 35: break; - case 13: - { return myTokenTypes.tagValueComma(); - } - case 36: break; - case 14: - { if (myJdk15Enabled) { - yybegin(DOC_TAG_VALUE_IN_LTGT); - return myTokenTypes.tagValueLT(); - } - else { - yybegin(COMMENT_DATA); - return myTokenTypes.commentData(); - } - } - case 37: break; - case 4: - { if (checkAhead('@')) { - yybegin(INLINE_TAG_NAME); - return myTokenTypes.inlineTagStart(); - } - else{ - yybegin(COMMENT_DATA); - return myTokenTypes.inlineTagStart(); - } - } - case 38: break; - case 2: - { yybegin(COMMENT_DATA); return myTokenTypes.commentData(); - } - case 39: break; - case 17: - { return myTokenTypes.commentEnd(); - } - case 40: break; - default: - if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { - zzAtEOF = true; - zzDoEOF(); - return null; - } - else { - zzScanError(ZZ_NO_MATCH); - } - } - } - } - - -} diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.flex b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.flex index 4d3de09b8d34..67615506afda 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.flex +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.flex @@ -19,6 +19,7 @@ import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.JavaTokenType; import com.intellij.psi.impl.source.tree.JavaDocElementType; import com.intellij.psi.tree.IElementType; +import com.intellij.lexer.FlexLexer; @SuppressWarnings({"ALL"}) %% diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.java b/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.java deleted file mode 100644 index 517108e8bcf2..000000000000 --- a/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.java +++ /dev/null @@ -1,1451 +0,0 @@ -/* - * Copyright 2000-2013 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. - */ - -/* The following code was generated by JFlex 1.4.3 on 05.06.13 17:47 */ -package com.intellij.lang.java.lexer; - -import com.intellij.lexer.FlexLexer; -import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.JavaTokenType; -import com.intellij.psi.impl.source.tree.JavaDocElementType; -import com.intellij.psi.tree.IElementType; - -@SuppressWarnings({"ALL"}) - -/** - * This class is a scanner generated by - * <a href="http://www.jflex.de/">JFlex</a> 1.4.3 - * on 05.06.13 17:47 from the specification file - * <tt>C:/Users/roman.shevchenko/Projects/IDEA/tools/lexer/../../community/java/java-psi-impl/src/com/intellij/lang/java/lexer/_JavaLexer.flex</tt> - */ -class _JavaLexer implements FlexLexer { - /** initial size of the lookahead buffer */ - private static final int ZZ_BUFFERSIZE = 16384; - - /** lexical states */ - public static final int YYINITIAL = 0; - - /** - * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l - * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l - * at the beginning of a line - * l is of the form l = 2*k, k a non negative integer - */ - private static final int ZZ_LEXSTATE[] = { - 0, 0 - }; - - /** - * Translates characters to character classes - */ - private static final String ZZ_CMAP_PACKED = - "\11\3\1\1\1\6\1\0\1\1\1\6\16\3\4\0\1\1\1\60"+ - "\1\26\1\0\1\2\1\67\1\65\1\24\1\70\1\71\1\5\1\62"+ - "\1\77\1\22\1\20\1\4\1\13\11\7\1\102\1\76\1\63\1\57"+ - "\1\64\1\101\1\103\1\11\1\15\1\11\1\17\1\21\1\16\5\2"+ - "\1\12\3\2\1\23\7\2\1\14\2\2\1\74\1\25\1\75\1\66"+ - "\1\10\1\0\1\34\1\40\1\41\1\47\1\32\1\33\1\52\1\45"+ - "\1\46\1\2\1\43\1\35\1\50\1\37\1\42\1\53\1\2\1\30"+ - "\1\36\1\27\1\31\1\54\1\55\1\51\1\44\1\56\1\72\1\61"+ - "\1\73\1\100\41\3\2\0\4\2\4\0\1\2\2\0\1\3\7\0"+ - "\1\2\4\0\1\2\5\0\27\2\1\0\37\2\1\0\u01ca\2\4\0"+ - "\14\2\16\0\5\2\7\0\1\2\1\0\1\2\21\0\160\3\5\2"+ - "\1\0\2\2\2\0\4\2\10\0\1\2\1\0\3\2\1\0\1\2"+ - "\1\0\24\2\1\0\123\2\1\0\213\2\1\0\5\3\2\0\236\2"+ - "\11\0\46\2\2\0\1\2\7\0\47\2\11\0\55\3\1\0\1\3"+ - "\1\0\2\3\1\0\2\3\1\0\1\3\10\0\33\2\5\0\3\2"+ - "\15\0\4\3\7\0\1\2\4\0\13\3\5\0\53\2\37\3\4\0"+ - "\2\2\1\3\143\2\1\0\1\2\10\3\1\0\6\3\2\2\2\3"+ - "\1\0\4\3\2\2\12\3\3\2\2\0\1\2\17\0\1\3\1\2"+ - "\1\3\36\2\33\3\2\0\131\2\13\3\1\2\16\0\12\3\41\2"+ - "\11\3\2\2\4\0\1\2\5\0\26\2\4\3\1\2\11\3\1\2"+ - "\3\3\1\2\5\3\22\0\31\2\3\3\244\0\4\3\66\2\3\3"+ - "\1\2\22\3\1\2\7\3\12\2\2\3\2\0\12\3\1\0\7\2"+ - "\1\0\7\2\1\0\3\3\1\0\10\2\2\0\2\2\2\0\26\2"+ - "\1\0\7\2\1\0\1\2\3\0\4\2\2\0\1\3\1\2\7\3"+ - "\2\0\2\3\2\0\3\3\1\2\10\0\1\3\4\0\2\2\1\0"+ - "\3\2\2\3\2\0\12\3\4\2\7\0\1\2\5\0\3\3\1\0"+ - "\6\2\4\0\2\2\2\0\26\2\1\0\7\2\1\0\2\2\1\0"+ - "\2\2\1\0\2\2\2\0\1\3\1\0\5\3\4\0\2\3\2\0"+ - "\3\3\3\0\1\3\7\0\4\2\1\0\1\2\7\0\14\3\3\2"+ - "\1\3\13\0\3\3\1\0\11\2\1\0\3\2\1\0\26\2\1\0"+ - "\7\2\1\0\2\2\1\0\5\2\2\0\1\3\1\2\10\3\1\0"+ - "\3\3\1\0\3\3\2\0\1\2\17\0\2\2\2\3\2\0\12\3"+ - "\1\0\1\2\17\0\3\3\1\0\10\2\2\0\2\2\2\0\26\2"+ - "\1\0\7\2\1\0\2\2\1\0\5\2\2\0\1\3\1\2\7\3"+ - "\2\0\2\3\2\0\3\3\10\0\2\3\4\0\2\2\1\0\3\2"+ - "\2\3\2\0\12\3\1\0\1\2\20\0\1\3\1\2\1\0\6\2"+ - "\3\0\3\2\1\0\4\2\3\0\2\2\1\0\1\2\1\0\2\2"+ - "\3\0\2\2\3\0\3\2\3\0\14\2\4\0\5\3\3\0\3\3"+ - "\1\0\4\3\2\0\1\2\6\0\1\3\16\0\12\3\11\0\1\2"+ - "\7\0\3\3\1\0\10\2\1\0\3\2\1\0\27\2\1\0\12\2"+ - "\1\0\5\2\3\0\1\2\7\3\1\0\3\3\1\0\4\3\7\0"+ - "\2\3\1\0\2\2\6\0\2\2\2\3\2\0\12\3\22\0\2\3"+ - "\1\0\10\2\1\0\3\2\1\0\27\2\1\0\12\2\1\0\5\2"+ - "\2\0\1\3\1\2\7\3\1\0\3\3\1\0\4\3\7\0\2\3"+ - "\7\0\1\2\1\0\2\2\2\3\2\0\12\3\1\0\2\2\17\0"+ - "\2\3\1\0\10\2\1\0\3\2\1\0\51\2\2\0\1\2\7\3"+ - "\1\0\3\3\1\0\4\3\1\2\10\0\1\3\10\0\2\2\2\3"+ - "\2\0\12\3\12\0\6\2\2\0\2\3\1\0\22\2\3\0\30\2"+ - "\1\0\11\2\1\0\1\2\2\0\7\2\3\0\1\3\4\0\6\3"+ - "\1\0\1\3\1\0\10\3\22\0\2\3\15\0\60\2\1\3\2\2"+ - "\7\3\4\0\10\2\10\3\1\0\12\3\47\0\2\2\1\0\1\2"+ - "\2\0\2\2\1\0\1\2\2\0\1\2\6\0\4\2\1\0\7\2"+ - "\1\0\3\2\1\0\1\2\1\0\1\2\2\0\2\2\1\0\4\2"+ - "\1\3\2\2\6\3\1\0\2\3\1\2\2\0\5\2\1\0\1\2"+ - "\1\0\6\3\2\0\12\3\2\0\2\2\42\0\1\2\27\0\2\3"+ - "\6\0\12\3\13\0\1\3\1\0\1\3\1\0\1\3\4\0\2\3"+ - "\10\2\1\0\44\2\4\0\24\3\1\0\2\3\5\2\13\3\1\0"+ - "\44\3\11\0\1\3\71\0\53\2\24\3\1\2\12\3\6\0\6\2"+ - "\4\3\4\2\3\3\1\2\3\3\2\2\7\3\3\2\4\3\15\2"+ - "\14\3\1\2\17\3\2\0\46\2\12\0\53\2\1\0\1\2\3\0"+ - "\u0149\2\1\0\4\2\2\0\7\2\1\0\1\2\1\0\4\2\2\0"+ - "\51\2\1\0\4\2\2\0\41\2\1\0\4\2\2\0\7\2\1\0"+ - "\1\2\1\0\4\2\2\0\17\2\1\0\71\2\1\0\4\2\2\0"+ - "\103\2\2\0\3\3\40\0\20\2\20\0\125\2\14\0\u026c\2\2\0"+ - "\21\2\1\0\32\2\5\0\113\2\3\0\3\2\17\0\15\2\1\0"+ - "\4\2\3\3\13\0\22\2\3\3\13\0\22\2\2\3\14\0\15\2"+ - "\1\0\3\2\1\0\2\3\14\0\64\2\40\3\3\0\1\2\3\0"+ - "\2\2\1\3\2\0\12\3\41\0\3\3\2\0\12\3\6\0\130\2"+ - "\10\0\51\2\1\3\1\2\5\0\106\2\12\0\35\2\3\0\14\3"+ - "\4\0\14\3\12\0\12\3\36\2\2\0\5\2\13\0\54\2\4\0"+ - "\21\3\7\2\2\3\6\0\12\3\46\0\27\2\5\3\4\0\65\2"+ - "\12\3\1\0\35\3\2\0\13\3\6\0\12\3\15\0\1\2\130\0"+ - "\5\3\57\2\21\3\7\2\4\0\12\3\21\0\11\3\14\0\3\3"+ - "\36\2\12\3\3\0\2\2\12\3\6\0\46\2\16\3\14\0\44\2"+ - "\24\3\10\0\12\3\3\0\3\2\12\3\44\2\122\0\3\3\1\0"+ - "\25\3\4\2\1\3\4\2\1\3\15\0\300\2\47\3\25\0\4\3"+ - "\u0116\2\2\0\6\2\2\0\46\2\2\0\6\2\2\0\10\2\1\0"+ - "\1\2\1\0\1\2\1\0\1\2\1\0\37\2\2\0\65\2\1\0"+ - "\7\2\1\0\1\2\3\0\3\2\1\0\7\2\3\0\4\2\2\0"+ - "\6\2\4\0\15\2\5\0\3\2\1\0\7\2\16\0\5\3\32\0"+ - "\5\3\20\0\2\2\23\0\1\2\13\0\5\3\5\0\6\3\1\0"+ - "\1\2\15\0\1\2\20\0\15\2\3\0\32\2\26\0\15\3\4\0"+ - "\1\3\3\0\14\3\21\0\1\2\4\0\1\2\2\0\12\2\1\0"+ - "\1\2\3\0\5\2\6\0\1\2\1\0\1\2\1\0\1\2\1\0"+ - "\4\2\1\0\13\2\2\0\4\2\5\0\5\2\4\0\1\2\21\0"+ - "\51\2\u0a77\0\57\2\1\0\57\2\1\0\205\2\6\0\4\2\3\3"+ - "\16\0\46\2\12\0\66\2\11\0\1\2\17\0\1\3\27\2\11\0"+ - "\7\2\1\0\7\2\1\0\7\2\1\0\7\2\1\0\7\2\1\0"+ - "\7\2\1\0\7\2\1\0\7\2\1\0\40\3\57\0\1\2\u01d5\0"+ - "\3\2\31\0\11\2\6\3\1\0\5\2\2\0\5\2\4\0\126\2"+ - "\2\0\2\3\2\0\3\2\1\0\132\2\1\0\4\2\5\0\51\2"+ - "\3\0\136\2\21\0\33\2\65\0\20\2\u0200\0\u19b6\2\112\0\u51cc\2"+ - "\64\0\u048d\2\103\0\56\2\2\0\u010d\2\3\0\20\2\12\3\2\2"+ - "\24\0\57\2\1\3\14\0\2\3\1\0\31\2\10\0\120\2\2\3"+ - "\45\0\11\2\2\0\147\2\2\0\4\2\1\0\2\2\16\0\12\2"+ - "\120\0\10\2\1\3\3\2\1\3\4\2\1\3\27\2\5\3\20\0"+ - "\1\2\7\0\64\2\14\0\2\3\62\2\21\3\13\0\12\3\6\0"+ - "\22\3\6\2\3\0\1\2\4\0\12\3\34\2\10\3\2\0\27\2"+ - "\15\3\14\0\35\2\3\0\4\3\57\2\16\3\16\0\1\2\12\3"+ - "\46\0\51\2\16\3\11\0\3\2\1\3\10\2\2\3\2\0\12\3"+ - "\6\0\27\2\3\0\1\2\1\3\4\0\60\2\1\3\1\2\3\3"+ - "\2\2\2\3\5\2\2\3\1\2\1\3\1\2\30\0\3\2\43\0"+ - "\6\2\2\0\6\2\2\0\6\2\11\0\7\2\1\0\7\2\221\0"+ - "\43\2\10\3\1\0\2\3\2\0\12\3\6\0\u2ba4\2\14\0\27\2"+ - "\4\0\61\2\u2104\0\u012e\2\2\0\76\2\2\0\152\2\46\0\7\2"+ - "\14\0\5\2\5\0\1\2\1\3\12\2\1\0\15\2\1\0\5\2"+ - "\1\0\1\2\1\0\2\2\1\0\2\2\1\0\154\2\41\0\u016b\2"+ - "\22\0\100\2\2\0\66\2\50\0\15\2\3\0\20\3\20\0\7\3"+ - "\14\0\2\2\30\0\3\2\31\0\1\2\6\0\5\2\1\0\207\2"+ - "\2\0\1\3\4\0\1\2\13\0\12\3\7\0\32\2\4\0\1\2"+ - "\1\0\32\2\13\0\131\2\3\0\6\2\2\0\6\2\2\0\6\2"+ - "\2\0\3\2\3\0\2\2\3\0\2\2\22\0\3\3\4\0"; - - /** - * Translates characters to character classes - */ - private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); - - /** - * Translates DFA states to action switch labels. - */ - private static final int [] ZZ_ACTION = zzUnpackAction(); - - private static final String ZZ_ACTION_PACKED_0 = - "\1\0\1\1\1\2\1\3\1\4\1\5\2\6\1\7"+ - "\1\10\1\11\1\12\20\3\1\13\1\14\1\15\1\16"+ - "\1\17\1\20\1\21\1\22\1\23\1\24\1\25\1\26"+ - "\1\27\1\30\1\31\1\32\1\33\1\34\1\35\1\36"+ - "\1\37\1\40\1\41\1\42\1\43\1\44\1\45\3\46"+ - "\2\6\1\0\1\47\1\50\1\51\2\11\2\12\34\3"+ - "\1\52\3\3\1\53\6\3\1\54\1\55\1\56\1\57"+ - "\1\60\1\61\1\62\1\63\1\64\1\65\1\66\1\67"+ - "\1\70\1\41\1\71\1\46\1\6\1\0\1\72\2\3"+ - "\1\73\10\3\1\74\13\3\1\75\11\3\1\76\14\3"+ - "\1\77\1\0\2\71\1\0\1\100\2\3\1\101\1\3"+ - "\1\102\1\103\6\3\1\104\6\3\1\105\3\3\1\106"+ - "\1\3\1\107\3\3\1\110\6\3\1\111\5\3\1\112"+ - "\1\3\1\41\1\0\1\3\1\113\2\3\1\114\1\115"+ - "\1\116\4\3\1\117\1\3\1\120\2\3\1\121\1\3"+ - "\1\122\1\123\1\3\1\124\13\3\1\125\1\3\1\126"+ - "\1\127\2\3\1\130\2\3\1\131\1\3\1\132\1\133"+ - "\5\3\1\134\1\3\1\135\2\3\1\136\3\3\1\137"+ - "\1\140\3\3\1\141\4\3\1\142\1\3\1\143\1\144"+ - "\2\3\1\145\1\146\1\3\1\147\4\3\1\150\1\151"+ - "\1\3\1\152\2\3\1\153\1\3\1\154\1\155\1\3"+ - "\1\156"; - - private static int [] zzUnpackAction() { - int [] result = new int[320]; - int offset = 0; - offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackAction(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int count = packed.charAt(i++); - int value = packed.charAt(i++); - do result[j++] = value; while (--count > 0); - } - return j; - } - - - /** - * Translates a state to a row index in the transition table - */ - private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); - - private static final String ZZ_ROWMAP_PACKED_0 = - "\0\0\0\104\0\210\0\314\0\u0110\0\u0154\0\u0198\0\u01dc"+ - "\0\u0220\0\u0264\0\u02a8\0\u02ec\0\u0330\0\u0374\0\u03b8\0\u03fc"+ - "\0\u0440\0\u0484\0\u04c8\0\u050c\0\u0550\0\u0594\0\u05d8\0\u061c"+ - "\0\u0660\0\u06a4\0\u06e8\0\u072c\0\u0770\0\u07b4\0\u07f8\0\u083c"+ - "\0\u0880\0\104\0\u08c4\0\u0908\0\u094c\0\104\0\104\0\104"+ - "\0\104\0\104\0\104\0\104\0\104\0\104\0\104\0\u0990"+ - "\0\104\0\u09d4\0\u0a18\0\104\0\104\0\104\0\104\0\104"+ - "\0\u0a5c\0\u0aa0\0\u0ae4\0\u0b28\0\u0b6c\0\104\0\104\0\104"+ - "\0\104\0\u0bb0\0\u0bf4\0\104\0\u0c38\0\u0c7c\0\u0cc0\0\u0d04"+ - "\0\u0d48\0\u0d8c\0\u0dd0\0\u0e14\0\u0e58\0\u0e9c\0\u0ee0\0\u0f24"+ - "\0\u0f68\0\u0fac\0\u0ff0\0\u1034\0\u1078\0\u10bc\0\u1100\0\u1144"+ - "\0\u1188\0\u11cc\0\u1210\0\u1254\0\u1298\0\u12dc\0\u1320\0\u1364"+ - "\0\314\0\u13a8\0\u13ec\0\u1430\0\u1474\0\u14b8\0\u14fc\0\u1540"+ - "\0\u1584\0\u15c8\0\u160c\0\104\0\104\0\104\0\104\0\104"+ - "\0\104\0\104\0\u1650\0\104\0\104\0\104\0\104\0\104"+ - "\0\u1694\0\u16d8\0\u171c\0\u1760\0\u17a4\0\104\0\u17e8\0\u182c"+ - "\0\314\0\u1870\0\u18b4\0\u18f8\0\u193c\0\u1980\0\u19c4\0\u1a08"+ - "\0\u1a4c\0\314\0\u1a90\0\u1ad4\0\u1b18\0\u1b5c\0\u1ba0\0\u1be4"+ - "\0\u1c28\0\u1c6c\0\u1cb0\0\u1cf4\0\u1d38\0\314\0\u1d7c\0\u1dc0"+ - "\0\u1e04\0\u1e48\0\u1e8c\0\u1ed0\0\u1f14\0\u1f58\0\u1f9c\0\u1fe0"+ - "\0\u2024\0\u2068\0\u20ac\0\u20f0\0\u2134\0\u2178\0\u21bc\0\u2200"+ - "\0\u2244\0\u2288\0\u22cc\0\u2310\0\104\0\u2354\0\u2398\0\104"+ - "\0\u23dc\0\314\0\u2420\0\u2464\0\314\0\u24a8\0\314\0\314"+ - "\0\u24ec\0\u2530\0\u2574\0\u25b8\0\u25fc\0\u2640\0\314\0\u2684"+ - "\0\u26c8\0\u270c\0\u2750\0\u2794\0\u27d8\0\314\0\u281c\0\u2860"+ - "\0\u28a4\0\314\0\u28e8\0\314\0\u292c\0\u2970\0\u29b4\0\314"+ - "\0\u29f8\0\u2a3c\0\u2a80\0\u2ac4\0\u2b08\0\u2b4c\0\314\0\u2b90"+ - "\0\u2bd4\0\u2c18\0\u2c5c\0\u2ca0\0\314\0\u2ce4\0\104\0\u2d28"+ - "\0\u2d6c\0\u2db0\0\u2df4\0\u2e38\0\314\0\314\0\u2e7c\0\u2ec0"+ - "\0\u2f04\0\u2f48\0\u2f8c\0\314\0\u2fd0\0\314\0\u3014\0\u3058"+ - "\0\314\0\u309c\0\314\0\314\0\u30e0\0\314\0\u3124\0\u3168"+ - "\0\u31ac\0\u31f0\0\u3234\0\u3278\0\u32bc\0\u3300\0\u3344\0\u3388"+ - "\0\u33cc\0\314\0\u3410\0\314\0\314\0\u3454\0\u3498\0\314"+ - "\0\u34dc\0\u3520\0\314\0\u3564\0\314\0\314\0\u35a8\0\u35ec"+ - "\0\u3630\0\u3674\0\u36b8\0\314\0\u36fc\0\314\0\u3740\0\u3784"+ - "\0\314\0\u37c8\0\u380c\0\u3850\0\314\0\314\0\u3894\0\u38d8"+ - "\0\u391c\0\314\0\u3960\0\u39a4\0\u39e8\0\u3a2c\0\314\0\u3a70"+ - "\0\314\0\314\0\u3ab4\0\u3af8\0\314\0\314\0\u3b3c\0\314"+ - "\0\u3b80\0\u3bc4\0\u3c08\0\u3c4c\0\314\0\314\0\u3c90\0\314"+ - "\0\u3cd4\0\u3d18\0\314\0\u3d5c\0\314\0\314\0\u3da0\0\314"; - - private static int [] zzUnpackRowMap() { - int [] result = new int[320]; - int offset = 0; - offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackRowMap(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int high = packed.charAt(i++) << 16; - result[j++] = high | packed.charAt(i++); - } - return j; - } - - /** - * The transition table of the DFA - */ - private static final int [] ZZ_TRANS = zzUnpackTrans(); - - private static final String ZZ_TRANS_PACKED_0 = - "\1\2\1\3\1\4\1\2\1\5\1\6\1\3\1\7"+ - "\3\4\1\10\4\4\1\11\1\4\1\12\1\4\1\13"+ - "\1\2\1\14\1\15\1\16\1\4\1\17\1\20\1\21"+ - "\1\22\1\23\1\24\1\25\1\26\4\4\1\27\1\30"+ - "\2\4\1\31\1\32\1\33\1\34\1\4\1\35\1\36"+ - "\1\37\1\40\1\41\1\42\1\43\1\44\1\45\1\46"+ - "\1\47\1\50\1\51\1\52\1\53\1\54\1\55\1\56"+ - "\1\57\1\60\1\61\105\0\1\3\4\0\1\3\77\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\30\4\31\0\1\62\1\63\51\0\1\64\103\0\1\65"+ - "\33\0\2\7\1\0\1\66\1\7\2\0\1\67\1\70"+ - "\1\71\1\72\10\0\1\72\1\67\1\0\1\66\11\0"+ - "\1\70\43\0\2\7\1\0\1\66\1\7\1\73\1\74"+ - "\1\67\1\70\1\71\1\72\10\0\1\72\1\67\1\0"+ - "\1\66\2\0\1\74\6\0\1\70\1\0\1\73\41\0"+ - "\1\71\3\0\1\71\4\0\1\75\105\0\1\76\34\0"+ - "\1\77\4\0\1\100\17\0\6\13\1\0\15\13\1\101"+ - "\1\102\56\13\6\14\1\0\16\14\1\103\1\104\55\14"+ - "\2\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\1\4\1\105\14\4\1\106\11\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\3\4"+ - "\1\107\24\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\6\4\1\110\1\4\1\111\11\4"+ - "\1\112\5\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\5\4\1\113\1\114\4\4\1\115"+ - "\3\4\1\116\10\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\7\4\1\117\1\4\1\120"+ - "\16\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\13\4\1\121\14\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\1\122\1\4"+ - "\1\123\12\4\1\124\1\125\7\4\1\126\1\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\2\4\1\127\1\130\1\4\1\131\22\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\1\4"+ - "\1\132\11\4\1\133\1\4\1\134\12\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\5\4"+ - "\1\135\1\136\4\4\1\137\2\4\1\140\11\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\4\4\1\141\3\4\1\142\10\4\1\143\6\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\3\4\1\144\7\4\1\145\14\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\13\4\1\146"+ - "\14\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\1\4\1\147\1\150\2\4\1\151\22\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\13\4\1\152\14\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\16\4\1\153\11\4"+ - "\104\0\1\154\103\0\1\155\103\0\1\156\1\0\1\157"+ - "\101\0\1\160\2\0\1\161\100\0\1\162\3\0\1\163"+ - "\77\0\1\164\5\0\1\165\75\0\1\166\103\0\1\167"+ - "\126\0\1\170\1\0\6\62\1\0\75\62\5\171\1\172"+ - "\76\171\7\0\2\71\2\0\1\71\2\0\1\67\1\70"+ - "\1\0\1\72\10\0\1\72\1\67\13\0\1\70\43\0"+ - "\2\173\2\0\1\173\2\0\1\67\1\70\2\0\1\173"+ - "\10\0\1\67\13\0\1\70\12\0\1\173\30\0\3\174"+ - "\1\66\1\174\1\0\3\174\1\175\1\174\10\0\3\174"+ - "\1\66\2\0\2\174\5\0\1\174\43\0\2\74\1\0"+ - "\1\66\1\74\21\0\1\66\66\0\1\176\63\0\6\13"+ - "\1\0\75\13\6\14\1\0\75\14\2\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\2\4\1\177"+ - "\2\4\1\200\7\4\1\201\12\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\1\4\1\202"+ - "\15\4\1\203\10\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\204\27\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\7\4"+ - "\1\205\20\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\2\4\1\206\25\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\1\207"+ - "\27\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\6\4\1\210\21\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\13\4\1\211"+ - "\14\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\1\4\1\212\26\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\10\4\1\213"+ - "\17\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\7\4\1\214\20\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\7\4\1\215"+ - "\20\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\10\4\1\216\17\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\1\4\1\217"+ - "\3\4\1\220\22\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\24\4\1\221\3\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\10\4\1\222\17\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\13\4\1\223\14\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\17\4\1\224\10\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\6\4\1\225\21\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\26\4\1\226\1\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\227\27\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\3\4"+ - "\1\230\24\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\13\4\1\231\14\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\1\232"+ - "\27\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\1\233\6\4\1\234\20\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\5\4"+ - "\1\235\22\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\10\4\1\236\17\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\5\4"+ - "\1\237\22\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\1\240\6\4\1\241\20\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\24\4\1\242\3\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\4\4\1\243\23\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\2\4\1\244\25\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\245\27\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\13\4"+ - "\1\246\3\4\1\247\10\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\11\4\1\250\16\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\12\4\1\251\15\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\6\4\1\252\10\4"+ - "\1\253\10\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\17\4\1\254\10\4\104\0\1\255"+ - "\24\0\5\171\1\256\76\171\4\257\1\260\1\172\76\257"+ - "\7\0\2\173\2\0\1\173\2\0\1\67\1\70\13\0"+ - "\1\67\13\0\1\70\43\0\3\174\1\66\1\174\1\0"+ - "\3\174\1\261\1\174\1\0\1\72\6\0\3\174\1\66"+ - "\2\0\2\174\5\0\1\174\3\0\1\72\37\0\3\261"+ - "\1\0\1\261\1\0\3\261\1\0\1\261\10\0\3\261"+ - "\3\0\2\261\5\0\1\261\36\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\3\4\1\262\24\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\10\4\1\263\17\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\13\4\1\264\14\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\7\4\1\265\20\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\2\4\1\266\25\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\3\4\1\267\24\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\21\4\1\270\6\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\3\4\1\271\24\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\7\4\1\272\20\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\5\4\1\273\22\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\5\4\1\274\22\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\3\4\1\275\24\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\1\276\27\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\23\4\1\277\4\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\17\4\1\300\10\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\1\301\27\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\3\4\1\302\24\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\12\4"+ - "\1\303\15\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\1\4\1\304\26\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\1\305"+ - "\27\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\6\4\1\306\21\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\17\4\1\307"+ - "\10\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\5\4\1\310\22\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\6\4\1\311"+ - "\21\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\3\4\1\312\24\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\12\4\1\313"+ - "\15\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\3\4\1\314\24\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\7\4\1\315"+ - "\20\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\1\316\6\4\1\317\20\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\1\4"+ - "\1\320\26\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\3\4\1\321\24\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\1\322"+ - "\27\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\6\4\1\323\4\4\1\324\14\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\5\4\1\325\22\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\11\4\1\326\16\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\13\4\1\327\14\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\330\27\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\25\4"+ - "\1\331\2\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\6\4\1\332\21\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\14\4"+ - "\1\333\13\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\5\4\1\334\22\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\20\4"+ - "\1\335\7\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\6\4\1\336\21\4\25\0\4\171"+ - "\1\337\1\256\76\171\5\257\1\340\76\257\7\0\3\261"+ - "\1\0\1\261\1\0\3\261\1\0\1\261\1\0\1\72"+ - "\6\0\3\261\3\0\2\261\5\0\1\261\3\0\1\72"+ - "\32\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\7\4\1\341\20\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\26\4\1\342\1\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\1\4\1\343\26\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\10\4\1\344\17\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\3\4\1\345\24\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\1\346\27\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\6\4\1\347\21\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\4\1\350\26\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\1\4\1\351\26\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\12\4\1\352\15\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\17\4\1\353\10\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\4\1\354\26\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\16\4\1\355\11\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\356\27\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\12\4"+ - "\1\357\15\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\25\4\1\360\2\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\14\4"+ - "\1\361\13\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\3\4\1\362\24\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\16\4"+ - "\1\363\11\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\7\4\1\364\20\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\17\4"+ - "\1\365\10\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\1\366\27\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\1\4\1\367"+ - "\26\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\5\4\1\370\22\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\3\4\1\371"+ - "\24\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\1\4\1\372\26\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\2\4\1\373"+ - "\25\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\6\4\1\374\21\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\3\4\1\375"+ - "\24\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\5\4\1\376\22\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\17\4\1\377"+ - "\10\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\5\4\1\u0100\22\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\1\u0101\27\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\3\4\1\u0102\24\4\25\0\4\257\1\260\1\340"+ - "\76\257\2\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\17\4\1\u0103\10\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\7\4\1\u0104"+ - "\20\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\10\4\1\u0105\17\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\20\4\1\u0106"+ - "\7\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\6\4\1\u0107\21\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\1\u0108\27\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\5\4\1\u0109\22\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\1\u010a\27\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\12\4\1\u010b\15\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\4\1\u010c\26\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\16\4\1\u010d\11\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\3\4\1\u010e\24\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\5\4\1\u010f\22\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\10\4\1\u0110\17\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\4\4\1\u0111\23\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\10\4\1\u0112\17\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\21\4\1\u0113\6\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\u0114\27\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\6\4"+ - "\1\u0115\21\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\3\4\1\u0116\24\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\12\4"+ - "\1\u0117\15\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\1\u0118\27\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\12\4\1\u0119"+ - "\15\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\23\4\1\u011a\4\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\17\4\1\u011b"+ - "\10\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\3\4\1\u011c\24\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\7\4\1\u011d"+ - "\20\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\15\4\1\u011e\12\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\12\4\1\u011f"+ - "\15\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\4\4\1\u0120\23\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\13\4\1\u0121"+ - "\14\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\10\4\1\u0122\17\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\2\4\1\u0123"+ - "\25\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\5\4\1\u0124\22\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\12\4\1\u0125"+ - "\15\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\3\4\1\u0126\24\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\1\u0127\27\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\1\u0128\27\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\3\4\1\u0129\24\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\3\4\1\u012a\24\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\6\4\1\u012b\21\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\10\4\1\u012c\17\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\1\u012d\27\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\24\4"+ - "\1\u012e\3\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\10\4\1\u012f\17\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\3\4"+ - "\1\u0130\24\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\12\4\1\u0131\15\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\3\4"+ - "\1\u0132\24\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\10\4\1\u0133\17\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\3\4"+ - "\1\u0134\24\4\27\0\2\4\3\0\11\4\1\0\1\4"+ - "\1\0\1\4\3\0\3\4\1\u0135\24\4\27\0\2\4"+ - "\3\0\11\4\1\0\1\4\1\0\1\4\3\0\1\u0136"+ - "\27\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\17\4\1\u0137\10\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\3\4\1\u0138"+ - "\24\4\27\0\2\4\3\0\11\4\1\0\1\4\1\0"+ - "\1\4\3\0\13\4\1\u0139\14\4\27\0\2\4\3\0"+ - "\11\4\1\0\1\4\1\0\1\4\3\0\1\u013a\27\4"+ - "\27\0\2\4\3\0\11\4\1\0\1\4\1\0\1\4"+ - "\3\0\20\4\1\u013b\7\4\27\0\2\4\3\0\11\4"+ - "\1\0\1\4\1\0\1\4\3\0\27\4\1\u013c\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\4\4\1\u013d\23\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\7\4\1\u013e\20\4\27\0"+ - "\2\4\3\0\11\4\1\0\1\4\1\0\1\4\3\0"+ - "\3\4\1\u013f\24\4\27\0\2\4\3\0\11\4\1\0"+ - "\1\4\1\0\1\4\3\0\20\4\1\u0140\7\4\25\0"; - - private static int [] zzUnpackTrans() { - int [] result = new int[15844]; - int offset = 0; - offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackTrans(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int count = packed.charAt(i++); - int value = packed.charAt(i++); - value--; - do result[j++] = value; while (--count > 0); - } - return j; - } - - - /* error codes */ - private static final int ZZ_UNKNOWN_ERROR = 0; - private static final int ZZ_NO_MATCH = 1; - private static final int ZZ_PUSHBACK_2BIG = 2; - private static final char[] EMPTY_BUFFER = new char[0]; - private static final int YYEOF = -1; - private static java.io.Reader zzReader = null; // Fake - - /* error messages for the codes above */ - private static final String ZZ_ERROR_MSG[] = { - "Unkown internal scanner error", - "Error: could not match input", - "Error: pushback value was too large" - }; - - /** - * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code> - */ - private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); - - private static final String ZZ_ATTRIBUTE_PACKED_0 = - "\1\0\1\11\37\1\1\11\3\1\12\11\1\1\1\11"+ - "\2\1\5\11\4\1\1\0\4\11\2\1\1\11\47\1"+ - "\7\11\1\1\5\11\4\1\1\0\1\11\56\1\1\11"+ - "\1\0\1\1\1\11\1\0\55\1\1\11\1\0\140\1"; - - private static int [] zzUnpackAttribute() { - int [] result = new int[320]; - int offset = 0; - offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackAttribute(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int count = packed.charAt(i++); - int value = packed.charAt(i++); - do result[j++] = value; while (--count > 0); - } - return j; - } - - /** the current state of the DFA */ - private int zzState; - - /** the current lexical state */ - private int zzLexicalState = YYINITIAL; - - /** this buffer contains the current text to be matched and is - the source of the yytext() string */ - private CharSequence zzBuffer = ""; - - /** this buffer may contains the current text array to be matched when it is cheap to acquire it */ - private char[] zzBufferArray; - - /** the textposition at the last accepting state */ - private int zzMarkedPos; - - /** the textposition at the last state to be included in yytext */ - private int zzPushbackPos; - - /** the current text position in the buffer */ - private int zzCurrentPos; - - /** startRead marks the beginning of the yytext() string in the buffer */ - private int zzStartRead; - - /** endRead marks the last character in the buffer, that has been read - from input */ - private int zzEndRead; - - /** - * zzAtBOL == true <=> the scanner is currently at the beginning of a line - */ - private boolean zzAtBOL = true; - - /** zzAtEOF == true <=> the scanner is at the EOF */ - private boolean zzAtEOF; - - /** denotes if the user-EOF-code has already been executed */ - private boolean zzEOFDone; - - /* user code: */ - private boolean myAssertKeyword; - private boolean myEnumKeyword; - - public _JavaLexer(LanguageLevel level) { - this((java.io.Reader)null); - myAssertKeyword = level.isAtLeast(LanguageLevel.JDK_1_4); - myEnumKeyword = level.isAtLeast(LanguageLevel.JDK_1_5); - } - - public void goTo(int offset) { - zzCurrentPos = zzMarkedPos = zzStartRead = offset; - zzPushbackPos = 0; - zzAtEOF = offset < zzEndRead; - } - - - _JavaLexer(java.io.Reader in) { - this.zzReader = in; - } - - /** - * Creates a new scanner. - * There is also java.io.Reader version of this constructor. - * - * @param in the java.io.Inputstream to read input from. - */ - _JavaLexer(java.io.InputStream in) { - this(new java.io.InputStreamReader(in)); - } - - /** - * Unpacks the compressed character translation table. - * - * @param packed the packed character translation table - * @return the unpacked character translation table - */ - private static char [] zzUnpackCMap(String packed) { - char [] map = new char[0x10000]; - int i = 0; /* index in packed string */ - int j = 0; /* index in unpacked array */ - while (i < 2238) { - int count = packed.charAt(i++); - char value = packed.charAt(i++); - do map[j++] = value; while (--count > 0); - } - return map; - } - - public final int getTokenStart(){ - return zzStartRead; - } - - public final int getTokenEnd(){ - return getTokenStart() + yylength(); - } - - public void reset(CharSequence buffer, int start, int end,int initialState){ - zzBuffer = buffer; - zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer); - zzCurrentPos = zzMarkedPos = zzStartRead = start; - zzPushbackPos = 0; - zzAtEOF = false; - zzAtBOL = true; - zzEndRead = end; - yybegin(initialState); - } - - /** - * Refills the input buffer. - * - * @return <code>false</code>, iff there was new input. - * - * @exception java.io.IOException if any I/O-Error occurs - */ - private boolean zzRefill() throws java.io.IOException { - return true; - } - - - /** - * Returns the current lexical state. - */ - public final int yystate() { - return zzLexicalState; - } - - - /** - * Enters a new lexical state - * - * @param newState the new lexical state - */ - public final void yybegin(int newState) { - zzLexicalState = newState; - } - - - /** - * Returns the text matched by the current regular expression. - */ - public final CharSequence yytext() { - return zzBuffer.subSequence(zzStartRead, zzMarkedPos); - } - - - /** - * Returns the character at position <tt>pos</tt> from the - * matched text. - * - * It is equivalent to yytext().charAt(pos), but faster - * - * @param pos the position of the character to fetch. - * A value from 0 to yylength()-1. - * - * @return the character at position pos - */ - public final char yycharat(int pos) { - return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos); - } - - - /** - * Returns the length of the matched text region. - */ - public final int yylength() { - return zzMarkedPos-zzStartRead; - } - - - /** - * Reports an error that occured while scanning. - * - * In a wellformed scanner (no or only correct usage of - * yypushback(int) and a match-all fallback rule) this method - * will only be called with things that "Can't Possibly Happen". - * If this method is called, something is seriously wrong - * (e.g. a JFlex bug producing a faulty scanner etc.). - * - * Usual syntax/scanner level error handling should be done - * in error fallback rules. - * - * @param errorCode the code of the errormessage to display - */ - private void zzScanError(int errorCode) { - String message; - try { - message = ZZ_ERROR_MSG[errorCode]; - } - catch (ArrayIndexOutOfBoundsException e) { - message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; - } - - throw new Error(message); - } - - - /** - * Pushes the specified amount of characters back into the input stream. - * - * They will be read again by then next call of the scanning method - * - * @param number the number of characters to be read again. - * This number must not be greater than yylength()! - */ - public void yypushback(int number) { - if ( number > yylength() ) - zzScanError(ZZ_PUSHBACK_2BIG); - - zzMarkedPos -= number; - } - - - /** - * Contains user EOF-code, which will be executed exactly once, - * when the end of file is reached - */ - private void zzDoEOF() { - if (!zzEOFDone) { - zzEOFDone = true; - - } - } - - - /** - * Resumes scanning until the next regular expression is matched, - * the end of input is encountered or an I/O-Error occurs. - * - * @return the next token - * @exception java.io.IOException if any I/O-Error occurs - */ - public IElementType advance() throws java.io.IOException { - int zzInput; - int zzAction; - - // cached fields: - int zzCurrentPosL; - int zzMarkedPosL; - int zzEndReadL = zzEndRead; - CharSequence zzBufferL = zzBuffer; - char[] zzBufferArrayL = zzBufferArray; - char [] zzCMapL = ZZ_CMAP; - - int [] zzTransL = ZZ_TRANS; - int [] zzRowMapL = ZZ_ROWMAP; - int [] zzAttrL = ZZ_ATTRIBUTE; - - while (true) { - zzMarkedPosL = zzMarkedPos; - - zzAction = -1; - - zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; - - zzState = ZZ_LEXSTATE[zzLexicalState]; - - - zzForAction: { - while (true) { - - if (zzCurrentPosL < zzEndReadL) - zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); - else if (zzAtEOF) { - zzInput = YYEOF; - break zzForAction; - } - else { - // store back cached positions - zzCurrentPos = zzCurrentPosL; - zzMarkedPos = zzMarkedPosL; - boolean eof = zzRefill(); - // get translated positions and possibly new buffer - zzCurrentPosL = zzCurrentPos; - zzMarkedPosL = zzMarkedPos; - zzBufferL = zzBuffer; - zzEndReadL = zzEndRead; - if (eof) { - zzInput = YYEOF; - break zzForAction; - } - else { - zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); - } - } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; - if (zzNext == -1) break zzForAction; - zzState = zzNext; - - int zzAttributes = zzAttrL[zzState]; - if ( (zzAttributes & 1) == 1 ) { - zzAction = zzState; - zzMarkedPosL = zzCurrentPosL; - if ( (zzAttributes & 8) == 8 ) break zzForAction; - } - - } - } - - // store back cached position - zzMarkedPos = zzMarkedPosL; - - switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { - case 68: - { return JavaTokenType.LONG_KEYWORD; - } - case 111: break; - case 99: - { return JavaTokenType.PRIVATE_KEYWORD; - } - case 112: break; - case 27: - { return JavaTokenType.COMMA; - } - case 113: break; - case 23: - { return JavaTokenType.RBRACE; - } - case 114: break; - case 22: - { return JavaTokenType.LBRACE; - } - case 115: break; - case 65: - { return JavaTokenType.THIS_KEYWORD; - } - case 116: break; - case 83: - { return JavaTokenType.CLASS_KEYWORD; - } - case 117: break; - case 14: - { return JavaTokenType.PLUS; - } - case 118: break; - case 54: - { return JavaTokenType.XOREQ; - } - case 119: break; - case 62: - { return JavaTokenType.INT_KEYWORD; - } - case 120: break; - case 80: - { return JavaTokenType.SHORT_KEYWORD; - } - case 121: break; - case 44: - { return JavaTokenType.EQEQ; - } - case 122: break; - case 67: - { return myEnumKeyword ? JavaTokenType.ENUM_KEYWORD : JavaTokenType.IDENTIFIER; - } - case 123: break; - case 101: - { return JavaTokenType.ABSTRACT_KEYWORD; - } - case 124: break; - case 69: - { return JavaTokenType.NULL_KEYWORD; - } - case 125: break; - case 95: - { return JavaTokenType.EXTENDS_KEYWORD; - } - case 126: break; - case 51: - { return JavaTokenType.LTLT; - } - case 127: break; - case 20: - { return JavaTokenType.LPARENTH; - } - case 128: break; - case 12: - { return JavaTokenType.EXCL; - } - case 129: break; - case 102: - { return JavaTokenType.STRICTFP_KEYWORD; - } - case 130: break; - case 34: - { return JavaTokenType.DIVEQ; - } - case 131: break; - case 89: - { return JavaTokenType.STATIC_KEYWORD; - } - case 132: break; - case 39: - { return JavaTokenType.MINUSMINUS; - } - case 133: break; - case 76: - { return JavaTokenType.FALSE_KEYWORD; - } - case 134: break; - case 1: - { return JavaTokenType.BAD_CHARACTER; - } - case 135: break; - case 90: - { return JavaTokenType.SWITCH_KEYWORD; - } - case 136: break; - case 26: - { return JavaTokenType.SEMICOLON; - } - case 137: break; - case 18: - { return JavaTokenType.XOR; - } - case 138: break; - case 38: - { return JavaTokenType.DOUBLE_LITERAL; - } - case 139: break; - case 46: - { return JavaTokenType.OREQ; - } - case 140: break; - case 11: - { return JavaTokenType.EQ; - } - case 141: break; - case 4: - { return JavaTokenType.DIV; - } - case 142: break; - case 66: - { return JavaTokenType.ELSE_KEYWORD; - } - case 143: break; - case 61: - { return JavaTokenType.NEW_KEYWORD; - } - case 144: break; - case 58: - { return JavaTokenType.ELLIPSIS; - } - case 145: break; - case 53: - { return JavaTokenType.ANDAND; - } - case 146: break; - case 81: - { return JavaTokenType.BREAK_KEYWORD; - } - case 147: break; - case 9: - { return JavaTokenType.CHARACTER_LITERAL; - } - case 148: break; - case 52: - { return JavaTokenType.ANDEQ; - } - case 149: break; - case 6: - { return JavaTokenType.INTEGER_LITERAL; - } - case 150: break; - case 77: - { return JavaTokenType.FLOAT_KEYWORD; - } - case 151: break; - case 10: - { return JavaTokenType.STRING_LITERAL; - } - case 152: break; - case 72: - { return JavaTokenType.CHAR_KEYWORD; - } - case 153: break; - case 91: - { return JavaTokenType.NATIVE_KEYWORD; - } - case 154: break; - case 43: - { return JavaTokenType.DO_KEYWORD; - } - case 155: break; - case 7: - { return JavaTokenType.DOT; - } - case 156: break; - case 28: - { return JavaTokenType.TILDE; - } - case 157: break; - case 110: - { return JavaTokenType.SYNCHRONIZED_KEYWORD; - } - case 158: break; - case 32: - { return JavaTokenType.END_OF_LINE_COMMENT; - } - case 159: break; - case 35: - { return JavaTokenType.ASTERISKEQ; - } - case 160: break; - case 79: - { return JavaTokenType.SUPER_KEYWORD; - } - case 161: break; - case 40: - { return JavaTokenType.MINUSEQ; - } - case 162: break; - case 63: - { return JavaTokenType.LTLTEQ; - } - case 163: break; - case 73: - { return JavaTokenType.GOTO_KEYWORD; - } - case 164: break; - case 25: - { return JavaTokenType.RBRACKET; - } - case 165: break; - case 33: - { return JavaTokenType.C_STYLE_COMMENT; - } - case 166: break; - case 15: - { return JavaTokenType.LT; - } - case 167: break; - case 42: - { return JavaTokenType.IF_KEYWORD; - } - case 168: break; - case 8: - { return JavaTokenType.MINUS; - } - case 169: break; - case 85: - { return JavaTokenType.WHILE_KEYWORD; - } - case 170: break; - case 70: - { return JavaTokenType.BYTE_KEYWORD; - } - case 171: break; - case 96: - { return JavaTokenType.FINALLY_KEYWORD; - } - case 172: break; - case 74: - { return JavaTokenType.VOID_KEYWORD; - } - case 173: break; - case 29: - { return JavaTokenType.QUEST; - } - case 174: break; - case 19: - { return JavaTokenType.PERC; - } - case 175: break; - case 109: - { return JavaTokenType.IMPLEMENTS_KEYWORD; - } - case 176: break; - case 86: - { return JavaTokenType.THROWS_KEYWORD; - } - case 177: break; - case 41: - { return JavaTokenType.ARROW; - } - case 178: break; - case 78: - { return JavaTokenType.FINAL_KEYWORD; - } - case 179: break; - case 93: - { return JavaTokenType.DOUBLE_KEYWORD; - } - case 180: break; - case 88: - { return myAssertKeyword ? JavaTokenType.ASSERT_KEYWORD : JavaTokenType.IDENTIFIER; - } - case 181: break; - case 107: - { return JavaTokenType.PROTECTED_KEYWORD; - } - case 182: break; - case 103: - { return JavaTokenType.CONTINUE_KEYWORD; - } - case 183: break; - case 100: - { return JavaTokenType.PACKAGE_KEYWORD; - } - case 184: break; - case 16: - { return JavaTokenType.GT; - } - case 185: break; - case 24: - { return JavaTokenType.LBRACKET; - } - case 186: break; - case 36: - { return JavaTokenType.LONG_LITERAL; - } - case 187: break; - case 60: - { return JavaTokenType.FOR_KEYWORD; - } - case 188: break; - case 98: - { return JavaTokenType.DEFAULT_KEYWORD; - } - case 189: break; - case 48: - { return JavaTokenType.PLUSEQ; - } - case 190: break; - case 87: - { return JavaTokenType.RETURN_KEYWORD; - } - case 191: break; - case 64: - { return JavaTokenType.TRUE_KEYWORD; - } - case 192: break; - case 49: - { return JavaTokenType.PLUSPLUS; - } - case 193: break; - case 47: - { return JavaTokenType.OROR; - } - case 194: break; - case 13: - { return JavaTokenType.OR; - } - case 195: break; - case 3: - { return JavaTokenType.IDENTIFIER; - } - case 196: break; - case 55: - { return JavaTokenType.PERCEQ; - } - case 197: break; - case 30: - { return JavaTokenType.COLON; - } - case 198: break; - case 104: - { return JavaTokenType.VOLATILE_KEYWORD; - } - case 199: break; - case 106: - { return JavaTokenType.INTERFACE_KEYWORD; - } - case 200: break; - case 108: - { return JavaTokenType.INSTANCEOF_KEYWORD; - } - case 201: break; - case 105: - { return JavaTokenType.TRANSIENT_KEYWORD; - } - case 202: break; - case 97: - { return JavaTokenType.BOOLEAN_KEYWORD; - } - case 203: break; - case 71: - { return JavaTokenType.CASE_KEYWORD; - } - case 204: break; - case 5: - { return JavaTokenType.ASTERISK; - } - case 205: break; - case 92: - { return JavaTokenType.IMPORT_KEYWORD; - } - case 206: break; - case 31: - { return JavaTokenType.AT; - } - case 207: break; - case 45: - { return JavaTokenType.NE; - } - case 208: break; - case 59: - { return JavaTokenType.TRY_KEYWORD; - } - case 209: break; - case 82: - { return JavaTokenType.CATCH_KEYWORD; - } - case 210: break; - case 37: - { return JavaTokenType.FLOAT_LITERAL; - } - case 211: break; - case 17: - { return JavaTokenType.AND; - } - case 212: break; - case 75: - { return JavaTokenType.THROW_KEYWORD; - } - case 213: break; - case 57: - { return JavaDocElementType.DOC_COMMENT; - } - case 214: break; - case 56: - { return JavaTokenType.DOUBLE_COLON; - } - case 215: break; - case 21: - { return JavaTokenType.RPARENTH; - } - case 216: break; - case 2: - { return JavaTokenType.WHITE_SPACE; - } - case 217: break; - case 94: - { return JavaTokenType.PUBLIC_KEYWORD; - } - case 218: break; - case 50: - { return JavaTokenType.LE; - } - case 219: break; - case 84: - { return JavaTokenType.CONST_KEYWORD; - } - case 220: break; - default: - if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { - zzAtEOF = true; - zzDoEOF(); - return null; - } - else { - zzScanError(ZZ_NO_MATCH); - } - } - } - } - - -} diff --git a/java/java-psi-impl/src/com/intellij/psi/PsiDiamondTypeImpl.java b/java/java-psi-impl/src/com/intellij/psi/PsiDiamondTypeImpl.java index 49b0b557ef7e..e1116894f14f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/PsiDiamondTypeImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/PsiDiamondTypeImpl.java @@ -22,8 +22,13 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.codeStyle.JavaCodeStyleManager; +import com.intellij.psi.infos.CandidateInfo; import com.intellij.psi.infos.MethodCandidateInfo; +import com.intellij.psi.scope.PsiConflictResolver; +import com.intellij.psi.scope.conflictResolvers.JavaMethodsConflictResolver; +import com.intellij.psi.scope.processor.MethodCandidatesProcessor; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; @@ -33,9 +38,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; +import java.util.*; /** * @author anna @@ -139,10 +142,7 @@ public class PsiDiamondTypeImpl extends PsiDiamondType { final PsiSubstitutor inferredSubstitutor = ourDiamondGuard.doPreventingRecursion(context, false, new Computable<PsiSubstitutor>() { @Override public PsiSubstitutor compute() { - final PsiMethod constructor = findConstructor(psiClass, newExpression); - PsiTypeParameter[] params = getAllTypeParams(constructor, psiClass); - - final PsiMethod staticFactory = generateStaticFactory(constructor, psiClass, params, newExpression.getClassReference()); + final PsiMethod staticFactory = findConstructorStaticFactory(psiClass, newExpression); if (staticFactory == null) { return null; } @@ -164,6 +164,11 @@ public class PsiDiamondTypeImpl extends PsiDiamondType { final PsiJavaCodeReferenceElement classOrAnonymousClassReference = newExpression.getClassOrAnonymousClassReference(); LOG.assertTrue(classOrAnonymousClassReference != null); final DiamondInferenceResult result = new DiamondInferenceResult(classOrAnonymousClassReference.getReferenceName() + "<>"); + + if (PsiUtil.isRawSubstitutor(staticFactory, inferredSubstitutor)) { + return result; + } + for (PsiTypeParameter parameter : parameters) { for (PsiTypeParameter classParameter : classParameters) { if (Comparing.strEqual(classParameter.getName(), parameter.getName())) { @@ -177,14 +182,42 @@ public class PsiDiamondTypeImpl extends PsiDiamondType { @Nullable - private static PsiMethod findConstructor(PsiClass containingClass, PsiNewExpression newExpression) { + private static PsiMethod findConstructorStaticFactory(final PsiClass containingClass, PsiNewExpression newExpression) { final PsiExpressionList argumentList = newExpression.getArgumentList(); - final Project project = newExpression.getProject(); - final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); - final PsiResolveHelper resolveHelper = facade.getResolveHelper(); - final JavaResolveResult result = - resolveHelper.resolveConstructor(facade.getElementFactory().createType(containingClass, PsiSubstitutor.EMPTY), argumentList, argumentList); - return (PsiMethod)result.getElement(); + if (argumentList == null) return null; + + final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(newExpression); + final List<CandidateInfo> conflicts = new ArrayList<CandidateInfo>(); + PsiMethod[] constructors = containingClass.getConstructors(); + if (constructors.length == 0) { + //default constructor + constructors = new PsiMethod[] {null}; + } + + final PsiConflictResolver[] conflictResolvers = {new JavaMethodsConflictResolver(argumentList, languageLevel)}; + final MethodCandidatesProcessor processor = new MethodCandidatesProcessor(argumentList, argumentList.getContainingFile(), conflictResolvers, conflicts) { + @Override + protected boolean isAccepted(PsiMethod candidate) { + return true; + } + + @Override + protected PsiClass getContainingClass(PsiMethod method) { + return containingClass; + } + }; + processor.setArgumentList(argumentList); + + for (PsiMethod constructor : constructors) { + final PsiTypeParameter[] params = getAllTypeParams(constructor, containingClass); + final PsiMethod staticFactory = generateStaticFactory(constructor, containingClass, params, newExpression.getClassReference()); + if (staticFactory != null) { + processor.add(staticFactory, PsiSubstitutor.EMPTY); + } + } + + final JavaResolveResult[] result = processor.getResult(); + return result.length == 1 ? (PsiMethod)result[0].getElement() : null; } @Nullable @@ -220,7 +253,11 @@ public class PsiDiamondTypeImpl extends PsiDiamondType { PsiTypeParameter[] params, PsiJavaCodeReferenceElement reference) { final StringBuilder buf = new StringBuilder(); - buf.append("public static "); + buf.append(constructor != null ? constructor.getModifierList().getText() : containingClass.getModifierList().getText()); + if (buf.length() > 0) { + buf.append(" "); + } + buf.append("static "); buf.append("<"); buf.append(StringUtil.join(params, new Function<PsiTypeParameter, String>() { @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/EmptySubstitutorImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/EmptySubstitutorImpl.java index dc8a2e8eeef8..c03bb1ce3821 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/EmptySubstitutorImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/EmptySubstitutorImpl.java @@ -75,4 +75,6 @@ public final class EmptySubstitutorImpl extends EmptySubstitutor { return true; } + @Override + public void ensureValid() { } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/ExpressionConverter.java b/java/java-psi-impl/src/com/intellij/psi/impl/ExpressionConverter.java new file mode 100644 index 000000000000..60c054aeb80c --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/ExpressionConverter.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2014 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 com.intellij.psi.impl; + +import com.intellij.lang.Language; +import com.intellij.lang.LanguageExtension; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.Nullable; + +/** + * @author Maxim.Medvedev + */ +public abstract class ExpressionConverter { + public static final LanguageExtension<ExpressionConverter> EP = + new LanguageExtension<ExpressionConverter>("com.intellij.expressionConverter"); + + protected abstract PsiElement convert(PsiElement expression, Project project); + + @Nullable + public static PsiElement getExpression(PsiElement expression, Language language, Project project) { + if (expression.getLanguage() == language) return expression; + + final ExpressionConverter converter = EP.forLanguage(language); + if (converter == null) return null; + return converter.convert(expression, project); + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java index 3f4cea44d90a..748d907aec47 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java @@ -925,7 +925,7 @@ public class PsiClassImplUtil { final PsiMethod[] methodsByName = psiClass.findMethodsByName(name, false); final List<Pair<PsiMethod, PsiSubstitutor>> ret = new ArrayList<Pair<PsiMethod, PsiSubstitutor>>(methodsByName.length); for (final PsiMethod method : methodsByName) { - ret.add(new Pair<PsiMethod, PsiSubstitutor>(method, PsiSubstitutor.EMPTY)); + ret.add(Pair.create(method, PsiSubstitutor.EMPTY)); } return ret; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiImplUtil.java index 22518474710f..2e666639d566 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiImplUtil.java @@ -481,8 +481,8 @@ public class PsiImplUtil { } public static PsiType normalizeWildcardTypeByPosition(@NotNull PsiType type, @NotNull PsiExpression expression) { - LOG.assertTrue(expression.isValid()); - LOG.assertTrue(type.isValid()); + PsiUtilCore.ensureValid(expression); + PsiUtil.ensureValidType(type); PsiExpression toplevel = expression; while (toplevel.getParent() instanceof PsiArrayAccessExpression && diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java index 05819c471a27..2ededda029f8 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java @@ -168,7 +168,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ANNOTATION, level(context)), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiAnnotation)) { - throw new IncorrectOperationException("Incorrect annotation \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect annotation '" + text + "'"); } return (PsiAnnotation)element; } @@ -194,7 +194,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final PsiJavaFile aFile = createDummyJavaFile(StringUtil.join("class _Dummy_ {\n", body, "\n}")); final PsiClass[] classes = aFile.getClasses(); if (classes.length != 1) { - throw new IncorrectOperationException("Incorrect class \"" + body + "\"."); + throw new IncorrectOperationException("Incorrect class '" + body + "'"); } return classes[0]; } @@ -205,7 +205,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level(context)), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiField)) { - throw new IncorrectOperationException("Incorrect field \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect field '" + text + "'"); } return (PsiField)element; } @@ -216,7 +216,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiMethod)) { - throw newException("Incorrect method \"" + text + "\".", holder); + throw newException("Incorrect method '" + text + "'", holder); } return (PsiMethod)element; } @@ -234,7 +234,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, PARAMETER, level(context)), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiParameter)) { - throw new IncorrectOperationException("Incorrect parameter \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect parameter '" + text + "'"); } return (PsiParameter)element; } @@ -245,7 +245,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, RESOURCE, level(context)), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiResourceVariable)) { - throw new IncorrectOperationException("Incorrect resource \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect resource '" + text + "'"); } return (PsiResourceVariable)element; } @@ -259,10 +259,11 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { @NotNull @Override public PsiTypeElement createTypeElementFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException { - final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE, level(context)), context); + final LanguageLevel level = level(context); + final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE, level), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiTypeElement)) { - throw new IncorrectOperationException("Incorrect type \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect type '" + text + "' (" + level + ")"); } return (PsiTypeElement)element; } @@ -289,7 +290,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, wrapper, level(context)), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiJavaCodeReferenceElement)) { - throw new IncorrectOperationException("Incorrect reference \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect reference '" + text + "'"); } return (PsiJavaCodeReferenceElement)element; } @@ -300,7 +301,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CODE_BLOCK, level(context), true), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiCodeBlock)) { - throw new IncorrectOperationException("Incorrect code block \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect code block '" + text + "'"); } return (PsiCodeBlock)element; } @@ -311,7 +312,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, STATEMENT, level(context)), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiStatement)) { - throw new IncorrectOperationException("Incorrect statement \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect statement '" + text + "'"); } return (PsiStatement)element; } @@ -322,7 +323,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, EXPRESSION, level(context)), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiExpression)) { - throw new IncorrectOperationException("Incorrect expression \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect expression '" + text + "'"); } return (PsiExpression)element; } @@ -339,7 +340,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiTypeParameter)) { - throw new IncorrectOperationException("Incorrect type parameter \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect type parameter '" + text + "'"); } return (PsiTypeParameter)element; } @@ -359,7 +360,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { } } - throw new IncorrectOperationException("Incorrect comment \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect comment '" + text + "'"); } @NotNull @@ -368,7 +369,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ENUM_CONSTANT, level(context)), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiEnumConstant)) { - throw new IncorrectOperationException("Incorrect enum constant \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect enum constant '" + text + "'"); } return (PsiEnumConstant)element; } @@ -378,7 +379,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { public PsiType createPrimitiveType(@NotNull final String text, @NotNull final PsiAnnotation[] annotations) throws IncorrectOperationException { final PsiPrimitiveType primitiveType = getPrimitiveType(text); if (primitiveType == null) { - throw new IncorrectOperationException("Incorrect primitive type \"" + text + "\"."); + throw new IncorrectOperationException("Incorrect primitive type '" + text + "'"); } return annotations.length == 0 ? primitiveType : new PsiPrimitiveType(text, annotations); } @@ -396,9 +397,7 @@ public class PsiJavaParserFacadeImpl implements PsiJavaParserFacade { if (root instanceof JavaDummyElement) { final Throwable cause = ((JavaDummyElement)root).getParserError(); if (cause != null) { - return new IncorrectOperationException(msg) { - @Override public Throwable getCause() { return cause; } - }; + return new IncorrectOperationException(msg, cause); } } return new IncorrectOperationException(msg); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java index e7e3dd073e3c..994bc1ef0976 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSubstitutorImpl.java @@ -171,7 +171,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor { return newBound; } - return rebound(wildcardType, newBound); + return newBound == PsiType.NULL ? newBound : rebound(wildcardType, newBound); } } @@ -395,7 +395,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor { final PsiType[] boundTypes = typeParameter.getExtendsListTypes(); for (PsiType boundType : boundTypes) { if (TypeConversionUtil.isAssignable(erasure, boundType)) { - return boundType; + return boundType.accept(mySimpleSubstitutionVisitor); } } } @@ -533,14 +533,22 @@ public class PsiSubstitutorImpl implements PsiSubstitutor { @Override public boolean isValid() { - Collection<PsiType> substitutorValues = mySubstitutionMap.values(); - for (PsiType type : substitutorValues) { + for (PsiType type : mySubstitutionMap.values()) { if (type != null && !type.isValid()) return false; } return true; } @Override + public void ensureValid() { + for (PsiType type : mySubstitutionMap.values()) { + if (type != null) { + PsiUtil.ensureValidType(type); + } + } + } + + @Override @NotNull public Map<PsiTypeParameter, PsiType> getSubstitutionMap() { return Collections.unmodifiableMap(mySubstitutionMap); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java index f4f9e881d4ba..d70fa1f4be4b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiSuperMethodImplUtil.java @@ -184,7 +184,7 @@ public class PsiSuperMethodImplUtil { // methods must be inherited from unrelated classes, so flatten hierarchy here // class C implements SAM1, SAM2 { void methodimpl() {} } //hms.getSuperSignatures().remove(aSuper); - flattened.add(new Pair<MethodSignature, HierarchicalMethodSignature>(signature, aSuper)); + flattened.add(Pair.create(signature, aSuper)); } } putInMap(aClass, result, map, hms, signature); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/ImplicitVariableImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/ImplicitVariableImpl.java new file mode 100644 index 000000000000..b6333d42c796 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/ImplicitVariableImpl.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2014 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 com.intellij.psi.impl.light; + +import com.intellij.psi.*; +import com.intellij.psi.search.SearchScope; +import com.intellij.psi.search.LocalSearchScope; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; + +/** + * @author dsl + */ +public abstract class ImplicitVariableImpl extends LightVariableBase implements ImplicitVariable { + + public ImplicitVariableImpl(PsiManager manager, PsiIdentifier nameIdentifier, PsiType type, boolean writable, PsiElement scope) { + super(manager, nameIdentifier, type, writable, scope); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof JavaElementVisitor) { + ((JavaElementVisitor)visitor).visitImplicitVariable(this); + } + else { + visitor.visitElement(this); + } + } + + public String toString() { + return "Implicit variable:" + getName(); + } + + @Override + public void setInitializer(PsiExpression initializer) throws IncorrectOperationException { + throw new IncorrectOperationException(); + } + + @Override + @NotNull + public SearchScope getUseScope() { + return new LocalSearchScope(getDeclarationScope()); + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightFieldBuilder.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightFieldBuilder.java new file mode 100644 index 000000000000..72256079a0fd --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightFieldBuilder.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2014 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 com.intellij.psi.impl.light; + +import com.intellij.lang.java.JavaLanguage; +import com.intellij.psi.*; +import com.intellij.psi.javadoc.PsiDocComment; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Maxim.Medvedev + */ +public class LightFieldBuilder extends LightVariableBuilder<LightFieldBuilder> implements PsiField { + private PsiClass myContainingClass = null; + private PsiExpression myInitializer = null; + private PsiDocComment myDocComment = null; + private boolean myIsDeprecated = false; + + public LightFieldBuilder(@NotNull String name, @NotNull String type, @NotNull PsiElement navigationElement) { + super(name, JavaPsiFacade.getElementFactory(navigationElement.getProject()).createTypeFromText(type, navigationElement), + navigationElement); + } + + public LightFieldBuilder(@NotNull String name, @NotNull PsiType type, @NotNull PsiElement navigationElement) { + super(name, type, navigationElement); + } + + public LightFieldBuilder(PsiManager manager, @NotNull String name, @NotNull PsiType type) { + super(manager, name, type, JavaLanguage.INSTANCE); + } + + public LightFieldBuilder setContainingClass(PsiClass psiClass) { + myContainingClass = psiClass; + return this; + } + + @Override + public void setInitializer(@Nullable PsiExpression initializer) throws IncorrectOperationException { + myInitializer = initializer; + } + + @Override + public PsiExpression getInitializer() { + return myInitializer; + } + + @Override + public PsiDocComment getDocComment() { + return myDocComment; + } + + public LightFieldBuilder setDocComment(PsiDocComment docComment) { + myDocComment = docComment; + return this; + } + + @Override + public boolean isDeprecated() { + return myIsDeprecated; + } + + public LightFieldBuilder setIsDeprecated(boolean isDeprecated) { + myIsDeprecated = isDeprecated; + return this; + } + + @Override + public PsiClass getContainingClass() { + return myContainingClass; + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightMethodBuilder.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightMethodBuilder.java new file mode 100644 index 000000000000..ae2ab543eab9 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightMethodBuilder.java @@ -0,0 +1,440 @@ +/* + * Copyright 2000-2014 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 com.intellij.psi.impl.light; + +import com.intellij.psi.OriginInfoAwareElement; +import com.intellij.lang.Language; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.navigation.ItemPresentation; +import com.intellij.navigation.ItemPresentationProviders; +import com.intellij.openapi.util.Computable; +import com.intellij.psi.*; +import com.intellij.psi.impl.ElementPresentationUtil; +import com.intellij.psi.impl.PsiClassImplUtil; +import com.intellij.psi.impl.PsiImplUtil; +import com.intellij.psi.impl.PsiSuperMethodImplUtil; +import com.intellij.psi.javadoc.PsiDocComment; +import com.intellij.psi.search.SearchScope; +import com.intellij.psi.util.MethodSignature; +import com.intellij.psi.util.MethodSignatureBackedByPsiMethod; +import com.intellij.ui.RowIcon; +import com.intellij.util.IncorrectOperationException; +import com.intellij.util.PlatformIcons; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.List; + +/** + * @author peter + */ +public class LightMethodBuilder extends LightElement implements PsiMethod, OriginInfoAwareElement { + private final String myName; + private Computable<PsiType> myReturnType; + private final PsiModifierList myModifierList; + private final PsiParameterList myParameterList; + private final PsiTypeParameterList myTypeParameterList; + private final PsiReferenceList myThrowsList; + private Icon myBaseIcon; + private PsiClass myContainingClass; + private boolean myConstructor; + private String myMethodKind = "LightMethodBuilder"; + private String myOriginInfo = null; + + public LightMethodBuilder(PsiClass constructedClass, Language language) { + this(constructedClass.getManager(), language, constructedClass.getName()); + setContainingClass(constructedClass); + } + + public LightMethodBuilder(PsiManager manager, String name) { + this(manager, JavaLanguage.INSTANCE, name); + } + + public LightMethodBuilder(PsiManager manager, Language language, String name) { + this(manager, language, name, new LightParameterListBuilder(manager, language), new LightModifierList(manager, language)); + } + + public LightMethodBuilder(PsiManager manager, + Language language, + String name, + PsiParameterList parameterList, + PsiModifierList modifierList) { + this(manager, language, name, parameterList, modifierList, + new LightReferenceListBuilder(manager, language, PsiReferenceList.Role.THROWS_LIST), + new LightTypeParameterListBuilder(manager, language)); + } + + public LightMethodBuilder(PsiManager manager, + Language language, + String name, + PsiParameterList parameterList, + PsiModifierList modifierList, + PsiReferenceList throwsList, + PsiTypeParameterList typeParameterList) { + super(manager, language); + myName = name; + myParameterList = parameterList; + myModifierList = modifierList; + myThrowsList = throwsList; + myTypeParameterList = typeParameterList; + } + + @Override + public ItemPresentation getPresentation() { + return ItemPresentationProviders.getItemPresentation(this); + } + + @Override + public boolean hasTypeParameters() { + return PsiImplUtil.hasTypeParameters(this); + } + + @Override + @NotNull + public PsiTypeParameter[] getTypeParameters() { + return PsiImplUtil.getTypeParameters(this); + } + + @Override + public PsiTypeParameterList getTypeParameterList() { + return myTypeParameterList; + } + + @Override + public PsiDocComment getDocComment() { + //todo + return null; + } + + @Override + public boolean isDeprecated() { + return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this); + } + + @Override + public PsiElement setName(@NotNull String name) throws IncorrectOperationException { + final String className = myContainingClass == null ? "null" : myContainingClass.getQualifiedName(); + throw new UnsupportedOperationException("Please don't rename light methods: writable=" + isWritable() + + "; class=" + getClass() + + "; name=" + getName() + + "; inClass=" + className); + } + + @Override + @NotNull + public String getName() { + return myName; + } + + @Override + @NotNull + public HierarchicalMethodSignature getHierarchicalMethodSignature() { + return PsiSuperMethodImplUtil.getHierarchicalMethodSignature(this); + } + + @Override + public boolean hasModifierProperty(@NotNull String name) { + return getModifierList().hasModifierProperty(name); + } + + @Override + @NotNull + public PsiModifierList getModifierList() { + return myModifierList; + } + + public LightMethodBuilder addModifiers(String... modifiers) { + for (String modifier : modifiers) { + addModifier(modifier); + } + return this; + } + + public LightMethodBuilder addModifier(String modifier) { + ((LightModifierList)myModifierList).addModifier(modifier); + return this; + } + + public LightMethodBuilder setModifiers(String... modifiers) { + ((LightModifierList)myModifierList).clearModifiers(); + addModifiers(modifiers); + return this; + } + + @Override + public PsiType getReturnType() { + return myReturnType == null ? null : myReturnType.compute(); + } + + public LightMethodBuilder setMethodReturnType(Computable<PsiType> returnType) { + myReturnType = returnType; + return this; + } + + public LightMethodBuilder setMethodReturnType(PsiType returnType) { + return setMethodReturnType(new Computable.PredefinedValueComputable<PsiType>(returnType)); + } + + public LightMethodBuilder setMethodReturnType(@NotNull final String returnType) { + return setMethodReturnType(new Computable.NotNullCachedComputable<PsiType>() { + @NotNull + @Override + protected PsiType internalCompute() { + return JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory().createTypeByFQClassName(returnType, getResolveScope()); + } + }); + } + + @Override + public PsiTypeElement getReturnTypeElement() { + return null; + } + + @Override + @NotNull + public PsiParameterList getParameterList() { + return myParameterList; + } + + public LightMethodBuilder addParameter(@NotNull PsiParameter parameter) { + ((LightParameterListBuilder)myParameterList).addParameter(parameter); + return this; + } + + public LightMethodBuilder addParameter(@NotNull String name, @NotNull String type) { + return addParameter(name, JavaPsiFacade.getElementFactory(getProject()).createTypeFromText(type, this)); + } + + public LightMethodBuilder addParameter(@NotNull String name, @NotNull PsiType type) { + return addParameter(new LightParameter(name, type, this, JavaLanguage.INSTANCE)); + } + + public LightMethodBuilder addParameter(@NotNull String name, @NotNull PsiType type, boolean isVarArgs) { + if (isVarArgs && !(type instanceof PsiEllipsisType)) { + type = new PsiEllipsisType(type); + } + return addParameter(new LightParameter(name, type, this, JavaLanguage.INSTANCE, isVarArgs)); + } + + public LightMethodBuilder addException(PsiClassType type) { + ((LightReferenceListBuilder)myThrowsList).addReference(type); + return this; + } + + public LightMethodBuilder addException(String fqName) { + ((LightReferenceListBuilder)myThrowsList).addReference(fqName); + return this; + } + + + @Override + @NotNull + public PsiReferenceList getThrowsList() { + return myThrowsList; + } + + @Override + public PsiCodeBlock getBody() { + return null; + } + + public LightMethodBuilder setConstructor(boolean constructor) { + myConstructor = constructor; + return this; + } + + @Override + public boolean isConstructor() { + return myConstructor; + } + + @Override + public boolean isVarArgs() { + return PsiImplUtil.isVarArgs(this); + } + + @Override + @NotNull + public MethodSignature getSignature(@NotNull PsiSubstitutor substitutor) { + return MethodSignatureBackedByPsiMethod.create(this, substitutor); + } + + @Override + public PsiIdentifier getNameIdentifier() { + return null; + } + + @Override + @NotNull + public PsiMethod[] findSuperMethods() { + return PsiSuperMethodImplUtil.findSuperMethods(this); + } + + @Override + @NotNull + public PsiMethod[] findSuperMethods(boolean checkAccess) { + return PsiSuperMethodImplUtil.findSuperMethods(this, checkAccess); + } + + @Override + @NotNull + public PsiMethod[] findSuperMethods(PsiClass parentClass) { + return PsiSuperMethodImplUtil.findSuperMethods(this, parentClass); + } + + @Override + @NotNull + public List<MethodSignatureBackedByPsiMethod> findSuperMethodSignaturesIncludingStatic(boolean checkAccess) { + return PsiSuperMethodImplUtil.findSuperMethodSignaturesIncludingStatic(this, checkAccess); + } + + @Override + public PsiMethod findDeepestSuperMethod() { + return PsiSuperMethodImplUtil.findDeepestSuperMethod(this); + } + + @Override + @NotNull + public PsiMethod[] findDeepestSuperMethods() { + return PsiSuperMethodImplUtil.findDeepestSuperMethods(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof JavaElementVisitor) { + ((JavaElementVisitor)visitor).visitMethod(this); + } + } + + @Override + public PsiClass getContainingClass() { + return myContainingClass; + } + + public LightMethodBuilder setContainingClass(PsiClass containingClass) { + myContainingClass = containingClass; + return this; + } + + public LightMethodBuilder setMethodKind(String debugKindName) { + myMethodKind = debugKindName; + return this; + } + + public String toString() { + return myMethodKind + ":" + getName(); + } + + @Override + public Icon getElementIcon(final int flags) { + Icon methodIcon = myBaseIcon != null ? myBaseIcon : + hasModifierProperty(PsiModifier.ABSTRACT) ? PlatformIcons.ABSTRACT_METHOD_ICON : PlatformIcons.METHOD_ICON; + RowIcon baseIcon = ElementPresentationUtil.createLayeredIcon(methodIcon, this, false); + return ElementPresentationUtil.addVisibilityIcon(this, flags, baseIcon); + } + + @Override + protected boolean isVisibilitySupported() { + return true; + } + + public LightMethodBuilder setBaseIcon(Icon baseIcon) { + myBaseIcon = baseIcon; + return this; + } + + @Override + public boolean isEquivalentTo(final PsiElement another) { + return PsiClassImplUtil.isMethodEquivalentTo(this, another); + } + + @Override + @NotNull + public SearchScope getUseScope() { + return PsiImplUtil.getMemberUseScope(this); + } + + @Nullable + @Override + public PsiFile getContainingFile() { + final PsiClass containingClass = getContainingClass(); + return containingClass == null ? null : containingClass.getContainingFile(); + } + + @Override + public PsiElement getContext() { + final PsiElement navElement = getNavigationElement(); + if (navElement != this) { + return navElement; + } + + final PsiClass cls = getContainingClass(); + if (cls != null) { + return cls; + } + + return getContainingFile(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + LightMethodBuilder that = (LightMethodBuilder)o; + + if (myConstructor != that.myConstructor) return false; + if (myBaseIcon != null ? !myBaseIcon.equals(that.myBaseIcon) : that.myBaseIcon != null) return false; + if (myContainingClass != null ? !myContainingClass.equals(that.myContainingClass) : that.myContainingClass != null) return false; + if (!myMethodKind.equals(that.myMethodKind)) return false; + if (!myModifierList.equals(that.myModifierList)) return false; + if (!myName.equals(that.myName)) return false; + if (!myParameterList.equals(that.myParameterList)) return false; + if (myReturnType != null ? !myReturnType.equals(that.myReturnType) : that.myReturnType != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = myName.hashCode(); + result = 31 * result + (myReturnType != null ? myReturnType.hashCode() : 0); + result = 31 * result + myModifierList.hashCode(); + result = 31 * result + myParameterList.hashCode(); + result = 31 * result + (myBaseIcon != null ? myBaseIcon.hashCode() : 0); + result = 31 * result + (myContainingClass != null ? myContainingClass.hashCode() : 0); + result = 31 * result + (myConstructor ? 1 : 0); + result = 31 * result + myMethodKind.hashCode(); + return result; + } + + public LightMethodBuilder addTypeParameter(PsiTypeParameter parameter) { + ((LightTypeParameterListBuilder)myTypeParameterList).addParameter(new LightTypeParameter(parameter)); + return this; + } + + @Nullable + @Override + public String getOriginInfo() { + return myOriginInfo; + } + + public void setOriginInfo(@Nullable String originInfo) { + myOriginInfo = originInfo; + } + +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightModifierList.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightModifierList.java index beabfe469619..4988c6b530ea 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightModifierList.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightModifierList.java @@ -118,6 +118,23 @@ public class LightModifierList extends LightElement implements PsiModifierList { return "PsiModifierList"; } + @Override + public String getText() { + StringBuilder buffer = new StringBuilder(); + + for (String modifier : PsiModifier.MODIFIERS) { + if (hasExplicitModifier(modifier)) { + buffer.append(modifier); + buffer.append(' '); + } + } + + if (buffer.length() > 0) { + buffer.delete(buffer.length() - 1, buffer.length()); + } + return buffer.toString(); + } + public String[] getModifiers() { return ArrayUtil.toStringArray(myModifiers); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightParameter.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightParameter.java new file mode 100644 index 000000000000..44834f7999e9 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightParameter.java @@ -0,0 +1,62 @@ +/* + * Copyright 2000-2014 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 com.intellij.psi.impl.light; + +import com.intellij.lang.Language; +import com.intellij.psi.*; +import org.jetbrains.annotations.NotNull; + +/** + * @author peter + */ +public class LightParameter extends LightVariableBuilder<LightVariableBuilder> implements PsiParameter { + public static final LightParameter[] EMPTY_ARRAY = new LightParameter[0]; + + private final PsiElement myDeclarationScope; + private final boolean myVarArgs; + + public LightParameter(@NotNull String name, @NotNull PsiType type, PsiElement declarationScope, Language language) { + this(name, type, declarationScope, language, type instanceof PsiEllipsisType); + } + + public LightParameter(@NotNull String name, @NotNull PsiType type, PsiElement declarationScope, Language language, boolean isVarArgs) { + super(declarationScope.getManager(), name, type, language); + myDeclarationScope = declarationScope; + myVarArgs = isVarArgs; + } + + @NotNull + @Override + public PsiElement getDeclarationScope() { + return myDeclarationScope; + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof JavaElementVisitor) { + ((JavaElementVisitor)visitor).visitParameter(this); + } + } + + public String toString() { + return "Light Parameter"; + } + + @Override + public boolean isVarArgs() { + return myVarArgs; + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightReferenceListBuilder.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightReferenceListBuilder.java new file mode 100644 index 000000000000..cfcc7a9267d8 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightReferenceListBuilder.java @@ -0,0 +1,106 @@ +/* + * Copyright 2000-2014 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 com.intellij.psi.impl.light; + +import com.intellij.lang.Language; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.psi.*; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Max Medvedev + */ +public class LightReferenceListBuilder extends LightElement implements PsiReferenceList { + private final List<PsiJavaCodeReferenceElement> myRefs = new ArrayList<PsiJavaCodeReferenceElement>(); + private PsiJavaCodeReferenceElement[] myCachedRefs = null; + private PsiClassType[] myCachedTypes = null; + private final Role myRole; + private final PsiElementFactory myFactory; + + public LightReferenceListBuilder(PsiManager manager, Role role) { + this(manager, JavaLanguage.INSTANCE, role); + } + + public LightReferenceListBuilder(PsiManager manager, Language language, Role role) { + super(manager, language); + myRole = role; + myFactory = JavaPsiFacade.getElementFactory(getProject()); + } + + @Override + public String toString() { + return "light reference list"; + } + + public void addReference(PsiClass aClass) { + addReference(aClass.getQualifiedName()); + } + + public void addReference(String qualifiedName) { + final PsiJavaCodeReferenceElement ref = myFactory.createReferenceElementByFQClassName(qualifiedName, getResolveScope()); + myRefs.add(ref); + } + + public void addReference(PsiClassType type) { + final PsiClass resolved = type.resolve(); + if (resolved == null) return; + + final PsiJavaCodeReferenceElement ref = myFactory.createReferenceElementByType(type); + myRefs.add(ref); + } + + @NotNull + @Override + public PsiJavaCodeReferenceElement[] getReferenceElements() { + if (myCachedRefs == null) { + if (myRefs.isEmpty()) { + myCachedRefs = PsiJavaCodeReferenceElement.EMPTY_ARRAY; + } + else { + myCachedRefs = ContainerUtil.toArray(myRefs, new PsiJavaCodeReferenceElement[myRefs.size()]); + } + } + return myCachedRefs; + } + + @NotNull + @Override + public PsiClassType[] getReferencedTypes() { + if (myCachedTypes == null) { + if (myRefs.isEmpty()) { + myCachedTypes = PsiClassType.EMPTY_ARRAY; + } + else { + final int size = myRefs.size(); + myCachedTypes = new PsiClassType[size]; + for (int i = 0; i < size; i++) { + myCachedTypes[i] = myFactory.createType(myRefs.get(i)); + } + } + } + + return myCachedTypes; + } + + @Override + public Role getRole() { + return myRole; + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightVariableBase.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightVariableBase.java new file mode 100644 index 000000000000..ca486682259b --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightVariableBase.java @@ -0,0 +1,166 @@ +/* + * Copyright 2000-2014 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 com.intellij.psi.impl.light; + +import com.intellij.psi.OriginInfoAwareElement; +import com.intellij.lang.Language; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.*; +import com.intellij.psi.impl.ElementPresentationUtil; +import com.intellij.psi.impl.PsiImplUtil; +import com.intellij.ui.RowIcon; +import com.intellij.util.IncorrectOperationException; +import com.intellij.util.PlatformIcons; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * @author ven + */ +public abstract class LightVariableBase extends LightElement implements PsiVariable, OriginInfoAwareElement { + protected PsiElement myScope; + protected PsiIdentifier myNameIdentifier; + protected PsiType myType; + protected final PsiModifierList myModifierList; + protected boolean myWritable; + private String myOriginInfo = null; + + public LightVariableBase(PsiManager manager, PsiIdentifier nameIdentifier, PsiType type, boolean writable, PsiElement scope) { + this(manager, nameIdentifier, JavaLanguage.INSTANCE, type, writable, scope); + } + + public LightVariableBase(PsiManager manager, PsiIdentifier nameIdentifier, Language language, PsiType type, boolean writable, PsiElement scope) { + super(manager, language); + myNameIdentifier = nameIdentifier; + myWritable = writable; + myType = type; + myScope = scope; + myModifierList = createModifierList(); + } + + protected PsiModifierList createModifierList() { + return new LightModifierList(getManager()); + } + + @NotNull + public PsiElement getDeclarationScope() { + return myScope; + } + + @Override + public PsiIdentifier getNameIdentifier() { + return myNameIdentifier; + } + + @Override + public boolean isValid() { + return myNameIdentifier == null || myNameIdentifier.isValid(); + } + + @Override + @NotNull + public String getName() { + return StringUtil.notNullize(getNameIdentifier().getText()); + } + + @Override + public PsiElement setName(@NotNull String name) throws IncorrectOperationException{ + PsiImplUtil.setName(getNameIdentifier(), name); + return this; + } + + @Override + @NotNull + public PsiType getType() { + if (myType == null) { + myType = computeType(); + } + return myType; + } + + @NotNull + protected PsiType computeType() { + return PsiType.VOID; + } + + @Override + @NotNull + public PsiTypeElement getTypeElement() { + return JavaPsiFacade.getInstance(getProject()).getElementFactory().createTypeElement(myType); + } + + @Override + public PsiModifierList getModifierList() { + return myModifierList; + } + + @Override + public boolean hasModifierProperty(@NotNull String name) { + return getModifierList().hasModifierProperty(name); + } + + @Override + public PsiExpression getInitializer() { + return null; + } + + @Override + public boolean hasInitializer() { + return false; + } + + @Override + public String getText() { + return myNameIdentifier.getText(); + } + + @Override + public Object computeConstantValue() { + return null; + } + + @Override + public void normalizeDeclaration() throws IncorrectOperationException { + } + + @Override + public boolean isWritable() { + return myWritable; + } + @Override + protected boolean isVisibilitySupported() { + return true; + } + + @Override + public Icon getElementIcon(final int flags) { + final RowIcon baseIcon = ElementPresentationUtil.createLayeredIcon(PlatformIcons.VARIABLE_ICON, this, false); + return ElementPresentationUtil.addVisibilityIcon(this, flags, baseIcon); + } + + @Nullable + @Override + public String getOriginInfo() { + return myOriginInfo; + } + + public void setOriginInfo(String originInfo) { + myOriginInfo = originInfo; + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java new file mode 100644 index 000000000000..fc2a90e24406 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightVariableBuilder.java @@ -0,0 +1,156 @@ +/* + * Copyright 2000-2014 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 com.intellij.psi.impl.light; + +import com.intellij.psi.OriginInfoAwareElement; +import com.intellij.lang.Language; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.navigation.NavigationItem; +import com.intellij.psi.*; +import com.intellij.psi.impl.ElementPresentationUtil; +import com.intellij.ui.RowIcon; +import com.intellij.util.IncorrectOperationException; +import com.intellij.util.PlatformIcons; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * @author peter + */ +public class LightVariableBuilder<T extends LightVariableBuilder> extends LightElement implements PsiVariable, NavigationItem, OriginInfoAwareElement { + private final String myName; + private final PsiType myType; + private volatile LightModifierList myModifierList; + private volatile Icon myBaseIcon = PlatformIcons.VARIABLE_ICON; + private String myOriginInfo; + + public LightVariableBuilder(@NotNull String name, @NotNull String type, @NotNull PsiElement navigationElement) { + this(name, JavaPsiFacade.getElementFactory(navigationElement.getProject()).createTypeFromText(type, navigationElement), navigationElement); + } + + public LightVariableBuilder(@NotNull String name, @NotNull PsiType type, @NotNull PsiElement navigationElement) { + this(navigationElement.getManager(), name, type, JavaLanguage.INSTANCE); + setNavigationElement(navigationElement); + } + + public LightVariableBuilder(PsiManager manager, @NotNull String name, @NotNull PsiType type, Language language) { + super(manager, language); + myName = name; + myType = type; + myModifierList = new LightModifierList(manager); + } + + @Override + public String toString() { + return "LightVariableBuilder:" + getName(); + } + + @NotNull + @Override + public PsiType getType() { + return myType; + } + + @Override + @NotNull + public PsiModifierList getModifierList() { + return myModifierList; + } + + public T setModifiers(String... modifiers) { + myModifierList = new LightModifierList(getManager(), getLanguage(), modifiers); + return (T)this; + } + + public T setModifierList(LightModifierList modifierList) { + myModifierList = modifierList; + return (T)this; + } + + @Override + public boolean hasModifierProperty(@NonNls @NotNull String name) { + return myModifierList.hasModifierProperty(name); + } + + @NotNull + @Override + public String getName() { + return myName; + } + + @Override + public PsiTypeElement getTypeElement() { + return null; + } + + @Override + public PsiExpression getInitializer() { + return null; + } + + @Override + public boolean hasInitializer() { + return false; + } + + @Override + public void normalizeDeclaration() throws IncorrectOperationException { + } + + @Override + public Object computeConstantValue() { + return null; + } + + @Override + public PsiIdentifier getNameIdentifier() { + return null; + } + + @Override + public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { + throw new UnsupportedOperationException("setName is not implemented yet in com.intellij.psi.impl.light.LightVariableBuilder"); + } + + @Override + protected boolean isVisibilitySupported() { + return true; + } + + @Override + public Icon getElementIcon(final int flags) { + final RowIcon baseIcon = ElementPresentationUtil.createLayeredIcon(myBaseIcon, this, false); + return ElementPresentationUtil.addVisibilityIcon(this, flags, baseIcon); + } + + public T setBaseIcon(Icon baseIcon) { + myBaseIcon = baseIcon; + return (T)this; + } + + @Nullable + @Override + public String getOriginInfo() { + return myOriginInfo; + } + + public void setOriginInfo(@Nullable String originInfo) { + myOriginInfo = originInfo; + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java index 77a45011144d..fe8193039998 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java @@ -169,7 +169,7 @@ public class PsiImmediateClassType extends PsiClassType.Stub { private enum TextType { PRESENTABLE, CANONICAL, INT_CANONICAL } private String getText(@NotNull TextType textType, boolean annotated) { - assert mySubstitutor.isValid(); + mySubstitutor.ensureValid(); StringBuilder buffer = new StringBuilder(); buildText(myClass, mySubstitutor, buffer, textType, annotated); return buffer.toString(); @@ -184,6 +184,9 @@ public class PsiImmediateClassType extends PsiClassType.Stub { ClassResolveResult baseResolveResult = ((PsiAnonymousClass)aClass).getBaseClassType().resolveGenerics(); PsiClass baseClass = baseResolveResult.getElement(); if (baseClass != null) { + if (textType == TextType.INT_CANONICAL) { + buffer.append("anonymous "); + } buildText(baseClass, baseResolveResult.getSubstitutor(), buffer, textType, false); } return; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java index 1b60c157e248..60cb54cefe6b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java @@ -376,6 +376,7 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme PsiFile containingFile = SharedImplUtil.getContainingFile(fileElement); boolean valid = containingFile != null && containingFile.isValid(); if (!valid) { + PsiUtilCore.ensureValid(this); LOG.error("invalid!"); return JavaResolveResult.EMPTY_ARRAY; } @@ -587,8 +588,8 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme text += parameterList.getText(); } PsiJavaCodeReferenceElement ref = facade.getParserFacade().createReferenceFromText(text, getParent()); - getTreeParent().replaceChildInternal(this, (TreeElement)ref.getNode()); ((PsiJavaCodeReferenceElementImpl)ref).setAnnotations(annotations); + getTreeParent().replaceChildInternal(this, (TreeElement)ref.getNode()); if (!preserveQualification) { JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocTokenImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocTokenImpl.java index 5fcf7791b850..85301458d047 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocTokenImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocTokenImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -23,7 +23,7 @@ import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; public class PsiDocTokenImpl extends LeafPsiElement implements PsiDocToken{ - public PsiDocTokenImpl(IElementType type, CharSequence text) { + public PsiDocTokenImpl(@NotNull IElementType type, CharSequence text) { super(type, text); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java index ebeebe24b88d..663a76c66f42 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java @@ -130,8 +130,7 @@ public class JavaResolveUtil { PsiClass topAccessClass = getTopLevelClass(accessObjectClass, memberClass); if (!manager.areElementsEquivalent(topMemberClass, topAccessClass)) return false; if (accessObjectClass instanceof PsiAnonymousClass && accessObjectClass.isInheritor(memberClass, true)) { - if (place instanceof PsiMethodCallExpression && - ((PsiMethodCallExpression)place).getMethodExpression().getQualifierExpression() instanceof PsiThisExpression) { + if (place instanceof PsiMethodCallExpression) { return false; } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiOldInferenceHelper.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiOldInferenceHelper.java index 67b06a0e5629..84e3b27dd60a 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiOldInferenceHelper.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiOldInferenceHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -157,7 +157,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper { } if (rawInference != null) return rawInference; - if (lowerBound != PsiType.NULL) return new Pair<PsiType, ConstraintType>(lowerBound, ConstraintType.EQUALS); + if (lowerBound != PsiType.NULL) return Pair.create(lowerBound, ConstraintType.EQUALS); if (parent != null) { final Pair<PsiType, ConstraintType> constraint = @@ -168,14 +168,14 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper { } if (upperBound != PsiType.NULL) { - return new Pair<PsiType, ConstraintType>(upperBound, ConstraintType.SUBTYPE); + return Pair.create(upperBound, ConstraintType.SUBTYPE); } return constraint; } } - if (upperBound != PsiType.NULL) return new Pair<PsiType, ConstraintType>(upperBound, ConstraintType.SUBTYPE); + if (upperBound != PsiType.NULL) return Pair.create(upperBound, ConstraintType.SUBTYPE); return null; } @@ -403,7 +403,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper { final boolean captureWildcard) { if (arg instanceof PsiWildcardType && !captureWildcard) return FAILED_INFERENCE; if (arg != PsiType.NULL) { - return new Pair<PsiType, ConstraintType>(arg, constraintType); + return Pair.create(arg, constraintType); } return null; } @@ -460,7 +460,7 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper { arg instanceof PsiIntersectionType || (psiClass != null && (isContraVariantPosition || !CommonClassNames.JAVA_LANG_OBJECT.equals(psiClass.getQualifiedName()) || (arg instanceof PsiArrayType)))) { PsiType bound = intersectAllExtends(typeParam, arg); - return new Pair<PsiType, ConstraintType>(bound, ConstraintType.SUPERTYPE); + return Pair.create(bound, ConstraintType.SUPERTYPE); } if (psiClass == null && arg instanceof PsiClassType) { return Pair.create(arg, ConstraintType.EQUALS); @@ -512,16 +512,16 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper { PsiType patternType, final ConstraintType constraintType, final int depth) { + if (patternType.equals(param)) { + return processArgType(arg, constraintType, depth < 2); + } + if (arg instanceof PsiCapturedWildcardType && (depth < 2 || constraintType != ConstraintType.EQUALS || param instanceof PsiWildcardType)) { arg = ((PsiCapturedWildcardType)arg).getWildcard(); //reopen } - if (patternType.equals(param)) { - return processArgType(arg, constraintType, depth < 2); - } - if (param instanceof PsiWildcardType) { final PsiWildcardType wildcardParam = (PsiWildcardType)param; final PsiType paramBound = wildcardParam.getBound(); @@ -651,8 +651,8 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper { } } - if (lowerBound != PsiType.NULL) return new Pair<PsiType, ConstraintType>(lowerBound, ConstraintType.SUPERTYPE); - if (upperBound != PsiType.NULL) return new Pair<PsiType, ConstraintType>(upperBound, ConstraintType.SUBTYPE); + if (lowerBound != PsiType.NULL) return Pair.create(lowerBound, ConstraintType.SUPERTYPE); + if (upperBound != PsiType.NULL) return Pair.create(upperBound, ConstraintType.SUBTYPE); return wildcardCaptured; } @@ -787,6 +787,6 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper { } } - return new Pair<PsiType, ConstraintType>(guess, constraint.getSecond()); + return Pair.create(guess, constraint.getSecond()); } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 9d9c373159f9..f16231ac8d26 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -23,10 +23,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.graphInference.constraints.*; import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.util.PsiTypesUtil; -import com.intellij.psi.util.PsiUtil; -import com.intellij.psi.util.TypeConversionUtil; +import com.intellij.psi.util.*; import com.intellij.util.ArrayUtilRt; import com.intellij.util.Function; import com.intellij.util.Processor; @@ -77,7 +74,7 @@ public class InferenceSession { for (int i = 0; i < leftTypes.length; i++) { final PsiType rightType = mySiteSubstitutor.substitute(rightTypes[i]); if (rightType != null) { - myConstraints.add(new TypeCompatibilityConstraint(leftTypes[i], rightType)); + addConstraint(new TypeCompatibilityConstraint(leftTypes[i], rightType)); } } } @@ -118,7 +115,7 @@ public class InferenceSession { for (int i = 0; i < args.length; i++) { if (args[i] != null && isPertinentToApplicability(args[i], method)) { PsiType parameterType = getParameterType(parameters, i, mySiteSubstitutor, varargs); - myConstraints.add(new ExpressionCompatibilityConstraint(args[i], parameterType)); + addConstraint(new ExpressionCompatibilityConstraint(args[i], parameterType)); } } } @@ -288,11 +285,20 @@ public class InferenceSession { } } - private void collectAdditionalConstraints(Set<ConstraintFormula> additionalConstraints, - PsiCallExpression callExpression) { + private void collectAdditionalConstraints(final Set<ConstraintFormula> additionalConstraints, + final PsiCallExpression callExpression) { PsiExpressionList argumentList = callExpression.getArgumentList(); if (argumentList != null) { - final JavaResolveResult result = callExpression.resolveMethodGenerics(); + final PsiLambdaExpression expression = PsiTreeUtil.getParentOfType(argumentList, PsiLambdaExpression.class); + final Computable<JavaResolveResult> computableResolve = new Computable<JavaResolveResult>() { + @Override + public JavaResolveResult compute() { + return callExpression.resolveMethodGenerics(); + } + }; + final JavaResolveResult result = expression == null + ? computableResolve.compute() + : PsiResolveHelper.ourGraphGuard.doPreventingRecursion(expression, false, computableResolve); if (result instanceof MethodCandidateInfo) { final PsiMethod method = ((MethodCandidateInfo)result).getElement(); //need to get type parameters for 2 level nested expressions (they won't be covered by expression constraints on this level?!) @@ -374,7 +380,7 @@ public class InferenceSession { if (!PsiType.VOID.equals(returnType) && returnType != null) { PsiType targetType = getTargetType(context); if (targetType != null) { - registerConstraints(PsiUtil.isRawSubstitutor(method, mySiteSubstitutor) ? returnType : mySiteSubstitutor.substitute(returnType), targetType); + registerReturnTypeConstraints(PsiUtil.isRawSubstitutor(method, mySiteSubstitutor) ? returnType : mySiteSubstitutor.substitute(returnType), targetType); } } } @@ -387,13 +393,13 @@ public class InferenceSession { } } - public void registerConstraints(PsiType returnType, PsiType targetType) { + public void registerReturnTypeConstraints(PsiType returnType, PsiType targetType) { final InferenceVariable inferenceVariable = shouldResolveAndInstantiate(returnType, targetType); if (inferenceVariable != null) { final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor); final PsiType substitutedReturnType = substitutor.substitute(inferenceVariable.getParameter()); if (substitutedReturnType != null) { - myConstraints.add(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutedReturnType, myContext))); + addConstraint(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutedReturnType, myContext))); } } else { @@ -414,10 +420,10 @@ public class InferenceSession { } final PsiType substitutedCapture = PsiUtil.captureToplevelWildcards(subst.substitute(returnType), myContext); myIncorporationPhase.addCapture(copy, (PsiClassType)returnType); - myConstraints.add(new TypeCompatibilityConstraint(targetType, substitutedCapture)); + addConstraint(new TypeCompatibilityConstraint(targetType, substitutedCapture)); } } else { - myConstraints.add(new TypeCompatibilityConstraint(targetType, myErased ? TypeConversionUtil.erasure(returnType) : returnType)); + addConstraint(new TypeCompatibilityConstraint(targetType, myErased ? TypeConversionUtil.erasure(returnType) : returnType)); } } } @@ -528,11 +534,22 @@ public class InferenceSession { return getTargetType((PsiExpression)parent); } else if (parent instanceof PsiLambdaExpression) { - if (PsiUtil.skipParenthesizedExprUp(parent.getParent()) instanceof PsiExpressionList) { - final PsiType typeTypeByParentCall = getTargetType((PsiLambdaExpression)parent); - return LambdaUtil.getFunctionalInterfaceReturnType(FunctionalInterfaceParameterizationUtil.getGroundTargetType(typeTypeByParentCall, (PsiLambdaExpression)parent)); + return getTargetTypeByContainingLambda((PsiLambdaExpression)parent); + } + else if (parent instanceof PsiReturnStatement) { + return getTargetTypeByContainingLambda(PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class)); + } + return null; + } + + private static PsiType getTargetTypeByContainingLambda(PsiLambdaExpression lambdaExpression) { + if (lambdaExpression != null) { + if (PsiUtil.skipParenthesizedExprUp(lambdaExpression.getParent()) instanceof PsiExpressionList) { + final PsiType typeTypeByParentCall = getTargetType(lambdaExpression); + return LambdaUtil.getFunctionalInterfaceReturnType( + FunctionalInterfaceParameterizationUtil.getGroundTargetType(typeTypeByParentCall, lambdaExpression)); } - return LambdaUtil.getFunctionalInterfaceReturnType(((PsiLambdaExpression)parent).getFunctionalInterfaceType()); + return LambdaUtil.getFunctionalInterfaceReturnType(lambdaExpression.getFunctionalInterfaceType()); } return null; } @@ -857,7 +874,7 @@ public class InferenceSession { try { for (ConstraintFormula additionalConstraint : subset) { - additionalConstraint.apply(substitutor); + additionalConstraint.apply(substitutor, true); } myConstraints.addAll(subset); @@ -920,6 +937,76 @@ public class InferenceSession { return subset; } + public PsiSubstitutor collectApplicabilityConstraints(final PsiMethodReferenceExpression reference, + final MethodCandidateInfo candidateInfo, + final PsiType functionalInterfaceType) { + final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType); + final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult); + LOG.assertTrue(interfaceMethod != null, myContext); + final PsiSubstitutor functionalInterfaceSubstitutor = LambdaUtil.getSubstitutor(interfaceMethod, resolveResult); + final MethodSignature signature = interfaceMethod.getSignature(functionalInterfaceSubstitutor); + + final boolean varargs = candidateInfo.isVarargs(); + final PsiMethod method = candidateInfo.getElement(); + + final PsiMethodReferenceUtil.QualifierResolveResult qualifierResolveResult = PsiMethodReferenceUtil.getQualifierResolveResult(reference); + + final PsiClass containingClass = qualifierResolveResult.getContainingClass(); + LOG.assertTrue(containingClass != null, myContext); + + final PsiParameter[] functionalMethodParameters = interfaceMethod.getParameterList().getParameters(); + final PsiParameter[] parameters = method.getParameterList().getParameters(); + + final boolean isStatic = method.hasModifierProperty(PsiModifier.STATIC); + + if (parameters.length == functionalMethodParameters.length && !varargs || isStatic && varargs) {//static methods + + if (method.isConstructor() && PsiUtil.isRawSubstitutor(containingClass, qualifierResolveResult.getSubstitutor())) { + initBounds(containingClass.getTypeParameters()); + } + + for (int i = 0; i < functionalMethodParameters.length; i++) { + final PsiType pType = signature.getParameterTypes()[i]; + addConstraint(new TypeCompatibilityConstraint(getParameterType(parameters, i, PsiSubstitutor.EMPTY, varargs), pType)); + } + } + else if (parameters.length + 1 == functionalMethodParameters.length && !varargs || !isStatic && varargs && functionalMethodParameters.length > 0) { //instance methods + initBounds(containingClass.getTypeParameters()); + + final PsiType pType = signature.getParameterTypes()[0]; + + PsiSubstitutor psiSubstitutor = qualifierResolveResult.getSubstitutor(); + // 15.28.1 If the ReferenceType is a raw type, and there exists a parameterization of this type, T, that is a supertype of P1, + // the type to search is the result of capture conversion (5.1.10) applied to T; + // otherwise, the type to search is the same as the type of the first search. Again, the type arguments, if any, are given by the method reference. + if (PsiUtil.isRawSubstitutor(containingClass, qualifierResolveResult.getSubstitutor())) { + final PsiClassType.ClassResolveResult pResult = PsiUtil.resolveGenericsClassInType(pType); + final PsiClass pClass = pResult.getElement(); + final PsiSubstitutor receiverSubstitutor = pClass != null ? TypeConversionUtil + .getClassSubstitutor(containingClass, pClass, pResult.getSubstitutor()) : null; + if (receiverSubstitutor != null) { + if (!method.hasTypeParameters()) { + if (signature.getParameterTypes().length == 1 || PsiUtil.isRawSubstitutor(containingClass, receiverSubstitutor)) { + return receiverSubstitutor; + } + } + psiSubstitutor = receiverSubstitutor; + } + } + + final PsiType qType = JavaPsiFacade.getElementFactory(method.getProject()).createType(containingClass, psiSubstitutor); + + addConstraint(new TypeCompatibilityConstraint(qType, pType)); + + for (int i = 0; i < signature.getParameterTypes().length - 1; i++) { + final PsiType interfaceParamType = signature.getParameterTypes()[i + 1]; + addConstraint(new TypeCompatibilityConstraint(getParameterType(parameters, i, PsiSubstitutor.EMPTY, varargs), interfaceParamType)); + } + } + + return null; + } + public void setErased() { myErased = true; } @@ -949,8 +1036,8 @@ public class InferenceSession { final int paramsLength = !varargs ? parameters1.length : parameters1.length - 1; for (int i = 0; i < paramsLength; i++) { - PsiType sType = siteSubstitutor2.substitute(parameters1[i].getType()); - PsiType tType = siteSubstitutor2.substitute(getVarargParameterType(varargs, i, parameters2)); + PsiType sType = getParameterType(parameters1, i, siteSubstitutor2, false); + PsiType tType = getParameterType(parameters2, i, siteSubstitutor2, varargs); if (session.isProperType(sType) && session.isProperType(tType)) { if (!TypeConversionUtil.isAssignable(tType, sType)) { return false; @@ -967,24 +1054,14 @@ public class InferenceSession { } if (varargs) { - PsiType sType = siteSubstitutor2.substitute(getVarargParameterType(true, paramsLength, parameters1)); - PsiType tType = siteSubstitutor2.substitute(getVarargParameterType(true, paramsLength, parameters2)); + PsiType sType = getParameterType(parameters1, paramsLength, siteSubstitutor2, true); + PsiType tType = getParameterType(parameters2, paramsLength, siteSubstitutor2, true); session.addConstraint(new StrictSubtypingConstraint(tType, sType)); } return session.repeatInferencePhases(true); } - public static PsiType getVarargParameterType(boolean varargs, int i, PsiParameter[] parameters2) { - if (varargs && i >= parameters2.length - 1) { - final PsiType lastParamType = parameters2[parameters2.length - 1].getType(); - if (lastParamType instanceof PsiEllipsisType) { - return ((PsiEllipsisType)lastParamType).getComponentType(); - } - } - return parameters2[i].getType(); - } - /** * 15.12.2.5 Choosing the Most Specific Method * "a functional interface type S is more specific than a functional interface type T for an expression exp" part diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java index 13497e3d4557..a606e90e8a98 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceVariable.java @@ -15,27 +15,30 @@ */ package com.intellij.psi.impl.source.resolve.graphInference; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiType; import com.intellij.psi.PsiTypeParameter; +import com.intellij.psi.impl.light.LightTypeParameter; import java.util.*; /** * User: anna */ -public class InferenceVariable { +public class InferenceVariable extends LightTypeParameter { public PsiTypeParameter getParameter() { - return myParameter; + return getDelegate(); } private boolean myThrownBound = false; private final Map<InferenceBound, List<PsiType>> myBounds = new HashMap<InferenceBound, List<PsiType>>(); - private final PsiTypeParameter myParameter; private PsiType myInstantiation = PsiType.NULL; - public InferenceVariable(PsiTypeParameter parameter) { - myParameter = parameter; + + InferenceVariable(PsiTypeParameter parameter) { + super(parameter); } + public PsiType getInstantiation() { return myInstantiation; } @@ -117,12 +120,13 @@ public class InferenceVariable { myThrownBound = true; } - public void replaceBounds(InferenceBound boundType, LinkedHashSet<PsiType> bounds) { - + @Override + public boolean isEquivalentTo(PsiElement another) { + return this == another || getDelegate() == another; } @Override public String toString() { - return myParameter.toString(); + return getDelegate().toString(); } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ConstraintFormula.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ConstraintFormula.java index e9ca0b0179b2..0caaa075bb8a 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ConstraintFormula.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ConstraintFormula.java @@ -25,5 +25,5 @@ import java.util.List; */ public interface ConstraintFormula { boolean reduce(InferenceSession session, List<ConstraintFormula> constraints); - void apply(PsiSubstitutor substitutor); + void apply(PsiSubstitutor substitutor, boolean cache); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java index 6fa5fb46cb07..c33e2c31fa12 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java @@ -52,6 +52,11 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm } final PsiType exprType = myExpression.getType(); + + if (exprType instanceof PsiLambdaParameterType) { + return false; + } + if (exprType != null && exprType != PsiType.NULL) { constraints.add(new TypeCompatibilityConstraint(myT, exprType)); } @@ -145,7 +150,9 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm if (!accepted) { return false; } - callSession.registerConstraints(method != null && !PsiUtil.isRawSubstitutor(method, siteSubstitutor) ? siteSubstitutor.substitute(returnType) : returnType, substitutor.substitute(returnType)); + callSession.registerReturnTypeConstraints( + method != null && !PsiUtil.isRawSubstitutor(method, siteSubstitutor) ? siteSubstitutor.substitute(returnType) : returnType, + substitutor.substitute(returnType)); if (callSession.repeatInferencePhases(true)) { final Collection<InferenceVariable> inferenceVariables = callSession.getInferenceVariables(); if (sameMethodCall) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/InputOutputConstraintFormula.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/InputOutputConstraintFormula.java index 67097df574a0..e5f5a8a8d483 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/InputOutputConstraintFormula.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/InputOutputConstraintFormula.java @@ -109,14 +109,16 @@ public abstract class InputOutputConstraintFormula implements ConstraintFormula } @Override - public void apply(PsiSubstitutor substitutor) { + public void apply(PsiSubstitutor substitutor, boolean cache) { setT(substitutor.substitute(getT())); - Map<PsiElement, PsiType> map = LambdaUtil.ourFunctionTypes.get(); - if (map == null) { - map = new HashMap<PsiElement, PsiType>(); - LambdaUtil.ourFunctionTypes.set(map); + if (cache) { + Map<PsiElement, PsiType> map = LambdaUtil.ourFunctionTypes.get(); + if (map == null) { + map = new HashMap<PsiElement, PsiType>(); + LambdaUtil.ourFunctionTypes.set(map); + } + map.put(getExpression(), getT()); } - map.put(getExpression(), getT()); } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java index 8de976b55acd..cbed2ea59491 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java @@ -74,7 +74,7 @@ public class LambdaExpressionCompatibilityConstraint implements ConstraintFormul } @Override - public void apply(PsiSubstitutor substitutor) { + public void apply(PsiSubstitutor substitutor, boolean cache) { myT = substitutor.substitute(myT); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java index 6e5632847561..cd2e27f27b11 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java @@ -20,7 +20,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; -import com.intellij.psi.impl.source.tree.java.PsiMethodReferenceExpressionImpl; +import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.util.containers.ContainerUtil; @@ -68,7 +68,7 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm } else { final PsiMethodReferenceUtil.QualifierResolveResult qualifierResolveResult = PsiMethodReferenceUtil.getQualifierResolveResult(myExpression); PsiSubstitutor psiSubstitutor = qualifierResolveResult.getSubstitutor(); - final PsiMember applicableMember = ((PsiMethodReferenceExpressionImpl)myExpression).getPotentiallyApplicableMember(); + final PsiMember applicableMember = myExpression.getPotentiallyApplicableMember(); LOG.assertTrue(applicableMember != null); PsiType applicableMethodReturnType = applicableMember instanceof PsiMethod ? ((PsiMethod)applicableMember).getReturnType() : null; int idx = 0; @@ -111,16 +111,17 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm final Map<PsiMethodReferenceExpression, PsiType> map = PsiMethodReferenceUtil.getFunctionalTypeMap(); final PsiType added = map.put(myExpression, groundTargetType); - final PsiElement resolve; + final JavaResolveResult resolve; try { - resolve = myExpression.resolve(); + resolve = myExpression.advancedResolve(true); } finally { if (added == null) { map.remove(myExpression); } } - if (resolve == null) { + final PsiElement element = resolve.getElement(); + if (element == null) { return false; } @@ -128,8 +129,8 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm return true; } - if (resolve instanceof PsiMethod) { - final PsiMethod method = (PsiMethod)resolve; + if (element instanceof PsiMethod) { + final PsiMethod method = (PsiMethod)element; final PsiType referencedMethodReturnType; final PsiClass containingClass = method.getContainingClass(); LOG.assertTrue(containingClass != null, method); @@ -158,8 +159,8 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm ContainerUtil.newHashSet(method.getTypeParameters()))) { //the constraint reduces to the bound set B3 which would be used to determine the method reference's invocation type //when targeting the return type of the function type, as defined in 18.5.2. - //as there is no parameters, only constraint for return types is left. Here you are: - session.registerConstraints(referencedMethodReturnType, returnType); + session.collectApplicabilityConstraints(myExpression, ((MethodCandidateInfo)resolve), groundTargetType); + session.registerReturnTypeConstraints(referencedMethodReturnType, returnType); return true; } } @@ -191,21 +192,19 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm List<ConstraintFormula> constraints, PsiSubstitutor substitutor, PsiParameter[] targetParameters) { - final PsiTypeElement qualifierTypeElement = myExpression.getQualifierType(); - final PsiExpression qualifierExpression = myExpression.getQualifierExpression(); - PsiType qualifierType; - if (qualifierTypeElement != null) { - qualifierType = qualifierTypeElement.getType(); + final PsiElement qualifier = myExpression.getQualifier(); + PsiType qualifierType = null; + if (qualifier instanceof PsiTypeElement) { + qualifierType = ((PsiTypeElement)qualifier).getType(); final PsiClass qualifierClass = PsiUtil.resolveClassInType(qualifierType); if (qualifierClass != null) { qualifierType = JavaPsiFacade.getElementFactory(myExpression.getProject()).createType(qualifierClass, PsiSubstitutor.EMPTY); } } - else { - LOG.assertTrue(qualifierExpression != null); - qualifierType = qualifierExpression.getType(); - if (qualifierType == null && qualifierExpression instanceof PsiReferenceExpression) { - final JavaResolveResult resolveResult = ((PsiReferenceExpression)qualifierExpression).advancedResolve(false); + else if (qualifier instanceof PsiExpression) { + qualifierType = ((PsiExpression)qualifier).getType(); + if (qualifierType == null && qualifier instanceof PsiReferenceExpression) { + final JavaResolveResult resolveResult = ((PsiReferenceExpression)qualifier).advancedResolve(false); final PsiElement res = resolveResult.getElement(); if (res instanceof PsiClass) { PsiClass containingClass = (PsiClass)res; @@ -224,7 +223,7 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm } @Override - public void apply(PsiSubstitutor substitutor) { + public void apply(PsiSubstitutor substitutor, boolean cache) { myT = substitutor.substitute(myT); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/StrictSubtypingConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/StrictSubtypingConstraint.java index 92745cb14d01..412b09eadec3 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/StrictSubtypingConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/StrictSubtypingConstraint.java @@ -37,7 +37,7 @@ public class StrictSubtypingConstraint implements ConstraintFormula { } @Override - public void apply(PsiSubstitutor substitutor) { + public void apply(PsiSubstitutor substitutor, boolean cache) { myT = substitutor.substitute(myT); myS = substitutor.substitute(myS); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/SubtypingConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/SubtypingConstraint.java index e539e943a433..f1502b248a79 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/SubtypingConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/SubtypingConstraint.java @@ -36,7 +36,7 @@ public class SubtypingConstraint implements ConstraintFormula { } @Override - public void apply(PsiSubstitutor substitutor) { + public void apply(PsiSubstitutor substitutor, boolean cache) { myT = substitutor.substitute(myT); myS = substitutor.substitute(myS); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeCompatibilityConstraint.java index 4038f9af5125..f01c82cae769 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeCompatibilityConstraint.java @@ -84,7 +84,7 @@ public class TypeCompatibilityConstraint implements ConstraintFormula { } @Override - public void apply(PsiSubstitutor substitutor) { + public void apply(PsiSubstitutor substitutor, boolean cache) { myT = substitutor.substitute(myT); myS = substitutor.substitute(myS); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java index 1f4717ddc79e..fa3df6669cb9 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java @@ -118,7 +118,7 @@ public class TypeEqualityConstraint implements ConstraintFormula { } @Override - public void apply(PsiSubstitutor substitutor) { + public void apply(PsiSubstitutor substitutor, boolean cache) { myT = substitutor.substitute(myT); myS = substitutor.substitute(myS); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/CoreJavaASTFactory.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/CoreJavaASTFactory.java index dc7b6e576871..9c888c006b99 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/CoreJavaASTFactory.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/CoreJavaASTFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -27,6 +27,7 @@ import com.intellij.psi.impl.source.tree.java.PsiKeywordImpl; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.java.IJavaDocElementType; import com.intellij.psi.tree.java.IJavaElementType; +import org.jetbrains.annotations.NotNull; /** * @author yole @@ -35,7 +36,7 @@ public class CoreJavaASTFactory extends ASTFactory implements Constants { private final DefaultASTFactory myDefaultASTFactory = ServiceManager.getService(DefaultASTFactory.class); @Override - public LeafElement createLeaf(final IElementType type, final CharSequence text) { + public LeafElement createLeaf(@NotNull final IElementType type, final CharSequence text) { if (type == C_STYLE_COMMENT || type == END_OF_LINE_COMMENT) { return myDefaultASTFactory.createComment(type, text); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java index 503cbf48ddd3..ca40ef122c99 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java @@ -21,7 +21,6 @@ import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy; import com.intellij.psi.impl.source.resolve.ResolveCache; import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; -import com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeCompatibilityConstraint; import com.intellij.psi.infos.CandidateInfo; import com.intellij.psi.infos.ClassCandidateInfo; import com.intellij.psi.infos.MethodCandidateInfo; @@ -41,7 +40,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -class MethodReferenceResolver implements ResolveCache.PolyVariantContextResolver<PsiMethodReferenceExpressionImpl> { +public class MethodReferenceResolver implements ResolveCache.PolyVariantContextResolver<PsiMethodReferenceExpressionImpl> { private static final Logger LOG = Logger.getInstance("#" + MethodReferenceResolver.class.getName()); @NotNull @@ -70,7 +69,7 @@ class MethodReferenceResolver implements ResolveCache.PolyVariantContextResolver final PsiClassType returnType = composeReturnType(containingClass, substitutor); final InferenceSession session = new InferenceSession(containingClass.getTypeParameters(), substitutor, reference.getManager(), null); if (!(session.isProperType(returnType) && session.isProperType(interfaceMethodReturnType))) { - session.registerConstraints(returnType, interfaceMethodReturnType); + session.registerReturnTypeConstraints(returnType, interfaceMethodReturnType); substitutor = session.infer(); } } @@ -111,12 +110,11 @@ class MethodReferenceResolver implements ResolveCache.PolyVariantContextResolver @NotNull @Override public PsiSubstitutor inferTypeArguments(@NotNull ParameterTypeInferencePolicy policy, boolean includeReturnConstraint) { - return inferTypeArguments(varargs); + return inferTypeArguments(); } - public PsiSubstitutor inferTypeArguments(boolean varargs) { + private PsiSubstitutor inferTypeArguments() { if (interfaceMethod == null) return substitutor; - final PsiSubstitutor qualifierResultSubstitutor = qualifierResolveResult.getSubstitutor(); final InferenceSession session = new InferenceSession(method.getTypeParameters(), substitutor, reference.getManager(), reference); //lift parameters from outer call @@ -125,53 +123,9 @@ class MethodReferenceResolver implements ResolveCache.PolyVariantContextResolver session.initBounds(methodSubstitutorPair.getMethod().getTypeParameters()); } - final PsiParameter[] functionalMethodParameters = interfaceMethod.getParameterList().getParameters(); - final PsiParameter[] parameters = method.getParameterList().getParameters(); - final boolean isStatic = method.hasModifierProperty(PsiModifier.STATIC); - if (parameters.length == functionalMethodParameters.length && !varargs || isStatic && varargs) {//static methods - - if (method.isConstructor() && PsiUtil.isRawSubstitutor(containingClass, qualifierResultSubstitutor)) { - session.initBounds(containingClass.getTypeParameters()); - } - - for (int i = 0; i < functionalMethodParameters.length; i++) { - final PsiType pType = signature.getParameterTypes()[i]; - session.addConstraint(new TypeCompatibilityConstraint(getParameterType(parameters, i, varargs), pType)); - } - } - else if (parameters.length + 1 == functionalMethodParameters.length && !varargs || !isStatic && varargs && functionalMethodParameters.length > 0) { //instance methods - final PsiClass aClass = qualifierResolveResult.getContainingClass(); - session.initBounds(aClass.getTypeParameters()); - - final PsiType pType = signature.getParameterTypes()[0]; - - PsiSubstitutor psiSubstitutor = qualifierResultSubstitutor; - // 15.28.1 If the ReferenceType is a raw type, and there exists a parameterization of this type, T, that is a supertype of P1, - // the type to search is the result of capture conversion (5.1.10) applied to T; - // otherwise, the type to search is the same as the type of the first search. Again, the type arguments, if any, are given by the method reference. - if (PsiUtil.isRawSubstitutor(containingClass, qualifierResultSubstitutor)) { - final PsiClassType.ClassResolveResult pResult = PsiUtil.resolveGenericsClassInType(pType); - final PsiClass pClass = pResult.getElement(); - final PsiSubstitutor receiverSubstitutor = pClass != null ? TypeConversionUtil - .getClassSubstitutor(containingClass, pClass, pResult.getSubstitutor()) : null; - if (receiverSubstitutor != null) { - if (!method.hasTypeParameters()) { - if (signature.getParameterTypes().length == 1 || PsiUtil.isRawSubstitutor(containingClass, receiverSubstitutor)) { - return receiverSubstitutor; - } - } - psiSubstitutor = receiverSubstitutor; - } - } - - final PsiType qType = JavaPsiFacade.getElementFactory(reference.getProject()).createType(containingClass, psiSubstitutor); - - session.addConstraint(new TypeCompatibilityConstraint(qType, pType)); - - for (int i = 0; i < signature.getParameterTypes().length - 1; i++) { - final PsiType interfaceParamType = signature.getParameterTypes()[i + 1]; - session.addConstraint(new TypeCompatibilityConstraint(getParameterType(parameters, i, varargs), interfaceParamType)); - } + final PsiSubstitutor psiSubstitutor = session.collectApplicabilityConstraints(reference, this, functionalInterfaceType); + if (psiSubstitutor != null) { + return psiSubstitutor; } if (!session.repeatInferencePhases(false)) { @@ -181,19 +135,10 @@ class MethodReferenceResolver implements ResolveCache.PolyVariantContextResolver if (interfaceMethodReturnType != PsiType.VOID && interfaceMethodReturnType != null) { final PsiType returnType = method.isConstructor() ? composeReturnType(containingClass, substitutor) : method.getReturnType(); if (returnType != null) { - session.registerConstraints(returnType, interfaceMethodReturnType); + session.registerReturnTypeConstraints(returnType, interfaceMethodReturnType); } } - return session.infer(parameters, null, null); - } - - private PsiType getParameterType(PsiParameter[] parameters, int i, boolean varargs) { - if (varargs && i >= parameters.length - 1) { - final PsiType type = parameters[parameters.length - 1].getType(); - LOG.assertTrue(type instanceof PsiEllipsisType); - return ((PsiEllipsisType)type).getComponentType(); - } - return parameters[i].getType(); + return session.infer(method.getParameterList().getParameters(), null, null); } }; } @@ -254,8 +199,7 @@ class MethodReferenceResolver implements ResolveCache.PolyVariantContextResolver private static PsiClassType composeReturnType(PsiClass containingClass, PsiSubstitutor substitutor) { final boolean isRawSubst = PsiUtil.isRawSubstitutor(containingClass, substitutor); - return JavaPsiFacade.getElementFactory(containingClass.getProject()) - .createType(containingClass, isRawSubst ? PsiSubstitutor.EMPTY : substitutor); + return JavaPsiFacade.getElementFactory(containingClass.getProject()).createType(containingClass, isRawSubst ? PsiSubstitutor.EMPTY : substitutor); } private static class MethodReferenceConflictResolver extends JavaMethodsConflictResolver { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCodeBlockImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCodeBlockImpl.java index e530554341fd..5c8e425301fb 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCodeBlockImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCodeBlockImpl.java @@ -18,7 +18,7 @@ package com.intellij.psi.impl.source.tree.java; import com.intellij.lang.ASTNode; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.Ref; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; @@ -92,7 +92,7 @@ public class PsiCodeBlockImpl extends LazyParseablePsiElement implements PsiCode // return Pair(classes, locals) or null if there was conflict @Nullable - private Pair<Set<String>, Set<String>> buildMaps() { + private Couple<Set<String>> buildMaps() { Set<String> set1 = myClassesSet; Set<String> set2 = myVariablesSet; boolean wasConflict = myConflict; @@ -129,7 +129,7 @@ public class PsiCodeBlockImpl extends LazyParseablePsiElement implements PsiCode myVariablesSet = set2 = localsSet.isEmpty() ? Collections.<String>emptySet() : localsSet; myConflict = wasConflict = conflict.get(); } - return wasConflict ? null : Pair.create(set1, set2); + return wasConflict ? null : Couple.newOne(set1, set2); } @Override @@ -218,7 +218,7 @@ public class PsiCodeBlockImpl extends LazyParseablePsiElement implements PsiCode // Parent element should not see our vars return true; } - Pair<Set<String>, Set<String>> pair = buildMaps(); + Couple<Set<String>> pair = buildMaps(); boolean conflict = pair == null; final Set<String> classesSet = conflict ? null : pair.getFirst(); final Set<String> variablesSet = conflict ? null : pair.getSecond(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiJavaTokenImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiJavaTokenImpl.java index b5759a188084..38447a9bc324 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiJavaTokenImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiJavaTokenImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -23,7 +23,7 @@ import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; public class PsiJavaTokenImpl extends LeafPsiElement implements PsiJavaToken{ - public PsiJavaTokenImpl(IElementType type, CharSequence text) { + public PsiJavaTokenImpl(@NotNull IElementType type, CharSequence text) { super(type, text); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiKeywordImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiKeywordImpl.java index fa69e5c28083..f39a88e8b35c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiKeywordImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiKeywordImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -27,7 +27,7 @@ import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; public class PsiKeywordImpl extends LeafPsiElement implements PsiKeyword, PsiJavaToken { - public PsiKeywordImpl(IElementType type, CharSequence text) { + public PsiKeywordImpl(@NotNull IElementType type, CharSequence text) { super(type, text); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java index 311b161df557..94cce501d521 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.impl.PsiManagerEx; +import com.intellij.psi.impl.source.resolve.JavaResolveUtil; import com.intellij.psi.impl.source.resolve.ResolveCache; import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; @@ -43,6 +44,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.Map; public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase implements PsiMethodReferenceExpression { @@ -136,7 +140,14 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase if (containingClass != null) { PsiMethod[] methods = null; if (element instanceof PsiIdentifier) { - methods = containingClass.findMethodsByName(element.getText(), !qualifierResolveResult.isReferenceTypeQualified()); + final String identifierName = element.getText(); + final List<PsiMethod> result = new ArrayList<PsiMethod>(); + for (HierarchicalMethodSignature signature : containingClass.getVisibleSignatures()) { + if (identifierName.equals(signature.getName())) { + result.add(signature.getMethod()); + } + } + methods = result.toArray(new PsiMethod[result.size()]); } else if (isConstructor()) { final PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject()); diff --git a/java/java-psi-impl/src/com/intellij/psi/presentation/java/ClassPresentationUtil.java b/java/java-psi-impl/src/com/intellij/psi/presentation/java/ClassPresentationUtil.java index 42171ad26d7e..9dfae2dda9fb 100644 --- a/java/java-psi-impl/src/com/intellij/psi/presentation/java/ClassPresentationUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/presentation/java/ClassPresentationUtil.java @@ -63,13 +63,14 @@ public class ClassPresentationUtil { } public static String getContextName(@NotNull PsiElement element, boolean qualified) { - PsiElement parent = PsiTreeUtil.getParentOfType(element, PsiMember.class, PsiFile.class); + PsiElement parent = PsiTreeUtil.getStubOrPsiParentOfType(element, PsiMember.class); + if (parent == null) parent = element.getContainingFile(); while(true){ if (parent == null) return null; String name = getNameForElement(parent, qualified); if (name != null) return name; if (parent instanceof PsiFile) return null; - parent = parent.getParent(); + parent = PsiTreeUtil.getStubOrPsiParent(parent); } } diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java index 93a444036bef..df053c53291e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java @@ -153,6 +153,10 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ if (methodParameters.length == 0) continue; final PsiParameter param = i < methodParameters.length ? methodParameters[i] : methodParameters[methodParameters.length - 1]; final PsiType paramType = param.getType(); + // http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.12.2.1 + // A lambda expression or a method reference expression is potentially compatible with a type variable if the type variable is a type parameter of the candidate method. + final PsiClass paramClass = PsiUtil.resolveClassInType(paramType); + if (paramClass instanceof PsiTypeParameter && ((PsiTypeParameter)paramClass).getOwner() == method) continue; if (!lambdaExpression.isAcceptable(((MethodCandidateInfo)conflict).getSubstitutor(false).substitute(paramType), lambdaExpression.hasFormalParameterTypes())) { iterator.remove(); } @@ -719,9 +723,9 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ LOG.assertTrue(typeParameter != null); if (!substitutor.getSubstitutionMap().containsKey(typeParameter)) { PsiType type = siteSubstitutor.substitute(typeParameter); - if (type instanceof PsiClassType) { + if (type instanceof PsiClassType && typeParameter.getOwner() == method) { final PsiClass aClass = ((PsiClassType)type).resolve(); - if (aClass instanceof PsiTypeParameter && ((PsiTypeParameter)aClass).getOwner() == typeParameter.getOwner()) { + if (aClass instanceof PsiTypeParameter && ((PsiTypeParameter)aClass).getOwner() == method) { type = TypeConversionUtil.erasure(type, siteSubstitutor); } } diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/processor/MethodCandidatesProcessor.java b/java/java-psi-impl/src/com/intellij/psi/scope/processor/MethodCandidatesProcessor.java index 7106063217b5..2b36a9c49b47 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/processor/MethodCandidatesProcessor.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/processor/MethodCandidatesProcessor.java @@ -51,7 +51,7 @@ public class MethodCandidatesProcessor extends MethodsProcessor{ } public void addMethod(@NotNull PsiMethod method, final PsiSubstitutor substitutor, final boolean staticProblem) { - final boolean isAccessible = JavaResolveUtil.isAccessible(method, method.getContainingClass(), method.getModifierList(), + final boolean isAccessible = JavaResolveUtil.isAccessible(method, getContainingClass(method), method.getModifierList(), myPlace, myAccessClass, myCurrentFileContext, myPlaceFile) && !isShadowed(method); if (isAccepted(method)) { @@ -63,6 +63,10 @@ public class MethodCandidatesProcessor extends MethodsProcessor{ } } + protected PsiClass getContainingClass(PsiMethod method) { + return method.getContainingClass(); + } + protected boolean acceptVarargs() { return false; } @@ -106,10 +110,10 @@ public class MethodCandidatesProcessor extends MethodsProcessor{ if (!candidate.isConstructor()) return false; if (myAccessClass == null) return true; if (myAccessClass instanceof PsiAnonymousClass) { - final PsiClass containingClass = candidate.getContainingClass(); + final PsiClass containingClass = getContainingClass(candidate); return containingClass != null && containingClass.equals(myAccessClass.getSuperClass()); } - return myAccessClass.isEquivalentTo(candidate.getContainingClass()); + return myAccessClass.isEquivalentTo(getContainingClass(candidate)); } } diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/util/PsiScopesUtil.java b/java/java-psi-impl/src/com/intellij/psi/scope/util/PsiScopesUtil.java index 2c3bb5cf9c80..2c2d8b2e1256 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/util/PsiScopesUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/util/PsiScopesUtil.java @@ -442,11 +442,9 @@ public class PsiScopesUtil { if (!(qualifier instanceof PsiSuperExpression)) { processor.setAccessClass((PsiClass)PsiUtil.getAccessObjectClass(qualifier).getElement()); } - else if (((PsiSuperExpression)qualifier).getQualifier() != null && PsiUtil.isLanguageLevel8OrHigher(qualifier)) { - final PsiClass accessClass = (PsiClass)PsiUtil.getAccessObjectClass(qualifier).getElement(); - if (accessClass != null && accessClass.isInterface()) { - processor.setAccessClass(accessClass); - } + else if (((PsiSuperExpression)qualifier).getQualifier() != null && PsiUtil.isLanguageLevel8OrHigher(qualifier) && + CommonClassNames.JAVA_LANG_CLONEABLE.equals(((PsiClass)resolve).getQualifiedName()) && ((PsiClass)resolve).isInterface()) { + processor.setAccessClass((PsiClass)resolve); } } diff --git a/java/java-psi-impl/src/com/intellij/refactoring/util/CanonicalTypes.java b/java/java-psi-impl/src/com/intellij/refactoring/util/CanonicalTypes.java new file mode 100644 index 000000000000..131750f17179 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/refactoring/util/CanonicalTypes.java @@ -0,0 +1,346 @@ +/* + * Copyright 2000-2014 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 com.intellij.refactoring.util; + +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiUtil; +import com.intellij.util.Function; +import com.intellij.util.IncorrectOperationException; +import com.intellij.util.ObjectUtils; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Map; + +/** + * @author dsl + */ +public class CanonicalTypes { + private CanonicalTypes() { } + + public abstract static class Type { + @NotNull + public abstract PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException; + + @NonNls + public abstract String getTypeText(); + + public void addImportsTo(JavaCodeFragment fragment) { } + + public boolean isValid() { + return true; + } + } + + private abstract static class AnnotatedType extends Type { + protected final PsiAnnotation[] myAnnotations; + + protected AnnotatedType(PsiAnnotation[] annotations) { + myAnnotations = annotations; + } + } + + private static class Primitive extends AnnotatedType { + private final PsiPrimitiveType myType; + + private Primitive(PsiPrimitiveType type) { + super(type.getAnnotations()); + myType = type; + } + + @NotNull + @Override + public PsiType getType(PsiElement context, PsiManager manager) { + return myAnnotations.length == 0 ? myType : new PsiPrimitiveType(myType.getCanonicalText(false), myAnnotations); + } + + @Override + public String getTypeText() { + return myType.getPresentableText(); + } + } + + private static class Array extends AnnotatedType { + protected final Type myComponentType; + + private Array(PsiType original, Type componentType) { + super(original.getAnnotations()); + myComponentType = componentType; + } + + @NotNull + @Override + public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException { + return myComponentType.getType(context, manager).createArrayType(myAnnotations); + } + + @Override + public String getTypeText() { + return myComponentType.getTypeText() + "[]"; + } + + @Override + public void addImportsTo(JavaCodeFragment fragment) { + myComponentType.addImportsTo(fragment); + } + + @Override + public boolean isValid() { + return myComponentType.isValid(); + } + } + + private static class Ellipsis extends Array { + private Ellipsis(PsiType original, Type componentType) { + super(original, componentType); + } + + @NotNull + @Override + public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException { + return new PsiEllipsisType(myComponentType.getType(context, manager), myAnnotations); + } + + @Override + public String getTypeText() { + return myComponentType.getTypeText() + "..."; + } + } + + private static class WildcardType extends AnnotatedType { + private final boolean myIsExtending; + private final Type myBound; + + private WildcardType(PsiType original, boolean isExtending, Type bound) { + super(original.getAnnotations()); + myIsExtending = isExtending; + myBound = bound; + } + + @NotNull + @Override + public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException { + PsiWildcardType type; + if (myBound == null) { + type = PsiWildcardType.createUnbounded(manager); + } + else if (myIsExtending) { + type = PsiWildcardType.createExtends(manager, myBound.getType(context, manager)); + } + else { + type = PsiWildcardType.createSuper(manager, myBound.getType(context, manager)); + } + return type.annotate(myAnnotations); + } + + @Override + public String getTypeText() { + if (myBound == null) { + return "?"; + } + else { + return "? " + (myIsExtending ? "extends " : "super ") + myBound.getTypeText(); + } + } + + @Override + public void addImportsTo(JavaCodeFragment fragment) { + if (myBound != null) { + myBound.addImportsTo(fragment); + } + } + + @Override + public boolean isValid() { + return myBound == null || myBound.isValid(); + } + } + + private static class UnresolvedType extends Type { + private final String myPresentableText; + private final String myCanonicalText; + + private UnresolvedType(PsiType original) { + myPresentableText = original.getPresentableText(); + myCanonicalText = original.getCanonicalText(true); + } + + @NotNull + @Override + public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException { + return JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createTypeFromText(myCanonicalText, context); + } + + @Override + public String getTypeText() { + return myPresentableText; + } + + @Override + public boolean isValid() { + return false; + } + } + + private static class ClassType extends AnnotatedType { + private final String myPresentableText; + private final String myClassQName; + private final Map<String, Type> mySubstitutor; + + private ClassType(PsiType original, String classQName, Map<String, Type> substitutor) { + super(original.getAnnotations()); + myPresentableText = original.getPresentableText(); + myClassQName = classQName; + mySubstitutor = substitutor; + } + + @NotNull + @Override + public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException { + JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject()); + PsiElementFactory factory = facade.getElementFactory(); + + PsiClass aClass = facade.getResolveHelper().resolveReferencedClass(myClassQName, context); + if (aClass == null) { + return factory.createTypeFromText(myClassQName, context); + } + + Map<PsiTypeParameter, PsiType> substitutionMap = ContainerUtil.newHashMap(); + for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(aClass)) { + Type substitute = mySubstitutor.get(typeParameter.getName()); + substitutionMap.put(typeParameter, substitute != null ? substitute.getType(context, manager) : null); + } + return factory.createType(aClass, factory.createSubstitutor(substitutionMap), null, myAnnotations); + } + + @Override + public String getTypeText() { + return myPresentableText; + } + + @Override + public void addImportsTo(JavaCodeFragment fragment) { + fragment.addImportsFromString(myClassQName); + for (Type type : mySubstitutor.values()) { + if (type != null) { + type.addImportsTo(fragment); + } + } + } + } + + private static class DisjunctionType extends Type { + private final List<Type> myTypes; + + private DisjunctionType(List<Type> types) { + myTypes = types; + } + + @NotNull + @Override + public PsiType getType(final PsiElement context, final PsiManager manager) throws IncorrectOperationException { + List<PsiType> types = ContainerUtil.map(myTypes, new Function<Type, PsiType>() { + @Override + public PsiType fun(Type type) { + return type.getType(context, manager); + } + }); + return new PsiDisjunctionType(types, manager); + } + + @Override + public String getTypeText() { + return StringUtil.join(myTypes, new Function<Type, String>() { + @Override + public String fun(Type type) { + return type.getTypeText(); + } + }, "|"); + } + + @Override + public void addImportsTo(JavaCodeFragment fragment) { + for (Type type : myTypes) { + type.addImportsTo(fragment); + } + } + } + + private static class Creator extends PsiTypeVisitor<Type> { + public static final Creator INSTANCE = new Creator(); + + @Override + public Type visitPrimitiveType(PsiPrimitiveType type) { + return new Primitive(type); + } + + @Override + public Type visitEllipsisType(PsiEllipsisType type) { + return new Ellipsis(type, type.getComponentType().accept(this)); + } + + @Override + public Type visitArrayType(PsiArrayType type) { + return new Array(type, type.getComponentType().accept(this)); + } + + @Override + public Type visitWildcardType(PsiWildcardType type) { + PsiType bound = type.getBound(); + return new WildcardType(type, type.isExtends(), bound == null ? null : bound.accept(this)); + } + + @Override + public Type visitClassType(PsiClassType type) { + PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics(); + PsiClass aClass = resolveResult.getElement(); + if (aClass instanceof PsiAnonymousClass) { + return visitClassType(((PsiAnonymousClass)aClass).getBaseClassType()); + } + else if (aClass == null) { + return new UnresolvedType(type); + } + else { + Map<String, Type> substitutionMap = ContainerUtil.newHashMap(); + PsiSubstitutor substitutor = resolveResult.getSubstitutor(); + for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(aClass)) { + PsiType substitute = substitutor.substitute(typeParameter); + substitutionMap.put(typeParameter.getName(), substitute != null ? substitute.accept(this) : null); + } + String qualifiedName = ObjectUtils.notNull(aClass.getQualifiedName(), aClass.getName()); + return new ClassType(type, qualifiedName, substitutionMap); + } + } + + @Override + public Type visitDisjunctionType(PsiDisjunctionType type) { + List<Type> types = ContainerUtil.map(type.getDisjunctions(), new Function<PsiType, Type>() { + @Override + public Type fun(PsiType type) { + return type.accept(Creator.this); + } + }); + return new DisjunctionType(types); + } + } + + public static Type createTypeWrapper(@NotNull PsiType type) { + return type.accept(Creator.INSTANCE); + } +} |