use of com.intellij.util.SmartList in project android by JetBrains.
the class AndroidPsiElementFinder method findClasses.
@NotNull
@Override
public PsiClass[] findClasses(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
Project project = scope.getProject();
if (project == null || !ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID)) {
return PsiClass.EMPTY_ARRAY;
}
if (INTERNAL_R_CLASS_QNAME.equals(qualifiedName)) {
CommonProcessors.CollectUniquesProcessor<PsiClass> processor = new CommonProcessors.CollectUniquesProcessor<PsiClass>();
processInternalRClasses(project, scope, processor);
Collection<PsiClass> results = processor.getResults();
return results.isEmpty() ? PsiClass.EMPTY_ARRAY : results.toArray(new PsiClass[results.size()]);
}
final int lastDot = qualifiedName.lastIndexOf('.');
if (lastDot < 0) {
return PsiClass.EMPTY_ARRAY;
}
final String shortName = qualifiedName.substring(lastDot + 1);
final String parentName = qualifiedName.substring(0, lastDot);
if (shortName.length() == 0 || !parentName.endsWith(".R")) {
return PsiClass.EMPTY_ARRAY;
}
List<PsiClass> result = new SmartList<PsiClass>();
for (PsiClass parentClass : JavaPsiFacade.getInstance(project).findClasses(parentName, scope)) {
ContainerUtil.addIfNotNull(result, parentClass.findInnerClassByName(shortName, false));
}
return result.isEmpty() ? PsiClass.EMPTY_ARRAY : result.toArray(new PsiClass[result.size()]);
}
use of com.intellij.util.SmartList in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoPsiTreeUtil method getStubChildrenOfTypeAsList.
@NotNull
public static <T extends PsiElement> List<T> getStubChildrenOfTypeAsList(@Nullable PsiElement element, @NotNull Class<T> aClass) {
if (element == null)
return Collections.emptyList();
StubElement<?> stub = element instanceof StubBasedPsiElement ? ((StubBasedPsiElement) element).getStub() : null;
if (stub == null) {
return getChildrenOfTypeAsList(element, aClass);
}
List<T> result = new SmartList<T>();
for (StubElement childStub : stub.getChildrenStubs()) {
PsiElement child = childStub.getPsi();
if (aClass.isInstance(child)) {
//noinspection unchecked
result.add((T) child);
}
}
return result;
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class ArtifactUtil method findSourceFilesByOutputPath.
public static List<VirtualFile> findSourceFilesByOutputPath(CompositePackagingElement<?> parent, final String outputPath, final PackagingElementResolvingContext context, final ArtifactType artifactType) {
final String path = StringUtil.trimStart(outputPath, "/");
if (path.isEmpty()) {
return Collections.emptyList();
}
int i = path.indexOf('/');
final String firstName = i != -1 ? path.substring(0, i) : path;
final String tail = i != -1 ? path.substring(i + 1) : "";
final List<VirtualFile> result = new SmartList<>();
processElementsWithSubstitutions(parent.getChildren(), context, artifactType, PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {
@Override
public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath elementPath) {
//todo[nik] replace by method findSourceFile() in PackagingElement
if (element instanceof CompositePackagingElement) {
final CompositePackagingElement<?> compositeElement = (CompositePackagingElement<?>) element;
if (firstName.equals(compositeElement.getName())) {
result.addAll(findSourceFilesByOutputPath(compositeElement, tail, context, artifactType));
}
} else if (element instanceof FileCopyPackagingElement) {
final FileCopyPackagingElement fileCopyElement = (FileCopyPackagingElement) element;
if (firstName.equals(fileCopyElement.getOutputFileName()) && tail.isEmpty()) {
ContainerUtil.addIfNotNull(result, fileCopyElement.findFile());
}
} else if (element instanceof DirectoryCopyPackagingElement || element instanceof ExtractedDirectoryPackagingElement) {
final VirtualFile sourceRoot = ((FileOrDirectoryCopyPackagingElement<?>) element).findFile();
if (sourceRoot != null) {
ContainerUtil.addIfNotNull(result, sourceRoot.findFileByRelativePath(path));
}
} else if (element instanceof ModuleOutputPackagingElement) {
final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(context.getProject());
for (VirtualFile sourceRoot : ((ModuleOutputPackagingElement) element).getSourceRoots(context)) {
final VirtualFile sourceFile = sourceRoot.findFileByRelativePath(path);
if (sourceFile != null && compilerConfiguration.isResourceFile(sourceFile)) {
result.add(sourceFile);
}
}
}
return true;
}
});
return result;
}
use of com.intellij.util.SmartList in project intellij-plugins by JetBrains.
the class AS3InterfaceStubDumper method processModifierList.
@Override
protected void processModifierList(MemberInfo memberInfo, String attr, String indent) {
StringTokenizer tokenizer = new StringTokenizer(attr, " ");
List<JSAttributeList.ModifierType> modifiers = new SmartList<>();
JSAttributeList.AccessType accessType = null;
String ns = null;
while (tokenizer.hasMoreTokens()) {
String next = tokenizer.nextToken();
boolean foundModifier = false;
for (JSAttributeList.AccessType type : ourAccessTypes) {
if (next.equalsIgnoreCase(type.name())) {
accessType = type;
foundModifier = true;
break;
}
}
if (!foundModifier) {
for (JSAttributeList.ModifierType type : ourModifierTypes) {
if (next.equalsIgnoreCase(type.name())) {
modifiers.add(type);
foundModifier = true;
break;
}
}
}
if (!foundModifier)
ns = next;
}
Traits parentTraits = memberInfo.parentTraits;
if (parentTraits.staticTrait != null) {
parentTraits = parentTraits.staticTrait;
}
String resolvedNs = null;
if (parentTraits.usedNamespacesToNamesMap != null) {
List<String> keysByValue = parentTraits.usedNamespacesToNamesMap.getKeysByValue(ns);
resolvedNs = keysByValue != null && keysByValue.size() > 0 ? keysByValue.get(0) : null;
}
parents.add(new ActionScriptAttributeListStubImpl(parents.getLast(), ns, resolvedNs, accessType, modifiers.toArray(new JSAttributeList.ModifierType[modifiers.size()])));
super.processModifierList(memberInfo, attr, indent);
parents.removeLast();
}
use of com.intellij.util.SmartList in project android by JetBrains.
the class InstantRunBuildAnalyzer method getApks.
private static Collection<ApkInfo> getApks(@NotNull InstantRunBuildInfo buildInfo, @NotNull InstantRunContext context) throws ExecutionException {
List<ApkInfo> apks = new SmartList<>();
for (InstantRunArtifact artifact : buildInfo.getArtifacts()) {
if (artifact.type != MAIN) {
String msg = "Expected to only find apks, but got : " + artifact.type + "\n";
BuildSelection buildSelection = context.getBuildSelection();
assert buildSelection != null : "Build must have completed before apks are obtained";
if (buildSelection.getBuildMode() == BuildMode.HOT) {
msg += "Could not use hot-swap artifacts when there is no existing session.";
} else {
msg += "Unexpected artifacts for build mode: " + buildSelection.getBuildMode();
}
InstantRunManager.LOG.error(msg);
throw new ExecutionException(msg);
}
apks.add(new ApkInfo(artifact.file, context.getApplicationId()));
}
return apks;
}
Aggregations