当前位置: 首页>>代码示例>>Java>>正文


Java JavaFileType类代码示例

本文整理汇总了Java中com.intellij.ide.highlighter.JavaFileType的典型用法代码示例。如果您正苦于以下问题:Java JavaFileType类的具体用法?Java JavaFileType怎么用?Java JavaFileType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JavaFileType类属于com.intellij.ide.highlighter包,在下文中一共展示了JavaFileType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createUIComponents

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
private void createUIComponents() {
    final EditorFactory editorFactory = EditorFactory.getInstance();
    previewDocument = editorFactory.createDocument(EMPTY_TEXT);
    previewEditor = editorFactory.createEditor(previewDocument, null, JavaFileType.INSTANCE, true);

    final EditorSettings settings = previewEditor.getSettings();
    settings.setWhitespacesShown(true);
    settings.setLineMarkerAreaShown(false);
    settings.setIndentGuidesShown(false);
    settings.setLineNumbersShown(false);
    settings.setFoldingOutlineShown(false);
    settings.setRightMarginShown(false);
    settings.setVirtualSpace(false);
    settings.setWheelFontChangeEnabled(false);
    settings.setUseSoftWraps(false);
    settings.setAdditionalColumnsCount(0);
    settings.setAdditionalLinesCount(1);

    previewPanel = (JPanel) previewEditor.getComponent();
    previewPanel.setName(PREVIEW_PANEL_NAME);
    previewPanel.setPreferredSize(new Dimension(PREFERRED_PREVIEW_WIDTH, PREFERRED_PREVIEW_HEIGHT));
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:23,代码来源:SettingsPanel.java

示例2: run

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的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);
    }
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:27,代码来源:NewClassCommandAction.java

示例3: createJavaFile

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
private PsiClass createJavaFile(String javaFileName, @NonNls String text) {
    PsiJavaFile psiJavaFile = (PsiJavaFile) PsiFileFactory.getInstance(mPsiClass.getProject()).createFileFromText(
            javaFileName + "." + JavaFileType.INSTANCE.getDefaultExtension(),
            JavaFileType.INSTANCE, text);
    PsiClass[] classes = psiJavaFile.getClasses();
    if (classes.length != 1) {
        throw new IncorrectOperationException("Incorrect class '" + text + "'");
    } else {
        PsiClass pc = classes[0];
        if (pc == null) {
            throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null",
                    "com/intellij/psi/impl/PsiJavaParserFacadeImpl", "createJavaFile"));
        } else {
            return pc;
        }
    }
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:18,代码来源:PropertyProcessor.java

示例4: postProcessSelectedMainSketchClass

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public static PsiFile postProcessSelectedMainSketchClass(@NotNull Project project,
                                                         @NotNull PsiClass selectedMainClass,
                                                         @NotNull PsiImportList correspondingImportList) {
    // Construct a valid Java class from the selected main sketch class.
    selectedMainClass.getModifierList().setModifierProperty(PsiModifier.PUBLIC, true);

    PsiJavaCodeReferenceElement pAppletReference = JavaPsiFacade.getElementFactory(project)
            .createFQClassNameReferenceElement("processing.core.PApplet", GlobalSearchScope.projectScope(project));
    selectedMainClass.getExtendsList().add(pAppletReference);

    PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);

    StringJoiner mainFileJoiner = new StringJoiner("\n\n");
    StringJoiner importStatementJoiner = new StringJoiner("\n");

    for (PsiImportStatementBase importStatement : correspondingImportList.getAllImportStatements()) {
        importStatementJoiner.add(importStatement.getText());
    }

    mainFileJoiner.add(importStatementJoiner.toString());
    mainFileJoiner.add(selectedMainClass.getText());

    return psiFileFactory.createFileFromText(selectedMainClass.getName() + ".java", JavaFileType.INSTANCE, mainFileJoiner.toString());
}
 
开发者ID:mistodev,项目名称:processing-idea,代码行数:25,代码来源:MigrationActions.java

示例5: findMethodLikeCalls

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public static List<PsiMethodCallExpression> findMethodLikeCalls(SmcMethodLikeElement psiMethodLike) {
    SmcFile containingFile = (SmcFile) psiMethodLike.getContainingFile().getContainingFile();
    PsiClass fsmClass = containingFile.getFsmClass();
    Project project = psiMethodLike.getProject();
    if (fsmClass == null) return Collections.emptyList();
    Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, JavaFileType.INSTANCE,
            GlobalSearchScope.projectScope(project));
    List<PsiMethodCallExpression> result = new ArrayList<>();
    for (VirtualFile virtualFile : virtualFiles) {
        PsiJavaFile psiJavaFile = (PsiJavaFile) PsiManager.getInstance(project).findFile(virtualFile);
        if (psiJavaFile != null) {
            Collection<PsiMethodCallExpression> methodCallExpressions = PsiTreeUtil.findChildrenOfType(psiJavaFile, PsiMethodCallExpression.class);
            for (PsiMethodCallExpression methodCall : methodCallExpressions) {
                PsiMethod psiMethod = methodCall.resolveMethod();
                if (psiMethod != null && psiMethodLike.matches(psiMethod)) {
                    result.add(methodCall);
                }
            }
        }
    }
    return result;
}
 
开发者ID:menshele,项目名称:smcplugin,代码行数:23,代码来源:SmcPsiUtil.java

示例6: findJavaMethod

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public static List<PsiMethod> findJavaMethod(Project project, String name) {
    List<PsiMethod> result = null;
    Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, JavaFileType.INSTANCE,
            GlobalSearchScope.projectScope(project));
    for (VirtualFile virtualFile : virtualFiles) {
        PsiJavaFile javaFile = (PsiJavaFile) PsiManager.getInstance(project).findFile(virtualFile);
        if (javaFile != null) {
            Collection<PsiMethod> properties = PsiTreeUtil.findChildrenOfType(javaFile, PsiMethod.class);
            for (PsiMethod javaMethod : properties) {
                if (name.equals(javaMethod.getName())) {
                    if (result == null) {
                        result = new ArrayList<PsiMethod>();
                    }
                    result.add(javaMethod);
                }
            }
        }
    }
    return result != null ? result : Collections.<PsiMethod>emptyList();
}
 
开发者ID:menshele,项目名称:smcplugin,代码行数:21,代码来源:SmcPsiUtil.java

示例7: testGenerateDoc

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public void testGenerateDoc() throws Exception {
    myFixture.configureByText(JavaFileType.INSTANCE, getJavaTestDataWithCursorAfterQuestionMark());

    PsiElement element = myFixture.findElementByText("\"file:inbox?\"", PsiLiteralExpression.class);
    String componentName = "file";
    String lookup = componentName + ":inbox?delete";
    PsiManager manager = myFixture.getPsiManager();

    PsiElement docInfo = new CamelDocumentationProvider().getDocumentationElementForLookupItem(manager, lookup, element);

    String doc = new CamelDocumentationProvider().generateDoc(docInfo, null);
    assertEquals(readExpectedFile(), doc);

    String documentation = new CamelDocumentationProvider().generateDoc(element, null);
    assertNotNull(documentation);
    assertTrue(documentation.startsWith("<b>File Component</b><br/>The file component is used for reading or writing files.<br/>"));
}
 
开发者ID:camel-idea-plugin,项目名称:camel-idea-plugin,代码行数:18,代码来源:CamelDocumentationProviderTestIT.java

示例8: getIndentSpecial

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
/**
 * Computes indentation of PsiClass, PsiMethod and PsiField elements after formatting
 * @param element PsiClass or PsiMethod or PsiField
 * @return indentation size
 */
private int getIndentSpecial(@NotNull PsiElement element) {
  if (element instanceof PsiDocComment) {
    return 0;
  }
  LOG.assertTrue(element instanceof PsiClass ||
                 element instanceof PsiField ||
                 element instanceof PsiMethod);

  int indentSize = mySettings.getIndentSize(JavaFileType.INSTANCE);
  boolean doNotIndentTopLevelClassMembers = mySettings.getCommonSettings(JavaLanguage.INSTANCE).DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS;

  int indent = 0;
  PsiClass top = PsiUtil.getTopLevelClass(element);
  while (top != null && !element.isEquivalentTo(top)) {
    if (doNotIndentTopLevelClassMembers && element.getParent().isEquivalentTo(top)) {
      break;
    }
    element = element.getParent();
    indent += indentSize;
  }

  return indent;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:CommentFormatter.java

示例9: getAdditionalResolveScope

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
@Override
public SearchScope getAdditionalResolveScope(@NotNull VirtualFile file, Project project) {
  ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
  if (index.isInLibraryClasses(file) || index.isInContent(file)) {
    return null;
  }

  String fileExtension = file.getExtension();
  if ("class".equals(fileExtension) || JavaFileType.DEFAULT_EXTENSION.equals(fileExtension)) {
    for (PsiElementFinder finder : Extensions.getExtensions(PsiElementFinder.EP_NAME, project)) {
      if (finder instanceof NonClasspathClassFinder) {
        final List<VirtualFile> roots = ((NonClasspathClassFinder)finder).getClassRoots();
        for (VirtualFile root : roots) {
          if (VfsUtilCore.isAncestor(root, file, true)) {
            return NonClasspathDirectoriesScope.compose(roots);
          }
        }
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:NonClasspathResolveScopeEnlarger.java

示例10: testPointersRefCount

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public void testPointersRefCount() throws Exception {
  PsiFile file = configureByText(JavaFileType.INSTANCE, "class X{}");
  PsiClass aClass = ((PsiClassOwner)file).getClasses()[0];
  SmartPointerManagerImpl smartPointerManager = getPointerManager();
  SmartPsiElementPointer pointer1 = createPointer(aClass);
  SmartPsiElementPointer pointer2 = createPointer(aClass);
  assertSame(pointer1, pointer2);

  assertNotNull(pointer1.getRange());

  boolean removed2 = smartPointerManager.removePointer(pointer2);
  assertFalse(removed2);
  assertNotNull(pointer1.getRange());

  boolean removed1 = smartPointerManager.removePointer(pointer1);
  assertTrue(removed1);
  assertNull(pointer1.getRange());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:SmartPsiElementPointersTest.java

示例11: testPointersRefCountSaturated

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public void testPointersRefCountSaturated() throws Exception {
  PsiFile file = configureByText(JavaFileType.INSTANCE, "class X{}");
  PsiClass aClass = ((PsiClassOwner)file).getClasses()[0];
  SmartPointerManagerImpl smartPointerManager = getPointerManager();
  SmartPsiElementPointerImpl pointer1 = (SmartPsiElementPointerImpl)createPointer(aClass);
  for (int i=0; i<1000; i++) {
    SmartPsiElementPointer<PsiClass> pointer2 = createPointer(aClass);
    assertSame(pointer1, pointer2);
  }

  assertNotNull(pointer1.getRange());
  assertEquals(Byte.MAX_VALUE, pointer1.incrementAndGetReferenceCount(0));

  for (int i=0; i<1100; i++) {
    boolean removed1 = smartPointerManager.removePointer(pointer1);
    assertFalse(removed1);
    Assert.assertNotNull(pointer1.getRange());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:SmartPsiElementPointersTest.java

示例12: testInsertImport

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public void testInsertImport() {
  final PsiFile file = configureByText(JavaFileType.INSTANCE,
                                       "class S {\n" +
                                       "}");

  PsiClass aClass = ((PsiJavaFile)file).getClasses()[0];

  WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
    @Override
    public void run() {
      getEditor().getDocument().insertString(0, "import java.util.Map;\n");
    }
  });

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

  PsiClass aClass2 = ((PsiJavaFile)file).getClasses()[0];
  assertSame(aClass, aClass2);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:SmartPsiElementPointersTest.java

示例13: testEqualPointerRangesWhenCreatedFromStubAndAST

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public void testEqualPointerRangesWhenCreatedFromStubAndAST() {
  final PsiFile file = configureByText(JavaFileType.INSTANCE,
                                       "class S {\n" +
                                       "}");

  PsiClass aClass = ((PsiJavaFile)file).getClasses()[0];
  assertNotNull(((PsiFileImpl)file).getStubTree());

  final SmartPointerManager manager = getPointerManager();
  final SmartPsiElementPointer<PsiClass> pointer1 = createPointer(aClass);
  Segment range1 = pointer1.getRange();
  manager.removePointer(pointer1);

  final FileASTNode node = file.getNode();
  final SmartPsiElementPointer<PsiClass> pointer2 = createPointer(aClass);
  assertEquals(range1, pointer2.getRange());
  assertNotNull(node);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:SmartPsiElementPointersTest.java

示例14: testMoveText

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public void testMoveText() {
  PsiJavaFile file = (PsiJavaFile)configureByText(JavaFileType.INSTANCE, "class C1{}\nclass C2 {}");
  DocumentEx document = (DocumentEx)file.getViewProvider().getDocument();

  SmartPsiElementPointer<PsiClass> pointer1 =
    createPointer(file.getClasses()[0]);
  SmartPsiElementPointer<PsiClass> pointer2 =
    createPointer(file.getClasses()[1]);
  assertEquals("C1", pointer1.getElement().getName());
  assertEquals("C2", pointer2.getElement().getName());

  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(((SmartPointerEx) pointer1).getCachedElement());
  assertNull(((SmartPointerEx) pointer2).getCachedElement());

  TextRange range = file.getClasses()[1].getTextRange();
  document.moveText(range.getStartOffset(), range.getEndOffset(), 0);

  System.out.println(pointer1.getRange());
  System.out.println(pointer2.getRange());

  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  assertEquals("C1", pointer1.getElement().getName());
  assertEquals("C2", pointer2.getElement().getName());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:SmartPsiElementPointersTest.java

示例15: testPointerToEmptyElement2

import com.intellij.ide.highlighter.JavaFileType; //导入依赖的package包/类
public void testPointerToEmptyElement2() {
  PsiFile file = configureByText(JavaFileType.INSTANCE, "class Foo {\n" +
                                                           "  void foo() {}\n" +
                                                           "}");
  PsiMethod method = PsiTreeUtil.findElementOfClassAtOffset(file, file.getText().indexOf("void"), PsiMethod.class, false);
  SmartPointerEx pointer1 = (SmartPointerEx)createPointer(method.getModifierList());
  SmartPointerEx pointer2 = (SmartPointerEx)createPointer(method.getTypeParameterList());
  method = null;

  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(pointer1.getCachedElement());
  assertNull(pointer2.getCachedElement());

  assertInstanceOf(pointer1.getElement(), PsiModifierList.class);
  assertInstanceOf(pointer2.getElement(), PsiTypeParameterList.class);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:SmartPsiElementPointersTest.java


注:本文中的com.intellij.ide.highlighter.JavaFileType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。