Java Code Examples for com.intellij.psi.PsiFile#getName()

The following examples show how to use com.intellij.psi.PsiFile#getName() . 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: FileResourcesIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static boolean isValidForIndex(FileContent inputData, PsiFile psiFile) {

        String fileName = psiFile.getName();

        if(fileName.startsWith(".") || fileName.endsWith("Test")) {
            return false;
        }

        String extension = inputData.getFile().getExtension();
        if(extension == null || !(extension.equalsIgnoreCase("xml") || extension.equalsIgnoreCase("yml")|| extension.equalsIgnoreCase("yaml"))) {
            return false;
        }

        if(inputData.getFile().getLength() > MAX_FILE_BYTE_SIZE) {
            return false;
        }

        return true;
    }
 
Example 2
Source File: ShopwareSubscriperMethodInspection.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    PsiFile psiFile = holder.getFile();

    if(!ShopwareProjectComponent.isValidForProject(psiFile)) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    String name = psiFile.getName();

    if(name.contains("Bootstrap")) {
        psiFile.acceptChildren(new MyBootstrapRecursiveElementWalkingVisitor(holder));
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new MySubscriberRecursiveElementWalkingVisitor(holder);
}
 
Example 3
Source File: IndexUtil.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
public static boolean isValidForIndex(@NotNull FileContent inputData, @NotNull PsiFile psiFile) {

        String fileName = psiFile.getName();
        if(fileName.startsWith(".") || fileName.endsWith("Test")) {
            return false;
        }

        VirtualFile baseDir = inputData.getProject().getBaseDir();
        if(baseDir == null) {
            return false;
        }

        // is Test file in path name
        String relativePath = VfsUtil.getRelativePath(inputData.getFile(), baseDir, '/');
        if(relativePath != null && (relativePath.contains("/Test/") || relativePath.contains("/Fixtures/"))) {
            return false;
        }

        return true;
    }
 
Example 4
Source File: AbstractBashFileReference.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
    if (!element.isWritable()) {
        throw new IncorrectOperationException("bindToElement not possible for read-only element: " + element);
    }

    if (element instanceof PsiFile) {
        //findRelativeFilePath already leaves the injection host file
        PsiFile currentFile = cmd.getContainingFile();
        if (!currentFile.isWritable()) {
            throw new IncorrectOperationException("bindToElement not possible for read-only file: " + currentFile.getName());
        }

        String relativeFilePath = BashPsiFileUtils.findRelativeFilePath(currentFile, (PsiFile) element);

        return handleElementRename(relativeFilePath);
    }

    throw new IncorrectOperationException("unsupported for element " + element);
}
 
Example 5
Source File: FileIncludeManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void processIncludingFiles(PsiFile context, Processor<? super Pair<VirtualFile, FileIncludeInfo>> processor) {
  context = context.getOriginalFile();
  VirtualFile contextFile = context.getVirtualFile();
  if (contextFile == null) return;

  String originalName = context.getName();
  Collection<String> names = getPossibleIncludeNames(context, originalName);

  GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
  for (String name : names) {
    MultiMap<VirtualFile, FileIncludeInfoImpl> infoList = FileIncludeIndex.getIncludingFileCandidates(name, scope);
    for (VirtualFile candidate : infoList.keySet()) {
      PsiFile psiFile = myPsiManager.findFile(candidate);
      if (psiFile == null || context.equals(psiFile)) continue;
      for (FileIncludeInfo info : infoList.get(candidate)) {
        PsiFileSystemItem item = resolveFileInclude(info, psiFile);
        if (item != null && contextFile.equals(item.getVirtualFile())) {
          if (!processor.process(Pair.create(candidate, info))) {
            return;
          }
        }
      }
    }
  }
}
 
Example 6
Source File: RoutesStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private static boolean isValidForIndex(FileContent inputData, PsiFile psiFile) {

        String fileName = psiFile.getName();
        if(fileName.startsWith(".") || fileName.endsWith("Test")) {
            return false;
        }

        VirtualFile baseDir = ProjectUtil.getProjectDir(inputData.getProject());
        if(baseDir == null) {
            return false;
        }

        // is Test file in path name
        String relativePath = VfsUtil.getRelativePath(inputData.getFile(), baseDir, '/');
        if(relativePath != null && (relativePath.contains("/Test/") || relativePath.contains("/Fixtures/"))) {
            return false;
        }

        return true;
    }
 
Example 7
Source File: ThriftTopLevelDeclarationPresentationProvider.java    From intellij-thrift with Apache License 2.0 6 votes vote down vote up
@Override
public ItemPresentation getPresentation(final ThriftDeclaration item) {
  return new ItemPresentation() {
    @Nullable
    @Override
    public String getPresentableText() {
      return item.getName();
    }

    @Nullable
    @Override
    public String getLocationString() {
      PsiFile containingFile = item.getContainingFile();
      return containingFile == null ? null : containingFile.getName();
    }

    @Nullable
    @Override
    public Icon getIcon(boolean unused) {
      return item.getIcon(Iconable.ICON_FLAG_VISIBILITY);
    }
  };
}
 
Example 8
Source File: MsilToNativeElementTransformer.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static MsilClassEntry findRootClassEntry(@Nonnull MsilClassEntry element)
{
	PsiFile containingFile = element.getContainingFile();
	if(!(containingFile instanceof MsilFile))
	{
		return element;
	}

	MsilClassEntry originalClassEntry = null;

	PsiElement temp = element;
	while(!(temp instanceof MsilFile))
	{
		if(temp instanceof MsilClassEntry && temp.getParent() instanceof MsilFile)
		{
			originalClassEntry = (MsilClassEntry) temp;
			break;
		}

		temp = temp.getParent();
	}

	if(originalClassEntry == null)
	{
		throw new IllegalArgumentException("Cant determinate parent msil class for: " + containingFile.getName());
	}

	return originalClassEntry;
}
 
Example 9
Source File: RTInfoFilter.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Override
    public boolean accept(@NotNull HighlightInfo highlightInfo, PsiFile psiFile) {
        if (psiFile != null && psiFile.getName() != null && psiFile.getName().endsWith(".rt") && MSG_EMPTY_TAG.equals(highlightInfo.getDescription())) {
            return false;
        }
//        System.out.println(highlightInfo.getSeverity() + " " + highlightInfo.getDescription());
        return true;
    }
 
Example 10
Source File: EventsList.java    From droidtestrec with Apache License 2.0 5 votes vote down vote up
public void clear(Project project, Module module, PsiFile activityFile) {
    listModel.removeAllElements();
    events.clear();

    this.project = project;
    this.module = module;

    this.activityFile = activityFile;
    activityClassName = activityFile.getName();
    int pos = activityClassName.indexOf('.');
    if (pos > 0) {
        activityClassName = activityClassName.substring(0, pos);
    }
    testClassField.setText(activityClassName +"Test");
}
 
Example 11
Source File: YamlLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void attachEntityClass(@NotNull Collection<LineMarkerInfo> lineMarkerInfos, @NotNull PsiElement psiElement) {
    if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) {
        return;
    }

    PsiElement yamlKeyValue = psiElement.getParent();
    if(!(yamlKeyValue instanceof YAMLKeyValue)) {
        return;
    }

    if(yamlKeyValue.getParent() instanceof YAMLMapping && yamlKeyValue.getParent().getParent() instanceof YAMLDocument) {
        PsiFile containingFile;
        try {
            containingFile = yamlKeyValue.getContainingFile();
        } catch (PsiInvalidElementAccessException e) {
            return;
        }

        String fileName = containingFile.getName();
        if(isMetadataFile(fileName)) {
            String keyText = ((YAMLKeyValue) yamlKeyValue).getKeyText();
            if(StringUtils.isNotBlank(keyText)) {
                Collection<PhpClass> phpClasses = PhpElementsUtil.getClassesInterface(psiElement.getProject(), keyText);
                if(phpClasses.size() > 0) {
                    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.DOCTRINE_LINE_MARKER).
                        setTargets(phpClasses).
                        setTooltipText("Navigate to class");

                    lineMarkerInfos.add(builder.createLineMarkerInfo(psiElement));
                }
            }
        }
    }
}
 
Example 12
Source File: SkylarkDebuggerEditorsProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static String codeFragmentFileName(@Nullable PsiElement context) {
  if (context == null) {
    return "fragment.bzl";
  }
  PsiFile contextFile = context.getContainingFile();
  return contextFile != null ? contextFile.getName() : "fragment.bzl";
}
 
Example 13
Source File: GoSyncStatusContributor.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public PsiFileAndName toPsiFileAndName(BlazeProjectData projectData, ProjectViewNode<?> node) {
  if (!(node instanceof PsiFileNode)) {
    return null;
  }
  PsiFile psiFile = ((PsiFileNode) node).getValue();
  if (!(psiFile instanceof GoFile)) {
    return null;
  }
  return new PsiFileAndName(psiFile, psiFile.getName());
}
 
Example 14
Source File: ExecuteAllAction.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = getEventProject(e);
    if (project == null) {
        Notifier.error("Query execution error", "No project present.");
        return;
    }
    MessageBus messageBus = project.getMessageBus();
    ParametersService parameterService = ServiceManager.getService(project, ParametersService.class);
    PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);

    StatementCollector statementCollector = new StatementCollector(messageBus, parameterService);

    // This should never happen
    if (psiFile == null) {
        Notifier.error("Internal error", "No PsiFile present.");
    }
    psiFile.acceptChildren(statementCollector);
    if (!statementCollector.hasErrors()) {
        ExecuteQueryPayload executeQueryPayload =
            new ExecuteQueryPayload(statementCollector.getQueries(), statementCollector.getParameters(), psiFile.getName());
        ConsoleToolWindow.ensureOpen(project);

        DataSourcesComponent dataSourcesComponent = project.getComponent(DataSourcesComponent.class);
        ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(
            "Choose Data Source",
            new ChooseDataSourceActionGroup(messageBus, dataSourcesComponent, executeQueryPayload),
            e.getDataContext(),
            JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
            false
        );
        popup.showInBestPositionFor(e.getDataContext());
    } else {
        Notifier.error("Query execution error", "File contains errors");
    }
}
 
Example 15
Source File: FakeCamelPsiElement.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String getLocationString() {
    PsiFile file = getContainingFile();
    if (file != null) {
        return file.getName();
    }
    return null;
}
 
Example 16
Source File: SmartRefElementPointerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private String getContainingFileName(RefElement ref) {
  SmartPsiElementPointer pointer = ref.getPointer();
  if (pointer == null) return null;
  PsiFile file = pointer.getContainingFile();
  if (file == null) return null;
  return file.getName();
}
 
Example 17
Source File: FilePathCompletionContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FilePathLookupItem(@Nonnull final PsiFile file, @Nonnull final List<FileReferenceHelper> helpers) {
  myName = file.getName();
  myPath = file.getVirtualFile().getPath();

  myHelpers = helpers;

  myInfo = FileInfoManager.getFileAdditionalInfo(file);
  myIcon = TargetAWT.to(file.getFileType().getIcon());

  myFile = file;
}
 
Example 18
Source File: CompletionAssertions.java    From consulo with Apache License 2.0 4 votes vote down vote up
static void assertCommitSuccessful(Editor editor, PsiFile psiFile) {
  Document document = editor.getDocument();
  int docLength = document.getTextLength();
  int psiLength = psiFile.getTextLength();
  PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
  boolean committed = !manager.isUncommited(document);
  if (docLength == psiLength && committed) {
    return;
  }

  FileViewProvider viewProvider = psiFile.getViewProvider();

  String message = "unsuccessful commit:";
  message += "\nmatching=" + (psiFile == manager.getPsiFile(document));
  message += "\ninjectedEditor=" + (editor instanceof EditorWindow);
  message += "\ninjectedFile=" + InjectedLanguageManager.getInstance(psiFile.getProject()).isInjectedFragment(psiFile);
  message += "\ncommitted=" + committed;
  message += "\nfile=" + psiFile.getName();
  message += "\nfile class=" + psiFile.getClass();
  message += "\nfile.valid=" + psiFile.isValid();
  message += "\nfile.physical=" + psiFile.isPhysical();
  message += "\nfile.eventSystemEnabled=" + viewProvider.isEventSystemEnabled();
  message += "\nlanguage=" + psiFile.getLanguage();
  message += "\ndoc.length=" + docLength;
  message += "\npsiFile.length=" + psiLength;
  String fileText = psiFile.getText();
  if (fileText != null) {
    message += "\npsiFile.text.length=" + fileText.length();
  }
  FileASTNode node = psiFile.getNode();
  if (node != null) {
    message += "\nnode.length=" + node.getTextLength();
    String nodeText = node.getText();
    message += "\nnode.text.length=" + nodeText.length();
  }
  VirtualFile virtualFile = viewProvider.getVirtualFile();
  message += "\nvirtualFile=" + virtualFile;
  message += "\nvirtualFile.class=" + virtualFile.getClass();
  message += "\n" + DebugUtil.currentStackTrace();

  throw new RuntimeExceptionWithAttachments("Commit unsuccessful", message, new Attachment(virtualFile.getPath() + "_file.txt", StringUtil.notNullize(fileText)), createAstAttachment(psiFile, psiFile),
                                            new Attachment("docText.txt", document.getText()));
}
 
Example 19
Source File: RefElementImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected RefElementImpl(PsiFile file, RefManager manager) {
  this(file.getName(), file, manager);
}
 
Example 20
Source File: AbstractLayoutCodeProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
private String getPresentablePath(@Nonnull PsiFile file) {
  VirtualFile vFile = file.getVirtualFile();
  return vFile != null ? ProjectUtil.calcRelativeToProjectPath(vFile, myProject) : file.getName();
}