com.intellij.openapi.fileTypes.StdFileTypes Java Examples

The following examples show how to use com.intellij.openapi.fileTypes.StdFileTypes. 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: DustLayeredSyntaxHighlighter.java    From Intellij-Dust with MIT License 6 votes vote down vote up
public DustLayeredSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) {
  // create main highlighter
  super(new DustSyntaxHighlighter(), colors);

  // highlighter for outer lang
  FileType type = null;
  if(project == null || virtualFile == null) {
    type = StdFileTypes.PLAIN_TEXT;
  } else {
    Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(virtualFile);
    if(language != null) type = language.getAssociatedFileType();
    if(type == null) type = StdFileTypes.HTML;
  }
  SyntaxHighlighter outerHighlighter = SyntaxHighlighter.PROVIDER.create(type, project, virtualFile);

  registerLayer(DustTypes.HTML, new LayerDescriptor(outerHighlighter, ""));
}
 
Example #2
Source File: PolygeneFacetType.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
@Override
public final void registerDetectors( FacetDetectorRegistry<PolygeneFacetConfiguration> registry )
{
    registry.registerOnTheFlyDetector(
        StdFileTypes.JAVA, VirtualFileFilter.ALL, new HasPolygeneImportPackageCondition(),
        new FacetDetector<PsiFile, PolygeneFacetConfiguration>( "PolygeneFacetDetector" )
        {
            @Override
            public PolygeneFacetConfiguration detectFacet( PsiFile source,
                                                       Collection<PolygeneFacetConfiguration> existingConfigurations )
            {
                if( !existingConfigurations.isEmpty() )
                {
                    return existingConfigurations.iterator().next();
                }

                return createDefaultConfiguration();
            }
        }
    );
}
 
Example #3
Source File: FluidFileViewProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
public FluidFileViewProvider(PsiManager manager, VirtualFile file, boolean physical) {
    super(manager, file, physical);

    Language dataLang = TemplateDataLanguageMappings.getInstance(manager.getProject()).getMapping(file);
    if (dataLang == null) {
        dataLang = StdFileTypes.HTML.getLanguage();
    }

    if (dataLang instanceof TemplateLanguage) {
        myTemplateDataLanguage = PlainTextLanguage.INSTANCE;
    } else {
        // The substitutor signals, that a files content should be substituted
        Language mySubstitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(dataLang, file, manager.getProject());
        if (mySubstitutedLanguage == FluidLanguage.INSTANCE) {
            this.myTemplateDataLanguage = StdFileTypes.HTML.getLanguage();
        } else {
            this.myTemplateDataLanguage = mySubstitutedLanguage;
        }
    }
}
 
Example #4
Source File: SoyLayeredHighlighter.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
public SoyLayeredHighlighter(
    @Nullable Project project,
    @Nullable VirtualFile virtualFile,
    @NotNull EditorColorsScheme colors) {
  // Creating main highlighter.
  super(new SoySyntaxHighlighter(), colors);

  // Highlighter for the outer language.
  FileType type = null;
  if (project == null || virtualFile == null) {
    type = StdFileTypes.PLAIN_TEXT;
  } else {
    Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(virtualFile);
    if (language != null) type = language.getAssociatedFileType();
    if (type == null) type = SoyLanguage.getDefaultTemplateLang();
  }

  SyntaxHighlighter outerHighlighter =
      SyntaxHighlighterFactory.getSyntaxHighlighter(type, project, virtualFile);

  registerLayer(OTHER, new LayerDescriptor(outerHighlighter, ""));
}
 
Example #5
Source File: NewClassCommandAction.java    From json2java4idea with Apache License 2.0 6 votes vote down vote up
@Override
protected void run(@NotNull Result<PsiFile> result) throws Throwable {
    final PsiPackage packageElement = directoryService.getPackage(directory);
    if (packageElement == null) {
        throw new InvalidDirectoryException("Target directory does not provide a package");
    }

    final String fileName = Extensions.append(name, StdFileTypes.JAVA);
    final PsiFile found = directory.findFile(fileName);
    if (found != null) {
        throw new ClassAlreadyExistsException("Class '" + name + "'already exists in " + packageElement.getName());
    }

    final String packageName = packageElement.getQualifiedName();
    final String className = Extensions.remove(this.name, StdFileTypes.JAVA);
    try {
        final String java = converter.convert(packageName, className, json);
        final PsiFile classFile = fileFactory.createFileFromText(fileName, JavaFileType.INSTANCE, java);
        CodeStyleManager.getInstance(classFile.getProject()).reformat(classFile);
        JavaCodeStyleManager.getInstance(classFile.getProject()).optimizeImports(classFile);
        final PsiFile created = (PsiFile) directory.add(classFile);
        result.setResult(created);
    } catch (IOException e) {
        throw new ClassCreationException("Failed to create new class from JSON", e);
    }
}
 
Example #6
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
public static List<XmlTag> findFlowRefsForFlow(@NotNull XmlTag flow) {
    List<XmlTag> flowRefs = new ArrayList<>();

    final Project project = flow.getProject();
    final String flowName = flow.getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE);

    Collection<VirtualFile> vFiles = FileTypeIndex.getFiles(StdFileTypes.XML, ProjectScope.getContentScope(project));
    for (VirtualFile virtualFile : vFiles) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
        if (psiFile != null) {
            XmlFile xmlFile = (XmlFile) psiFile;
            XmlTag mule = xmlFile.getRootTag();

            FlowRefsFinder finder = new FlowRefsFinder(flowName);
            mule.accept(finder);
            flowRefs.addAll(finder.getFlowRefs());
        }
    }
    return flowRefs;
}
 
Example #7
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@NotNull
private static List<XmlTag> getGlobalElementsInScope(Project project, GlobalSearchScope searchScope) {
    final List<XmlTag> result = new ArrayList<>();
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    final DomManager manager = DomManager.getDomManager(project);
    for (VirtualFile file : files) {
        final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
        if (isMuleFile(xmlFile)) {
            final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
            if (fileElement != null) {
                final Mule rootElement = fileElement.getRootElement();
                final XmlTag[] subTags = rootElement.getXmlTag().getSubTags();
                for (XmlTag subTag : subTags) {
                    if (isGlobalElement(subTag)) {
                        result.add(subTag);
                    }
                }
            }
        }
    }
    return result;
}
 
Example #8
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@NotNull
private static List<DomElement> getFlowsInScope(Project project, GlobalSearchScope searchScope) {
    final List<DomElement> result = new ArrayList<>();
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    final DomManager manager = DomManager.getDomManager(project);
    for (VirtualFile file : files) {
        final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
        if (isMuleFile(xmlFile)) {
            final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
            if (fileElement != null) {
                final Mule rootElement = fileElement.getRootElement();
                result.addAll(rootElement.getFlows());
                result.addAll(rootElement.getSubFlows());
            }
        }
    }
    return result;
}
 
Example #9
Source File: GlobalConfigsTreeStructure.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
        protected SimpleNode[] buildChildren() {
            List<SimpleNode> myConfigNodes = new ArrayList<>();

            final DomManager manager = DomManager.getDomManager(myProject);

            final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, GlobalSearchScope.projectScope(myProject));

            for (VirtualFile file : files) {

                final PsiFile xmlFile = PsiManager.getInstance(myProject).findFile(file);

                if (xmlFile != null) {
//                    PsiDirectory directory = xmlFile.getParent();
//                    Module module = ModuleUtilCore.findModuleForPsiElement((PsiElement) (directory == null ? xmlFile : directory));

                    if (MuleConfigUtils.isMuleFile(xmlFile)) {
                        final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);

                        if (fileElement != null) {
                            final Mule rootElement = fileElement.getRootElement();
                            XmlTag[] subTags = rootElement.getXmlTag().getSubTags();

                            for (XmlTag nextTag : subTags) {
                                MuleElementType muleElementType = MuleConfigUtils.getMuleElementTypeFromXmlElement(nextTag);

                                if (muleElementType != null && //This is a global config file and it has at least one connector
                                        (MuleElementType.CONFIG.equals(muleElementType) || (MuleElementType.TRANSPORT_CONNECTOR.equals(muleElementType)))) {
                                    MuleConfigNode nextConfigNode = new MuleConfigNode(this, xmlFile);
                                    myConfigNodes.add(nextConfigNode);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return myConfigNodes.toArray(new SimpleNode[]{});
        }
 
Example #10
Source File: DustFileViewProvider.java    From Intellij-Dust with MIT License 5 votes vote down vote up
public DustFileViewProvider(PsiManager manager, VirtualFile file, boolean physical) {
  super(manager, file, physical);

  // get the main language of the file
  Language dataLang = TemplateDataLanguageMappings.getInstance(manager.getProject()).getMapping(file);
  if (dataLang == null) dataLang = StdFileTypes.HTML.getLanguage();

  // some magic?
  if (dataLang instanceof TemplateLanguage) {
    myTemplateDataLanguage = PlainTextLanguage.INSTANCE;
  } else {
    myTemplateDataLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(dataLang, file, manager.getProject());
  }
}
 
Example #11
Source File: AbstractDelombokAction.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void processFile(Project project, VirtualFile file) {
  if (StdFileTypes.JAVA.equals(file.getFileType())) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    PsiJavaFile psiFile = (PsiJavaFile) psiManager.findFile(file);
    if (psiFile != null) {
      process(project, psiFile);
    }
  }
}
 
Example #12
Source File: BaseRefactorAction.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean isActionAvailable(AnActionEvent e) {
  final VirtualFile file = getVirtualFiles(e);
  if (getEventProject(e) != null && file != null) {
    final FileType fileType = file.getFileType();
    return StdFileTypes.JAVA.equals(fileType);
  }
  return false;
}
 
Example #13
Source File: AbstractCaseConvertingAction.java    From StringManipulation with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean selectSomethingUnderCaret(Editor editor, DataContext dataContext, SelectionModel selectionModel) {
	try {
		PsiFile psiFile = PsiDocumentManager.getInstance(editor.getProject()).getPsiFile(editor.getDocument());
		if (psiFile == null) {// select whole line in plaintext
			return super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
		}
		FileType fileType = psiFile.getFileType();
		boolean handled = false;
		if (fileType.equals(StdFileTypes.JAVA) && isJavaInstalled()) {
			handled = javaHandling(editor, dataContext, selectionModel, psiFile);
		}
		if (!handled && fileType.equals(StdFileTypes.PROPERTIES)) {
			handled = propertiesHandling(editor, dataContext, selectionModel, psiFile);
		}
		if (!handled && fileType.equals(StdFileTypes.PLAIN_TEXT)) {
			handled = super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
		}
		if (!handled) {
			handled = genericHandling(editor, dataContext, selectionModel, psiFile);
		}
		return handled;
	} catch (Exception e) {
		LOG.error("please report this, so I can fix it :(", e);
		return super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
	}
}
 
Example #14
Source File: AbstractCreateElementActionBase.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
protected static PsiClass createClassFromTemplate( @NotNull PsiDirectory directory,
                                                   @NotNull String className,
                                                   @NotNull String templateName,
                                                   @NonNls String... parameters )
    throws IncorrectOperationException
{
    String classFileName = className + "." + StdFileTypes.JAVA.getDefaultExtension();
    PsiFile file = createFromTemplateInternal( directory, className, classFileName, templateName, parameters );
    return ( (PsiJavaFile) file ).getClasses()[ 0 ];
}
 
Example #15
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Nullable
private static XmlTag findFlowInScope(Project project, String flowName, GlobalSearchScope searchScope) {
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    for (VirtualFile file : files) {
        XmlTag flow = findFlowInFile(project, flowName, file);
        if (flow != null) {
            return flow;
        }
    }
    return null;
}
 
Example #16
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
public static boolean isMUnitFile(PsiFile psiFile) {
    if (!(psiFile instanceof XmlFile)) {
        return false;
    }
    if (psiFile.getFileType() != StdFileTypes.XML) {
        return false;
    }
    final XmlFile psiFile1 = (XmlFile) psiFile;
    final XmlTag rootTag = psiFile1.getRootTag();
    if (rootTag == null || !isMuleTag(rootTag)) {
        return false;
    }
    final XmlTag[] munitTags = rootTag.findSubTags(MUNIT_TEST_LOCAL_NAME, rootTag.getNamespaceByPrefix(MUNIT_NAMESPACE));
    return munitTags.length > 0;
}
 
Example #17
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
public static boolean isMuleFile(PsiFile psiFile) {
    if (!(psiFile instanceof XmlFile)) {
        return false;
    }
    if (psiFile.getFileType() != StdFileTypes.XML) {
        return false;
    }
    final XmlFile psiFile1 = (XmlFile) psiFile;
    final XmlTag rootTag = psiFile1.getRootTag();
    return isMuleTag(rootTag);
}
 
Example #18
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Nullable
private static XmlTag findGlobalElementInScope(Project project, String elementName, GlobalSearchScope searchScope) {
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    for (VirtualFile file : files) {
        XmlTag flow = findGlobalElementInFile(project, elementName, file);
        if (flow != null) {
            return flow;
        }
    }
    return null;
}
 
Example #19
Source File: ComponentGenerateUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
public static PsiFile createFileFromModel(
    String clsQualifiedName, SpecModel model, Project project) {
  String fileContent = createFileContentFromModel(clsQualifiedName, model);
  return PsiFileFactory.getInstance(project)
      .createFileFromText(
          StringUtil.getShortName(clsQualifiedName) + ".java", StdFileTypes.JAVA, fileContent);
}
 
Example #20
Source File: ComponentScope.java    From litho with Apache License 2.0 5 votes vote down vote up
/** Creates new dummy file included in the scope. */
static VirtualFile createDummyFile(Project project) {
  final PsiFile dummyFile =
      PsiFileFactory.getInstance(project)
          .createFileFromText("Dummy.java", StdFileTypes.JAVA, "class Dummy {}");
  return include(dummyFile);
}
 
Example #21
Source File: SpringReformatter.java    From spring-javaformat with Apache License 2.0 4 votes vote down vote up
public boolean canReformat(PsiFile file) {
	return StdFileTypes.JAVA.equals(file.getFileType());
}
 
Example #22
Source File: FileUtils.java    From EclipseCodeFormatter with Apache License 2.0 4 votes vote down vote up
public static boolean isJava(PsiFile psiFile) {
	return StdFileTypes.JAVA.equals(psiFile.getFileType());
}
 
Example #23
Source File: ImportSorterAdapter.java    From EclipseCodeFormatter with Apache License 2.0 4 votes vote down vote up
public void sortImports(PsiJavaFile file, PsiJavaFile dummy) {
	List<String> imports = new ArrayList<String>();
	List<PsiElement> nonImports = new ArrayList<PsiElement>();

	PsiImportList actualImportList = file.getImportList();
	if (actualImportList == null) {
		return;
	}
	PsiImportList dummyImportList = dummy.getImportList();
	if (dummyImportList == null) {
		return;
	}

	PsiElement[] children = dummyImportList.getChildren();
	for (int i = 0; i < children.length; i++) {
		PsiElement child = children[i];
		if (child instanceof PsiImportStatementBase) {
			imports.add(child.getText());
		} else if (!(child instanceof PsiWhiteSpace)) { //todo wild guess
			nonImports.add(child);
		}
	}

	List<String> sort = getImportsSorter(file).sort(StringUtils.trimImports(imports));

	StringBuilder text = new StringBuilder();
	for (int i = 0; i < sort.size(); i++) {
		text.append(sort.get(i));
	}
	for (int i = 0; i < nonImports.size(); i++) {
		PsiElement psiElement = nonImports.get(i);
		text.append("\n").append(psiElement.getText());
	}

	PsiFileFactory factory = PsiFileFactory.getInstance(file.getProject());
	String ext = StdFileTypes.JAVA.getDefaultExtension();
	final PsiJavaFile dummyFile = (PsiJavaFile) factory.createFileFromText("_Dummy_." + ext, StdFileTypes.JAVA,
			text);

	PsiImportList newImportList = dummyFile.getImportList();
	PsiImportList result = (PsiImportList) newImportList.copy();
	if (actualImportList.isReplaceEquivalent(result))
		return;
	if (!nonImports.isEmpty()) {
		PsiElement firstPrevious = newImportList.getPrevSibling();
		while (firstPrevious != null && firstPrevious.getPrevSibling() != null) {
			firstPrevious = firstPrevious.getPrevSibling();
		}
		for (PsiElement element = firstPrevious;
			 element != null && element != newImportList; element = element.getNextSibling()) {
			result.add(element.copy());
		}
		for (PsiElement element = newImportList.getNextSibling();
			 element != null; element = element.getNextSibling()) {
			result.add(element.copy());
		}
	}
	
	actualImportList.replace(result);
}
 
Example #24
Source File: ModuleSelector.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
private static EditorTextField createEditorTextField(Project project) {
    return new EditorTextField("", project, StdFileTypes.PLAIN_TEXT);
}
 
Example #25
Source File: OnEventChangeSignatureDialog.java    From litho with Apache License 2.0 4 votes vote down vote up
@Override
protected LanguageFileType getFileType() {
  return StdFileTypes.JAVA;
}
 
Example #26
Source File: ComponentScope.java    From litho with Apache License 2.0 4 votes vote down vote up
private static boolean containsInternal(VirtualFile file) {
  return StdFileTypes.JAVA.equals(file.getFileType()) && file.getUserData(KEY) != null;
}
 
Example #27
Source File: NoSqlConsoleView.java    From nosql4idea with Apache License 2.0 4 votes vote down vote up
public NoSqlConsoleView(Project project, String title, ServerConfiguration configuration) {
    super(project, title, StdFileTypes.PLAIN_TEXT.getLanguage());
    setPrompt(String.format("%s> ", configuration.getServerUrl()));
}
 
Example #28
Source File: PsiFileUtils.java    From react-templates-plugin with MIT License 4 votes vote down vote up
public static boolean isHtmlFile(PsiFile psiFile) {
    return psiFile.getFileType().equals(StdFileTypes.HTML);
}
 
Example #29
Source File: GoogleJavaFormatCodeStyleManager.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
/** Return whether or not this formatter can handle formatting the given file. */
private boolean overrideFormatterForFile(PsiFile file) {
  return StdFileTypes.JAVA.equals(file.getFileType())
      && GoogleJavaFormatSettings.getInstance(getProject()).isEnabled();
}
 
Example #30
Source File: Transformer.java    From svgtoandroid with MIT License 4 votes vote down vote up
private XmlFile getDistXml() {
    String template = FileTemplateManager.getInstance(project).getInternalTemplate("vector").getText();
    return (XmlFile) PsiFileFactory.getInstance(project).createFileFromText(xmlName, StdFileTypes.XML, template);
}