From fe2ef4c2f9ec6f7fb1fde8a1690d1af9b08492dc Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 22 May 2015 16:27:14 +0200 Subject: [PATCH] java: annotation parsing avoided for simple cases (optimization + Kotlin compatibility) --- .../psi/impl/compiled/ClsAnnotationImpl.java | 16 ++++--- .../psi/cls/tree/KeywordAnnotatedClass.class | Bin 0 -> 791 bytes .../testSrc/com/intellij/psi/ClsPsiTest.java | 43 ++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 java/java-tests/testData/psi/cls/tree/KeywordAnnotatedClass.class create mode 100644 java/java-tests/testSrc/com/intellij/psi/ClsPsiTest.java 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 3cdc7dfaa82b..e42d4b8d459b 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-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -44,23 +44,27 @@ public class ClsAnnotationImpl extends ClsRepositoryPsiElement 0 ? annotationText.substring(1, index) : annotationText.substring(1); + return new ClsJavaCodeReferenceElementImpl(ClsAnnotationImpl.this, refText); } }; myParameterList = new AtomicNotNullLazyValue() { @NotNull @Override protected ClsAnnotationParameterListImpl compute() { - PsiAnnotationParameterList paramList = PsiTreeUtil.getRequiredChildOfType(getStub().getPsiElement(), PsiAnnotationParameterList.class); - return new ClsAnnotationParameterListImpl(ClsAnnotationImpl.this, paramList.getAttributes()); + PsiNameValuePair[] attrs = getStub().getText().indexOf('(') > 0 + ? PsiTreeUtil.getRequiredChildOfType(getStub().getPsiElement(), PsiAnnotationParameterList.class).getAttributes() + : PsiNameValuePair.EMPTY_ARRAY; + return new ClsAnnotationParameterListImpl(ClsAnnotationImpl.this, attrs); } }; } @Override public void appendMirrorText(int indentLevel, @NotNull StringBuilder buffer) { - buffer.append("@").append(myReferenceElement.getValue().getCanonicalText()); + buffer.append('@').append(myReferenceElement.getValue().getCanonicalText()); appendText(getParameterList(), indentLevel, buffer); } diff --git a/java/java-tests/testData/psi/cls/tree/KeywordAnnotatedClass.class b/java/java-tests/testData/psi/cls/tree/KeywordAnnotatedClass.class new file mode 100644 index 0000000000000000000000000000000000000000..7dbe64039001e6ba92bf3c2d7948232e80a5c3f6 GIT binary patch literal 791 zcmah{T~8BH5IwWocG-5TY_VXif`!Ha(Qe=YNg$Zg_BnhC{IM{RIU-m*4wV~RJ1|R=NFosFZcb3kA^&i zsm3UD0(s~%hf^OW7@1lh;w+?Lq>(^|kcf^{NGJ|l{PSXrD_t=5P6v+iA{ltXb?TQ* zxh5@Iswsm|`JT?Non-31@;Zb&{{xrnT*nN_TBEwV%ean+1mVMSe*fkEy@T~*nX}~f zo7I!r&fUiY`+lpty|+YfSB~;oQ&whD#*2;elS*+llYRHJTPdzRSX!`Yj#7qAq>(|H zWVKM*)RKD1tZG!Fg1$9d+9Wfv|LS>F*E^c9?T1xevvqStkgiW8OT@F7K3DONH}8xj zxSZlh`GpG!{+ft|0&b*n9YqUcFimKz@Q|`AEes5pDRU3}9JOH7>Lq0o3C z?!$i?`xJQRaGRq%`}i|++85mXgz1mNkQ@9end6eUD7p9