下面列出了com.intellij.psi.PsiStatement#com.intellij.util.SmartList 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Nonnull
@Override
public List<String> getDescriptions(@Nonnull VirtualFile[] classRoots, final Set<LibraryKind> excludedKinds) {
final SmartList<String> result = new SmartList<>();
LibraryDetectionManager.getInstance().processProperties(Arrays.asList(classRoots), new LibraryDetectionManager.LibraryPropertiesProcessor() {
@Override
public <P extends LibraryProperties> boolean processProperties(@Nonnull LibraryKind kind, @Nonnull P properties) {
if (!excludedKinds.contains(kind)) {
final LibraryPresentationProvider<P> provider = getPresentationProvider(kind);
if (provider != null) {
ContainerUtil.addIfNotNull(result, provider.getDescription(properties));
}
}
return true;
}
});
return result;
}
/**
* Collects statements that can be extracted into a separate method.
*/
public SmartList<PsiStatement> getStatementsToExtract(ASTSlice slice) {
Set<PDGNode> nodes = slice.getSliceNodes();
SmartList<PsiStatement> statementsToExtract = new SmartList<>();
for (PDGNode pdgNode : nodes) {
boolean isNotChild = true;
for (PDGNode node : nodes) {
if (isChild(node.getASTStatement(), pdgNode.getASTStatement())) {
isNotChild = false;
}
}
if (isNotChild) {
statementsToExtract.add(pdgNode.getASTStatement());
}
}
return statementsToExtract;
}
@Override
@Nullable
public List<Pair<PsiElement, TextRange>> getInjectedPsiFiles(@Nonnull final PsiElement host) {
if (!(host instanceof PsiLanguageInjectionHost) || !((PsiLanguageInjectionHost)host).isValidHost()) {
return null;
}
final PsiElement inTree = InjectedLanguageUtil.loadTree(host, host.getContainingFile());
final List<Pair<PsiElement, TextRange>> result = new SmartList<>();
enumerate(inTree, (injectedPsi, places) -> {
for (PsiLanguageInjectionHost.Shred place : places) {
if (place.getHost() == inTree) {
result.add(new Pair<>(injectedPsi, place.getRangeInsideHost()));
}
}
});
return result.isEmpty() ? null : result;
}
@Override
@Nonnull
public List<RunContentDescriptor> getAllDescriptors() {
if (myToolwindowIdToContentManagerMap.isEmpty()) {
return Collections.emptyList();
}
List<RunContentDescriptor> descriptors = new SmartList<>();
for (String id : myToolwindowIdToContentManagerMap.keySet()) {
for (Content content : myToolwindowIdToContentManagerMap.get(id).getContents()) {
RunContentDescriptor descriptor = getRunContentDescriptorByContent(content);
if (descriptor != null) {
descriptors.add(descriptor);
}
}
}
return descriptors;
}
@RequiredReadAction
@Nullable
@Override
public CSharpElementGroup<CSharpIndexMethodDeclaration> indexMethodGroup(boolean deep)
{
List<CSharpElementGroup<CSharpIndexMethodDeclaration>> groups = new SmartList<CSharpElementGroup<CSharpIndexMethodDeclaration>>();
for(CSharpResolveContext context : myContexts)
{
CSharpElementGroup<CSharpIndexMethodDeclaration> elementGroup = context.indexMethodGroup(deep);
if(elementGroup != null)
{
groups.add(elementGroup);
}
}
return groups.isEmpty() ? null : new CSharpCompositeElementGroupImpl<CSharpIndexMethodDeclaration>(myProject, groups);
}
@RequiredReadAction
@Nullable
@Override
public CSharpElementGroup<CSharpConstructorDeclaration> constructorGroup()
{
List<CSharpElementGroup<CSharpConstructorDeclaration>> groups = new SmartList<CSharpElementGroup<CSharpConstructorDeclaration>>();
for(CSharpResolveContext context : myContexts)
{
CSharpElementGroup<CSharpConstructorDeclaration> elementGroup = context.constructorGroup();
if(elementGroup != null)
{
groups.add(elementGroup);
}
}
return groups.isEmpty() ? null : new CSharpCompositeElementGroupImpl<CSharpConstructorDeclaration>(myProject, groups);
}
/**
* Order is deterministic. First element matches {@link FileViewProvider#getStubBindingRoot()}
*/
@Nonnull
public static List<Pair<IStubFileElementType, PsiFile>> getStubbedRoots(@Nonnull FileViewProvider viewProvider) {
final List<Trinity<Language, IStubFileElementType, PsiFile>> roots = new SmartList<>();
final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
for (Language language : viewProvider.getLanguages()) {
final PsiFile file = viewProvider.getPsi(language);
if (file instanceof PsiFileImpl) {
final IElementType type = ((PsiFileImpl)file).getElementTypeForStubBuilder();
if (type != null) {
roots.add(Trinity.create(language, (IStubFileElementType)type, file));
}
}
}
ContainerUtil.sort(roots, (o1, o2) -> {
if (o1.third == stubBindingRoot) return o2.third == stubBindingRoot ? 0 : -1;
else if (o2.third == stubBindingRoot) return 1;
else return StringUtil.compare(o1.first.getID(), o2.first.getID(), false);
});
return ContainerUtil.map(roots, trinity -> Pair.create(trinity.second, trinity.third));
}
@RequiredReadAction
@Nullable
@Override
public CSharpElementGroup<CSharpMethodDeclaration> findOperatorGroupByTokenType(@Nonnull IElementType type, boolean deep)
{
List<CSharpElementGroup<CSharpMethodDeclaration>> groups = new SmartList<CSharpElementGroup<CSharpMethodDeclaration>>();
for(CSharpResolveContext context : myContexts)
{
CSharpElementGroup<CSharpMethodDeclaration> elementGroup = context.findOperatorGroupByTokenType(type, deep);
if(elementGroup != null)
{
groups.add(elementGroup);
}
}
return groups.isEmpty() ? null : new CSharpCompositeElementGroupImpl<CSharpMethodDeclaration>(myProject, groups);
}
@RequiredReadAction
@Nullable
@Override
public CSharpElementGroup<CSharpConversionMethodDeclaration> findConversionMethodGroup(@Nonnull CSharpCastType castType, boolean deep)
{
List<CSharpElementGroup<CSharpConversionMethodDeclaration>> groups = new SmartList<CSharpElementGroup<CSharpConversionMethodDeclaration>>();
for(CSharpResolveContext context : myContexts)
{
CSharpElementGroup<CSharpConversionMethodDeclaration> elementGroup = context.findConversionMethodGroup(castType, deep);
if(elementGroup != null)
{
groups.add(elementGroup);
}
}
return groups.isEmpty() ? null : new CSharpCompositeElementGroupImpl<CSharpConversionMethodDeclaration>(myProject, groups);
}
@Nullable
private static CSharpElementGroup<CSharpMethodDeclaration> filterElementGroupToExtensionGroup(CSharpElementGroup<PsiElement> elementGroup)
{
final List<CSharpMethodDeclaration> extensions = new SmartList<>();
elementGroup.process(element ->
{
if(element instanceof CSharpMethodDeclaration && ((CSharpMethodDeclaration) element).isExtension())
{
extensions.add((CSharpMethodDeclaration) element);
}
return true;
});
if(extensions.isEmpty())
{
return null;
}
return new CSharpElementGroupImpl<>(elementGroup.getProject(), elementGroup.getKey(), extensions);
}
@Nonnull
private Collection<VfsFileBasedStorage> getCachedFileStorages(@Nonnull Collection<String> fileSpecs) {
if (fileSpecs.isEmpty()) {
return Collections.emptyList();
}
List<VfsFileBasedStorage> result = null;
for (String fileSpec : fileSpecs) {
StateStorage storage = myStorages.get(fileSpec);
if (storage instanceof VfsFileBasedStorage) {
if (result == null) {
result = new SmartList<>();
}
result.add((VfsFileBasedStorage)storage);
}
}
return result == null ? Collections.<VfsFileBasedStorage>emptyList() : result;
}
@Nonnull
@RequiredReadAction
private static List<DotNetTypeDeclaration> collectAllTypes(@Nonnull PsiElement place)
{
List<DotNetTypeDeclaration> typeDeclarations = new SmartList<>();
if(place instanceof CSharpTypeDeclaration)
{
typeDeclarations.add((DotNetTypeDeclaration) place);
}
PsiElement type = place;
while((type = PsiTreeUtil.getContextOfType(type, DotNetTypeDeclaration.class)) != null)
{
typeDeclarations.add((DotNetTypeDeclaration) type);
}
return typeDeclarations;
}
@Nonnull
public static <T extends PsiElement> List<T> getStubChildrenOfTypeAsList(@Nullable PsiElement element, @Nonnull 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<>();
for (StubElement childStub : stub.getChildrenStubs()) {
PsiElement child = childStub.getPsi();
if (aClass.isInstance(child)) {
result.add(aClass.cast(child));
}
}
return result;
}
@Nonnull
private List<SemElement> createSemElements(SemKey key, PsiElement psi) {
List<SemElement> result = null;
final Collection<NullableFunction<PsiElement, ? extends SemElement>> producers = myProducers.get(key);
if (!producers.isEmpty()) {
for (final NullableFunction<PsiElement, ? extends SemElement> producer : producers) {
myCreatingSem.incrementAndGet();
try {
final SemElement element = producer.fun(psi);
if (element != null) {
if (result == null) result = new SmartList<>();
result.add(element);
}
}
finally {
myCreatingSem.decrementAndGet();
}
}
}
return result == null ? Collections.emptyList() : Collections.unmodifiableList(result);
}
@Nonnull
@Override
public List<GraphEdge> getAdjacentEdges(int nodeIndex, @Nonnull EdgeFilter filter) {
List<GraphEdge> result = new SmartList<>();
boolean hasUpSimpleEdge = nodeIndex != 0 && mySimpleNodes.get(nodeIndex - 1);
if (hasUpSimpleEdge && filter.upNormal) result.add(new GraphEdge(nodeIndex - 1, nodeIndex, null, USUAL));
for (int i = myNodeToEdgeIndex.get(nodeIndex); i < myNodeToEdgeIndex.get(nodeIndex + 1); i++) {
int adjacentNode = myLongEdges.get(i);
if (adjacentNode < 0 && filter.special) {
result.add(GraphEdge.createEdgeWithTargetId(nodeIndex, adjacentNode, GraphEdgeType.NOT_LOAD_COMMIT));
}
if (adjacentNode < 0) continue;
if (nodeIndex > adjacentNode && filter.upNormal) result.add(new GraphEdge(adjacentNode, nodeIndex, null, USUAL));
if (nodeIndex < adjacentNode && filter.downNormal) result.add(new GraphEdge(nodeIndex, adjacentNode, null, USUAL));
}
if (mySimpleNodes.get(nodeIndex) && filter.downNormal) result.add(new GraphEdge(nodeIndex, nodeIndex + 1, null, USUAL));
return result;
}
@Override
public final void setBeforeRunTasks(final RunConfiguration runConfiguration, @Nonnull List<BeforeRunTask> tasks, boolean addEnabledTemplateTasksIfAbsent) {
List<BeforeRunTask> result = new SmartList<>(tasks);
if (addEnabledTemplateTasksIfAbsent) {
List<BeforeRunTask> templates = getTemplateBeforeRunTasks(runConfiguration);
Set<Key<BeforeRunTask>> idsToSet = new THashSet<>();
for (BeforeRunTask task : tasks) {
idsToSet.add(task.getProviderId());
}
int i = 0;
for (BeforeRunTask template : templates) {
if (!idsToSet.contains(template.getProviderId())) {
result.add(i, template);
i++;
}
}
}
myConfigurationToBeforeTasksMap.put(runConfiguration, ContainerUtil.notNullize(result));
fireBeforeRunTasksUpdated();
}
@Override
@Nullable
public PathReference getPathReference(@Nonnull final String path, @Nonnull final PsiElement element) {
final List<PsiReference> list = new SmartList<PsiReference>();
createReferences(element, list, true);
if (list.isEmpty()) return null;
final PsiElement target = list.get(list.size() - 1).resolve();
if (target == null) return null;
return new PathReference(path, PathReference.ResolveFunction.NULL_RESOLVE_FUNCTION) {
@Override
public PsiElement resolve() {
return target;
}
};
}
@Override
@Nullable
public ProblemDescriptor[] checkFile(@Nonnull PsiFile file, @Nonnull InspectionManager manager, boolean isOnTheFly) {
if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) return null;
if (!file.isPhysical()) return null;
FileViewProvider viewProvider = file.getViewProvider();
if (viewProvider.getBaseLanguage() != file.getLanguage()) return null;
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) return null;
if (!virtualFile.isInLocalFileSystem()) return null;
CharSequence text = viewProvider.getContents();
Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text);
// no sense in checking transparently decoded file: all characters there are already safely encoded
if (charset instanceof Native2AsciiCharset) return null;
List<ProblemDescriptor> descriptors = new SmartList<ProblemDescriptor>();
boolean ok = checkFileLoadedInWrongEncoding(file, manager, isOnTheFly, virtualFile, charset, descriptors);
if (ok) {
checkIfCharactersWillBeLostAfterSave(file, manager, isOnTheFly, text, charset, descriptors);
}
return descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
public static String validatePathMappings(@Nonnull Project project, @Nonnull RemoteSdkAdditionalData data) {
boolean found = false;
final List<String> locations = new SmartList<>();
for (PathMappingProvider mappingProvider : PathMappingProvider.getSuitableMappingProviders(data)) {
found = found || !mappingProvider.getPathMappingSettings(project, data).isEmpty();
locations.add(mappingProvider.getProviderPresentableName(data));
}
if (!found) {
final StringBuilder builder = new StringBuilder();
builder.append("No path mappings were found.");
if (!locations.isEmpty()) {
builder.append(" Please, configure them at ").append(StringUtil.join(locations, " or "));
}
return builder.toString();
}
return null;
}
@Override
protected CachedValue<PsiReference[]> compute(final PsiElement element, Object p) {
return CachedValuesManager.getManager(element.getProject()).createCachedValue(() -> {
IssueNavigationConfiguration navigationConfiguration = IssueNavigationConfiguration.getInstance(element.getProject());
if (navigationConfiguration == null) {
return CachedValueProvider.Result.create(PsiReference.EMPTY_ARRAY, element);
}
List<PsiReference> refs = null;
GlobalPathReferenceProvider provider = myReferenceProvider.get();
CharSequence commentText = StringUtil.newBombedCharSequence(element.getText(), 500);
for (IssueNavigationConfiguration.LinkMatch link : navigationConfiguration.findIssueLinks(commentText)) {
if (refs == null) refs = new SmartList<>();
if (provider == null) {
provider = (GlobalPathReferenceProvider)PathReferenceManager.getInstance().getGlobalWebPathReferenceProvider();
myReferenceProvider.lazySet(provider);
}
provider.createUrlReference(element, link.getTargetUrl(), link.getRange(), refs);
}
PsiReference[] references = refs != null ? refs.toArray(new PsiReference[refs.size()]) : PsiReference.EMPTY_ARRAY;
return new CachedValueProvider.Result<>(references, element, navigationConfiguration);
}, false);
}
@Nonnull
@Override
public List<String> getInvalidRootUrls(@Nonnull OrderRootType type) {
if (myDisposed) return Collections.emptyList();
VirtualFilePointerContainer container = myRoots.get(type);
final List<VirtualFilePointer> pointers = container == null ? Collections.emptyList() : container.getList();
List<String> invalidPaths = null;
for (VirtualFilePointer pointer : pointers) {
if (!pointer.isValid()) {
if (invalidPaths == null) {
invalidPaths = new SmartList<>();
}
invalidPaths.add(pointer.getUrl());
}
}
return ContainerUtil.notNullize(invalidPaths);
}
protected ExtensibleQueryFactory(@NonNls final String epNamespace) {
myPoint = new NotNullLazyValue<SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>>>() {
@Override
@Nonnull
protected SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>> compute() {
return new SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>>(new SmartList<QueryExecutor<Result, Parameters>>()){
@Override
@Nonnull
protected ExtensionPoint<QueryExecutor<Result, Parameters>> getExtensionPoint() {
String epName = ExtensibleQueryFactory.this.getClass().getName();
int pos = epName.lastIndexOf('.');
if (pos >= 0) {
epName = epName.substring(pos+1);
}
epName = epNamespace + "." + StringUtil.decapitalize(epName);
return Application.get().getExtensionPoint(ExtensionPointName.create(epName));
}
};
}
};
}
/**
* Template configuration is not included
*/
@Override
@Nonnull
public List<RunConfiguration> getConfigurationsList(@Nonnull ConfigurationType type) {
List<RunConfiguration> result = null;
for (RunnerAndConfigurationSettings settings : getSortedConfigurations()) {
RunConfiguration configuration = settings.getConfiguration();
if (type.getId().equals(configuration.getType().getId())) {
if (result == null) {
result = new SmartList<>();
}
result.add(configuration);
}
}
return ContainerUtil.notNullize(result);
}
@Override
@Nonnull
public Editor[] getEditors(@Nonnull Document document, Project project) {
List<Editor> list = null;
for (Editor editor : myEditors) {
if (editor.getDocument().equals(document) && (project == null || project.equals(editor.getProject()))) {
if (list == null) list = new SmartList<>();
list.add(editor);
}
}
return list == null ? Editor.EMPTY_ARRAY : list.toArray(Editor.EMPTY_ARRAY);
}
private void addUnderdoneEdge(int upNodeIndex, CommitId downCommitId) {
List<Integer> upNodes = upAdjacentNodes.get(downCommitId);
if (upNodes == null) {
upNodes = new SmartList<>();
upAdjacentNodes.put(downCommitId, upNodes);
}
upNodes.add(upNodeIndex);
}
@Nonnull
private List<BeforeRunTask> getHardcodedBeforeRunTasks(@Nonnull RunConfiguration settings) {
List<BeforeRunTask> _tasks = new SmartList<>();
for (BeforeRunTaskProvider<? extends BeforeRunTask> provider : BeforeRunTaskProvider.EP_NAME.getExtensionList(myProject)) {
BeforeRunTask task = provider.createTask(settings);
if (task != null && task.isEnabled()) {
Key<? extends BeforeRunTask> providerID = provider.getId();
settings.getFactory().configureBeforeRunTaskDefaults(providerID, task);
if (task.isEnabled()) {
_tasks.add(task);
}
}
}
return _tasks;
}
public List<TryStatementObject> getTryStatements() {
SmartList<TryStatementObject> tryStatements = new SmartList<>(super.getTryStatements());
for (CatchClauseObject catchClause : catchClauses) {
tryStatements.addAll(catchClause.getTryStatements());
}
if (finallyClause != null) {
tryStatements.addAll(finallyClause.getTryStatements());
}
return tryStatements;
}
void addChild(@Nonnull ObjectNode child) {
List<ObjectNode> children = myChildren;
if (children == null) {
myChildren = new SmartList<>(child);
}
else {
children.add(child);
}
child.myParent = this;
}
public DartStaticFieldsGroup(@NotNull final DartVmServiceDebugProcess debugProcess,
@NotNull final String isolateId,
@NotNull final String className,
@NotNull final SmartList<FieldRef> fieldsRefs) {
super("static");
myDebugProcess = debugProcess;
myIsolateId = isolateId;
myClassName = className;
myFieldRefs = fieldsRefs;
}
private void updateNodesContaining(@Nonnull Collection<VirtualFile> filesToRefresh, @Nonnull DefaultMutableTreeNode rootNode) {
if (!(rootNode.getUserObject() instanceof ProjectViewNode)) {
return;
}
ProjectViewNode node = (ProjectViewNode) rootNode.getUserObject();
Collection<VirtualFile> containingFiles = null;
for (VirtualFile virtualFile : filesToRefresh) {
if (!virtualFile.isValid()) {
addSubtreeToUpdate(rootNode); // file must be deleted
return;
}
if (node.contains(virtualFile)) {
if (containingFiles == null) {
containingFiles = new SmartList<VirtualFile>();
}
containingFiles.add(virtualFile);
}
}
if (containingFiles != null) {
updateNode(rootNode);
Enumeration children = rootNode.children();
while (children.hasMoreElements()) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
updateNodesContaining(containingFiles, child);
}
}
}