From c4c09245e19c5315fb7a5d55af8e7a56d026f570 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 26 Oct 2012 22:07:31 +0200 Subject: [PATCH] Cls*.setMirror(): cleanup, fixes, and better diagnostic --- .../src/com/intellij/psi/PsiPackage.java | 5 +- .../psi/impl/compiled/ClsAnnotationImpl.java | 46 ++-- .../ClsAnnotationParameterListImpl.java | 22 +- .../impl/compiled/ClsAnnotationValueImpl.java | 30 ++- .../ClsArrayInitializerMemberValueImpl.java | 21 +- .../compiled/ClsBinaryExpressionImpl.java | 15 +- .../psi/impl/compiled/ClsClassImpl.java | 233 +++++------------- .../ClsClassObjectAccessExpressionImpl.java | 20 +- .../psi/impl/compiled/ClsDocCommentImpl.java | 20 +- .../psi/impl/compiled/ClsDocTagImpl.java | 48 ++-- .../psi/impl/compiled/ClsElementImpl.java | 171 +++++++++---- .../impl/compiled/ClsEnumConstantImpl.java | 34 +-- .../psi/impl/compiled/ClsFieldImpl.java | 121 +++------ .../psi/impl/compiled/ClsFileImpl.java | 109 +++----- .../psi/impl/compiled/ClsIdentifierImpl.java | 24 +- .../ClsJavaCodeReferenceElementImpl.java | 19 +- .../psi/impl/compiled/ClsJavaTokenImpl.java | 6 +- .../compiled/ClsLiteralExpressionImpl.java | 4 +- .../psi/impl/compiled/ClsMemberImpl.java | 74 ++++++ .../psi/impl/compiled/ClsMethodImpl.java | 201 +++++---------- .../impl/compiled/ClsModifierListImpl.java | 44 +--- .../impl/compiled/ClsNameValuePairImpl.java | 38 ++- .../compiled/ClsPackageStatementImpl.java | 45 ++-- .../psi/impl/compiled/ClsParameterImpl.java | 108 ++++---- .../impl/compiled/ClsParameterListImpl.java | 29 +-- .../psi/impl/compiled/ClsParsingUtil.java | 2 +- .../compiled/ClsPrefixExpressionImpl.java | 6 +- .../compiled/ClsReferenceExpressionImpl.java | 38 ++- .../impl/compiled/ClsReferenceListImpl.java | 41 ++- .../ClsReferenceParametersListImpl.java | 98 -------- .../psi/impl/compiled/ClsTypeElementImpl.java | 58 ++--- .../impl/compiled/ClsTypeParameterImpl.java | 25 +- .../ClsTypeParameterReferenceImpl.java | 216 ---------------- .../compiled/ClsTypeParametersListImpl.java | 36 +-- .../impl/compiled/StubBuildingVisitor.java | 30 ++- .../impl/java/stubs/PsiAnnotationStub.java | 13 +- .../stubs/impl/PsiAnnotationStubImpl.java | 22 +- .../java/stubs/impl/PsiClassStubImpl.java | 8 +- .../java/stubs/impl/PsiFieldStubImpl.java | 14 +- .../java/stubs/impl/PsiParameterStubImpl.java | 29 ++- .../source/tree/java/PsiAnnotationImpl.java | 3 +- .../testData/psi/cls/mirror/$BuckClass.txt | 5 +- .../testData/psi/cls/mirror/Annotations.txt | 58 +++++ .../testData/psi/cls/mirror/Deprecated.txt | 22 ++ .../testData/psi/cls/mirror/EmptyEnum.txt | 7 +- .../psi/cls/mirror/EnumWithFields.txt | 18 ++ .../testData/psi/cls/mirror/ExtMethods.txt | 5 +- .../psi/cls/mirror/MethodReceiver.txt | 9 +- .../testData/psi/cls/mirror/NormalClass.txt | 17 ++ .../psi/cls/mirror/ParameterNames.txt | 13 + .../testData/psi/cls/mirror/SimpleEnum.txt | 15 ++ .../testData/psi/cls/mirror/package-info.txt | 2 +- .../psi/cls/mirror/pkg/Annotations$A1.class | Bin 0 -> 206 bytes .../psi/cls/mirror/pkg/Annotations$A2.class | Bin 0 -> 278 bytes .../psi/cls/mirror/pkg/Annotations$A3.class | Bin 0 -> 356 bytes .../psi/cls/mirror/pkg/Annotations$A4.class | Bin 0 -> 256 bytes .../pkg/Annotations$IndeterminateAnno.class | Bin 0 -> 442 bytes .../psi/cls/mirror/pkg/Annotations.class | Bin 0 -> 786 bytes .../psi/cls/mirror/pkg/Deprecated.class | Bin 0 -> 288 bytes .../psi/cls/mirror/pkg/EnumWithFields.class | Bin 0 -> 864 bytes .../psi/cls/mirror/pkg/NormalClass$1.class | Bin 0 -> 192 bytes .../cls/mirror/pkg/NormalClass$Inner.class | Bin 0 -> 373 bytes .../psi/cls/mirror/pkg/NormalClass.class | Bin 0 -> 470 bytes .../psi/cls/mirror/pkg/ParameterNames.class | Bin 0 -> 688 bytes .../psi/cls/mirror/pkg/SimpleEnum.class | Bin 0 -> 806 bytes .../psi/cls/mirror/src/pkg/Annotations.java | 37 +++ .../psi/cls/mirror/src/pkg/Deprecated.java | 10 + .../cls/mirror/src/pkg/EnumWithFields.java | 8 + .../psi/cls/mirror/src/pkg/NormalClass.java | 11 + .../cls/mirror/src/pkg/ParameterNames.class | Bin 0 -> 651 bytes .../cls/mirror/src/pkg/ParameterNames.java | 13 + .../psi/cls/mirror/src/pkg/SimpleEnum.java | 5 + .../intellij/psi/ClsMirrorBuildingTest.java | 17 +- .../intellij/psi/ClsRepositoryUseTest.java | 10 +- 74 files changed, 1042 insertions(+), 1366 deletions(-) create mode 100644 java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsMemberImpl.java delete mode 100644 java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsReferenceParametersListImpl.java delete mode 100644 java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeParameterReferenceImpl.java create mode 100644 java/java-tests/testData/psi/cls/mirror/Annotations.txt create mode 100644 java/java-tests/testData/psi/cls/mirror/Deprecated.txt create mode 100644 java/java-tests/testData/psi/cls/mirror/EnumWithFields.txt create mode 100644 java/java-tests/testData/psi/cls/mirror/NormalClass.txt create mode 100644 java/java-tests/testData/psi/cls/mirror/ParameterNames.txt create mode 100644 java/java-tests/testData/psi/cls/mirror/SimpleEnum.txt create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/Annotations$A1.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/Annotations$A2.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/Annotations$A3.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/Annotations$A4.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/Annotations$IndeterminateAnno.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/Annotations.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/Deprecated.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/EnumWithFields.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/NormalClass$1.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/NormalClass$Inner.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/NormalClass.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/ParameterNames.class create mode 100644 java/java-tests/testData/psi/cls/mirror/pkg/SimpleEnum.class create mode 100644 java/java-tests/testData/psi/cls/mirror/src/pkg/Annotations.java create mode 100644 java/java-tests/testData/psi/cls/mirror/src/pkg/Deprecated.java create mode 100644 java/java-tests/testData/psi/cls/mirror/src/pkg/EnumWithFields.java create mode 100644 java/java-tests/testData/psi/cls/mirror/src/pkg/NormalClass.java create mode 100644 java/java-tests/testData/psi/cls/mirror/src/pkg/ParameterNames.class create mode 100644 java/java-tests/testData/psi/cls/mirror/src/pkg/ParameterNames.java create mode 100644 java/java-tests/testData/psi/cls/mirror/src/pkg/SimpleEnum.java diff --git a/java/java-psi-api/src/com/intellij/psi/PsiPackage.java b/java/java-psi-api/src/com/intellij/psi/PsiPackage.java index fd68506ee2d5..ed68dc2ac204 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiPackage.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiPackage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -26,7 +26,8 @@ import org.jetbrains.annotations.Nullable; * Represents a Java package. */ public interface PsiPackage extends PsiCheckedRenameElement, NavigationItem, PsiModifierListOwner, PsiDirectoryContainer, PsiQualifiedNamedElement { - @NonNls String PACKAGE_INFO_FILE = "package-info.java"; + @NonNls String PACKAGE_INFO_CLASS = "package-info"; + @NonNls String PACKAGE_INFO_FILE = PACKAGE_INFO_CLASS + ".java"; PsiPackage[] EMPTY_ARRAY = new PsiPackage[0]; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationImpl.java index 2591124bb0a1..c0d9ca742706 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,17 +15,15 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.pom.Navigatable; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.java.stubs.PsiAnnotationStub; import com.intellij.psi.impl.meta.MetaRegistry; import com.intellij.psi.impl.source.SourceTreeToPsiMap; -import com.intellij.psi.impl.source.tree.ChildRole; -import com.intellij.psi.impl.source.tree.CompositeElement; import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.meta.PsiMetaData; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -35,28 +33,25 @@ import org.jetbrains.annotations.Nullable; * @author ven */ public class ClsAnnotationImpl extends ClsRepositoryPsiElement implements PsiAnnotation, Navigatable { - private static final Logger LOG = Logger.getInstance("com.intellij.psi.impl.compiled.ClsAnnotationImpl"); - private ClsJavaCodeReferenceElementImpl myReferenceElement; //protected by lock - private ClsAnnotationParameterListImpl myParameterList; //protected by lock - private final Object lock = new Object(); + private ClsJavaCodeReferenceElementImpl myReferenceElement; + private ClsAnnotationParameterListImpl myParameterList; public ClsAnnotationImpl(final PsiAnnotationStub stub) { super(stub); } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { buffer.append("@").append(getReferenceElement().getCanonicalText()); - ((ClsAnnotationParameterListImpl)getParameterList()).appendMirrorText(indentLevel, buffer); + appendText(getParameterList(), indentLevel, buffer); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - - PsiAnnotation mirror = (PsiAnnotation)SourceTreeToPsiMap.treeElementToPsi(element); - ((ClsElementImpl)getParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getParameterList())); - ((ClsElementImpl)getNameReferenceElement()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameReferenceElement())); + PsiAnnotation mirror = SourceTreeToPsiMap.treeToPsiNotNull(element); + setMirror(getNameReferenceElement(), mirror.getNameReferenceElement()); + setMirror(getParameterList(), mirror.getParameterList()); } @Override @@ -78,22 +73,18 @@ public class ClsAnnotationImpl extends ClsRepositoryPsiElement T setDeclaredAttributeValue(@NonNls String attributeName, T value) { + public T setDeclaredAttributeValue(@NonNls String attributeName, T value) { throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); } @@ -132,11 +123,10 @@ public class ClsAnnotationImpl extends ClsRepositoryPsiElement 0) buffer.append(", "); myAttributes[i].appendMirrorText(indentLevel, buffer); } - buffer.append(")"); } } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - - PsiAnnotationParameterList mirror = (PsiAnnotationParameterList)SourceTreeToPsiMap.treeElementToPsi(element); - PsiNameValuePair[] attrs = mirror.getAttributes(); - LOG.assertTrue(myAttributes.length == attrs.length); - for (int i = 0; i < myAttributes.length; i++) { - myAttributes[i].setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(attrs[i])); - } + setMirrors(myAttributes, SourceTreeToPsiMap.treeToPsiNotNull(element).getAttributes()); } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationValueImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationValueImpl.java index 5245e9767db9..56a509ad326e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationValueImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationValueImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.pom.Navigatable; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; @@ -32,16 +31,15 @@ import org.jetbrains.annotations.Nullable; * @author ven */ public abstract class ClsAnnotationValueImpl extends ClsElementImpl implements PsiAnnotation, Navigatable { - private static final Logger LOG = Logger.getInstance("com.intellij.psi.impl.compiled.ClsAnnotationValueImpl"); - public static final ClsAnnotationImpl[] EMPTY_ARRAY = new ClsAnnotationImpl[0]; + private final ClsElementImpl myParent; private final ClsJavaCodeReferenceElementImpl myReferenceElement; private final ClsAnnotationParameterListImpl myParameterList; - private final ClsElementImpl myParent; - public ClsAnnotationValueImpl(ClsElementImpl parent) { + @SuppressWarnings("AbstractMethodCallInConstructor") + public ClsAnnotationValueImpl(@NotNull ClsElementImpl parent) { + myParent = parent; myReferenceElement = createReference(); myParameterList = createParameterList(); - myParent = parent; } protected abstract ClsAnnotationParameterListImpl createParameterList(); @@ -49,18 +47,18 @@ public abstract class ClsAnnotationValueImpl extends ClsElementImpl implements P protected abstract ClsJavaCodeReferenceElementImpl createReference(); @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { buffer.append("@").append(myReferenceElement.getCanonicalText()); myParameterList.appendMirrorText(indentLevel, buffer); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - PsiAnnotation mirror = (PsiAnnotation)SourceTreeToPsiMap.treeElementToPsi(element); - ((ClsElementImpl)getParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getParameterList())); - ((ClsElementImpl)getNameReferenceElement()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameReferenceElement())); + PsiAnnotation mirror = SourceTreeToPsiMap.treeToPsiNotNull(element); + setMirror(getNameReferenceElement(), mirror.getNameReferenceElement()); + setMirror(getParameterList(), mirror.getParameterList()); } @Override @@ -91,9 +89,9 @@ public abstract class ClsAnnotationValueImpl extends ClsElementImpl implements P } @Override - @Nullable public String getQualifiedName() { - if (myReferenceElement == null) return null; - return myReferenceElement.getCanonicalText(); + @Nullable + public String getQualifiedName() { + return myReferenceElement != null ? myReferenceElement.getCanonicalText() : null; } @Override @@ -113,7 +111,7 @@ public abstract class ClsAnnotationValueImpl extends ClsElementImpl implements P } @Override - public T setDeclaredAttributeValue(@NonNls String attributeName, T value) { + public T setDeclaredAttributeValue(@NonNls String attributeName, T value) { throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsArrayInitializerMemberValueImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsArrayInitializerMemberValueImpl.java index 2e24c8a6ff81..516d39c591f4 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsArrayInitializerMemberValueImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsArrayInitializerMemberValueImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.impl.source.tree.TreeElement; @@ -27,9 +26,8 @@ import org.jetbrains.annotations.NotNull; public class ClsArrayInitializerMemberValueImpl extends ClsElementImpl implements PsiArrayInitializerMemberValue { private final ClsElementImpl myParent; private final PsiAnnotationMemberValue[] myInitializers; - private static final Logger LOG = Logger.getInstance("com.intellij.psi.impl.compiled.ClsArrayInitializerMemberValueImpl"); - public ClsArrayInitializerMemberValueImpl(ClsElementImpl parent, PsiAnnotationMemberValue[] initializers) { + public ClsArrayInitializerMemberValueImpl(@NotNull ClsElementImpl parent, @NotNull PsiAnnotationMemberValue[] initializers) { myParent = parent; myInitializers = initializers; } @@ -42,26 +40,19 @@ public class ClsArrayInitializerMemberValueImpl extends ClsElementImpl implement } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { buffer.append('{'); for (int i = 0; i < myInitializers.length; i++) { if (i > 0) buffer.append(", "); - ((ClsElementImpl)myInitializers[i]).appendMirrorText(0, buffer); + appendText(myInitializers[i], 0, buffer); } buffer.append('}'); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - - PsiArrayInitializerMemberValue mirror = (PsiArrayInitializerMemberValue)SourceTreeToPsiMap.treeElementToPsi(element); - PsiAnnotationMemberValue[] initializers = mirror.getInitializers(); - LOG.assertTrue(myInitializers.length == initializers.length); - for (int i = 0; i < myInitializers.length; i++) { - ClsElementImpl value = (ClsElementImpl)myInitializers[i]; - value.setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(initializers[i])); - } + setMirrors(getInitializers(), SourceTreeToPsiMap.treeToPsiNotNull(element).getInitializers()); } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java index 929d8e787302..7913e923b5f6 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -55,12 +55,12 @@ public class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBinary } @Override - public void appendMirrorText(int indentLevel, StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { buffer.append(getText()); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, JavaElementType.BINARY_EXPRESSION); } @@ -124,13 +124,14 @@ public class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBinary return myLOperand.getType(); } - @Override - public String toString() { - return "PsiBinaryExpression:" + getText(); - } @NotNull @Override public PsiExpression[] getOperands() { return new PsiExpression[]{getLOperand(), getROperand()}; } + + @Override + public String toString() { + return "PsiBinaryExpression:" + getText(); + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java index 891842d1f112..9eedddfcb8ab 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java @@ -17,12 +17,10 @@ package com.intellij.psi.impl.compiled; import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentationProviders; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.ui.Queryable; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.Ref; import com.intellij.psi.*; import com.intellij.psi.impl.InheritanceImplUtil; import com.intellij.psi.impl.PsiClassImplUtil; @@ -32,11 +30,10 @@ import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; import com.intellij.psi.impl.java.stubs.PsiClassStub; import com.intellij.psi.impl.source.*; import com.intellij.psi.impl.source.tree.TreeElement; -import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.psi.search.SearchScope; -import com.intellij.util.ArrayUtil; -import com.intellij.util.IncorrectOperationException; +import com.intellij.psi.util.PsiUtilCore; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,83 +44,24 @@ import java.util.Collection; import java.util.List; import java.util.Map; -public class ClsClassImpl extends ClsRepositoryPsiElement> implements PsiExtensibleClass, PsiQualifiedNamedElement, Queryable { +public class ClsClassImpl extends ClsMemberImpl> implements PsiExtensibleClass, PsiQualifiedNamedElement, Queryable { public static final Key DELEGATE_KEY = Key.create("DELEGATE"); - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsClassImpl"); - private final ClassInnerStuffCache myInnersCache = new ClassInnerStuffCache(this); - private final PsiIdentifier myNameIdentifier; - private final PsiDocComment myDocComment; public ClsClassImpl(final PsiClassStub stub) { super(stub); - myDocComment = isDeprecated() ? new ClsDocCommentImpl(this) : null; - myNameIdentifier = new ClsIdentifierImpl(this, getShortName()); } @Override @NotNull public PsiElement[] getChildren() { - PsiIdentifier name = getNameIdentifier(); - PsiDocComment docComment = getDocComment(); - PsiModifierList modifierList = getModifierList(); - PsiReferenceList extendsList = getExtendsList(); - PsiReferenceList implementsList = getImplementsList(); - List fields = getOwnFields(); - List methods = getOwnMethods(); - List classes = getOwnInnerClasses(); - - int count = - (docComment != null ? 1 : 0) - + 1 // modifierList - + 1 // name - + 1 // extends list - + 1 // implementsList - + fields.size() - + methods.size() - + classes.size(); - PsiElement[] children = new PsiElement[count]; - - int offset = 0; - if (docComment != null) { - children[offset++] = docComment; - } - - children[offset++] = modifierList; - children[offset++] = name; - children[offset++] = extendsList; - children[offset++] = implementsList; - - ArrayUtil.copy(fields, children, offset); - offset += fields.size(); - ArrayUtil.copy(methods, children, offset); - offset += methods.size(); - ArrayUtil.copy(classes, children, offset); - /*offset += classes.size();*/ - - return children; - } - - @Override - @NotNull - public PsiIdentifier getNameIdentifier() { - return myNameIdentifier; - } - - private String getShortName() { - String qName = getQualifiedName(); - String name = PsiNameHelper.getShortClassName(qName); - if (name.length() == 0) { - name = "_"; - } - return name; - } - - @Override - @NotNull - public String getName() { - return getStub().getName(); + List children = ContainerUtil.newArrayList(); + ContainerUtil.addAll(children, getChildren(getDocComment(), getModifierList(), getNameIdentifier(), getExtendsList(), getImplementsList())); + ContainerUtil.addAll(children, getOwnFields()); + ContainerUtil.addAll(children, getOwnMethods()); + ContainerUtil.addAll(children, getOwnInnerClasses()); + return PsiUtilCore.toPsiElementArray(children); } @Override @@ -137,12 +75,6 @@ public class ClsClassImpl extends ClsRepositoryPsiElement> imple return PsiImplUtil.hasTypeParameters(this); } - @Override - public PsiElement setName(@NotNull String name) throws IncorrectOperationException { - PsiImplUtil.setName(getNameIdentifier(), name); - return this; - } - @Override @NotNull public String getQualifiedName() { @@ -352,11 +284,6 @@ public class ClsClassImpl extends ClsRepositoryPsiElement> imple return name.substring(0, i) + ".java"; } - @Override - public PsiDocComment getDocComment() { - return myDocComment; - } - @Override public PsiJavaToken getLBrace() { return null; @@ -383,145 +310,109 @@ public class ClsClassImpl extends ClsRepositoryPsiElement> imple } @Override - public void appendMirrorText(final int indentLevel, @NonNls final StringBuilder buffer) { - ClsDocCommentImpl docComment = (ClsDocCommentImpl)getDocComment(); - if (docComment != null) { - docComment.appendMirrorText(indentLevel, buffer); - goNextLine(indentLevel, buffer); - } - ((ClsElementImpl)getModifierList()).appendMirrorText(indentLevel, buffer); + public void appendMirrorText(final int indentLevel, @NotNull @NonNls final StringBuilder buffer) { + appendText(getDocComment(), indentLevel, buffer, NEXT_LINE); + + appendText(getModifierList(), indentLevel, buffer); buffer.append(isEnum() ? "enum " : isAnnotationType() ? "@interface " : isInterface() ? "interface " : "class "); - ((ClsElementImpl)getNameIdentifier()).appendMirrorText(indentLevel, buffer); - ((ClsElementImpl)getTypeParameterList()).appendMirrorText(indentLevel, buffer); - buffer.append(' '); + appendText(getNameIdentifier(), indentLevel, buffer, " "); + appendText(getTypeParameterList(), indentLevel, buffer, " "); if (!isEnum() && !isAnnotationType()) { - ((ClsElementImpl)getExtendsList()).appendMirrorText(indentLevel, buffer); - buffer.append(' '); - } - if (!isInterface()) { - ((ClsElementImpl)getImplementsList()).appendMirrorText(indentLevel, buffer); + appendText(getExtendsList(), indentLevel, buffer, " "); } + appendText(getImplementsList(), indentLevel, buffer, " "); + buffer.append('{'); - final int newIndentLevel = indentLevel + getIndentSize(); + + int newIndentLevel = indentLevel + getIndentSize(); List fields = getOwnFields(); + List methods = getOwnMethods(); + List classes = getOwnInnerClasses(); + if (fields.size() > 0) { goNextLine(newIndentLevel, buffer); + for (int i = 0; i < fields.size(); i++) { PsiField field = fields.get(i); - ((ClsElementImpl)field).appendMirrorText(newIndentLevel, buffer); + appendText(field, newIndentLevel, buffer); + if (field instanceof ClsEnumConstantImpl) { if (i < fields.size() - 1 && fields.get(i + 1) instanceof ClsEnumConstantImpl) { buffer.append(", "); } else { - buffer.append(";"); + buffer.append(';'); if (i < fields.size() - 1) { + buffer.append('\n'); goNextLine(newIndentLevel, buffer); } } - } else if (i < fields.size() - 1) { + } + else if (i < fields.size() - 1) { goNextLine(newIndentLevel, buffer); } } } + else if (isEnum() && methods.size() + classes.size() > 0) { + goNextLine(newIndentLevel, buffer); + buffer.append(";"); + } - - List methods = getOwnMethods(); if (methods.size() > 0) { - goNextLine(newIndentLevel, buffer); - if (isEnum() && fields.size() == 0) { - buffer.append(";"); // avoid parse errors due to no fields in enum + if (isEnum() || fields.size() > 0) { + buffer.append('\n'); } goNextLine(newIndentLevel, buffer); + for (int i = 0; i < methods.size(); i++) { - PsiMethod method = methods.get(i); - ((ClsElementImpl)method).appendMirrorText(newIndentLevel, buffer); + appendText(methods.get(i), newIndentLevel, buffer); + if (i < methods.size() - 1) { - goNextLine(newIndentLevel, buffer); + buffer.append('\n'); goNextLine(newIndentLevel, buffer); } } } - List classes = getOwnInnerClasses(); if (classes.size() > 0) { + if (fields.size() + methods.size() > 0) { + buffer.append('\n'); + } goNextLine(newIndentLevel, buffer); - goNextLine(newIndentLevel, buffer); + for (int i = 0; i < classes.size(); i++) { - PsiClass aClass = classes.get(i); - ((ClsElementImpl)aClass).appendMirrorText(newIndentLevel, buffer); + appendText(classes.get(i), newIndentLevel, buffer); + if (i < classes.size() - 1) { - goNextLine(newIndentLevel, buffer); + buffer.append('\n'); goNextLine(newIndentLevel, buffer); } } } + goNextLine(indentLevel, buffer); buffer.append('}'); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); PsiClass mirror = SourceTreeToPsiMap.treeToPsiNotNull(element); - PsiDocComment docComment = getDocComment(); - if (docComment != null) { - ((ClsElementImpl)docComment).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment())); - } - ((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList())); - ((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier())); - if (!isAnnotationType() && !isEnum()) { - ((ClsElementImpl)getExtendsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList())); - } - ((ClsElementImpl)getImplementsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getImplementsList())); - ((ClsElementImpl)getTypeParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList())); + setMirrorIfPresent(getDocComment(), mirror.getDocComment()); - Ref extLog = Ref.create(true); + setMirror(getModifierList(), mirror.getModifierList()); + setMirror(getNameIdentifier(), mirror.getNameIdentifier()); + setMirror(getTypeParameterList(), mirror.getTypeParameterList()); + if (!isEnum() && !isAnnotationType()) { + setMirror(getExtendsList(), mirror.getExtendsList()); + } + setMirror(getImplementsList(), mirror.getImplementsList()); - List fields = getOwnFields(); - PsiField[] mirrorFields = mirror.getFields(); - if (fields.size() == mirrorFields.length) { - for (int i = 0; i < fields.size(); i++) { - ((ClsElementImpl)fields.get(i)).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorFields[i])); - } - } - else { - log(this, mirror, "fields:" + fields.size() + "!=" + mirrorFields.length, extLog); - } - - List methods = getOwnMethods(); - PsiMethod[] mirrorMethods = mirror.getMethods(); - if (methods.size() == mirrorMethods.length) { - for (int i = 0; i < methods.size(); i++) { - ((ClsElementImpl)methods.get(i)).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorMethods[i])); - } - } - else { - log(this, mirror, "methods:" + methods.size() + "!=" + mirrorMethods.length, extLog); - } - - List classes = getOwnInnerClasses(); - PsiClass[] mirrorClasses = mirror.getInnerClasses(); - if (classes.size() == mirrorClasses.length) { - for (int i = 0; i < classes.size(); i++) { - ((ClsElementImpl)classes.get(i)).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorClasses[i])); - } - } - else { - log(this, mirror, "classes:" + classes.size() + "!=" + mirrorClasses.length, extLog); - } - } - - private static void log(@NotNull ClsClassImpl stub, @NotNull PsiClass mirror, @NotNull String message, @NotNull Ref verbose) { - LOG.error(message + "; file:" + stub.getContainingFile().getName()); - if (verbose.get()) { - StringBuilder builder = new StringBuilder(); - stub.appendMirrorText(0, builder); - LOG.error("\nStub:\n" + builder.toString() + "\nMirror:\n" + mirror.getText()); - verbose.set(false); - } + setMirrors(getOwnFields(), mirror.getFields()); + setMirrors(getOwnMethods(), mirror.getMethods()); + setMirrors(getOwnInnerClasses(), mirror.getInnerClasses()); } @Override @@ -564,13 +455,13 @@ public class ClsClassImpl extends ClsRepositoryPsiElement> imple @Nullable public PsiClass getSourceMirrorClass() { - PsiClass delegate = getUserData(DELEGATE_KEY); + final PsiClass delegate = getUserData(DELEGATE_KEY); if (delegate instanceof ClsClassImpl) { return ((ClsClassImpl)delegate).getSourceMirrorClass(); } - PsiElement parent = getParent(); final String name = getName(); + final PsiElement parent = getParent(); if (parent instanceof PsiFile) { if (!(parent instanceof PsiClassOwner)) return null; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsClassObjectAccessExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsClassObjectAccessExpressionImpl.java index 6dd238c65001..79fe17419af0 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsClassObjectAccessExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsClassObjectAccessExpressionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.psi.impl.ElementBase; import com.intellij.psi.impl.PsiImplUtil; @@ -23,7 +22,6 @@ import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.ui.RowIcon; import com.intellij.util.PlatformIcons; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -32,28 +30,24 @@ import javax.swing.*; * @author ven */ public class ClsClassObjectAccessExpressionImpl extends ClsElementImpl implements PsiClassObjectAccessExpression { - private static final Logger LOG = Logger.getInstance("com.intellij.psi.impl.compiled.ClsClassObjectAccessExpressionImpl"); - private final ClsTypeElementImpl myTypeElement; private final ClsElementImpl myParent; - @NonNls private static final String CLASS_ENDING = ".class"; + private final ClsTypeElementImpl myTypeElement; - public ClsClassObjectAccessExpressionImpl(String canonicalClassText, ClsElementImpl parent) { + public ClsClassObjectAccessExpressionImpl(ClsElementImpl parent, String canonicalClassText) { myParent = parent; myTypeElement = new ClsTypeElementImpl(this, canonicalClassText, ClsTypeElementImpl.VARIANCE_NONE); } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { myTypeElement.appendMirrorText(0, buffer); - buffer.append(CLASS_ENDING); + buffer.append('.').append(PsiKeyword.CLASS); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - - PsiClassObjectAccessExpression mirror = (PsiClassObjectAccessExpression)SourceTreeToPsiMap.treeElementToPsi(element); - ((ClsElementImpl)getOperand()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getOperand())); + setMirror(getOperand(), SourceTreeToPsiMap.treeToPsiNotNull(element).getOperand()); } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocCommentImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocCommentImpl.java index 5c5e2cda0b99..4b44f4a49ae6 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocCommentImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocCommentImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -28,16 +28,13 @@ class ClsDocCommentImpl extends ClsElementImpl implements PsiDocComment, JavaTok private final PsiDocCommentOwner myParent; private final PsiDocTag[] myTags; - ClsDocCommentImpl(PsiDocCommentOwner parent) { + ClsDocCommentImpl(@NotNull PsiDocCommentOwner parent) { myParent = parent; - - PsiDocTag[] tags = new PsiDocTag[1]; - tags[0] = new ClsDocTagImpl(this, "@deprecated"); - myTags = tags; + myTags = new PsiDocTag[]{new ClsDocTagImpl(this, "@deprecated")}; } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(final int indentLevel, @NotNull final StringBuilder buffer) { buffer.append("/**"); for (PsiDocTag tag : getTags()) { goNextLine(indentLevel + 1, buffer); @@ -49,7 +46,7 @@ class ClsDocCommentImpl extends ClsElementImpl implements PsiDocComment, JavaTok } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, JavaDocElementType.DOC_COMMENT); } @@ -83,15 +80,13 @@ class ClsDocCommentImpl extends ClsElementImpl implements PsiDocComment, JavaTok @Override public PsiDocTag findTagByName(@NonNls String name) { - if (!name.equals("deprecated")) return null; - return getTags()[0]; + return name.equals("deprecated") ? getTags()[0] : null; } @Override @NotNull public PsiDocTag[] findTagsByName(@NonNls String name) { - if (!name.equals("deprecated")) return PsiDocTag.EMPTY_ARRAY; - return getTags(); + return name.equals("deprecated") ? getTags() : PsiDocTag.EMPTY_ARRAY; } @Override @@ -108,5 +103,4 @@ class ClsDocCommentImpl extends ClsElementImpl implements PsiDocComment, JavaTok visitor.visitElement(this); } } - } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocTagImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocTagImpl.java index 57dbd5902d3a..1588e835b9fe 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocTagImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsDocTagImpl.java @@ -1,6 +1,5 @@ - /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -16,12 +15,11 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.JavaElementVisitor; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.impl.PsiImplUtil; -import com.intellij.psi.impl.source.tree.ElementType; +import com.intellij.psi.impl.source.tree.JavaDocElementType; import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.javadoc.PsiDocTag; @@ -31,24 +29,22 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; class ClsDocTagImpl extends ClsElementImpl implements PsiDocTag { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsDocTagImpl"); - private final ClsDocCommentImpl myDocComment; private final PsiElement myNameElement; public ClsDocTagImpl(ClsDocCommentImpl docComment, @NonNls String name) { myDocComment = docComment; - myNameElement = new NameElement(name); + myNameElement = new NameElement(this, name); } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { buffer.append(myNameElement.getText()); } @Override - public void setMirror(@NotNull TreeElement element) { - setMirrorCheckingType(element, ElementType.DOC_TAG); + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { + setMirrorCheckingType(element, JavaDocElementType.DOC_TAG); } @Override @@ -58,11 +54,12 @@ class ClsDocTagImpl extends ClsElementImpl implements PsiDocTag { @Override @NotNull - public char[] textToCharArray(){ + public char[] textToCharArray() { return myNameElement.textToCharArray(); } @Override + @NotNull public String getName() { return getNameElement().getText().substring(1); } @@ -78,7 +75,7 @@ class ClsDocTagImpl extends ClsElementImpl implements PsiDocTag { } @Override - public int getTextLength(){ + public int getTextLength() { return myNameElement.getTextLength(); } @@ -123,10 +120,18 @@ class ClsDocTagImpl extends ClsElementImpl implements PsiDocTag { } } - private class NameElement extends ClsElementImpl { + @Override + public PsiElement setName(@NotNull String name) throws IncorrectOperationException { + PsiImplUtil.setName(getNameElement(), name); + return this; + } + + private static class NameElement extends ClsElementImpl { + private final ClsDocTagImpl myParent; private final String myText; - public NameElement(String text) { + public NameElement(ClsDocTagImpl parent, String text) { + myParent = parent; myText = text; } @@ -137,28 +142,28 @@ class ClsDocTagImpl extends ClsElementImpl implements PsiDocTag { @Override @NotNull - public char[] textToCharArray(){ + public char[] textToCharArray() { return myText.toCharArray(); } @Override @NotNull - public PsiElement[] getChildren(){ + public PsiElement[] getChildren() { return PsiElement.EMPTY_ARRAY; } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); } @Override public PsiElement getParent() { - return ClsDocTagImpl.this; + return myParent; } @Override @@ -166,9 +171,4 @@ class ClsDocTagImpl extends ClsElementImpl implements PsiDocTag { visitor.visitElement(this); } } - @Override - public PsiElement setName(@NotNull String name) throws IncorrectOperationException{ - PsiImplUtil.setName(getNameElement(), name); - return this; - } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java index dc277379bf82..5efc4909dfa7 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -29,16 +29,25 @@ import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.StringBuilderSpinAllocator; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; +import java.util.List; + public abstract class ClsElementImpl extends PsiElementBase implements PsiCompiledElement { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsElementImpl"); - private static final boolean CHECK_MIRROR_ENABLED = false; - protected static final Object LAZY_BUILT_LOCK = new String("lazy cls tree initialization lock"); public static final Key COMPILED_ELEMENT = Key.create("COMPILED_ELEMENT"); + protected static final Object LAZY_BUILT_LOCK = new String("lazy cls tree initialization lock"); + protected static final String CAN_NOT_MODIFY_MESSAGE = JavaCoreBundle.message("psi.error.attempt.to.edit.class.file"); + + private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsElementImpl"); + private volatile TreeElement myMirror = null; @Override @@ -56,8 +65,7 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil public PsiFile getContainingFile() { PsiElement parent = getParent(); if (parent == null) { - if (!isValid()) throw new PsiInvalidElementAccessException(this); - return null; + throw new PsiInvalidElementAccessException(this); } return parent.getContainingFile(); } @@ -83,6 +91,21 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil return this; } + @NotNull + protected PsiElement[] getChildren(@Nullable PsiElement... children) { + if (children == null) { + return PsiElement.EMPTY_ARRAY; + } + + List list = ContainerUtil.newArrayListWithExpectedSize(children.length); + for (PsiElement child : children) { + if (child != null) { + list.add(child); + } + } + return PsiUtilCore.toPsiElementArray(list); + } + @Override public void checkAdd(@NotNull PsiElement element) throws IncorrectOperationException { throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); @@ -118,20 +141,13 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); } - protected static final String CAN_NOT_MODIFY_MESSAGE = JavaCoreBundle.message("psi.error.attempt.to.edit.class.file"); - - public abstract void appendMirrorText(final int indentLevel, final StringBuilder buffer); - - protected static void goNextLine(int indentLevel, StringBuilder buffer) { - buffer.append('\n'); - for (int i = 0; i < indentLevel; i++) buffer.append(' '); - } + public abstract void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer); protected int getIndentSize() { return JavaCodeStyleSettingsFacade.getInstance(getProject()).getIndentSize(); } - public abstract void setMirror(@NotNull TreeElement element); + public abstract void setMirror(@NotNull TreeElement element) throws InvalidMirrorException; @Override public PsiElement getMirror() { @@ -158,36 +174,18 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil @Override public int getTextLength() { String text = getText(); - if (text == null){ - LOG.error("getText() == null, element = " + this + ", parent = " + getParent()); - return 0; - } - return text.length(); + return text == null ? 0 : text.length(); } @Override public PsiElement findElementAt(int offset) { PsiElement mirrorAt = getMirror().findElementAt(offset); - while(true){ + while (true) { if (mirrorAt == null) return null; PsiElement elementAt = mirrorToElement(mirrorAt); if (elementAt != null) return elementAt; mirrorAt = mirrorAt.getParent(); } - - /* - PsiElement[] children = getChildren(); - if (children.length == 0) return this; - for(int i = 0; i < children.length; i++){ - int start = children[i].getStartOffsetInParent(); - if (offset < start) return null; - int end = start + children[i].getTextLength(); - if (offset < end){ - return children[i].findElementAt(offset - start); - } - } - return null; - */ } @Override @@ -200,6 +198,7 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil return element.getReference(); } + @Nullable private PsiElement mirrorToElement(PsiElement mirror) { final PsiElement m = getMirror(); if (m == mirror) return this; @@ -227,7 +226,17 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil @Override public String getText() { PsiElement mirror = getMirror(); - return mirror != null ? mirror.getText() : null; + if (mirror != null) return mirror.getText(); + + StringBuilder buffer = StringBuilderSpinAllocator.alloc(); + try { + appendMirrorText(0, buffer); + LOG.error("Mirror wasn't set for " + this + ", expected text:\n" + buffer); + return buffer.toString(); + } + finally { + StringBuilderSpinAllocator.dispose(buffer); + } } @Override @@ -251,16 +260,94 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil return null; } - protected void setMirrorCheckingType(@NotNull TreeElement element, @Nullable IElementType type) { - if (CHECK_MIRROR_ENABLED) { - LOG.assertTrue(myMirror == null); - } + protected static void goNextLine(int indentLevel, @NotNull StringBuilder buffer) { + buffer.append('\n'); + for (int i = 0; i < indentLevel; i++) buffer.append(' '); + } - if (type != null) { - LOG.assertTrue(element.getElementType() == type, element.getElementType() + " != " + type); + protected static void appendText(@NotNull PsiElement stub, int indentLevel, @NotNull StringBuilder buffer) { + ((ClsElementImpl)stub).appendMirrorText(indentLevel, buffer); + } + + protected static final String NEXT_LINE = "go_to_next_line_and_indent"; + + protected static void appendText(@Nullable PsiElement stub, int indentLevel, @NotNull StringBuilder buffer, @NotNull String separator) { + if (stub == null) return; + int pos = buffer.length(); + ((ClsElementImpl)stub).appendMirrorText(indentLevel, buffer); + if (buffer.length() != pos) { + if (separator == NEXT_LINE) { + goNextLine(indentLevel, buffer); + } + else { + buffer.append(separator); + } + } + } + + protected void setMirrorCheckingType(@NotNull TreeElement element, @Nullable IElementType type) throws InvalidMirrorException { + // uncomment for extended consistency check + //if (myMirror != null) { + // throw new InvalidMirrorException("Mirror should be null: " + myMirror); + //} + + if (type != null && element.getElementType() != type) { + throw new InvalidMirrorException(element.getElementType() + " != " + type); } element.putUserData(COMPILED_ELEMENT, this); myMirror = element; } + + protected static void setMirror(@Nullable T stub, @Nullable T mirror) throws InvalidMirrorException { + if (stub == null || mirror == null) { + throw new InvalidMirrorException(stub, mirror); + } + ((ClsElementImpl)stub).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirror)); + } + + protected static void setMirrorIfPresent(@Nullable T stub, @Nullable T mirror) throws InvalidMirrorException { + if ((stub == null) != (mirror == null)) { + throw new InvalidMirrorException(stub, mirror); + } + else if (stub != null) { + ((ClsElementImpl)stub).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirror)); + } + } + + protected static void setMirrors(@NotNull T[] stubs, @NotNull T[] mirrors) throws InvalidMirrorException { + if (stubs.length != mirrors.length) { + throw new InvalidMirrorException(stubs, mirrors); + } + for (int i = 0; i < stubs.length; i++) { + setMirror(stubs[i], mirrors[i]); + } + } + + protected static void setMirrors(@NotNull List stubs, @NotNull T[] mirrors) throws InvalidMirrorException { + if (stubs.size() != mirrors.length) { + throw new InvalidMirrorException(stubs, mirrors); + } + for (int i = 0; i < stubs.size(); i++) { + setMirror(stubs.get(i), mirrors[i]); + } + } + + protected static class InvalidMirrorException extends RuntimeException { + public InvalidMirrorException(@NotNull @NonNls String message) { + super(message); + } + + public InvalidMirrorException(@Nullable PsiElement stubElement, @Nullable PsiElement mirrorElement) { + this("stub:" + stubElement + "; mirror:" + mirrorElement); + } + + public InvalidMirrorException(@NotNull PsiElement[] stubElements, @NotNull PsiElement[] mirrorElements) { + this("stub:" + Arrays.toString(stubElements) + "; mirror:" + Arrays.toString(mirrorElements)); + } + + public InvalidMirrorException(@NotNull List stubElements, @NotNull PsiElement[] mirrorElements) { + this("stub:" + stubElements + "; mirror:" + Arrays.toString(mirrorElements)); + } + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsEnumConstantImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsEnumConstantImpl.java index 568445a4e84e..3d5c9ad3cd69 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsEnumConstantImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsEnumConstantImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.psi.impl.java.stubs.PsiFieldStub; import com.intellij.psi.impl.source.SourceTreeToPsiMap; @@ -27,35 +26,25 @@ import org.jetbrains.annotations.NotNull; * @author ven */ public class ClsEnumConstantImpl extends ClsFieldImpl implements PsiEnumConstant { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsEnumConstantImpl"); - - public ClsEnumConstantImpl(final PsiFieldStub stub) { + public ClsEnumConstantImpl(@NotNull PsiFieldStub stub) { super(stub); } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { - ClsDocCommentImpl docComment = (ClsDocCommentImpl)getDocComment(); - if (docComment != null) { - docComment.appendMirrorText(indentLevel, buffer); - goNextLine(indentLevel, buffer); - } - - ((ClsElementImpl)getModifierList()).appendMirrorText(indentLevel, buffer); - buffer.append(' '); - ((ClsElementImpl)getNameIdentifier()).appendMirrorText(indentLevel, buffer); + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { + appendText(getDocComment(), indentLevel, buffer, NEXT_LINE); + appendText(getModifierList(), indentLevel, buffer, ""); + appendText(getNameIdentifier(), indentLevel, buffer); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - PsiField mirror = (PsiField)SourceTreeToPsiMap.treeElementToPsi(element); - if (getDocComment() != null) { - ((ClsElementImpl)getDocComment()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment())); - } - ((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList())); - ((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier())); + PsiField mirror = SourceTreeToPsiMap.treeToPsiNotNull(element); + setMirrorIfPresent(getDocComment(), mirror.getDocComment()); + setMirror(getModifierList(), mirror.getModifierList()); + setMirror(getNameIdentifier(), mirror.getNameIdentifier()); } @Override @@ -90,7 +79,6 @@ public class ClsEnumConstantImpl extends ClsFieldImpl implements PsiEnumConstant return null; } - @Override @NotNull public PsiType getType() { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFieldImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFieldImpl.java index 6aa5ef371d19..55d35bd76108 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFieldImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFieldImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -17,7 +17,6 @@ package com.intellij.psi.impl.compiled; import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentationProviders; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.util.Comparing; import com.intellij.psi.*; @@ -27,7 +26,6 @@ import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; import com.intellij.psi.impl.java.stubs.PsiFieldStub; import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.impl.source.tree.TreeElement; -import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.search.SearchScope; import com.intellij.ui.RowIcon; import com.intellij.util.IncorrectOperationException; @@ -39,51 +37,19 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.util.Set; -public class ClsFieldImpl extends ClsRepositoryPsiElement implements PsiField, PsiVariableEx, ClsModifierListOwner { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsFieldImpl"); +public class ClsFieldImpl extends ClsMemberImpl implements PsiField, PsiVariableEx, ClsModifierListOwner { + private PsiTypeElement myType = null; + private PsiExpression myInitializer = null; + private boolean myInitializerInitialized = false; - private final PsiIdentifier myNameIdentifier; - private final PsiDocComment myDocComment; - private PsiTypeElement myType = null; //guarded by PsiLock.LOCK - private PsiExpression myInitializer = null; //guarded by PsiLock.LOCK - private boolean myInitializerInitialized = false; //guarded by PsiLock.LOCK - - public ClsFieldImpl(final PsiFieldStub stub) { + public ClsFieldImpl(@NotNull PsiFieldStub stub) { super(stub); - myDocComment = isDeprecated() ? new ClsDocCommentImpl(this) : null; - myNameIdentifier = new ClsIdentifierImpl(this, getName()); } @Override @NotNull public PsiElement[] getChildren() { - PsiDocComment docComment = getDocComment(); - PsiModifierList modifierList = getModifierList(); - PsiTypeElement type = getTypeElement(); - PsiIdentifier name = getNameIdentifier(); - - int count = - (docComment != null ? 1 : 0) - + (modifierList != null ? 1 : 0) - + (type != null ? 1 : 0) - + (name != null ? 1 : 0); - PsiElement[] children = new PsiElement[count]; - - int offset = 0; - if (docComment != null) { - children[offset++] = docComment; - } - if (modifierList != null) { - children[offset++] = modifierList; - } - if (type != null) { - children[offset++] = type; - } - if (name != null) { - children[offset++] = name; - } - - return children; + return getChildren(getDocComment(), getModifierList(), getTypeElement(), getNameIdentifier()); } @Override @@ -91,25 +57,6 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implemen return (PsiClass)getParent(); } - @Override - @NotNull - public PsiIdentifier getNameIdentifier() { - return myNameIdentifier; - } - - @Override - @NotNull - @NonNls - public String getName() { - return getStub().getName(); - } - - @Override - public PsiElement setName(@NotNull String name) throws IncorrectOperationException { - PsiImplUtil.setName(getNameIdentifier(), name); - return this; - } - @Override @NotNull public PsiType getType() { @@ -117,10 +64,13 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implemen } @Override + @NotNull public PsiTypeElement getTypeElement() { synchronized (LAZY_BUILT_LOCK) { if (myType == null) { - String typeText = TypeInfo.createTypeText(getStub().getType(false)); + PsiFieldStub stub = getStub(); + String typeText = TypeInfo.createTypeText(stub.getType(false)); + assert typeText != null : stub; myType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE); } return myType; @@ -191,44 +141,35 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implemen return getStub().isDeprecated(); } - @Override - public PsiDocComment getDocComment() { - return myDocComment; - } - @Override public void normalizeDeclaration() throws IncorrectOperationException { } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { - ClsDocCommentImpl docComment = (ClsDocCommentImpl)getDocComment(); - if (docComment != null) { - docComment.appendMirrorText(indentLevel, buffer); - goNextLine(indentLevel, buffer); - } - ((ClsElementImpl)getModifierList()).appendMirrorText(indentLevel, buffer); - ((ClsElementImpl)getTypeElement()).appendMirrorText(indentLevel, buffer); - buffer.append(' '); - ((ClsElementImpl)getNameIdentifier()).appendMirrorText(indentLevel, buffer); - if (getInitializer() != null) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { + appendText(getDocComment(), indentLevel, buffer, NEXT_LINE); + appendText(getModifierList(), indentLevel, buffer, ""); + appendText(getTypeElement(), indentLevel, buffer, " "); + appendText(getNameIdentifier(), indentLevel, buffer); + + PsiExpression initializer = getInitializer(); + if (initializer != null) { buffer.append(" = "); - buffer.append(getInitializer().getText()); + buffer.append(initializer.getText()); } + buffer.append(';'); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - PsiField mirror = (PsiField)SourceTreeToPsiMap.treeElementToPsi(element); - if (getDocComment() != null) { - ((ClsElementImpl)getDocComment()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment())); - } - ((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList())); - ((ClsElementImpl)getTypeElement()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeElement())); - ((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier())); + PsiField mirror = SourceTreeToPsiMap.treeToPsiNotNull(element); + setMirrorIfPresent(getDocComment(), mirror.getDocComment()); + setMirror(getModifierList(), mirror.getModifierList()); + setMirror(getTypeElement(), mirror.getTypeElement()); + setMirror(getNameIdentifier(), mirror.getNameIdentifier()); } @Override @@ -241,10 +182,6 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implemen } } - public String toString() { - return "PsiField:" + getName(); - } - @Override @NotNull public PsiElement getNavigationElement() { @@ -297,4 +234,8 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement implemen return true; } + @Override + public String toString() { + return "PsiField:" + getName(); + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java index 908095984e8c..200510bc0046 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsFileImpl.java @@ -23,21 +23,15 @@ import com.intellij.lang.FileASTNode; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.editor.Document; import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.progress.NonCancelableSection; import com.intellij.openapi.progress.ProgressIndicatorProvider; import com.intellij.openapi.ui.Queryable; -import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; -import com.intellij.psi.impl.JavaPsiImplementationHelper; -import com.intellij.psi.impl.PsiFileEx; -import com.intellij.psi.impl.PsiManagerEx; -import com.intellij.psi.impl.PsiManagerImpl; +import com.intellij.psi.impl.*; import com.intellij.psi.impl.java.stubs.PsiClassStub; import com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl; import com.intellij.psi.impl.source.PsiFileImpl; @@ -65,22 +59,21 @@ public class ClsFileImpl extends ClsRepositoryPsiElement private static final MirrorLock MIRROR_LOCK = new MirrorLock(); private static class MirrorLock {} - private static final Key DOCUMENT_IN_MIRROR_KEY = Key.create("DOCUMENT_IN_MIRROR_KEY"); private final PsiManagerImpl myManager; private final boolean myIsForDecompiling; private final FileViewProvider myViewProvider; private volatile SoftReference myStub; - private TreeElement myMirrorFileElement; // guarded by MIRROR_LOCK + private TreeElement myMirrorFileElement; private volatile ClsPackageStatementImpl myPackageStatement = null; private boolean myIsPhysical = true; private ClsFileImpl(@NotNull PsiManagerImpl manager, @NotNull FileViewProvider viewProvider, boolean forDecompiling) { + //noinspection ConstantConditions super(null); myManager = manager; - JavaElementType.CLASS.getIndex(); // Initialize java stubs... - myIsForDecompiling = forDecompiling; myViewProvider = viewProvider; + JavaElementType.CLASS.getIndex(); // Initialize java stubs... } public ClsFileImpl(PsiManagerImpl manager, FileViewProvider viewProvider) { @@ -143,8 +136,7 @@ public class ClsFileImpl extends ClsRepositoryPsiElement @Override @NotNull public PsiClass[] getClasses() { - final PsiClassHolderFileStub fileStub = getStub(); - return fileStub != null ? fileStub.getClasses() : PsiClass.EMPTY_ARRAY; + return getStub().getClasses(); } @Override @@ -235,53 +227,30 @@ public class ClsFileImpl extends ClsRepositoryPsiElement } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { - buffer.append("\n // IntelliJ API Decompiler stub source generated from a class file\n // Implementation of methods is not available"); - goNextLine(indentLevel, buffer); - goNextLine(indentLevel, buffer); - final PsiPackageStatement packageStatement = getPackageStatement(); - if (packageStatement != null) { - ((ClsElementImpl)packageStatement).appendMirrorText(0, buffer); - goNextLine(indentLevel, buffer); - goNextLine(indentLevel, buffer); - } + public void appendMirrorText(final int indentLevel, @NotNull final StringBuilder buffer) { + buffer.append("\n"); + buffer.append(" // IntelliJ API Decompiler stub source generated from a class file\n"); + buffer.append(" // Implementation of methods is not available\n"); + buffer.append("\n"); - final PsiClass[] classes = getClasses(); + appendText(getPackageStatement(), 0, buffer, "\n\n"); + + PsiClass[] classes = getClasses(); if (classes.length > 0) { - PsiClass aClass = classes[0]; - ((ClsElementImpl)aClass).appendMirrorText(0, buffer); + appendText(classes[0], 0, buffer); } } @Override - public void setMirror(@NotNull TreeElement element) { - PsiElement mirrorFile = SourceTreeToPsiMap.treeElementToPsi(element); - if (mirrorFile instanceof PsiJavaFile) { - PsiPackageStatement packageStatementMirror = ((PsiJavaFile)mirrorFile).getPackageStatement(); - final PsiPackageStatement packageStatement = getPackageStatement(); - if (packageStatementMirror != null && packageStatement != null) { - ((ClsElementImpl)packageStatement).setMirror((TreeElement)packageStatementMirror.getNode()); - } - - PsiClass[] classes = getClasses(); - // Can happen for package-info.class, or classes compiled from languages, that support different class naming scheme, like Scala. - if (classes.length != 1 || JavaPsiFacade.getInstance(getProject()).getNameHelper().isIdentifier(classes[0].getName())) { - PsiClass[] mirrorClasses = ((PsiJavaFile)mirrorFile).getClasses(); - if (classes.length != mirrorClasses.length) { - LOG.error("file: " + mirrorFile + " classes: " + Arrays.toString(classes) + " mirrors: " + Arrays.toString(mirrorClasses)); - } - else { - for (int i = 0; i < classes.length; i++) { - PsiClass mirrorClass = mirrorClasses[i]; - assert mirrorClass != null : this +"; mirror classes: " + Arrays.asList(mirrorClasses); - PsiClass aClass = classes[i]; - assert aClass != null : this +"; classes: " + Arrays.asList(classes); - ((ClsElementImpl)aClass).setMirror((TreeElement)mirrorClass.getNode()); - } - } - } + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { + PsiElement mirrorElement = SourceTreeToPsiMap.treeToPsiNotNull(element); + if (!(mirrorElement instanceof PsiJavaFile)) { + throw new InvalidMirrorException("Unexpected mirror file: " + mirrorElement); } - myMirrorFileElement = element; + + PsiJavaFile mirrorFile = (PsiJavaFile)mirrorElement; + setMirrorIfPresent(getPackageStatement(), mirrorFile.getPackageStatement()); + setMirrors(getClasses(), mirrorFile.getClasses()); } @Override @@ -294,29 +263,29 @@ public class ClsFileImpl extends ClsRepositoryPsiElement public PsiElement getMirror() { synchronized (MIRROR_LOCK) { if (myMirrorFileElement == null) { - VirtualFile virtualFile = getVirtualFile(); - String mirrorText = decompile(getManager(), virtualFile); + VirtualFile file = getVirtualFile(); + String mirrorText = decompile(getManager(), file); String ext = JavaFileType.INSTANCE.getDefaultExtension(); PsiClass[] classes = getClasses(); - - String fileName = (classes.length > 0 ? classes[0].getName(): virtualFile.getNameWithoutExtension()) + "." + ext; - PsiManager manager = getManager(); - PsiFile mirror = PsiFileFactory.getInstance(manager.getProject()).createFileFromText(fileName, JavaLanguage.INSTANCE, mirrorText, false, false); - final ASTNode mirrorTreeElement = SourceTreeToPsiMap.psiElementToTree(mirror); + String fileName = (classes.length > 0 ? classes[0].getName() : file.getNameWithoutExtension()) + "." + ext; + PsiFileFactory factory = PsiFileFactory.getInstance(getManager().getProject()); + PsiFile mirror = factory.createFileFromText(fileName, JavaLanguage.INSTANCE, mirrorText, false, false); + TreeElement mirrorTreeElement = SourceTreeToPsiMap.psiToTreeNotNull(mirror); //IMPORTANT: do not take lock too early - FileDocumentManager.getInstance().saveToString() can run write action... final NonCancelableSection section = ProgressIndicatorProvider.startNonCancelableSectionIfSupported(); try { - setMirror((TreeElement)mirrorTreeElement); - - // TODO this code should be removed after 11.1 release. It is left just in case. - // Document is not actually used, maybe it is stored in mirror just to avoid garbage collecting - Document document = FileDocumentManager.getInstance().getDocument(virtualFile); - myMirrorFileElement.putUserData(DOCUMENT_IN_MIRROR_KEY, document); + setMirror(mirrorTreeElement); + } + catch (InvalidMirrorException e) { + // todo[r.sh] use logging API once available (to attach .class file) + LOG.error(file.getPath(), e); } finally { section.done(); } + + myMirrorFileElement = mirrorTreeElement; } return myMirrorFileElement.getPsi(); @@ -382,11 +351,12 @@ public class ClsFileImpl extends ClsRepositoryPsiElement } public static String decompile(PsiManager manager, VirtualFile file) { - final FileViewProvider provider = ((PsiManagerEx)manager).getFileManager().findViewProvider(file); ClsFileImpl psiFile = null; + + final FileViewProvider provider = ((PsiManagerEx)manager).getFileManager().findViewProvider(file); if (provider != null) { final PsiFile psi = provider.getPsi(provider.getBaseLanguage()); - if (psi instanceof PsiCompiledFile) { + if (psi instanceof ClsFileImpl) { psiFile = (ClsFileImpl)psi; } } @@ -423,7 +393,7 @@ public class ClsFileImpl extends ClsRepositoryPsiElement StubTree stubHolder = (StubTree)StubTreeLoader.getInstance().readOrBuild(getProject(), getVirtualFile(), this); if (stubHolder == null) { - // Must be corrupted classfile + // Must be corrupted .class file LOG.info("Class file is corrupted: " + getVirtualFile().getPresentableUrl()); StubTree emptyTree = new StubTree(new PsiJavaFileStubImpl("corrupted.classfiles", true)); @@ -512,6 +482,7 @@ public class ClsFileImpl extends ClsRepositoryPsiElement return myIsPhysical; } + @SuppressWarnings("UnusedDeclaration") // used by Kotlin compiler public void setPhysical(boolean isPhysical) { myIsPhysical = isPhysical; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsIdentifierImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsIdentifierImpl.java index ac8cbdeee9c2..c6306488d385 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsIdentifierImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsIdentifierImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -18,7 +18,6 @@ package com.intellij.psi.impl.compiled; import com.intellij.lexer.JavaLexer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; -import com.intellij.psi.impl.source.tree.ElementType; import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; @@ -27,7 +26,7 @@ class ClsIdentifierImpl extends ClsElementImpl implements PsiIdentifier, PsiJava private final PsiElement myParent; private final String myText; - ClsIdentifierImpl(PsiElement parent, String text) { + ClsIdentifierImpl(@NotNull PsiElement parent, String text) { myParent = parent; myText = text; } @@ -44,23 +43,23 @@ class ClsIdentifierImpl extends ClsElementImpl implements PsiIdentifier, PsiJava @Override @NotNull - public PsiElement[] getChildren(){ + public PsiElement[] getChildren() { return PsiElement.EMPTY_ARRAY; } @Override - public PsiElement getParent(){ + public PsiElement getParent() { return myParent; } private boolean isCorrectName(String name) { - if (name == null) return false; - - return StringUtil.isJavaIdentifier(name) && !JavaLexer.isKeyword(name, ((PsiJavaFile)getContainingFile()).getLanguageLevel()); + return name != null && + StringUtil.isJavaIdentifier(name) && + !JavaLexer.isKeyword(name, ((PsiJavaFile)getContainingFile()).getLanguageLevel()); } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer){ + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { String original = getText(); if (isCorrectName(original)) { buffer.append(original); @@ -71,12 +70,12 @@ class ClsIdentifierImpl extends ClsElementImpl implements PsiIdentifier, PsiJava } @Override - public void setMirror(@NotNull TreeElement element){ - setMirrorCheckingType(element, ElementType.IDENTIFIER); + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { + setMirrorCheckingType(element, JavaTokenType.IDENTIFIER); } @Override - public void accept(@NotNull PsiElementVisitor visitor){ + public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitIdentifier(this); } @@ -85,6 +84,7 @@ class ClsIdentifierImpl extends ClsElementImpl implements PsiIdentifier, PsiJava } } + @Override public String toString() { return "PsiIdentifier:" + getText(); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaCodeReferenceElementImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaCodeReferenceElementImpl.java index 69864e4efeb9..670660e66efe 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaCodeReferenceElementImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaCodeReferenceElementImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -36,14 +36,15 @@ import org.jetbrains.annotations.Nullable; import java.util.Map; public class ClsJavaCodeReferenceElementImpl extends ClsElementImpl implements PsiJavaCodeReferenceElement { + private static final ClsTypeElementImpl[] EMPTY_ARRAY = new ClsTypeElementImpl[0]; + @NonNls private static final String EXTENDS_PREFIX = "?extends"; + @NonNls private static final String SUPER_PREFIX = "?super"; + private final PsiElement myParent; private final String myCanonicalText; private final String myQualifiedName; private final ClsTypeElementImpl[] myTypeParameters; // in right-to-left order private volatile PsiType[] myTypeParametersCachedTypes = null; // in left-to-right-order - @NonNls private static final String EXTENDS_PREFIX = "?extends"; - @NonNls private static final String SUPER_PREFIX = "?super"; - public static final ClsJavaCodeReferenceElementImpl[] EMPTY_ARRAY = new ClsJavaCodeReferenceElementImpl[0]; public ClsJavaCodeReferenceElementImpl(PsiElement parent, String canonicalText) { myParent = parent; @@ -51,7 +52,7 @@ public class ClsJavaCodeReferenceElementImpl extends ClsElementImpl implements P myCanonicalText = canonicalText; final String[] classParametersText = PsiNameHelper.getClassParametersText(canonicalText); int length = classParametersText.length; - myTypeParameters = length == 0 ? ClsTypeElementImpl.EMPTY_ARRAY : new ClsTypeElementImpl[length]; + myTypeParameters = length == 0 ? EMPTY_ARRAY : new ClsTypeElementImpl[length]; for (int i = 0; i < length; i++) { String s = classParametersText[length - i - 1]; char variance = ClsTypeElementImpl.VARIANCE_NONE; @@ -138,7 +139,6 @@ public class ClsJavaCodeReferenceElementImpl extends ClsElementImpl implements P } } - @Override @NotNull public JavaResolveResult advancedResolve(boolean incompleteCode) { @@ -240,8 +240,7 @@ public class ClsJavaCodeReferenceElementImpl extends ClsElementImpl implements P public boolean isReferenceTo(PsiElement element) { if (!(element instanceof PsiClass)) return false; PsiClass aClass = (PsiClass)element; - return myCanonicalText.equals(aClass.getQualifiedName()) - || getManager().areElementsEquivalent(resolve(), element); + return myCanonicalText.equals(aClass.getQualifiedName()) || getManager().areElementsEquivalent(resolve(), element); } @Override @@ -256,12 +255,12 @@ public class ClsJavaCodeReferenceElementImpl extends ClsElementImpl implements P } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(final int indentLevel, @NotNull final StringBuilder buffer) { buffer.append(getCanonicalText()); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, JavaElementType.JAVA_CODE_REFERENCE); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaTokenImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaTokenImpl.java index 884bd72136e0..b2b676d08ac7 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaTokenImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaTokenImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -57,12 +57,12 @@ public class ClsJavaTokenImpl extends ClsElementImpl implements PsiJavaToken { } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { buffer.append(getText()); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, myTokenType); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsLiteralExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsLiteralExpressionImpl.java index 4c31f9f4fa94..6fb730d2fba6 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsLiteralExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsLiteralExpressionImpl.java @@ -53,12 +53,12 @@ public class ClsLiteralExpressionImpl extends ClsElementImpl implements PsiLiter } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { buffer.append(getText()); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, JavaElementType.LITERAL_EXPRESSION); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsMemberImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsMemberImpl.java new file mode 100644 index 000000000000..e59d9106e47c --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsMemberImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright 2000-2012 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.compiled; + +import com.intellij.psi.PsiDocCommentOwner; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiIdentifier; +import com.intellij.psi.PsiNameIdentifierOwner; +import com.intellij.psi.impl.PsiImplUtil; +import com.intellij.psi.javadoc.PsiDocComment; +import com.intellij.psi.stubs.NamedStub; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; + +public abstract class ClsMemberImpl + extends ClsRepositoryPsiElement + implements PsiDocCommentOwner, PsiNameIdentifierOwner { + + private PsiDocComment myDocComment; + private PsiIdentifier myNameIdentifier; + + protected ClsMemberImpl(T stub) { + super(stub); + } + + @Override + public PsiDocComment getDocComment() { + if (!isDeprecated()) return null; + + synchronized (LAZY_BUILT_LOCK) { + if (myDocComment == null) { + myDocComment = new ClsDocCommentImpl(this); + } + return myDocComment; + } + } + + @Override + @NotNull + public PsiIdentifier getNameIdentifier() { + synchronized (LAZY_BUILT_LOCK) { + if (myNameIdentifier == null) { + myNameIdentifier = new ClsIdentifierImpl(this, getName()); + } + return myNameIdentifier; + } + } + + @Override + @NotNull + public String getName() { + //noinspection ConstantConditions + return getStub().getName(); + } + + @Override + public PsiElement setName(@NotNull String name) throws IncorrectOperationException { + PsiImplUtil.setName(getNameIdentifier(), name); + return this; + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsMethodImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsMethodImpl.java index 2f03ef0da423..1cd215624027 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsMethodImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsMethodImpl.java @@ -17,7 +17,6 @@ package com.intellij.psi.impl.compiled; import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentationProviders; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -30,7 +29,6 @@ import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; import com.intellij.psi.impl.java.stubs.PsiMethodStub; import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.impl.source.tree.TreeElement; -import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.psi.scope.util.PsiScopesUtil; import com.intellij.psi.search.SearchScope; @@ -38,22 +36,16 @@ import com.intellij.psi.util.MethodSignature; import com.intellij.psi.util.MethodSignatureBackedByPsiMethod; import com.intellij.psi.util.MethodSignatureUtil; 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.*; import java.util.List; -public class ClsMethodImpl extends ClsRepositoryPsiElement implements PsiAnnotationMethod { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsMethodImpl"); - - private PsiIdentifier myNameIdentifier = null; //protected by PsiLock - private PsiTypeElement myReturnType = null; //protected by PsiLock - private PsiDocComment myDocComment = null; //protected by PsiLock - private PsiAnnotationMemberValue myDefaultValue = null; //protected by PsiLock +public class ClsMethodImpl extends ClsMemberImpl implements PsiAnnotationMethod { + private PsiTypeElement myReturnType = null; + private PsiAnnotationMemberValue myDefaultValue = null; public ClsMethodImpl(final PsiMethodStub stub) { super(stub); @@ -62,49 +54,8 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem @Override @NotNull public PsiElement[] getChildren() { - PsiDocComment docComment = getDocComment(); - PsiModifierList modifierList = getModifierList(); - PsiTypeElement returnType = getReturnTypeElement(); - PsiIdentifier name = getNameIdentifier(); - PsiParameterList parameterList = getParameterList(); - PsiReferenceList throwsList = getThrowsList(); - PsiAnnotationMemberValue defaultValue = getDefaultValue(); - - int count = - (docComment != null ? 1 : 0) - + (modifierList != null ? 1 : 0) - + (returnType != null ? 1 : 0) - + (name != null ? 1 : 0) - + (parameterList != null ? 1 : 0) - + (throwsList != null ? 1 : 0) - + (defaultValue != null ? 1 : 0); - - PsiElement[] children = new PsiElement[count]; - - int offset = 0; - if (docComment != null) { - children[offset++] = docComment; - } - if (modifierList != null) { - children[offset++] = modifierList; - } - if (returnType != null) { - children[offset++] = returnType; - } - if (name != null) { - children[offset++] = name; - } - if (parameterList != null) { - children[offset++] = parameterList; - } - if (throwsList != null) { - children[offset++] = throwsList; - } - if (defaultValue != null) { - children[offset++] = defaultValue; - } - - return children; + return getChildren(getDocComment(), getModifierList(), getReturnTypeElement(), getNameIdentifier(), getParameterList(), + getThrowsList(), getDefaultValue()); } @Override @@ -112,16 +63,6 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem return (PsiClass)getParent(); } - @Override - public PsiIdentifier getNameIdentifier() { - synchronized (LAZY_BUILT_LOCK) { - if (myNameIdentifier == null) { - myNameIdentifier = new ClsIdentifierImpl(this, getName()); - } - return myNameIdentifier; - } - } - @Override @NotNull public PsiMethod[] findSuperMethods() { @@ -157,31 +98,21 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem return PsiSuperMethodImplUtil.findDeepestSuperMethods(this); } - @Override - @NotNull - public String getName() { - return getStub().getName(); - } - @Override @NotNull public HierarchicalMethodSignature getHierarchicalMethodSignature() { return PsiSuperMethodImplUtil.getHierarchicalMethodSignature(this); } - @Override - public PsiElement setName(@NotNull String name) throws IncorrectOperationException { - PsiImplUtil.setName(getNameIdentifier(), name); - return this; - } - @Override public PsiTypeElement getReturnTypeElement() { if (isConstructor()) return null; synchronized (LAZY_BUILT_LOCK) { if (myReturnType == null) { - String typeText = TypeInfo.createTypeText(getStub().getReturnTypeText(false)); + PsiMethodStub stub = getStub(); + String typeText = TypeInfo.createTypeText(stub.getReturnTypeText(false)); + assert typeText != null : stub; myReturnType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE); } return myReturnType; @@ -217,6 +148,11 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem return getStub().findChildStubByType(JavaStubElementTypes.THROWS_LIST).getPsi(); } + @Override + public PsiTypeParameterList getTypeParameterList() { + return getStub().findChildStubByType(JavaStubElementTypes.TYPE_PARAMETER_LIST).getPsi(); + } + @Override public PsiCodeBlock getBody() { return null; @@ -232,27 +168,13 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem synchronized (LAZY_BUILT_LOCK) { if (myDefaultValue == null) { final String text = getStub().getDefaultValueText(); - if (StringUtil.isEmpty(text)) return null; - + if (text == null || StringUtil.isEmpty(text)) return null; myDefaultValue = ClsParsingUtil.createMemberValueFromText(text, getManager(), this); } return myDefaultValue; } } - @Override - public PsiDocComment getDocComment() { - if (!isDeprecated()) return null; - - synchronized (LAZY_BUILT_LOCK) { - if (myDocComment == null) { - myDocComment = new ClsDocCommentImpl(this); - } - return myDocComment; - } - } - - @Override public boolean isConstructor() { return getStub().isConstructor(); @@ -275,8 +197,27 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { - appendMethodHeader(buffer, indentLevel); + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { + appendText(getDocComment(), indentLevel, buffer, NEXT_LINE); + appendText(getModifierList(), indentLevel, buffer, ""); + appendText(getTypeParameterList(), indentLevel, buffer, " "); + if (!isConstructor()) { + appendText(getReturnTypeElement(), indentLevel, buffer, " "); + } + appendText(getNameIdentifier(), indentLevel, buffer, ""); + appendText(getParameterList(), indentLevel, buffer); + + PsiReferenceList throwsList = getThrowsList(); + if (throwsList.getReferencedTypes().length > 0) { + buffer.append(' '); + appendText(throwsList, indentLevel, buffer); + } + + PsiAnnotationMemberValue defaultValue = getDefaultValue(); + if (defaultValue != null) { + buffer.append(" default "); + appendText(defaultValue, indentLevel, buffer); + } if (hasModifierProperty(PsiModifier.ABSTRACT) || hasModifierProperty(PsiModifier.NATIVE)) { buffer.append(";"); @@ -286,54 +227,26 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem } } - private void appendMethodHeader(@NonNls StringBuilder buffer, final int indentLevel) { - ClsDocCommentImpl docComment = (ClsDocCommentImpl)getDocComment(); - if (docComment != null) { - docComment.appendMirrorText(indentLevel, buffer); - goNextLine(indentLevel, buffer); - } - ((ClsElementImpl)getModifierList()).appendMirrorText(indentLevel, buffer); - ((ClsElementImpl)getTypeParameterList()).appendMirrorText(indentLevel, buffer); + @Override + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { + setMirrorCheckingType(element, null); + + PsiMethod mirror = SourceTreeToPsiMap.treeToPsiNotNull(element); + + setMirrorIfPresent(getDocComment(), mirror.getDocComment()); + setMirror(getModifierList(), mirror.getModifierList()); + setMirror(getTypeParameterList(), mirror.getTypeParameterList()); if (!isConstructor()) { - ((ClsElementImpl)getReturnTypeElement()).appendMirrorText(indentLevel, buffer); - buffer.append(' '); - } - ((ClsElementImpl)getNameIdentifier()).appendMirrorText(indentLevel, buffer); - ((ClsElementImpl)getParameterList()).appendMirrorText(indentLevel, buffer); - final PsiReferenceList throwsList = getThrowsList(); - if (throwsList.getReferencedTypes().length > 0) { - buffer.append(' '); - ((ClsElementImpl)throwsList).appendMirrorText(indentLevel, buffer); + setMirror(getReturnTypeElement(), mirror.getReturnTypeElement()); } + setMirror(getNameIdentifier(), mirror.getNameIdentifier()); + setMirror(getParameterList(), mirror.getParameterList()); + setMirror(getThrowsList(), mirror.getThrowsList()); PsiAnnotationMemberValue defaultValue = getDefaultValue(); if (defaultValue != null) { - buffer.append(" default "); - ((ClsElementImpl)defaultValue).appendMirrorText(indentLevel, buffer); - } - } - - @Override - public void setMirror(@NotNull TreeElement element) { - setMirrorCheckingType(element, null); - - PsiMethod mirror = (PsiMethod)SourceTreeToPsiMap.treeElementToPsi(element); - if (getDocComment() != null) { - ((ClsElementImpl)getDocComment()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment())); - } - ((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList())); - if (!isConstructor() && mirror.getReturnTypeElement() != null) { - ((ClsElementImpl)getReturnTypeElement()).setMirror( - (TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getReturnTypeElement())); - } - ((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier())); - ((ClsElementImpl)getParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getParameterList())); - ((ClsElementImpl)getThrowsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getThrowsList())); - ((ClsElementImpl)getTypeParameterList()).setMirror( - (TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList())); - if (getDefaultValue() != null) { - LOG.assertTrue(mirror instanceof PsiAnnotationMethod); - ((ClsElementImpl)getDefaultValue()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(((PsiAnnotationMethod)mirror).getDefaultValue())); + assert mirror instanceof PsiAnnotationMethod : this; + setMirror(defaultValue, ((PsiAnnotationMethod)mirror).getDefaultValue()); } } @@ -347,10 +260,6 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem } } - public String toString() { - return "PsiMethod:" + getName(); - } - @Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @@ -395,11 +304,6 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem return method != null ? method.getNavigationElement() : this; } - @Override - public PsiTypeParameterList getTypeParameterList() { - return getStub().findChildStubByType(JavaStubElementTypes.TYPE_PARAMETER_LIST).getPsi(); - } - @Override public boolean hasTypeParameters() { return PsiImplUtil.hasTypeParameters(this); @@ -442,4 +346,9 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement implem protected boolean isVisibilitySupported() { return true; } + + @Override + public String toString() { + return "PsiMethod:" + getName(); + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsModifierListImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsModifierListImpl.java index 25f99d758334..038e13ed0350 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsModifierListImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsModifierListImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; @@ -28,9 +27,8 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +@SuppressWarnings("ForLoopReplaceableByForEach") public class ClsModifierListImpl extends ClsRepositoryPsiElement implements PsiModifierList { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsModifierListImpl"); - public ClsModifierListImpl(final PsiModifierListStub stub) { super(stub); } @@ -90,28 +88,15 @@ public class ClsModifierListImpl extends ClsRepositoryPsiElementtreeToPsiNotNull(element).getAnnotations(); - PsiAnnotation[] annotations = getAnnotations(); - LOG.assertTrue(annotations.length == mirrorAnnotations.length); - for (int i = 0; i < annotations.length; i++) { - ((ClsElementImpl)annotations[i]).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorAnnotations[i])); - } + setMirrors(getAnnotations(), SourceTreeToPsiMap.treeToPsiNotNull(element).getAnnotations()); } @Override @@ -190,6 +169,7 @@ public class ClsModifierListImpl extends ClsRepositoryPsiElement 0 ? psiClasses[0].getQualifiedName() : ""; - int index = className.lastIndexOf('.'); - myPackageName = index < 0 ? null : className.substring(0, index); + String packageName = null; + PsiClass[] psiClasses = file.getClasses(); + if (psiClasses.length > 0) { + String className = psiClasses[0].getQualifiedName(); + if (className != null) { + int index = className.lastIndexOf('.'); + if (index >= 0) { + packageName = className.substring(0, index); + } + } + } + myPackageName = packageName; } @Override @@ -45,8 +50,7 @@ class ClsPackageStatementImpl extends ClsElementImpl implements PsiPackageStatem */ @Override public PsiJavaCodeReferenceElement getPackageReference() { - LOG.error("method not implemented"); - return null; + throw new UnsupportedOperationException("Method not implemented"); } /** @@ -54,8 +58,7 @@ class ClsPackageStatementImpl extends ClsElementImpl implements PsiPackageStatem */ @Override public PsiModifierList getAnnotationList() { - LOG.error("method not implemented"); - return null; + throw new UnsupportedOperationException("Method not implemented"); } /** @@ -64,8 +67,7 @@ class ClsPackageStatementImpl extends ClsElementImpl implements PsiPackageStatem @Override @NotNull public PsiElement[] getChildren() { - LOG.error("method not implemented"); - return null; + throw new UnsupportedOperationException("Method not implemented"); } @Override @@ -74,15 +76,15 @@ class ClsPackageStatementImpl extends ClsElementImpl implements PsiPackageStatem } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { - buffer.append("package "); - buffer.append(getPackageName()); - buffer.append(";"); + public void appendMirrorText(final int indentLevel, @NotNull final StringBuilder buffer) { + if (myPackageName != null) { + buffer.append("package ").append(getPackageName()).append(";"); + } } @Override - public void setMirror(@NotNull TreeElement element) { - setMirrorCheckingType(element, ElementType.PACKAGE_STATEMENT); + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { + setMirrorCheckingType(element, JavaElementType.PACKAGE_STATEMENT); } @Override @@ -95,6 +97,7 @@ class ClsPackageStatementImpl extends ClsElementImpl implements PsiPackageStatem } } + @Override public String toString() { return "PsiPackageStatement:" + getPackageName(); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java index 96d6e794a481..129b441e761c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java @@ -15,13 +15,11 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.DumbService; import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.codeStyle.VariableKind; import com.intellij.psi.impl.ElementPresentationUtil; -import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.cache.TypeInfo; import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; import com.intellij.psi.impl.java.stubs.PsiParameterStub; @@ -38,17 +36,13 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import java.util.Arrays; public class ClsParameterImpl extends ClsRepositoryPsiElement implements PsiParameter { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsParameterImpl"); + private PsiTypeElement myType = null; + private String myName; + private String myMirrorName = null; - private volatile PsiTypeElement myType; //guarded by PsiLock - private String myMirrorName = null; //guarded by PsiLock - private String myName = null; //no point guarding - public static final ClsParameterImpl[] EMPTY_ARRAY = new ClsParameterImpl[0]; - - public ClsParameterImpl(final PsiParameterStub stub) { + public ClsParameterImpl(@NotNull PsiParameterStub stub) { super(stub); } @@ -81,22 +75,21 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement @Override public PsiElement setName(@NotNull String name) throws IncorrectOperationException { - PsiImplUtil.setName(getNameIdentifier(), name); - return this; + throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); } @Override @NotNull public PsiTypeElement getTypeElement() { - if (myType == null) { - synchronized (LAZY_BUILT_LOCK) { - if (myType == null) { - myType = new ClsTypeElementImpl(this, TypeInfo.createTypeText(getStub().getType(false)), ClsTypeElementImpl.VARIANCE_NONE); - } + synchronized (LAZY_BUILT_LOCK) { + if (myType == null) { + PsiParameterStub stub = getStub(); + String typeText = TypeInfo.createTypeText(stub.getType(false)); + assert typeText != null : stub; + myType = new ClsTypeElementImpl(this, typeText, ClsTypeElementImpl.VARIANCE_NONE); } + return myType; } - - return myType; } @Override @@ -138,52 +131,52 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { PsiAnnotation[] annotations = getModifierList().getAnnotations(); for (PsiAnnotation annotation : annotations) { - ((ClsAnnotationImpl)annotation).appendMirrorText(indentLevel, buffer); - buffer.append(" "); + appendText(annotation, indentLevel, buffer); + buffer.append(' '); } - ((ClsElementImpl)getTypeElement()).appendMirrorText(indentLevel, buffer); - buffer.append(" "); + appendText(getTypeElement(), indentLevel, buffer, " "); buffer.append(getMirrorName()); } private String getMirrorName() { synchronized (LAZY_BUILT_LOCK) { if (myMirrorName == null) { - final PsiParameterStubImpl parameterStub = (PsiParameterStubImpl) getStub(); - if (!parameterStub.isAutoGeneratedName()) { - myMirrorName = parameterStub.getName(); - return myMirrorName; - } - PsiParameter[] parms = ((PsiParameterList) getParent()).getParameters(); - if (DumbService.getInstance(getProject()).isDumb()) { - return "p" + Arrays.asList(parms).indexOf(this); - } + @NonNls String name; - String[] nameSuggestions = JavaCodeStyleManager.getInstance(getProject()).suggestVariableName(VariableKind.PARAMETER, null, - null, getType()) - .names; - - @NonNls String name = "p"; - if (nameSuggestions.length > 0) { - name = nameSuggestions[0]; + final PsiParameterStubImpl stub = (PsiParameterStubImpl)getStub(); + if (!stub.isAutoGeneratedName() || DumbService.getInstance(getProject()).isDumb()) { + name = stub.getName(); } + else { + JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(getProject()); + String[] nameSuggestions = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, null, null, getType()).names; - AttemptsLoop: - while (true) { - for (PsiParameter parm : parms) { - if (parm == this) break AttemptsLoop; - String name1 = ((ClsParameterImpl) parm).getMirrorName(); - if (name.equals(name1)) { - name = nextName(name); - continue AttemptsLoop; + name = "p"; + if (nameSuggestions.length > 0) { + name = nameSuggestions[0]; + } + + PsiParameter[] parameters = ((PsiParameterList) getParent()).getParameters(); + AttemptsLoop: + while (true) { + for (PsiParameter parameter : parameters) { + if (parameter == this) break AttemptsLoop; + String name1 = ((ClsParameterImpl) parameter).getMirrorName(); + if (name.equals(name1)) { + name = nextName(name); + continue AttemptsLoop; + } } } } + + assert name != null : stub; myMirrorName = name; } + return myMirrorName; } } @@ -207,18 +200,18 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement return name.substring(0, name.length() - count) + n; } catch (NumberFormatException e) { - LOG.assertTrue(false); + assert false : e.getMessage(); return null; } } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - PsiParameter mirror = (PsiParameter)SourceTreeToPsiMap.treeElementToPsi(element); - ((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList())); - ((ClsElementImpl)getTypeElement()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeElement())); + PsiParameter mirror = SourceTreeToPsiMap.treeToPsiNotNull(element); + setMirror(getModifierList(), mirror.getModifierList()); + setMirror(getTypeElement(), mirror.getTypeElement()); } @Override @@ -231,10 +224,6 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement } } - public String toString() { - return "PsiParameter"; - } - @Override @NotNull public PsiElement getDeclarationScope() { @@ -275,4 +264,9 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement public PsiType getTypeNoResolve() { return getType(); } + + @Override + public String toString() { + return "PsiParameter"; + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterListImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterListImpl.java index ab5d0b4b53e9..3ae62f074462 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterListImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterListImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.JavaElementVisitor; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiParameter; @@ -25,13 +24,10 @@ import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; import com.intellij.psi.impl.java.stubs.PsiParameterListStub; import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.impl.source.tree.TreeElement; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; public class ClsParameterListImpl extends ClsRepositoryPsiElement implements PsiParameterList { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsParameterListImpl"); - - public ClsParameterListImpl(final PsiParameterListStub stub) { + public ClsParameterListImpl(@NotNull PsiParameterListStub stub) { super(stub); } @@ -43,7 +39,7 @@ public class ClsParameterListImpl extends ClsRepositoryPsiElement 0) buffer.append(", "); - ((ClsElementImpl)parm).appendMirrorText(indentLevel, buffer); + appendText(parameters[i], indentLevel, buffer); } buffer.append(')'); } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - - PsiParameter[] parms = getParameters(); - PsiParameter[] parmMirrors = ((PsiParameterList)SourceTreeToPsiMap.treeElementToPsi(element)).getParameters(); - LOG.assertTrue(parms.length == parmMirrors.length); - if (parms.length == parmMirrors.length) { - for (int i = 0; i < parms.length; i++) { - ((ClsElementImpl)parms[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(parmMirrors[i])); - } - } + setMirrors(getParameters(), SourceTreeToPsiMap.treeToPsiNotNull(element).getParameters()); } @Override @@ -88,7 +75,7 @@ public class ClsParameterListImpl extends ClsRepositoryPsiElement implements PsiReferenceList { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsReferenceListImpl"); - private ClsJavaCodeReferenceElementImpl[] myRefs; //guarded by PsiLock + private static final ClsJavaCodeReferenceElementImpl[] EMPTY_REFS_ARRAY = new ClsJavaCodeReferenceElementImpl[0]; - public ClsReferenceListImpl(final PsiClassReferenceListStub stub) { + private ClsJavaCodeReferenceElementImpl[] myRefs; + + public ClsReferenceListImpl(@NotNull PsiClassReferenceListStub stub) { super(stub); } @@ -37,13 +37,15 @@ public class ClsReferenceListImpl extends ClsRepositoryPsiElement 0) { + myRefs = new ClsJavaCodeReferenceElementImpl[strings.length]; + for (int i = 0; i < strings.length; i++) { + myRefs[i] = new ClsJavaCodeReferenceElementImpl(this, strings[i]); + } + } + else { + myRefs = EMPTY_REFS_ARRAY; } - myRefs = res; } return myRefs; } @@ -67,7 +69,7 @@ public class ClsReferenceListImpl extends ClsRepositoryPsiElementtreeToPsiNotNull(element).getReferenceElements()); } @Override @@ -114,9 +108,8 @@ public class ClsReferenceListImpl extends ClsRepositoryPsiElement 0) buffer.append(" ,"); - ClsTypeElementImpl typeElement = (ClsTypeElementImpl)myTypeElements[i]; - typeElement.appendMirrorText(indentLevel, buffer); - } - buffer.append('>'); - } - } - - @Override - public void setMirror(@NotNull TreeElement element) { - setMirrorCheckingType(element, null); - - PsiTypeElement[] typeElements = getTypeParameterElements(); - PsiTypeElement[] typeMirrors = ((PsiReferenceParameterList)SourceTreeToPsiMap.treeElementToPsi(element)).getTypeParameterElements(); - LOG.assertTrue(typeElements.length == typeMirrors.length); - if (typeElements.length == typeMirrors.length) { - for (int i = 0; i < typeElements.length; i++) { - ((ClsElementImpl)typeElements[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(typeMirrors[i])); - } - } - } - - @Override - @NotNull - public PsiElement[] getChildren() { - return myTypeElements; - } - - @Override - @NotNull - public PsiTypeElement[] getTypeParameterElements() { - return myTypeElements; - } - - @Override - @NotNull - public PsiType[] getTypeArguments() { - return PsiImplUtil.typesByTypeElements(myTypeElements); - } - - @Override - public PsiElement getParent() { - return myParent; - } - - @Override - public void accept(@NotNull PsiElementVisitor visitor) { - if (visitor instanceof JavaElementVisitor) { - ((JavaElementVisitor)visitor).visitReferenceParameterList(this); - } - else { - visitor.visitElement(this); - } - } -} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeElementImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeElementImpl.java index 708765972e93..ff25271c26ce 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeElementImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeElementImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.source.PsiClassReferenceType; @@ -25,24 +24,21 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement { - public static final ClsTypeElementImpl[] EMPTY_ARRAY = new ClsTypeElementImpl[0]; - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsTypeImpl"); static final char VARIANCE_NONE = '\0'; static final char VARIANCE_EXTENDS = '+'; static final char VARIANCE_SUPER = '-'; static final char VARIANCE_INVARIANT = '*'; - - private final PsiElement myParent; - private final String myTypeText; - - private volatile ClsElementImpl myChild = null; - private boolean myChildSet = false; //guarded by PsiLock - private volatile PsiType myCachedType; - private final char myVariance; @NonNls private static final String VARIANCE_EXTENDS_PREFIX = "? extends "; @NonNls private static final String VARIANCE_SUPER_PREFIX = "? super "; - public ClsTypeElementImpl(PsiElement parent, String typeText, char variance) { + private final PsiElement myParent; + private final String myTypeText; + private volatile ClsElementImpl myChild = null; + private boolean myChildSet = false; + private volatile PsiType myCachedType; + private final char myVariance; + + public ClsTypeElementImpl(@NotNull PsiElement parent, String typeText, char variance) { myParent = parent; myTypeText = typeText; myVariance = variance; @@ -50,25 +46,24 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement @Override @NotNull - public PsiElement[] getChildren(){ + public PsiElement[] getChildren() { loadChild(); - if (myChild == null) return PsiElement.EMPTY_ARRAY; - return new PsiElement[] {myChild}; + return myChild != null ? new PsiElement[]{myChild} : PsiElement.EMPTY_ARRAY; } @Override - public PsiElement getParent(){ + public PsiElement getParent() { return myParent; } @Override - public String getText(){ + public String getText() { final String shortClassName = PsiNameHelper.getShortClassName(myTypeText); return decorateTypeText(shortClassName); } private String decorateTypeText(final String shortClassName) { - switch(myVariance) { + switch (myVariance) { case VARIANCE_NONE: return shortClassName; case VARIANCE_EXTENDS: @@ -78,22 +73,22 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement case VARIANCE_INVARIANT: return "?"; default: - LOG.assertTrue(false); + assert false : myVariance; return null; } } - public String getCanonicalText(){ + public String getCanonicalText() { return decorateTypeText(myTypeText); } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer){ + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { buffer.append(decorateTypeText(myTypeText)); } @Override - public void setMirror(@NotNull TreeElement element){ + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, JavaElementType.TYPE); loadChild(); @@ -172,7 +167,7 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement case VARIANCE_SUPER: return PsiWildcardType.createSuper(getManager(), ((PsiTypeElement)myChild).getType()); default: - LOG.assertTrue(false); + assert false : myVariance; return null; } } @@ -200,7 +195,7 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement case VARIANCE_INVARIANT: return PsiWildcardType.createUnbounded(getManager()); default: - LOG.assertTrue(false); + assert false : myVariance; return null; } } @@ -231,7 +226,7 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement myChild = new ClsTypeElementImpl(this, myTypeText.substring(0, myTypeText.length() - 3), myVariance); } else { - LOG.assertTrue(false); + assert false : myTypeText; } myChildSet = true; } @@ -239,7 +234,7 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement } @Override - public void accept(@NotNull PsiElementVisitor visitor){ + public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitTypeElement(this); } @@ -248,10 +243,6 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement } } - public String toString() { - return "PsiTypeElement:" + getText(); - } - @Override @NotNull public PsiAnnotation[] getAnnotations() { @@ -274,4 +265,9 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement public PsiAnnotation[] getApplicableAnnotations() { return getAnnotations(); } + + @Override + public String toString() { + return "PsiTypeElement:" + getText(); + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeParameterImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeParameterImpl.java index 0b091dd35eb8..937def146dab 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeParameterImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeParameterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl.compiled; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Pair; import com.intellij.psi.*; import com.intellij.psi.impl.InheritanceImplUtil; @@ -43,11 +42,9 @@ import java.util.List; * @author max */ public class ClsTypeParameterImpl extends ClsRepositoryPsiElement implements PsiTypeParameter { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsTypeParameterImpl"); - static final ClsTypeParameterImpl[] EMPTY_ARRAY = new ClsTypeParameterImpl[0]; private final LightEmptyImplementsList myLightEmptyImplementsList; - public ClsTypeParameterImpl(final PsiTypeParameterStub stub) { + public ClsTypeParameterImpl(@NotNull PsiTypeParameterStub stub) { super(stub); myLightEmptyImplementsList = new LightEmptyImplementsList(getManager()); } @@ -313,25 +310,23 @@ public class ClsTypeParameterImpl extends ClsRepositoryPsiElement 0) { buffer.append(" extends "); for (int i = 0; i < bounds.length; i++) { - PsiJavaCodeReferenceElement bound = bounds[i]; if (i > 0) buffer.append(" & "); - buffer.append(bound.getCanonicalText()); + buffer.append(bounds[i].getCanonicalText()); } } } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - - PsiTypeParameter mirror = (PsiTypeParameter)SourceTreeToPsiMap.treeElementToPsi(element); - ((ClsReferenceListImpl)getExtendsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList())); + setMirror(getExtendsList(), SourceTreeToPsiMap.treeToPsiNotNull(element).getExtendsList()); } @Override @@ -345,11 +340,10 @@ public class ClsTypeParameterImpl extends ClsRepositoryPsiElement implements PsiTypeParameterList { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsTypeParametersListImpl"); - - public ClsTypeParametersListImpl(final PsiTypeParameterListStub stub) { + public ClsTypeParametersListImpl(@NotNull PsiTypeParameterListStub stub) { super(stub); } @Override - public void appendMirrorText(final int indentLevel, final StringBuilder buffer) { + public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { final PsiTypeParameter[] params = getTypeParameters(); if (params.length != 0) { buffer.append('<'); for (int i = 0; i < params.length; i++) { - ClsTypeParameterImpl parameter = (ClsTypeParameterImpl)params[i]; if (i > 0) buffer.append(", "); - parameter.appendMirrorText(indentLevel, buffer); + appendText(params[i], indentLevel, buffer); } buffer.append("> "); } } @Override - public void setMirror(@NotNull TreeElement element) { + public void setMirror(@NotNull TreeElement element) throws InvalidMirrorException { setMirrorCheckingType(element, null); - - PsiTypeParameter[] parms = getTypeParameters(); - PsiTypeParameter[] parmMirrors = ((PsiTypeParameterList)SourceTreeToPsiMap.treeElementToPsi(element)).getTypeParameters(); - LOG.assertTrue(parms.length == parmMirrors.length); - if (parms.length == parmMirrors.length) { - for (int i = 0; i < parms.length; i++) { - ((ClsElementImpl)parms[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(parmMirrors[i])); - } - } + setMirrors(getTypeParameters(), SourceTreeToPsiMap.treeToPsiNotNull(element).getTypeParameters()); } - @Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { @@ -81,14 +68,10 @@ public class ClsTypeParametersListImpl extends ClsRepositoryPsiElement extends ClassVisitor { private static final Pattern REGEX_PATTERN = Pattern.compile("(?<=[^\\$\\.])\\${1}(?=[^\\$])"); // disallow .$ or $$ @@ -325,7 +326,7 @@ public class StubBuildingVisitor extends ClassVisitor { if (!isCorrectName(name)) return null; final byte flags = PsiFieldStubImpl.packFlags((access & Opcodes.ACC_ENUM) != 0, (access & Opcodes.ACC_DEPRECATED) != 0, false); - PsiFieldStub stub = new PsiFieldStubImpl(myResult, name, fieldType(desc, signature), constToString(value), flags); + final PsiFieldStub stub = new PsiFieldStubImpl(myResult, name, fieldType(desc, signature), constToString(value), flags); final PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packFieldFlags(access)); return new AnnotationCollectingVisitor(modList); } @@ -677,9 +678,8 @@ public class StubBuildingVisitor extends ClassVisitor { } } - @SuppressWarnings({"HardCodedStringLiteral"}) @Nullable - private static String constToString(final Object value) { + private static String constToString(@Nullable Object value) { if (value == null) return null; if (value instanceof String) return "\"" + StringUtil.escapeStringCharacters((String)value) + "\""; @@ -711,6 +711,22 @@ public class StubBuildingVisitor extends ClassVisitor { } } + if (value.getClass().isArray()) { + StringBuilder buffer = StringBuilderSpinAllocator.alloc(); + try { + buffer.append('{'); + for (int i = 0, length = Array.getLength(value); i < length; i++) { + if (i > 0) buffer.append(", "); + buffer.append(Array.get(value, i)); + } + buffer.append('}'); + return buffer.toString(); + } + finally { + StringBuilderSpinAllocator.dispose(buffer); + } + } + return null; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiAnnotationStub.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiAnnotationStub.java index b8d8fe6c07fe..424ff045a118 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiAnnotationStub.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiAnnotationStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * @author max - */ package com.intellij.psi.impl.java.stubs; import com.intellij.psi.PsiAnnotation; -import com.intellij.psi.impl.source.tree.CompositeElement; import com.intellij.psi.stubs.StubElement; +/** + * @author max + */ public interface PsiAnnotationStub extends StubElement { String getText(); - CompositeElement getTreeElement(); + + PsiAnnotation getPsiElement(); } \ No newline at end of file diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java index 4f88aee4dd1c..ed0b25bf2dbc 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java @@ -19,9 +19,9 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Pair; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiJavaParserFacade; import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; import com.intellij.psi.impl.java.stubs.PsiAnnotationStub; -import com.intellij.psi.impl.source.tree.CompositeElement; import com.intellij.psi.stubs.StubBase; import com.intellij.psi.stubs.StubElement; import com.intellij.util.IncorrectOperationException; @@ -38,7 +38,7 @@ public class PsiAnnotationStubImpl extends StubBase implements Ps private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.java.stubs.impl.PsiAnnotationStubImpl"); private final String myText; - private PatchedSoftReference myParsedFromRepository; + private PatchedSoftReference myParsedFromRepository; public PsiAnnotationStubImpl(final StubElement parent, final String text) { this(parent, text, null); @@ -61,18 +61,21 @@ public class PsiAnnotationStubImpl extends StubBase implements Ps } @Override - public CompositeElement getTreeElement() { + public PsiAnnotation getPsiElement() { if (myParsedFromRepository != null) { - CompositeElement parsed = myParsedFromRepository.get(); - if (parsed != null) return parsed; + PsiAnnotation annotation = myParsedFromRepository.get(); + if (annotation != null) { + return annotation; + } } final String text = getText(); try { - CompositeElement parsed = (CompositeElement)JavaPsiFacade.getInstance(getProject()).getParserFacade().createAnnotationFromText(text, getPsi()).getNode(); - myParsedFromRepository = new PatchedSoftReference(parsed); - assert parsed != null; - return parsed; + PsiJavaParserFacade facade = JavaPsiFacade.getInstance(getProject()).getParserFacade(); + PsiAnnotation annotation = facade.createAnnotationFromText(text, getPsi()); + myParsedFromRepository = new PatchedSoftReference(annotation); + assert annotation != null : text; + return annotation; } catch (IncorrectOperationException e) { LOG.error("Bad annotation in repository!", e); @@ -80,6 +83,7 @@ public class PsiAnnotationStubImpl extends StubBase implements Ps } } + @Override @SuppressWarnings({"HardCodedStringLiteral"}) public String toString() { return "PsiAnnotationStub[" + myText + "]"; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiClassStubImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiClassStubImpl.java index 9a12f719b62a..0e63de678ec1 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiClassStubImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiClassStubImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.psi.impl.java.stubs.impl; import com.intellij.pom.java.LanguageLevel; @@ -23,8 +22,9 @@ import com.intellij.psi.impl.java.stubs.PsiClassStub; import com.intellij.psi.stubs.StubBase; import com.intellij.psi.stubs.StubElement; import com.intellij.util.io.StringRef; +import org.jetbrains.annotations.Nullable; -/* +/** * @author max */ public class PsiClassStubImpl extends StubBase implements PsiClassStub { @@ -49,7 +49,7 @@ public class PsiClassStubImpl extends StubBase implements final StubElement parent, final String qualifiedName, final String name, - final String baseRefText, + @Nullable final String baseRefText, final byte flags) { this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name), StringRef.fromString(baseRefText), flags); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiFieldStubImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiFieldStubImpl.java index 8942865c38bf..b4383c1c73a3 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiFieldStubImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiFieldStubImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -13,10 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * @author max - */ package com.intellij.psi.impl.java.stubs.impl; import com.intellij.psi.PsiField; @@ -30,7 +26,11 @@ import com.intellij.psi.stubs.StubBase; import com.intellij.psi.stubs.StubElement; import com.intellij.util.io.StringRef; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +/** + * @author max + */ public class PsiFieldStubImpl extends StubBase implements PsiFieldStub { private final StringRef myName; private final TypeInfo myType; @@ -41,7 +41,7 @@ public class PsiFieldStubImpl extends StubBase implements PsiFieldStub private static final int DEPRECATED = 0x02; private static final int DEPRECATED_ANNOTATION = 0x04; - public PsiFieldStubImpl(final StubElement parent, final String name, @NotNull TypeInfo type, final String initializer, final byte flags) { + public PsiFieldStubImpl(final StubElement parent, final String name, @NotNull TypeInfo type, @Nullable String initializer, final byte flags) { this(parent, StringRef.fromString(name), type, StringRef.fromString(initializer), flags); } @@ -69,7 +69,7 @@ public class PsiFieldStubImpl extends StubBase implements PsiFieldStub for (StubElement child: modifierList.getChildrenStubs()){ if (!(child instanceof PsiAnnotationStub)) continue; PsiAnnotationStub annotationStub = (PsiAnnotationStub)child; - PsiAnnotationImpl annotation = (PsiAnnotationImpl)annotationStub.getTreeElement().getPsi(); + PsiAnnotationImpl annotation = (PsiAnnotationImpl)annotationStub.getPsiElement(); if (PsiAnnotationImpl.isAnnotationApplicableTo(annotation, true, "TYPE_USE")) { typeInfo.addAnnotation(annotationStub); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiParameterStubImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiParameterStubImpl.java index bfc56298dae7..9e732a209201 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiParameterStubImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiParameterStubImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -13,10 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * @author max - */ package com.intellij.psi.impl.java.stubs.impl; import com.intellij.psi.PsiParameter; @@ -31,6 +27,9 @@ import org.jetbrains.annotations.NotNull; import java.util.List; +/** + * @author max + */ public class PsiParameterStubImpl extends StubBase implements PsiParameterStub { private StringRef myName; private final TypeInfo myType; @@ -74,16 +73,6 @@ public class PsiParameterStubImpl extends StubBase implements PsiP return StringRef.toString(myName); } - @SuppressWarnings({"HardCodedStringLiteral"}) - public String toString() { - StringBuilder builder = new StringBuilder(); - builder. - append("PsiParameterStub["). - append(myName).append(':').append(TypeInfo.createTypeText(getType(false))). - append(']'); - return builder.toString(); - } - public void setName(String name) { myName = StringRef.fromString(name); } @@ -99,4 +88,14 @@ public class PsiParameterStubImpl extends StubBase implements PsiP } return ("p" + paramIndex).equals(getName()); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder. + append("PsiParameterStub["). + append(myName).append(':').append(TypeInfo.createTypeText(getType(false))). + append(']'); + return builder.toString(); + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationImpl.java index 9a2d8f0dbd09..60f613f5d977 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationImpl.java @@ -24,7 +24,6 @@ import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; import com.intellij.psi.impl.java.stubs.PsiAnnotationStub; import com.intellij.psi.impl.meta.MetaRegistry; import com.intellij.psi.impl.source.JavaStubPsiElement; -import com.intellij.psi.impl.source.tree.ChildRole; import com.intellij.psi.meta.PsiMetaData; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; @@ -58,7 +57,7 @@ public class PsiAnnotationImpl extends JavaStubPsiElement imp public PsiJavaCodeReferenceElement getNameReferenceElement() { final PsiAnnotationStub stub = getStub(); if (stub != null) { - return (PsiJavaCodeReferenceElement)stub.getTreeElement().findChildByRoleAsPsiElement(ChildRole.CLASS_REFERENCE); + return PsiTreeUtil.getRequiredChildOfType(stub.getPsiElement(), PsiJavaCodeReferenceElement.class); } final Object result = PsiTreeUtil.getChildOfType(this, PsiJavaCodeReferenceElement.class); diff --git a/java/java-tests/testData/psi/cls/mirror/$BuckClass.txt b/java/java-tests/testData/psi/cls/mirror/$BuckClass.txt index 4e3899f22d42..d94f6e32f2c1 100644 --- a/java/java-tests/testData/psi/cls/mirror/$BuckClass.txt +++ b/java/java-tests/testData/psi/cls/mirror/$BuckClass.txt @@ -4,9 +4,8 @@ package pkg; -class $BuckClass { - +class $BuckClass { $BuckClass() { /* compiled code */ } - + static pkg.$BuckClass getInstance() { /* compiled code */ } } diff --git a/java/java-tests/testData/psi/cls/mirror/Annotations.txt b/java/java-tests/testData/psi/cls/mirror/Annotations.txt new file mode 100644 index 000000000000..9bbe384da735 --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/Annotations.txt @@ -0,0 +1,58 @@ + + // IntelliJ API Decompiler stub source generated from a class file + // Implementation of methods is not available + +package pkg; + +abstract class Annotations { + Annotations() { /* compiled code */ } + + @pkg.Annotations.A1 + abstract void m1(); + + @pkg.Annotations.A2 + abstract void m2a(); + + @pkg.Annotations.A2("+") + abstract void m2b(); + + @pkg.Annotations.A3(a1 = @pkg.Annotations.A1, a2 = @pkg.Annotations.A2) + abstract void m3(); + + @pkg.Annotations.A4 + abstract void m4a(); + + @pkg.Annotations.A4(ids = {42, 84}) + abstract void m4b(); + + static @interface IndeterminateAnno { + float f1() default -1.0f / 0.0; + + float f2() default 0.0f / 0.0; + + float f3() default 1.0f / 0.0; + + double d1() default -1.0 / 0.0; + + double d2() default 0.0d / 0.0; + + double d3() default 1.0 / 0.0; + } + + static @interface A4 { + int[] ids() default {}; + } + + static @interface A3 { + pkg.Annotations.A1 a1(); + + pkg.Annotations.A2 a2(); + } + + static @interface A2 { + java.lang.String value() default "-"; + } + + static @interface A1 { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/Deprecated.txt b/java/java-tests/testData/psi/cls/mirror/Deprecated.txt new file mode 100644 index 000000000000..efa33fb4f4ae --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/Deprecated.txt @@ -0,0 +1,22 @@ + + // IntelliJ API Decompiler stub source generated from a class file + // Implementation of methods is not available + +package pkg; + +/** + * @deprecated + */ +class Deprecated { + /** + * @deprecated + */ + int f; + + Deprecated() { /* compiled code */ } + + /** + * @deprecated + */ + void m() { /* compiled code */ } +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/EmptyEnum.txt b/java/java-tests/testData/psi/cls/mirror/EmptyEnum.txt index 30c4cd130a63..33ea56d549a1 100644 --- a/java/java-tests/testData/psi/cls/mirror/EmptyEnum.txt +++ b/java/java-tests/testData/psi/cls/mirror/EmptyEnum.txt @@ -6,9 +6,10 @@ package pkg; final enum EmptyEnum { ; + public static pkg.EmptyEnum[] values() { /* compiled code */ } - + public static pkg.EmptyEnum valueOf(java.lang.String s) { /* compiled code */ } - + private EmptyEnum() { /* compiled code */ } -} +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/EnumWithFields.txt b/java/java-tests/testData/psi/cls/mirror/EnumWithFields.txt new file mode 100644 index 000000000000..46035f350a19 --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/EnumWithFields.txt @@ -0,0 +1,18 @@ + + // IntelliJ API Decompiler stub source generated from a class file + // Implementation of methods is not available + +package pkg; + +public final enum EnumWithFields { + public static final E1, public static final E2; + + boolean f1; + boolean f2; + + public static pkg.EnumWithFields[] values() { /* compiled code */ } + + public static pkg.EnumWithFields valueOf(java.lang.String s) { /* compiled code */ } + + private EnumWithFields() { /* compiled code */ } +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/ExtMethods.txt b/java/java-tests/testData/psi/cls/mirror/ExtMethods.txt index 5f4898ab4d87..e4d483989def 100644 --- a/java/java-tests/testData/psi/cls/mirror/ExtMethods.txt +++ b/java/java-tests/testData/psi/cls/mirror/ExtMethods.txt @@ -4,9 +4,8 @@ package pkg; -interface ExtMethods { - +interface ExtMethods { void m1(); - + void m2() { /* compiled code */ } } diff --git a/java/java-tests/testData/psi/cls/mirror/MethodReceiver.txt b/java/java-tests/testData/psi/cls/mirror/MethodReceiver.txt index 71213b8ead80..c5b7fc5a2f1c 100644 --- a/java/java-tests/testData/psi/cls/mirror/MethodReceiver.txt +++ b/java/java-tests/testData/psi/cls/mirror/MethodReceiver.txt @@ -4,12 +4,11 @@ package pkg; -class MethodReceiver { - +class MethodReceiver { MethodReceiver() { /* compiled code */ } - + void m(int i) { /* compiled code */ } - + static @interface A { } -} +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/NormalClass.txt b/java/java-tests/testData/psi/cls/mirror/NormalClass.txt new file mode 100644 index 000000000000..82532ce80097 --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/NormalClass.txt @@ -0,0 +1,17 @@ + + // IntelliJ API Decompiler stub source generated from a class file + // Implementation of methods is not available + +package pkg; + +class NormalClass { + private final java.lang.Object o; + + NormalClass() { /* compiled code */ } + + java.lang.Object get() { /* compiled code */ } + + private static class Inner { + private Inner() { /* compiled code */ } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/ParameterNames.txt b/java/java-tests/testData/psi/cls/mirror/ParameterNames.txt new file mode 100644 index 000000000000..71e6d4661eaa --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/ParameterNames.txt @@ -0,0 +1,13 @@ + + // IntelliJ API Decompiler stub source generated from a class file + // Implementation of methods is not available + +package pkg; + +public class ParameterNames { + public ParameterNames() { /* compiled code */ } + + public void test(int i, int i1, java.lang.String s) { /* compiled code */ } + + private void testImpl(int i, int i1, java.lang.String s, boolean b) { /* compiled code */ } +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/SimpleEnum.txt b/java/java-tests/testData/psi/cls/mirror/SimpleEnum.txt new file mode 100644 index 000000000000..e9a230c7accc --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/SimpleEnum.txt @@ -0,0 +1,15 @@ + + // IntelliJ API Decompiler stub source generated from a class file + // Implementation of methods is not available + +package pkg; + +public final enum SimpleEnum { + public static final E1, public static final E2; + + public static pkg.SimpleEnum[] values() { /* compiled code */ } + + public static pkg.SimpleEnum valueOf(java.lang.String s) { /* compiled code */ } + + private SimpleEnum() { /* compiled code */ } +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/package-info.txt b/java/java-tests/testData/psi/cls/mirror/package-info.txt index 48aa009cc146..5c25b9fb6b3d 100644 --- a/java/java-tests/testData/psi/cls/mirror/package-info.txt +++ b/java/java-tests/testData/psi/cls/mirror/package-info.txt @@ -5,5 +5,5 @@ package pkg; @pkg.PkgAnno -interface $$package-info /* Real name is 'package-info' */ { +interface $$package-info /* Real name is 'package-info' */ { } diff --git a/java/java-tests/testData/psi/cls/mirror/pkg/Annotations$A1.class b/java/java-tests/testData/psi/cls/mirror/pkg/Annotations$A1.class new file mode 100644 index 0000000000000000000000000000000000000000..61209608ab7ec9ccd1d015784d288e8ff2f3b842 GIT binary patch literal 206 zcmX^0Z`VEs1_mPrUUmj{b_OnX25v?MuHgLAqU2P!%$!t41_8&sy!?{HlFaK9+1|W+COtLa?0%V@o*L%z(a{+W5i;wP^EfqYb(V$B2{a}6 zhqTB}Y7=YbcFQ3<`-lj13H|FO3V)E%a!znQuDLZvWh*VMRhH@H-u*FACtfiuTk?Cr pj~Jozryc;T&Q{?U$tAe(xT zBfaEvH1v}HhvgH?TtvsiN=`PRWU${v23v6w98HGmm;6wxQnNM34TV~}^W|2q5{Axe zB%X=h!u^t?qrN>TwDn=^0Ax&+rVphu3>g>zVID<2LFv)U;Dl{rWnm%b7%&M7gd~ZI GW848O=~CeU literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/psi/cls/mirror/pkg/Annotations$A4.class b/java/java-tests/testData/psi/cls/mirror/pkg/Annotations$A4.class new file mode 100644 index 0000000000000000000000000000000000000000..040a84c053536eea041abcbff2f4c052a51b4e73 GIT binary patch literal 256 zcmZ8c%MQU%5IxhDOFdeCz($0PCgKN#NV>AHw7TkQ%FV5`<>M@TfR7SW3mS_#lQWNV zW}dJ61HcTvfGf}u=o0MYkQ1EoWET>83uDqk7D;MW>L{QO@bRcIt248A3>L%(8)$QOxkYHAHEO&8*t|T} literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/psi/cls/mirror/pkg/Annotations$IndeterminateAnno.class b/java/java-tests/testData/psi/cls/mirror/pkg/Annotations$IndeterminateAnno.class new file mode 100644 index 0000000000000000000000000000000000000000..d77b499c1f59ea89a719eed4d9eb3433fa867a62 GIT binary patch literal 442 zcmZvXO-{ow5QU$U5SLJ(6^MVRkg5tcM5HG`M3K5;!3j*`Rw=93=+|A@zGxQoHmKlvz44Z#; z4}S7cCY$284ugXgs$8n<2%JF61giu*6RZ(vWBpeWVuL`(1YH7KCfJ6B9rCxZi$l6S L5;N@KV9@#o9L!hW literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/psi/cls/mirror/pkg/Annotations.class b/java/java-tests/testData/psi/cls/mirror/pkg/Annotations.class new file mode 100644 index 0000000000000000000000000000000000000000..03f1f52f42b800d671827a1378fa3ffe529ae808 GIT binary patch literal 786 zcmZvaQBN8{6otvl=P)f15C^)I~aE1fBDqJ z2Y-M+%Jj^d5Ct~bJ)7^IIdkvM-ap*l0r1f%AcIdH4m=!ss0*xxwyzUCii}l>Zd*GP zD2CSR(aAu?v5q}_7Le`0!xyJ54_}@79*&$g1(v=WYmy%VnS;YW0@;&cUkj|B8moVe zqpluxRChokBbv9*#x^mL4(-ImhTLtLsKg9yEKokZzPe~ULDhEi8-pWXEiC$v#jZeZ zq6TAbB3!poYoWVEw^VFGD&K_$i$jAnG+=1P^y3V_Tirc60)_M8c+}HBjT@)*q|KvC zHBm*ZqQt>xMxfJG8v|u88o#@jx|ax4W=z!u$M9;_(+&jYA!nV3oNpdBvwM&{e|LGj z*)I48@U21>)Li`^#0_7#oX-O7;DRi6vcP(3FOw{>{u;#Cc*ZtUwl!rd^lkEf6XPw- z+tWgs@EyZjEC6>5?Cg8H(S{|{3)m#_c; literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/psi/cls/mirror/pkg/Deprecated.class b/java/java-tests/testData/psi/cls/mirror/pkg/Deprecated.class new file mode 100644 index 0000000000000000000000000000000000000000..89e87d5bf5df36e68bcdf87936bce2eac9e5dc05 GIT binary patch literal 288 zcmZ9GL2rUU5QX0$f>0Ga_F&Ru+k+%MH(qK?nlyUQ^uFMhKmiQ_|Cc9|9{L0Nqf8%| zXyRdZ-n{wt?f#v9egV8-{1zZA6J2(T3UtwAaCWH1>;>Zinc0JcW>DM^6N#c|M;ywS6rLG*lZXPsjfte4J zlaiN?AGv*jho*H8MA_+{xB}Ux7r1-TMa%8Ib6P%m)HrwlRKPTw=gy^5^_`$owZonl zbZXW;gmo|Q!YzT>2{~`9LxGg-bpj`hdPE_c?9u9Nf0(s8Lc|-WPh#1kZRmD4>b2cn zk2}rZT~>vgHIV1E7Yw{WMIbl6Qv*d*4Lru&P)s3XAd8GZ=5|~zEs$vY-GG=1rZv*x ze(T(Aht$oh(P4Ldr{AxQ!2WOSZq?fM23@>CuO+cv1d#)ziJv^cG#&{CqBO)WLyEoWJe2Y`ByOOLCrG>z0y4o< z$n*hfd4290$uDEopO8nwJT!vN4_V$)mwYNepd9B^`5M|4Qn8^cv5`*vq>wzIw{WZs akhZTNZfomQktZz?wS<2R3s@wdgr&dm9I4X) literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/psi/cls/mirror/pkg/NormalClass$1.class b/java/java-tests/testData/psi/cls/mirror/pkg/NormalClass$1.class new file mode 100644 index 0000000000000000000000000000000000000000..8369e5b8ac349f3064189a19b808fb0082854921 GIT binary patch literal 192 zcmX^0Z`VEs1_mPr9(D$Hb_Om+2Cm@z(xT*4x6GVWMg{@D{G!~%9Os~wu3wJL^;3=E76Jf3-ZsYPJjsl`CkKqlzt zB<7{-`zK|kCYJzBL(?dr0My0=bP)(J10e&D$HKr0q*)l)fFvgna{<*bf_MTP0L`N- Ac>n+a literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/psi/cls/mirror/pkg/NormalClass$Inner.class b/java/java-tests/testData/psi/cls/mirror/pkg/NormalClass$Inner.class new file mode 100644 index 0000000000000000000000000000000000000000..7137515b74427af0afcdfef88734017e42e23b4e GIT binary patch literal 373 zcmZWk%SyvQ6g@XhI(3XDRok85!bNpqs9VKNK@dt^DDEe9D5=v#lGgv~N^s!^_)+3X zsUVSoxsUU>_kMkUd;+*cU!#Rc!$+jhRX7y1ud_T`-UwQQvnPQ+DxR$%8fUqktQM&) zA5H44!jS-i@Gj47IdZ0|Y$fOq#;-54WKxt1<2K#X;Z<#;ABt5uwYQn0S^NjTn432f zB0yWAC+Ich8-GEtjd4v+oXKa&eLA<(rJ&oC47qNjhZElE^JKu|<23HBSRFI+5CrG% r@YYNO9sV^8=$HUP=D$>LOO=0Ay6zG5u#a8F17~0{$*dG$fk%1N>3O zX}K8mu)FhS=e?QTukZIy0B5K>uu!#8bD&`_2NU}?4s0CSI1)hMUPX~gdZ9m`tGU3; zN`b_Ja)0VS`R&k;ChhCdRE-y1fps24!Qw)oH@%_2=*9O+Q0NDd8Z2icmE8KHkc>W2 z3qhsn{Wrw9iI>S(T?VPLIEa&(A7&9wQ%4s&$P22E50mz5t$t2`~X*4Spfh5 literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/psi/cls/mirror/pkg/ParameterNames.class b/java/java-tests/testData/psi/cls/mirror/pkg/ParameterNames.class new file mode 100644 index 0000000000000000000000000000000000000000..dd92601c9a4e5a18a55c0f702ac3f853e38bfff7 GIT binary patch literal 688 zcmaJ<+e#xr5IvPloXI%eqA{+?u6Lb8)Y>xaJDBgEbOA;I|Gs7iK9wiF@bmP$V_#I^7O5!SqlYWiVq zN8>CFDAl8YFx3}ytWiT1CC)E@iReI_1=7I?MjcEbZDQHM3S7S7|L*%&eo&Q70-ZR> zqoBqD4JMz;9-N1iY{wjSu{mmD%t$au0`md^@sU40CA9>GutuVjj<>8i9!c-r|Y~;VZ2vPBf&ocNEWiW zqR~OD3yJAR>Op>R#{@$*)5a~Imqe2=Ag){jlnh?-HI^D ImMLujug4*m=l}o! literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/psi/cls/mirror/pkg/SimpleEnum.class b/java/java-tests/testData/psi/cls/mirror/pkg/SimpleEnum.class new file mode 100644 index 0000000000000000000000000000000000000000..00f1d0784bb873debaa92c5e218baf5ebc244ac1 GIT binary patch literal 806 zcmZuv?@!ub5Psga&{8TtWTK**ip;g>G@9%a#ApmlwvhRun~B+{!a7nd#Q^p1QcUJD zv&GN*qs;C)A}G8~?s9j}d(U(C_V2^5KLGadHUR~zI@VBBkyWv-!$676YYj6x6*n01 zMnjstslpPFYP$lN`o(!`$M)J6zFP~zc7^kM0&3~xu>PfH3uM1eLgJT>AG$q(oM}xd zD@UDgu0Xo(1@5P?-Eg~~orX^tHM)2FU7%#v&zwtV$9Dpv?{~eRRk5ZJRlUIL?+fIo z;6GR=0twq|1x`QgQhV9tj8<*>!&}8M5}vO5oME5l)$LB$ZMyG0R+t{GVw(jT$nZk5 z2FlnJNIl(_fjqVhEMReHW{@(FMv9Q5@t9d4*7Q38F}yIXF;&NnGq>3%74OCeJo24h zuQCRE+|bjmm4jV+PJ{jd`Ct)54v;5)AX8xFR8f$?EOH=bii+g<=mUr!knSO0Q6w-& zHXhYv!sjtR#IHk&vdJ8j@=wI>p-f(ocmo7vf)&X00cv@3`4;i(iS7l;NLYe~WwQTO zeI%89w(p>v&Z_b)v>PO%Kv$w58T(Boc|h-dstk~{Zy-j!b?V5I7KmCR%M35^D)KA; E05gxAlmGw# literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/psi/cls/mirror/src/pkg/Annotations.java b/java/java-tests/testData/psi/cls/mirror/src/pkg/Annotations.java new file mode 100644 index 000000000000..5aeda680f6dd --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/src/pkg/Annotations.java @@ -0,0 +1,37 @@ +package pkg; + +abstract class Annotations { + @interface A1 { } + + @interface A2 { + String value() default "-"; + } + + @interface A3 { + A1 a1(); + A2 a2(); + } + + @interface A4 { + int[] ids() default { }; + } + + @A1 abstract void m1(); + + @A2() abstract void m2a(); + @A2("+") abstract void m2b(); + + @A3(a1 = @A1, a2 = @A2) abstract void m3(); + + @A4 abstract void m4a(); + @A4(ids = {42, 84}) abstract void m4b(); + + @interface IndeterminateAnno { + float f1() default Float.NEGATIVE_INFINITY; + float f2() default Float.NaN; + float f3() default Float.POSITIVE_INFINITY; + double d1() default Double.NEGATIVE_INFINITY; + double d2() default Double.NaN; + double d3() default Double.POSITIVE_INFINITY; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/src/pkg/Deprecated.java b/java/java-tests/testData/psi/cls/mirror/src/pkg/Deprecated.java new file mode 100644 index 000000000000..e93e05795d7a --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/src/pkg/Deprecated.java @@ -0,0 +1,10 @@ +package pkg; + +/** @deprecated don't use */ +class Deprecated { + /** @deprecated don't use */ + int f; + + /** @deprecated don't use */ + void m() { } +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/src/pkg/EnumWithFields.java b/java/java-tests/testData/psi/cls/mirror/src/pkg/EnumWithFields.java new file mode 100644 index 000000000000..bb392f26a125 --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/src/pkg/EnumWithFields.java @@ -0,0 +1,8 @@ +package pkg; + +public enum EnumWithFields { + E1, E2; + + boolean f1; + boolean f2; +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/src/pkg/NormalClass.java b/java/java-tests/testData/psi/cls/mirror/src/pkg/NormalClass.java new file mode 100644 index 000000000000..42f1434c1302 --- /dev/null +++ b/java/java-tests/testData/psi/cls/mirror/src/pkg/NormalClass.java @@ -0,0 +1,11 @@ +package pkg; + +class NormalClass { + private final Object o = new Inner(); + + Object get() { + return o; + } + + private static class Inner { } +} \ No newline at end of file diff --git a/java/java-tests/testData/psi/cls/mirror/src/pkg/ParameterNames.class b/java/java-tests/testData/psi/cls/mirror/src/pkg/ParameterNames.class new file mode 100644 index 0000000000000000000000000000000000000000..6b1d495b9d8442038b15ed87d1fec22d58210acf GIT binary patch literal 651 zcmaJ<+fKqj5IqaU)>=_PMFkYR7Q~SFVj{)|eIoHff+5kjRW_tpN&~BjpWj5nV7)*I1*UUv1me584XJYk_uBQq)jYi zMMp+QmSOC`@f>-`5VmtQ2JN_A7X(stCBwX3K56oMUUa$FC{|_1@fsy1GZbHL`7T3Z zl;%o_CaaR)+@5m(f?vDB!X%;=VuC!u`$fr!$PVU@4NqPh(Y(2J=Y`0qrO-}mKJT% z;(;(|)QD1?qSFi^BaGyGU{8vt<8(i*=vn#!!h}XXS