use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.
the class PsiClassImpl method getContextStub.
@Nullable
private StubElement getContextStub() {
PsiClassStub<?> stub = getStub();
if (stub == null)
return null;
// if AST is not loaded, then we only can need context to resolve supertype references
// this can be done by stubs unless there are local/anonymous classes referencing other local classes
StubElement parent = stub.getParentStub();
if (parent instanceof PsiClassInitializerStub || parent instanceof PsiMethodStub) {
if (parent.getChildrenByType(JavaStubElementTypes.CLASS, PsiElement.ARRAY_FACTORY).length <= 1) {
parent = parent.getParentStub();
}
}
return parent instanceof PsiClassStub ? parent : null;
}
use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.
the class PsiMethodImpl method getName.
@Override
@NotNull
public String getName() {
final String name;
final PsiMethodStub stub = getGreenStub();
if (stub != null) {
name = stub.getName();
} else {
final PsiIdentifier nameIdentifier = getNameIdentifier();
name = nameIdentifier == null ? null : nameIdentifier.getText();
}
return name != null ? name : "<unnamed>";
}
use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.
the class PsiMethodImpl method getReturnType.
@Override
public PsiType getReturnType() {
if (isConstructor())
return null;
PsiMethodStub stub = getStub();
if (stub != null) {
PsiType type = SoftReference.dereference(myCachedType);
if (type == null) {
String typeText = TypeInfo.createTypeText(stub.getReturnTypeText(false));
assert typeText != null : stub;
type = JavaPsiFacade.getInstance(getProject()).getParserFacade().createTypeFromText(typeText, this);
type = JavaSharedImplUtil.applyAnnotations(type, getModifierList());
myCachedType = new SoftReference<>(type);
}
return type;
}
myCachedType = null;
PsiTypeElement typeElement = getReturnTypeElement();
return typeElement != null ? JavaSharedImplUtil.getType(typeElement, getParameterList()) : null;
}
use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.
the class PsiAnnotationMethodImpl method getDefaultValue.
@Override
public PsiAnnotationMemberValue getDefaultValue() {
final PsiMethodStub stub = getStub();
if (stub != null) {
final String text = stub.getDefaultValueText();
if (StringUtil.isEmpty(text))
return null;
PsiAnnotationMemberValue value = SoftReference.dereference(myCachedDefaultValue);
if (value != null) {
return value;
}
value = JavaPsiFacade.getElementFactory(getProject()).createAnnotationFromText("@Foo(" + text + ")", this).findAttributeValue(null);
myCachedDefaultValue = new SoftReference<>(value);
return value;
}
myCachedDefaultValue = null;
final ASTNode node = getNode().findChildByRole(ChildRole.ANNOTATION_DEFAULT_VALUE);
if (node == null)
return null;
return (PsiAnnotationMemberValue) node.getPsi();
}
use of com.intellij.psi.impl.java.stubs.PsiMethodStub in project intellij-community by JetBrains.
the class GrTraitUtil method doCollectCompiledTraitMethods.
private static void doCollectCompiledTraitMethods(final ClsClassImpl trait, final Collection<PsiMethod> result) {
for (PsiMethod method : trait.getMethods()) {
if (AnnotationUtil.isAnnotated(method, GROOVY_TRAIT_IMPLEMENTED, false)) {
result.add(method);
}
}
VirtualFile traitFile = trait.getContainingFile().getVirtualFile();
if (traitFile == null)
return;
VirtualFile helperFile = traitFile.getParent().findChild(trait.getName() + GroovyTraitMethodsFileIndex.HELPER_SUFFIX);
if (helperFile == null)
return;
int key = FileBasedIndex.getFileId(helperFile);
List<PsiJavaFileStub> values = FileBasedIndex.getInstance().getValues(GroovyTraitMethodsFileIndex.INDEX_ID, key, trait.getResolveScope());
values.forEach(root -> ((PsiJavaFileStubImpl) root).setPsi((PsiJavaFile) trait.getContainingFile()));
values.stream().map(root -> root.getChildrenStubs().get(0).getChildrenStubs()).<StubElement>flatMap(Collection::stream).filter(stub -> stub instanceof PsiMethodStub).forEach(stub -> result.add(createTraitMethodFromCompiledHelperMethod(((PsiMethodStub) stub).getPsi(), trait)));
}
Aggregations