public LocalQuickFixOnPsiElement(PsiElement startElement, PsiElement endElement) { if (startElement == null || endElement == null) { myStartElement = myEndElement = null; return; } LOG.assertTrue(startElement.isValid()); PsiFile startContainingFile = startElement.getContainingFile(); PsiFile endContainingFile = startElement == endElement ? startContainingFile : endElement.getContainingFile(); if (startElement != endElement) { LOG.assertTrue(endElement.isValid()); LOG.assertTrue(startContainingFile == endContainingFile, "Both elements must be from the same file"); } Project project = startContainingFile == null ? startElement.getProject() : startContainingFile.getProject(); // containingFile can be null for a directory myStartElement = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(startElement, startContainingFile); myEndElement = endElement == startElement ? null : SmartPointerManager.getInstance(project).createSmartPsiElementPointer(endElement, endContainingFile); }
public void setData(PsiElement _element, String text, final boolean clearHistory, String effectiveExternalUrl, String ref) { myEffectiveExternalUrl = effectiveExternalUrl; if (myElement != null) { myBackStack.push(saveContext()); myForwardStack.clear(); } final SmartPsiElementPointer element = _element != null && _element.isValid() ? SmartPointerManager.getInstance(_element.getProject()).createSmartPsiElementPointer(_element) : null; if (element != null) { setElement(element); } myIsEmpty = false; updateControlState(); setDataInternal(element, text, new Rectangle(0, 0), ref); if (clearHistory) clearHistory(); }
@Override public Object createAnchor(Object element) { if (element instanceof PsiElement) { final PsiElement psiElement = (PsiElement)element; return ApplicationManager.getApplication().runReadAction(new Computable<Object>() { @Override public Object compute() { SmartPointerWrapper pointer = psiElement.getUserData(PSI_ANCHORIZER_POINTER); if (!psiElement.isValid()) { return pointer != null ? pointer : psiElement; } if (pointer == null || pointer.myPointer.getElement() != psiElement) { Project project = psiElement.getProject(); SmartPsiElementPointer<PsiElement> psiElementPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(psiElement); pointer = new SmartPointerWrapper(psiElementPointer); psiElement.putUserData(PSI_ANCHORIZER_POINTER, pointer); } return pointer; } }); } return super.createAnchor(element); }
public UsageHolder(PsiElement element, UsageInfo[] usageInfos) { Project project = element.getProject(); myElementPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(element); GeneratedSourcesFilter[] filters = GeneratedSourcesFilter.EP_NAME.getExtensions(); for (UsageInfo usageInfo : usageInfos) { if (!(usageInfo instanceof SafeDeleteReferenceUsageInfo)) continue; final SafeDeleteReferenceUsageInfo usage = (SafeDeleteReferenceUsageInfo)usageInfo; if (usage.getReferencedElement() != element) continue; if (!usage.isSafeDelete()) { myUnsafeUsages++; if (usage.isNonCodeUsage || isInGeneratedCode(usage, project, filters)) { myNonCodeUnsafeUsages++; } } } }
public GroovyResolveSnapshot(final PsiElement scope) { myProject = scope.getProject(); myDocument = PsiDocumentManager.getInstance(myProject).getDocument(scope.getContainingFile()); final SmartPointerManager pointerManager = SmartPointerManager.getInstance(myProject); final Map<PsiElement, SmartPsiElementPointer> pointers = new HashMap<PsiElement, SmartPsiElementPointer>(); scope.accept(new GroovyPsiElementVisitor(new GroovyRecursiveElementVisitor() { @Override public void visitReferenceExpression(GrReferenceExpression refExpr) { if (!refExpr.isQualified()) { PsiElement resolved = refExpr.resolve(); if (resolved instanceof GrMember) { SmartPsiElementPointer key = pointerManager.createSmartPsiElementPointer(refExpr); SmartPsiElementPointer value = pointers.get(resolved); if (value == null) { value = pointerManager.createSmartPsiElementPointer(resolved); pointers.put(resolved, value); } myReferencesMap.put(key, value); } } super.visitReferenceExpression(refExpr); } })); }
public void setData(PsiElement _element, String text, final boolean clearHistory) { if (myElement != null) { myBackStack.push(saveContext()); myForwardStack.clear(); } final SmartPsiElementPointer element = _element != null && _element.isValid() ? SmartPointerManager.getInstance(_element.getProject()).createSmartPsiElementPointer(_element) : null; if (element != null) { myElement = element; } myIsEmpty = false; updateControlState(); setDataInternal(element, text, new Rectangle(0, 0)); if (clearHistory) clearHistory(); }
/** * Creates a line marker info for the element. * @param element the element for which the line marker is created. * @param range the range (relative to beginning of file) with which the marker is associated * @param icon the icon to show in the gutter for the line marker * @param updatePass the ID of the daemon pass during which the marker should be recalculated * @param tooltipProvider the callback to calculate the tooltip for the gutter icon * @param navHandler the handler executed when the gutter icon is clicked */ public LineMarkerInfo(@Nonnull T element, @Nonnull TextRange range, Icon icon, int updatePass, @Nullable Function<? super T, String> tooltipProvider, @Nullable GutterIconNavigationHandler<T> navHandler, @Nonnull GutterIconRenderer.Alignment alignment) { myIcon = icon; myTooltipProvider = tooltipProvider; myIconAlignment = alignment; elementRef = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element); myNavigationHandler = navHandler; startOffset = range.getStartOffset(); endOffset = range.getEndOffset(); this.updatePass = 11; //Pass.LINE_MARKERS; }
public PsiElement[] tryCreate(@Nonnull final String inputString) { if (inputString.length() == 0) { Messages.showMessageDialog(myProject, IdeBundle.message("error.name.should.be.specified"), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return PsiElement.EMPTY_ARRAY; } Ref<List<SmartPsiElementPointer>> createdElements = Ref.create(); Exception exception = executeCommand(getActionName(inputString), () -> { PsiElement[] psiElements = create(inputString); SmartPointerManager manager = SmartPointerManager.getInstance(myProject); createdElements.set(ContainerUtil.map(psiElements, manager::createSmartPsiElementPointer)); }); if (exception != null) { handleException(exception); return PsiElement.EMPTY_ARRAY; } return ContainerUtil.mapNotNull(createdElements.get(), SmartPsiElementPointer::getElement).toArray(PsiElement.EMPTY_ARRAY); }
public void setData(PsiElement _element, String text, final boolean clearHistory, String effectiveExternalUrl, String ref) { if (myElement != null) { myBackStack.push(saveContext()); myForwardStack.clear(); } myEffectiveExternalUrl = effectiveExternalUrl; final SmartPsiElementPointer element = _element != null && _element.isValid() ? SmartPointerManager.getInstance(_element.getProject()).createSmartPsiElementPointer(_element) : null; if (element != null) { setElement(element); } myIsEmpty = false; updateControlState(); setDataInternal(element, text, new Rectangle(0, 0), ref); if (clearHistory) clearHistory(); }
public static void cacheParticularEntity(PsiFile file, XmlEntityDecl decl) { synchronized(LOCK) { final Map<String, CachedValue<XmlEntityDecl>> cachingMap = getCachingMap(file); final String name = decl.getName(); if(cachingMap.containsKey(name)) { return; } final SmartPsiElementPointer declPointer = SmartPointerManager.getInstance(file.getProject()).createSmartPsiElementPointer(decl); cachingMap.put(name, CachedValuesManager.getManager(file.getProject()).createCachedValue(() -> { PsiElement declElement = declPointer.getElement(); if(declElement instanceof XmlEntityDecl && declElement.isValid() && name.equals(((XmlEntityDecl) declElement).getName())) { return new CachedValueProvider.Result<>((XmlEntityDecl) declElement, declElement); } cachingMap.put(name, null); return new CachedValueProvider.Result<>(null, ModificationTracker.NEVER_CHANGED); }, false)); } }
@Nullable public SmartPsiElementPointer<XmlTag> doFix(Project project, ProblemDescriptor descriptor, boolean reformat) { PsiElement element = descriptor.getPsiElement(); if (element instanceof XmlAttributeValue) { element = element.getParent(); } else if (!(element instanceof XmlAttribute)) { return null; } XmlAttribute attribute = (XmlAttribute)element; XmlTag parent = attribute.getParent(); if (!FileModificationService.getInstance().prepareFileForWrite(parent.getContainingFile())) return null; SmartPsiElementPointer<XmlTag> pointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(parent); doRemove(project, attribute, parent); if (reformat) { reformatStartTag(project, pointer); } return pointer; }
public void tryToInit() { if(myProvider == null || myElementPointer != null) { return; } ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { PsiElement psiElementById = myProvider.getPsiElementById(myPsiElementId, myProject); if(psiElementById == null) { return; } myElementPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(psiElementById); } }); }
public static Query<PsiClass> search(@NotNull SearchParameters parameters) { return INSTANCE.createUniqueResultsQuery(parameters, ContainerUtil.<SmartPsiElementPointer<PsiClass>>canonicalStrategy(), new Function<PsiClass, SmartPsiElementPointer<PsiClass>>() { @Override public SmartPsiElementPointer<PsiClass> fun(final PsiClass psiClass) { return ApplicationManager.getApplication().runReadAction(new Computable<SmartPsiElementPointer<PsiClass>>() { @Override public SmartPsiElementPointer<PsiClass> compute() { return SmartPointerManager.getInstance(psiClass.getProject()).createSmartPsiElementPointer(psiClass); } }); } }); }
@Override public int compareTo(UsageGroup usageGroup) { if (!(usageGroup instanceof MethodUsageGroup)) { LOG.error("MethodUsageGroup expected but " + usageGroup.getClass() + " found"); } MethodUsageGroup other = (MethodUsageGroup)usageGroup; if (SmartPointerManager.getInstance(myProject).pointToTheSameElement(myMethodPointer, other.myMethodPointer)) { return 0; } if (!UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) { Segment segment1 = myMethodPointer.getRange(); Segment segment2 = other.myMethodPointer.getRange(); if (segment1 != null && segment2 != null) { return segment1.getStartOffset() - segment2.getStartOffset(); } } return myName.compareToIgnoreCase(other.myName); }
public PropertyQuickFix( @NotNull final PhpClass primaryClass, @NotNull final String propertyName, @NotNull final String propertyType ) { final SmartPointerManager pointerManager = SmartPointerManager.getInstance(primaryClass.getProject()); primaryClassPointer = pointerManager.createSmartPsiElementPointer(primaryClass); this.propertyName = propertyName; this.propertyType = propertyType; familyName = String.format("Declare @property $%s on %s class", propertyName, primaryClass.getName()); }
public PsiElementUsageGroupBase(@NotNull T element, Icon icon) { String myName = element.getName(); if (myName == null) myName = "<anonymous>"; this.myName = myName; myElementPointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element); myIcon = icon; }
@NotNull private static List<SmartPsiElementPointer<PsiElement>> convertToSmartPointers(@NotNull PsiElement[] primaryElements) { if (primaryElements.length == 0) return Collections.emptyList(); final SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(primaryElements[0].getProject()); return ContainerUtil.mapNotNull(primaryElements, new Function<PsiElement, SmartPsiElementPointer<PsiElement>>() { @Override public SmartPsiElementPointer<PsiElement> fun(final PsiElement s) { return smartPointerManager.createSmartPsiElementPointer(s); } }); }
private void disposeSmartPointers() { SmartPointerManager pointerManager = SmartPointerManager.getInstance(getProject()); for (Usage usage : myUsageNodes.keySet()) { if (usage instanceof UsageInfo2UsageAdapter) { SmartPsiElementPointer<?> pointer = ((UsageInfo2UsageAdapter)usage).getUsageInfo().getSmartPointer(); pointerManager.removePointer(pointer); } } }
@Nullable public PsiElement getElement() { if (myPointer.getProject().isDisposed()) return null; PsiElement element = myPointer.getElement(); SmartPointerManager.getInstance(myPointer.getProject()).removePointer(myPointer); return element; }
public CoreProjectEnvironment(@NotNull Disposable parentDisposable, @NotNull CoreApplicationEnvironment applicationEnvironment) { myParentDisposable = parentDisposable; myEnvironment = applicationEnvironment; myProject = createProject(myEnvironment.getApplication().getPicoContainer(), myParentDisposable); preregisterServices(); myFileIndexFacade = createFileIndexFacade(); myMessageBus = MessageBusFactory.newMessageBus("CoreProjectEnvironment"); PsiModificationTrackerImpl modificationTracker = new PsiModificationTrackerImpl(myProject); myProject.registerService(PsiModificationTracker.class, modificationTracker); myProject.registerService(FileIndexFacade.class, myFileIndexFacade); myProject.registerService(ResolveCache.class, new ResolveCache(myMessageBus)); myPsiManager = new PsiManagerImpl(myProject, null, null, myFileIndexFacade, myMessageBus, modificationTracker); ((FileManagerImpl) myPsiManager.getFileManager()).markInitialized(); registerProjectComponent(PsiManager.class, myPsiManager); myProject.registerService(SmartPointerManager.class, SmartPointerManagerImpl.class); registerProjectComponent(PsiDocumentManager.class, new CorePsiDocumentManager(myProject, myPsiManager, myMessageBus, new MockDocumentCommitProcessor())); myProject.registerService(ResolveScopeManager.class, createResolveScopeManager(myPsiManager)); myProject.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager)); myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager))); myProject.registerService(PsiDirectoryFactory.class, new PsiDirectoryFactoryImpl(myPsiManager)); myProject.registerService(ProjectScopeBuilder.class, createProjectScopeBuilder()); myProject.registerService(DumbService.class, new MockDumbService(myProject)); myProject.registerService(CoreEncodingProjectManager.class, CoreEncodingProjectManager.class); }
public BasePsiNode(final T element) { super(element.getProject()); if (element.isValid()) { myPsiElementPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(element); } else { myPsiElementPointer = null; } }
public MyIntroduceLookupExpression(final String initialName, final LinkedHashSet<String> names, final PsiNamedElement elementToRename, final boolean shouldSelectAll, final String advertisementText) { super(initialName, names, elementToRename, elementToRename, shouldSelectAll, advertisementText); myPointer = SmartPointerManager.getInstance(elementToRename.getProject()).createSmartPsiElementPointer(elementToRename); }
public DocstringQuickFix(@Nullable PyNamedParameter missing, @Nullable String unexpectedParamName) { if (missing != null) { myMissingParam = SmartPointerManager.getInstance(missing.getProject()).createSmartPsiElementPointer(missing); } else { myMissingParam = null; } myUnexpectedParamName = unexpectedParamName; }
private static <T> List<SmartPsiElementPointer> calcPsiTargets(Project project, Collection<? extends T> targets, NotNullFunction<T, Collection<? extends PsiElement>> converter) { SmartPointerManager manager = SmartPointerManager.getInstance(project); Set<PsiElement> elements = new THashSet<PsiElement>(); final List<SmartPsiElementPointer> list = new ArrayList<SmartPsiElementPointer>(targets.size()); for (final T target : targets) { for (final PsiElement psiElement : converter.fun(target)) { if (elements.add(psiElement) && psiElement.isValid()) { list.add(manager.createSmartPsiElementPointer(psiElement)); } } } return list; }
public GrClassReferenceTypePointer(GrClassReferenceType type, Project project) { super(type); myProject = project; final GrReferenceElement reference = type.getReference(); mySmartPsiElementPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(reference); myReferenceText = reference.getText(); }
public static Query<SchemaTypeDef> search(@NotNull final SearchParameters parameters) { final Project project = parameters.schemaTypeDef.getProject(); return INSTANCE.createUniqueResultsQuery(parameters, ContainerUtil.canonicalStrategy(), schemaTypeDef -> schemaTypeDef == null ? null : ApplicationManager.getApplication().runReadAction( (Computable<SmartPsiElementPointer<SchemaTypeDef>>) () -> SmartPointerManager.getInstance(project).createSmartPsiElementPointer(schemaTypeDef) ) ); }
public static Query<SchemaTypeDef> search(@NotNull final SearchParameters parameters) { return INSTANCE.createUniqueResultsQuery(parameters, ContainerUtil.canonicalStrategy(), schemaTypeDef -> ApplicationManager.getApplication().runReadAction( (Computable<SmartPsiElementPointer<SchemaTypeDef>>) () -> SmartPointerManager.getInstance(schemaTypeDef.getProject()).createSmartPsiElementPointer(schemaTypeDef) ) ); }
@Nullable private SmartPsiElementPointer<SqlSelectStatement> getStatementPointer(final @NotNull Project project, final @NotNull PsiElement psiElement) { final SqlSelectStatement sqlSelectStatement = PsiTreeUtil.getParentOfType(psiElement.getContainingFile().findElementAt(psiElement.getTextOffset()), SqlSelectStatement.class); SmartPsiElementPointer<SqlSelectStatement> pointer = null; if (sqlSelectStatement != null) { pointer = SmartPointerManager.getInstance(project) .createSmartPsiElementPointer(sqlSelectStatement); } return pointer; }
private void disposeSmartPointers() { SmartPointerManager pointerManager = SmartPointerManager.getInstance(getProject()); for (Usage usage : myUsageNodes.keySet()) { if (usage instanceof UsageInfo2UsageAdapter) { SmartPsiElementPointer<?> pointer = ((UsageInfo2UsageAdapter)usage).getUsageInfo().getSmartPointer(); if (pointer != null) { pointerManager.removePointer(pointer); } } } }
public PsiNamedElementUsageGroupBase(@NotNull T element, Icon icon) { String myName = element.getName(); if (myName == null) myName = "<anonymous>"; this.myName = myName; myElementPointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element); myIcon = icon; }
public UsageHolder(PsiElement element, UsageInfo[] usageInfos) { myElementPointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element); ArrayList<SafeDeleteReferenceUsageInfo> elementUsages = new ArrayList<SafeDeleteReferenceUsageInfo>(); for (UsageInfo usageInfo : usageInfos) { if (usageInfo instanceof SafeDeleteReferenceUsageInfo) { final SafeDeleteReferenceUsageInfo referenceUsageInfo = (SafeDeleteReferenceUsageInfo)usageInfo; if (referenceUsageInfo.getReferencedElement() == element) { elementUsages.add(referenceUsageInfo); } } } myUsages = elementUsages.toArray(new SafeDeleteReferenceUsageInfo[elementUsages.size()]); }