本文整理汇总了Java中com.intellij.openapi.fileTypes.StdFileTypes类的典型用法代码示例。如果您正苦于以下问题:Java StdFileTypes类的具体用法?Java StdFileTypes怎么用?Java StdFileTypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StdFileTypes类属于com.intellij.openapi.fileTypes包,在下文中一共展示了StdFileTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SoyLayeredHighlighter
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
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, ""));
}
示例2: run
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
@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);
}
}
示例3: getJavaFileTree
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
public static List<VirtualFile> getJavaFileTree(Project project, VirtualFile file, boolean recursive) {
List<VirtualFile> list = new ArrayList<VirtualFile>();
if (!file.isDirectory()) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile instanceof PsiJavaFile || file.getFileType().equals(StdFileTypes.JAVA)) {
list.add(file);
}
} else if (recursive) {
VirtualFile[] vfs = file.getChildren();
if (vfs != null) {
for (VirtualFile vf : vfs) {
list.addAll(Utils.getJavaFileTree(project, vf, recursive));
}
}
}
return list;
}
示例4: handleEvent
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
private void handleEvent(final PsiTreeChangeEvent event) {
if (event.getParent() != null) {
PsiFile containingFile = event.getParent().getContainingFile();
if (containingFile instanceof PropertiesFile) {
LOG.debug("Received PSI change event for properties file");
myAlarm.cancelRequest(myRefreshPropertiesRequest);
myAlarm.addRequest(myRefreshPropertiesRequest, 500, ModalityState.stateForComponent(GuiEditor.this));
}
else if (containingFile instanceof PsiPlainTextFile && containingFile.getFileType().equals(StdFileTypes.GUI_DESIGNER_FORM)) {
// quick check if relevant
String resourceName = FormEditingUtil.buildResourceName(containingFile);
if (myDocument.getText().indexOf(resourceName) >= 0) {
LOG.debug("Received PSI change event for nested form");
// TODO[yole]: handle multiple nesting
myAlarm.cancelRequest(mySynchronizeRequest);
myAlarm.addRequest(mySynchronizeRequest, 500, ModalityState.stateForComponent(GuiEditor.this));
}
}
}
}
示例5: actionPerformed
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
super.actionPerformed(e);
psiFile = e.getData(LangDataKeys.PSI_FILE);
if (psiFile.getFileType() == StdFileTypes.XML) {
xmlFile = (XmlFile) psiFile;
String folderName = psiFile.getParent().getName();
String bucket = null;
if (folderName.startsWith(VALUES_PREFIX)) {
bucket = folderName.substring(VALUES_PREFIX.length());
} else if (folderName.equalsIgnoreCase(VALUES_PREFIX.substring(0, VALUES_PREFIX.length() - 1))) {
bucket = Constants.MDPI;
}
if (bucket != null) {
currentBucketIndex = getBucketIndex(psiFile);
showScaleDialog(bucket, currentBucketIndex != -1);
}
}
}
示例6: testUpdateAfterInsertingIdenticalText
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
public void testUpdateAfterInsertingIdenticalText() {
PsiJavaFile file = (PsiJavaFile)configureByText(StdFileTypes.JAVA, "class Foo {\n" +
" void m() {\n" +
" }\n" +
"<caret>}\n");
PsiMethod method = file.getClasses()[0].getMethods()[0];
TextRange originalRange = method.getTextRange();
SmartPsiElementPointer pointer = createPointer(method);
EditorModificationUtil.insertStringAtCaret(myEditor, " void m() {\n" +
" }\n");
PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
PsiElement element = pointer.getElement();
assertNotNull(element);
TextRange newRange = element.getTextRange();
assertEquals(originalRange, newRange);
}
示例7: getModuleNames
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
private static List<VirtualFile> getModuleNames(AnActionEvent e) {
final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
final Project project = getEventProject(e);
if (project == null || files == null || files.length == 0) {
return Collections.emptyList();
}
List<VirtualFile> modulesFiles = new ArrayList<VirtualFile>();
for (VirtualFile file : files) {
if (!file.getFileType().equals(StdFileTypes.IDEA_MODULE)) {
return Collections.emptyList();
}
modulesFiles.add(file);
}
final ModuleManager moduleManager = ModuleManager.getInstance(project);
for (Module module : moduleManager.getModules()) {
modulesFiles.remove(module.getModuleFile());
}
return modulesFiles;
}
示例8: scopeCanContainForms
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
private static boolean scopeCanContainForms(SearchScope scope) {
if (!(scope instanceof LocalSearchScope)) return true;
LocalSearchScope localSearchScope = (LocalSearchScope) scope;
final PsiElement[] elements = localSearchScope.getScope();
for (final PsiElement element : elements) {
if (element instanceof PsiDirectory) return true;
boolean isForm = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
PsiFile file;
if (element instanceof PsiFile) {
file = (PsiFile)element;
}
else {
if (!element.isValid()) return false;
file = element.getContainingFile();
}
return file.getFileType() == StdFileTypes.GUI_DESIGNER_FORM;
}
});
if (isForm) return true;
}
return false;
}
示例9: showTemplateExample
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
private void showTemplateExample(final PseudoLambdaReplaceTemplate template, final PsiMethod method) {
final PsiClass aClass = method.getContainingClass();
LOG.assertTrue(aClass != null);
final String fqn = aClass.getQualifiedName();
LOG.assertTrue(fqn != null);
final String parameters =
StringUtil.join(ContainerUtil.map(method.getParameterList().getParameters(), new Function<PsiParameter, String>() {
@Override
public String fun(PsiParameter parameter) {
return parameter.getName();
}
}), ", ");
final String expressionText = fqn + "." + method.getName() + "(" + parameters + ")";
final PsiExpression psiExpression = JavaPsiFacade.getElementFactory(method.getProject())
.createExpressionFromText(expressionText, null);
LOG.assertTrue(psiExpression instanceof PsiMethodCallExpression);
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)psiExpression;
template.convertToStream(methodCallExpression, method, false);
myBeforeActionPanel.reset("void example() {\n <spot>" + methodCallExpression.getText() + "</spot>;\n}", StdFileTypes.JAVA);
myAfterActionPanel.reset("void example() {\n <spot>" + template.convertToStream(methodCallExpression, method, true).getText() + "</spot>\n}", StdFileTypes.JAVA);
}
示例10: persistAttribute
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
@Override
public void persistAttribute(@NotNull Project project, @NotNull VirtualFile fileOrDir, @NotNull LanguageLevel level) throws IOException {
final DataInputStream iStream = PERSISTENCE.readAttribute(fileOrDir);
if (iStream != null) {
try {
final int oldLevelOrdinal = DataInputOutputUtil.readINT(iStream);
if (oldLevelOrdinal == level.ordinal()) return;
}
finally {
iStream.close();
}
}
final DataOutputStream oStream = PERSISTENCE.writeAttribute(fileOrDir);
DataInputOutputUtil.writeINT(oStream, level.ordinal());
oStream.close();
for (VirtualFile child : fileOrDir.getChildren()) {
if (!child.isDirectory() && StdFileTypes.JAVA.equals(child.getFileType())) {
PushedFilePropertiesUpdater.getInstance(project).filePropertiesChanged(child);
}
}
}
示例11: testMethodCallArgumentsAndSmartTabs
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
public void testMethodCallArgumentsAndSmartTabs() throws IncorrectOperationException {
// Inspired by IDEADEV-20144.
getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
doTextTest("class Foo {\n" +
" void foo() {\n" +
" bar(new Object[] {\n" +
" \"hello1\",\n" +
" \"hello2\", add(\"hello3\",\n" +
" \"world\")\n" +
"});" +
" }}", "class Foo {\n" +
"\tvoid foo() {\n" +
"\t\tbar(new Object[]{\n" +
"\t\t\t\t\"hello1\",\n" +
"\t\t\t\t\"hello2\", add(\"hello3\",\n" +
"\t\t\t\t \"world\")\n" +
"\t\t});\n" +
"\t}\n" +
"}");
}
示例12: processReferencesInFiles
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
private static boolean processReferencesInFiles(List<PsiFile> files,
PsiManager psiManager, String baseName,
PsiElement element,
LocalSearchScope filterScope,
Processor<PsiReference> processor) {
psiManager.startBatchFilesProcessingMode();
try {
for (PsiFile file : files) {
ProgressManager.checkCanceled();
if (file.getFileType() != StdFileTypes.GUI_DESIGNER_FORM) continue;
if (!processReferences(processor, file, baseName, element, filterScope)) return false;
}
}
finally {
psiManager.finishBatchFilesProcessingMode();
}
return true;
}
示例13: processTags
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
private static void processTags(@NotNull Project project,
@Nullable String templateText,
@NotNull PairProcessor<XmlTag, Boolean> processor) {
if (StringUtil.isNotEmpty(templateText)) {
final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);
XmlFile xmlFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.HTML, templateText);
XmlTag tag = xmlFile.getRootTag();
boolean firstTag = true;
while (tag != null) {
processor.process(tag, firstTag);
firstTag = false;
tag = PsiTreeUtil.getNextSiblingOfType(tag, XmlTag.class);
}
}
}
示例14: testLabel
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
public void testLabel() throws Exception {
final CommonCodeStyleSettings settings = getSettings();
settings.getRootSettings().getIndentOptions(StdFileTypes.JAVA).LABEL_INDENT_ABSOLUTE = true;
settings.SPECIAL_ELSE_IF_TREATMENT = true;
settings.FOR_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS;
myTextRange = new TextRange(59, 121);
doTextTest("public class Foo {\n" +
" public void foo() {\n" +
"label2:\n" +
" for (int i = 0; i < 5; i++)\n" +
" {doSomething(i);\n" +
" }\n" +
" }\n" +
"}", "public class Foo {\n" +
" public void foo() {\n" +
"label2:\n" +
" for (int i = 0; i < 5; i++) {\n" +
" doSomething(i);\n" +
" }\n" +
" }\n" +
"}");
}
示例15: setupPathComponent
import com.intellij.openapi.fileTypes.StdFileTypes; //导入依赖的package包/类
private void setupPathComponent(final JPanel northPanel) {
northPanel.add(new TextFieldAction() {
@Override
public void linkSelected(LinkLabel aSource, Object aLinkData) {
toggleShowPathComponent(northPanel, this);
}
}, BorderLayout.EAST);
myPathEditor = new EditorTextField(JavaReferenceEditorUtil.createDocument("", myProject, false), myProject, StdFileTypes.JAVA);
myPathEditor.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(new Runnable() {
@Override
public void run() {
updateTreeFromPath();
}
}, 300);
}
});
myPathEditor.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
northPanel.add(myPathEditor, BorderLayout.SOUTH);
}