use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class TestIntegrationUtils method findSuitableFrameworks.
public static List<TestFramework> findSuitableFrameworks(PsiClass targetClass) {
TestFramework[] frameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME);
Project project = targetClass.getProject();
List<TestFramework> result = new SmartList<>();
for (TestFramework framework : frameworks) {
if (isAvailableFor(project, framework)) {
if (framework.isTestClass(targetClass)) {
return Collections.singletonList(framework);
}
if (framework.isPotentialTestClass(targetClass)) {
result.add(framework);
}
}
}
return result;
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class ExtendsClassChecker method checkExtendClass.
@NotNull
public static List<DomElementProblemDescriptor> checkExtendClass(final GenericDomValue element, final PsiClass value, final String name, final boolean instantiatable, final boolean canBeDecorator, final boolean allowInterface, final boolean allowNonPublic, final boolean allowAbstract, final boolean allowEnum, final DomElementAnnotationHolder holder) {
final Project project = element.getManager().getProject();
PsiClass extendClass = JavaPsiFacade.getInstance(project).findClass(name, GlobalSearchScope.allScope(project));
final SmartList<DomElementProblemDescriptor> list = new SmartList<>();
if (extendClass != null) {
if (!name.equals(value.getQualifiedName()) && !value.isInheritor(extendClass, true)) {
String message = DomBundle.message("class.is.not.a.subclass", value.getQualifiedName(), extendClass.getQualifiedName());
list.add(holder.createProblem(element, message));
}
}
if (instantiatable) {
if (value.hasModifierProperty(PsiModifier.ABSTRACT)) {
list.add(holder.createProblem(element, DomBundle.message("class.is.not.concrete", value.getQualifiedName())));
} else if (!allowNonPublic && !value.hasModifierProperty(PsiModifier.PUBLIC)) {
list.add(holder.createProblem(element, DomBundle.message("class.is.not.public", value.getQualifiedName())));
} else if (!PsiUtil.hasDefaultConstructor(value, true)) {
if (canBeDecorator) {
boolean hasConstructor = false;
for (PsiMethod method : value.getConstructors()) {
final PsiParameterList psiParameterList = method.getParameterList();
if (psiParameterList.getParametersCount() != 1)
continue;
PsiTypeElement typeElement = psiParameterList.getParameters()[0].getTypeElement();
if (typeElement != null) {
final PsiType psiType = typeElement.getType();
if (psiType instanceof PsiClassType) {
final PsiClass psiClass = ((PsiClassType) psiType).resolve();
if (psiClass != null && InheritanceUtil.isInheritorOrSelf(psiClass, extendClass, true)) {
hasConstructor = true;
break;
}
}
}
}
if (!hasConstructor) {
list.add(holder.createProblem(element, DomBundle.message("class.decorator.or.has.default.constructor", value.getQualifiedName())));
}
} else {
list.add(holder.createProblem(element, DomBundle.message("class.has.no.default.constructor", value.getQualifiedName())));
}
}
}
if (!allowInterface && value.isInterface()) {
list.add(holder.createProblem(element, DomBundle.message("interface.not.allowed", value.getQualifiedName())));
}
if (!allowEnum && value.isEnum()) {
list.add(holder.createProblem(element, DomBundle.message("enum.not.allowed", value.getQualifiedName())));
}
if (!allowAbstract && value.hasModifierProperty(PsiModifier.ABSTRACT) && !value.isInterface()) {
list.add(holder.createProblem(element, DomBundle.message("abstract.class.not.allowed", value.getQualifiedName())));
}
return list;
}
use of com.intellij.util.SmartList in project intellij-plugins by JetBrains.
the class StructureViewTreeElement method getChildren.
@NotNull
public TreeElement[] getChildren() {
final DomElement element = getElement();
if (!element.isValid()) {
return EMPTY_ARRAY;
}
final List<TreeElement> result = new SmartList<>();
DomUtil.acceptAvailableChildren(element, new DomElementVisitor() {
@Override
public void visitDomElement(final DomElement domElement) {
result.add(new StructureViewTreeElement(domElement));
}
});
return ArrayUtil.toObjectArray(result, TreeElement.class);
}
use of com.intellij.util.SmartList in project intellij-plugins by JetBrains.
the class AngularJSCssInclusionContext method getContextFiles.
@NotNull
@Override
public PsiFile[] getContextFiles(@NotNull PsiFile current) {
final PsiElement context = current.getContext();
final JSProperty property = PsiTreeUtil.getParentOfType(context, JSProperty.class);
if (property != null && "template".equals(property.getName())) {
final JSObjectLiteralExpression object = (JSObjectLiteralExpression) property.getParent();
final JSProperty styles = object.findProperty("styles");
if (styles != null && styles.getValue() instanceof JSArrayLiteralExpression) {
final List<PsiFile> result = new SmartList<>();
for (JSExpression expression : ((JSArrayLiteralExpression) styles.getValue()).getExpressions()) {
if (expression instanceof JSLiteralExpression && ((JSLiteralExpression) expression).isQuotedLiteral()) {
final List<Pair<PsiElement, TextRange>> injected = InjectedLanguageManager.getInstance(context.getProject()).getInjectedPsiFiles(expression);
if (injected != null) {
for (Pair<PsiElement, TextRange> pair : injected) {
if (pair.first instanceof StylesheetFile) {
result.add((PsiFile) pair.first);
}
}
}
}
}
return result.toArray(PsiFile.EMPTY_ARRAY);
}
}
return PsiFile.EMPTY_ARRAY;
}
use of com.intellij.util.SmartList in project intellij-plugins by JetBrains.
the class DartFileUrlMapper method getUrls.
@NotNull
@Override
public List<Url> getUrls(@NotNull final VirtualFile file, @NotNull final Project project, @Nullable final String currentAuthority) {
if (currentAuthority == null || file.getFileType() != DartFileType.INSTANCE)
return Collections.emptyList();
if (Registry.is("dart.redirect.to.pub.server", true) && ProjectFileIndex.getInstance(project).isInContent(file)) {
final Pair<VirtualFile, String> servedDirAndPath = PubServerPathHandlerKt.getServedDirAndPathForPubServer(project, file);
if (servedDirAndPath != null) {
final VirtualFile servedDir = servedDirAndPath.first;
final String path = servedDirAndPath.second;
final String pubAuthority = BuiltInServerManagerImpl.isOnBuiltInWebServerByAuthority(currentAuthority) ? PubServerManager.getInstance(project).getPubServerAuthorityForServedDir(servedDir) : currentAuthority;
if (pubAuthority != null) {
return Collections.singletonList(Urls.newHttpUrl(pubAuthority, path));
}
}
}
final DartUrlResolver urlResolver = DartUrlResolver.getInstance(project, file);
final String dartUri = urlResolver.getDartUrlForFile(file);
if (!dartUri.startsWith(PACKAGE_PREFIX))
return Collections.emptyList();
if (BuiltInServerManagerImpl.isOnBuiltInWebServerByAuthority(currentAuthority)) {
final List<Url> result = new SmartList<>();
final VirtualFile pubspec = urlResolver.getPubspecYamlFile();
final VirtualFile dartRoot = pubspec != null ? pubspec.getParent() : null;
if (Registry.is("dart.redirect.to.pub.server", true)) {
// package:PackageName/subdir/foo.dart -> http://localhost:45455/packages/PackageName/subdir/foo.dart
final Collection<String> authorities = dartRoot != null ? PubServerManager.getInstance(project).getAlivePubServerAuthoritiesForDartRoot(pubspec.getParent()) : PubServerManager.getInstance(project).getAllAlivePubServerAuthorities();
for (String pubAuthority : authorities) {
final String pubUrlPath = "/packages/" + dartUri.substring(PACKAGE_PREFIX.length());
result.add(Urls.newHttpUrl(pubAuthority, pubUrlPath));
}
} else if (dartRoot != null) {
// for built-in server:
// package:PackageName/subdir/foo.dart -> http://localhost:63342/ProjectName/MayBeRelPathToDartProject/web/packages/PackageName/subdir/foo.dart
final String dartRootUrlPath = WebServerPathToFileManager.getInstance(project).getPath(dartRoot);
if (dartRootUrlPath == null)
return Collections.emptyList();
//BuiltInWebBrowserUrlProviderKt.getBuiltInServerUrls(pubspec, project, currentAuthority);
final Url dartRootUrl = Urls.newHttpUrl(currentAuthority, "/" + project.getName() + "/" + dartRootUrlPath);
final String urlPath = StringUtil.trimEnd(dartRootUrl.getPath(), "/") + "/web/packages/" + dartUri.substring(PACKAGE_PREFIX.length());
result.add(Urls.newHttpUrl(currentAuthority, urlPath));
}
return result;
} else {
// for any other server (e.g. localhost:8181):
// package:PackageName/subdir/foo.dart -> http://localhost:8181/packages/PackageName/subdir/foo.dart
final String urlPath = "/packages/" + dartUri.substring(PACKAGE_PREFIX.length());
return Collections.singletonList(Urls.newHttpUrl(currentAuthority, urlPath));
}
}
Aggregations