mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
java: annotation parsing avoided for simple cases
(optimization + Kotlin compatibility)
This commit is contained in:
@@ -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<PsiAnnotationStub
|
||||
@NotNull
|
||||
@Override
|
||||
protected ClsJavaCodeReferenceElementImpl compute() {
|
||||
String text = PsiTreeUtil.getRequiredChildOfType(getStub().getPsiElement(), PsiJavaCodeReferenceElement.class).getText();
|
||||
return new ClsJavaCodeReferenceElementImpl(ClsAnnotationImpl.this, text);
|
||||
String annotationText = getStub().getText();
|
||||
int index = annotationText.indexOf('(');
|
||||
String refText = index > 0 ? annotationText.substring(1, index) : annotationText.substring(1);
|
||||
return new ClsJavaCodeReferenceElementImpl(ClsAnnotationImpl.this, refText);
|
||||
}
|
||||
};
|
||||
myParameterList = new AtomicNotNullLazyValue<ClsAnnotationParameterListImpl>() {
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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;
|
||||
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.impl.compiled.ClsFileImpl;
|
||||
import com.intellij.testFramework.LightIdeaTestCase;
|
||||
|
||||
public class ClsPsiTest extends LightIdeaTestCase {
|
||||
public void testKeywordAnnotatedClass() {
|
||||
PsiModifierList modList = getFile().getClasses()[0].getModifierList();
|
||||
assertNotNull(modList);
|
||||
assertEquals("@pkg.native", modList.getAnnotations()[0].getText());
|
||||
}
|
||||
|
||||
private PsiJavaFile getFile() {
|
||||
return getFile(getTestName(false));
|
||||
}
|
||||
|
||||
private static PsiJavaFile getFile(String name) {
|
||||
String path = PathManagerEx.getTestDataPath() + "/psi/cls/tree/" + name + ".class";
|
||||
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
|
||||
assertNotNull(path, file);
|
||||
PsiFile clsFile = PsiManager.getInstance(getProject()).findFile(file);
|
||||
assertTrue(String.valueOf(clsFile), clsFile instanceof ClsFileImpl);
|
||||
return (PsiJavaFile)clsFile;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user