use of com.jetbrains.lang.dart.DartComponentType in project intellij-plugins by JetBrains.
the class DartIndexUtil method indexFileRoots.
private static DartFileIndexData indexFileRoots(PsiFile psiFile) {
DartFileIndexData result = new DartFileIndexData();
result.setLibraryName(DartResolveUtil.getLibraryName(psiFile));
result.setIsPart(PsiTreeUtil.getChildOfType(psiFile, DartPartOfStatement.class) != null);
for (PsiElement rootElement : DartResolveUtil.findDartRoots(psiFile)) {
PsiElement[] children = rootElement.getChildren();
for (DartComponentName componentName : DartControlFlowUtil.getSimpleDeclarations(children, null, false)) {
final String name = componentName.getName();
if (name == null) {
continue;
}
result.addSymbol(name);
PsiElement parent = componentName.getParent();
final DartComponentType type = DartComponentType.typeOf(parent);
if (type != null) {
result.addComponentInfo(name, new DartComponentInfo(type, result.getLibraryName()));
}
if (parent instanceof DartClass) {
result.addClassName(name);
if (((DartClass) parent).isEnum()) {
for (DartEnumConstantDeclaration enumConstantDeclaration : ((DartClass) parent).getEnumConstantDeclarationList()) {
result.addSymbol(enumConstantDeclaration.getName());
}
} else {
for (DartComponent subComponent : DartResolveUtil.getNamedSubComponents((DartClass) parent)) {
result.addSymbol(subComponent.getName());
}
}
}
}
for (PsiElement child : children) {
if (child instanceof DartImportOrExportStatement) {
processImportOrExportStatement(result, (DartImportOrExportStatement) child);
}
if (child instanceof DartPartStatement) {
result.addPartUri(((DartPartStatement) child).getUriString());
}
}
}
return result;
}
use of com.jetbrains.lang.dart.DartComponentType in project intellij-plugins by JetBrains.
the class DartInheritorsSearcher method processQuery.
@Override
public void processQuery(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Processor<PsiElement> consumer) {
final Ref<VirtualFile> fileRef = Ref.create();
final Ref<Integer> offsetRef = Ref.create();
final Ref<DartComponentType> componentTypeRef = Ref.create();
prepare(parameters, fileRef, offsetRef, componentTypeRef);
if (fileRef.isNull() || offsetRef.isNull() || componentTypeRef.isNull())
return;
ApplicationManager.getApplication().runReadAction(() -> {
final List<TypeHierarchyItem> hierarchyItems = CachedValuesManager.getCachedValue(parameters.getElement(), () -> {
final DartAnalysisServerService das = DartAnalysisServerService.getInstance(parameters.getElement().getProject());
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(fileRef.get(), offsetRef.get(), false);
return new CachedValueProvider.Result<>(items, PsiModificationTracker.MODIFICATION_COUNT);
});
final List<DartComponent> components = componentTypeRef.get() == DartComponentType.CLASS ? getSubClasses(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems) : getSubMembers(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems);
for (DartComponent component : components) {
consumer.process(component);
}
});
}
use of com.jetbrains.lang.dart.DartComponentType in project intellij-plugins by JetBrains.
the class DartInheritorsSearcher method prepare.
private static void prepare(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Ref<VirtualFile> fileRef, @NotNull final Ref<Integer> offsetRef, @NotNull final Ref<DartComponentType> componentTypeRef) {
ApplicationManager.getApplication().runReadAction(() -> {
final PsiElement element = parameters.getElement();
if (element.getLanguage() != DartLanguage.INSTANCE)
return;
final DartComponentType componentType = DartComponentType.typeOf(element);
if (componentType != DartComponentType.CLASS && componentType != DartComponentType.METHOD && componentType != DartComponentType.OPERATOR) {
return;
}
final DartComponentName componentName = element instanceof DartComponentName ? (DartComponentName) element : element instanceof DartComponent ? ((DartComponent) element).getComponentName() : null;
final VirtualFile file = componentName == null ? null : DartResolveUtil.getRealVirtualFile(componentName.getContainingFile());
if (file != null) {
fileRef.set(file);
offsetRef.set(componentName.getTextRange().getStartOffset());
componentTypeRef.set(componentType);
}
});
}
use of com.jetbrains.lang.dart.DartComponentType in project intellij-plugins by JetBrains.
the class DartParameterInfoHandler method getParametersForLookup.
@Override
public Object[] getParametersForLookup(LookupElement item, ParameterInfoContext context) {
final Object o = item.getObject();
if (o instanceof PsiElement) {
final PsiElement element = (PsiElement) o;
final DartComponentType type = DartComponentType.typeOf(element.getParent());
if (type == DartComponentType.METHOD || type == DartComponentType.CONSTRUCTOR) {
return new Object[] { element.getParent() };
}
}
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
use of com.jetbrains.lang.dart.DartComponentType in project intellij-plugins by JetBrains.
the class DartComponentInfoExternalizer method save.
@Override
public void save(@NotNull final DataOutput out, @NotNull final DartComponentInfo componentInfo) throws IOException {
final DartComponentType dartComponentType = componentInfo.getComponentType();
final int key = dartComponentType == null ? -1 : dartComponentType.getKey();
DataInputOutputUtil.writeINT(out, key);
final String libraryName = componentInfo.getLibraryName();
out.writeBoolean(libraryName != null);
if (libraryName != null) {
IOUtil.writeUTF(out, libraryName);
}
}
Aggregations