Java Code Examples for com.intellij.psi.PsiElement#getManager()

The following examples show how to use com.intellij.psi.PsiElement#getManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhpHeaderDocumentationProvider.java    From idea-php-advanced-autocomplete with MIT License 6 votes vote down vote up
@Override
public @Nullable PsiElement getCustomDocumentationElement(@NotNull Editor editor, @NotNull PsiFile file, @Nullable PsiElement contextElement) {
    if (!isCallToHeaderFunc(contextElement)) {
        return null;
    }

    if (!(contextElement instanceof StringLiteralExpression)) {
        contextElement = PhpPsiUtil.getParentByCondition(contextElement, true, StringLiteralExpression.INSTANCEOF);
    }

    if (contextElement instanceof StringLiteralExpression) {
        String contents = ((StringLiteralExpression)contextElement).getContents();
        if (!contents.contains(":")) {
            return null;
        }
        String headerName = StringUtils.substringBefore(contents, ":");
        if (headerName.isEmpty() || !isHeaderName(headerName)) {
            return null;
        }
        return new HeaderDocElement(contextElement.getManager(), contextElement.getLanguage(), headerName);
    }
    return null;
}
 
Example 2
Source File: ASTDelegatePsiElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public PsiManagerEx getManager() {
  Project project = ProjectCoreUtil.theOnlyOpenProject();
  if (project != null) {
    return PsiManagerEx.getInstanceEx(project);
  }
  PsiElement parent = this;

  while (parent instanceof ASTDelegatePsiElement) {
    parent = parent.getParent();
  }

  if (parent == null) {
    throw new PsiInvalidElementAccessException(this);
  }

  return (PsiManagerEx)parent.getManager();
}
 
Example 3
Source File: SqliteMagicLightParameter.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
public SqliteMagicLightParameter(@NotNull String name, @NotNull PsiType type, PsiElement declarationScope, Language language) {
  super(name, type, declarationScope, language);
  myName = name;
  PsiManager manager = declarationScope.getManager();
  myNameIdentifier = new SqliteMagicLightIdentifier(manager, name);
  ReflectionUtil.setFinalFieldPerReflection(LightVariableBuilder.class, this, LightModifierList.class,
      new SqliteMagicLightModifierList(manager, language));
}
 
Example 4
Source File: LombokLightClassBuilder.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public LombokLightClassBuilder(@NotNull PsiElement context, @NotNull String simpleName, @NotNull String qualifiedName) {
  super(context, simpleName);
  myIsEnum = false;
  myQualifiedName = qualifiedName;
  myBaseIcon = LombokIcons.CLASS_ICON;
  myModifierList = new LombokLightModifierList(context.getManager(), context.getLanguage(), Collections.emptyList());
}
 
Example 5
Source File: LombokLightParameter.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public LombokLightParameter(@NotNull String name, @NotNull PsiType type, PsiElement declarationScope, Language language) {
  super(name, type, declarationScope, language);
  myName = name;
  PsiManager manager = declarationScope.getManager();
  myNameIdentifier = new LombokLightIdentifier(manager, name);
  ReflectionUtil.setFinalFieldPerReflection(LightVariableBuilder.class, this, LightModifierList.class,
    new LombokLightModifierList(manager, language, Collections.emptySet()));
}
 
Example 6
Source File: FileElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public PsiManagerEx getManager() {
  CompositeElement treeParent = getTreeParent();
  if (treeParent != null) return treeParent.getManager();
  PsiElement psi = getPsi();
  if (psi == null) throw PsiInvalidElementAccessException.createByNode(this, null);
  return (PsiManagerEx)psi.getManager();
}
 
Example 7
Source File: FakePsiElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public PsiManager getManager() {
  final PsiElement parent = getParent();
  if(parent != null) {
    return parent.getManager();
  }
  throw new IllegalArgumentException("Parent must be not null for return PsiManager, or override this method. Class: " + getClass());
}
 
Example 8
Source File: RenameFileDirectory.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
public static void execute(final PsiElement element, final String newName, final UsageInfo[] usages,
                           @Nullable final RefactoringElementListener listener) throws IncorrectOperationException {
    try {
        final VirtualFile virtualFile;
        if (element instanceof PsiFile) {
            logger.info("Renaming file...");
            virtualFile = ((PsiFile) element).getVirtualFile();
        } else if (element instanceof PsiDirectory) {
            logger.info("Renaming directory...");
            virtualFile = ((PsiDirectory) element).getVirtualFile();
        } else {
            // should never reach here since we check if file/directory before making a rename
            logger.warn("RenameFile: failed to find proper object to rename: " + element.getClass());
            throw new IncorrectOperationException("Can't perform rename on objects other than files and directories");
        }

        final String currentPath = virtualFile.getPath();
        final String parentDirectory = virtualFile.getParent().getPath();
        final String newPath = Path.combine(parentDirectory, newName);
        final Project project = element.getProject();

        // a single file may have 0, 1, or 2 pending changes to it
        // 0 - file has not been touched in the local workspace
        // 1 - file has versioned OR unversioned changes
        // 2 - file has versioned AND unversioned changes (rare but can happen)
        final List<PendingChange> pendingChanges = new ArrayList<>(2);
        pendingChanges.addAll(
                CommandUtils.getStatusForFiles(
                        project,
                        TFSVcs.getInstance(project).getServerContext(true),
                        ImmutableList.of(currentPath)));

        // ** Rename logic **
        // If 1 change and it's an add that means it's a new unversioned file so rename thru the file system
        // Anything else can be renamed
        // Deleted files should not be at this point since IDE disables rename option for them
        if (pendingChanges.size() == 1 && pendingChanges.get(0).getChangeTypes().contains(ServerStatusType.ADD)) {
            logger.info("Renaming unversioned file thru file system");
            RenameUtil.doRenameGenericNamedElement(element, newName, usages, listener);
        } else {
            logger.info("Renaming file thru tf commandline");
            CommandUtils.renameFile(TFSVcs.getInstance(project).getServerContext(true), currentPath, newPath);

            // this alerts that a rename has taken place so any additional processing can take place
            final VFileEvent event = new VFilePropertyChangeEvent(element.getManager(), virtualFile, "name", currentPath, newName, false);
            PersistentFS.getInstance().processEvents(Collections.singletonList(event));
        }
    } catch (Throwable t) {
        logger.warn("renameElement experienced a failure while trying to rename a file", t);
        throw new IncorrectOperationException(t);
    }

    if (listener != null) {
        listener.elementRenamed(element);
    }
}
 
Example 9
Source File: CSharpLightElementBuilder.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CSharpLightElementBuilder(PsiElement element)
{
	super(element.getManager(), CSharpLanguage.INSTANCE);
}