Java 类com.intellij.lang.Language 实例源码

项目:bamboo-soy    文件:SoyLayeredHighlighter.java   
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, ""));
}
项目:bamboo-soy    文件:SoyFileViewProvider.java   
@Override
protected PsiFile createFile(@NotNull Language lang) {
  ParserDefinition parserDefinition = getDefinition(lang);
  if (parserDefinition == null) {
    return null;
  }

  if (lang.is(templateDataLanguage)) {
    PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
    file.setContentElementType(templateDataLanguageType);
    return file;
  } else if (lang.isKindOf(baseLanguage)) {
    return parserDefinition.createFile(this);
  } else {
    return null;
  }
}
项目:hybris-integration-intellij-idea-plugin    文件:DefaultImpexColumnHighlighterService.java   
@Override
@Contract
public void highlightCurrentColumn(@NotNull final Editor editor) {
    Validate.notNull(editor);

    final Project project = editor.getProject();

    if (null == project) {
        return;
    }

    if (project.isDisposed()) {
        return;
    }

    final Language languageInEditor = PsiUtilBase.getLanguageInEditor(editor, project);

    if (languageInEditor instanceof ImpexLanguage) {
        this.highlightColumnOfValueUnderCaret(editor);
    }
}
项目:hybris-integration-intellij-idea-plugin    文件:DefaultImpexHeaderNameHighlighterService.java   
@Override
@Contract(pure = false)
public void highlightCurrentHeader(@NotNull final Editor editor) {
    Validate.notNull(editor);

    final Project project = editor.getProject();

    if (null == project) {
        return;
    }

    if (project.isDisposed()) {
        return;
    }

    final Language languageInEditor = PsiUtilBase.getLanguageInEditor(editor, project);

    if (languageInEditor instanceof ImpexLanguage) {
        this.highlightHeaderOfValueUnderCaret(editor);
    }
}
项目:educational-plugin    文件:EduRemoteCourseModuleBuilder.java   
@Nullable
@Override
public Module commitModule(@NotNull Project project, @Nullable ModifiableModuleModel model) {
  Module module = super.commitModule(project, model);
  if (module == null) {
    return null;
  }
  String languageName = myCourse.getLanguageID();
  Language language = Language.findLanguageByID(languageName);
  if (language == null) {
    return module;
  }
  EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
  if (configurator == null) {
    return module;
  }
  configurator.configureModule(module);
  return module;
}
项目:educational-plugin    文件:EduRemoteCourseModuleBuilder.java   
@NotNull
@Override
public Module createModule(@NotNull ModifiableModuleModel moduleModel)
  throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
  Module baseModule = super.createModule(moduleModel);
  String languageName = myCourse.getLanguageID();
  Language language = Language.findLanguageByID(languageName);
  if (language != null) {
    EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
    if (configurator != null) {
      Project project = baseModule.getProject();
      myGenerator.setSelectedCourse(myCourse);
      myGenerator.generateProject(project, project.getBaseDir());
      Course course = StudyTaskManager.getInstance(project).getCourse();
      if (course == null) {
        LOG.info("failed to generate course");
        return baseModule;
      }
      configurator.createCourseModuleContent(moduleModel, project, course, getModuleFileDirectory());
    }
  }
  return baseModule;
}
项目:educational-plugin    文件:EduCustomCourseModuleBuilder.java   
@Nullable
@Override
public Module commitModule(@NotNull Project project, @Nullable ModifiableModuleModel model) {
  Module module = super.commitModule(project, model);
  if (module == null) {
    return null;
  }
  String languageName = mySelectedCourse.getLanguageID();
  Language language = Language.findLanguageByID(languageName);
  if (language == null) {
    return module;
  }
  EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
  if (configurator == null) {
    return module;
  }
  configurator.configureModule(module);
  return module;
}
项目:educational-plugin    文件:EduCustomCourseModuleBuilder.java   
@NotNull
@Override
public Module createModule(@NotNull ModifiableModuleModel moduleModel)
  throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
  Module baseModule = super.createModule(moduleModel);
  if (mySelectedCourse != null) {
    String languageName = mySelectedCourse.getLanguageID();
    Language language = Language.findLanguageByID(languageName);
    if (language != null) {
      EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
      if (configurator != null) {
        myGenerator.setSelectedCourse(mySelectedCourse);
        Project project = baseModule.getProject();
        myGenerator.generateProject(project, project.getBaseDir());
        Course course = StudyTaskManager.getInstance(project).getCourse();
        if (course == null) {
          LOG.info("failed to generate course");
          return baseModule;
        }
        configurator.createCourseModuleContent(moduleModel, project, course, getModuleFileDirectory());
      }
    }
  }
  return baseModule;
}
项目:educational-plugin    文件:StepicWrappers.java   
private static List<VirtualFile> getTestFiles(@NotNull Task task, @NotNull Project project) {
  final Course course = task.getLesson().getCourse();
  final Language language = course.getLanguageById();
  final EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
  List<VirtualFile> testFiles = new ArrayList<>();
  VirtualFile taskDir = task.getTaskDir(project);
  if (taskDir == null) {
    return testFiles;
  }
  if (!(task instanceof TaskWithSubtasks)) {
    VirtualFile testFile = taskDir.findChild(configurator.getTestFileName());
    testFiles.add(testFile);
    return testFiles;
  }
  testFiles.addAll(Arrays.stream(taskDir.getChildren())
                     .filter(file -> StudyUtils.isTestsFile(project, file.getName()))
                     .collect(Collectors.toList()));
  return testFiles;
}
项目:educational-plugin    文件:EduAdaptiveStepicConnector.java   
private static void createFilesForNewTask(@NotNull Project project,
                                          @NotNull Task task,
                                          @NotNull String lessonName,
                                          @NotNull Language language) {
  final VirtualFile lessonDir = project.getBaseDir().findChild(lessonName);
  if (lessonDir == null) {
    return;
  }

  ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
    PsiDirectory directory = PsiManager.getInstance(project).findDirectory(lessonDir);
    if (directory == null) {
      return;
    }

    EduPluginConfigurator.INSTANCE.forLanguage(language).createTaskContent(project, task, null, directory, task.getLesson().getCourse());
  }));
}
项目:educational-plugin    文件:EduAdaptiveStepicConnector.java   
private static void updateProjectFiles(@NotNull Project project, @NotNull Task task, @NotNull String lessonName, Language language) {
  final VirtualFile lessonDir = project.getBaseDir().findChild(lessonName);
  if (lessonDir == null) {
    return;
  }

  ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
    try {
      PsiDirectory directory = PsiManager.getInstance(project).findDirectory(lessonDir);
      if (directory == null) {
        return;
      }

      removeOldProjectFiles(lessonDir, task.getIndex());
      EduPluginConfigurator.INSTANCE.forLanguage(language).createTaskContent(project, task, null, directory, task.getLesson().getCourse());
    }
    catch (IOException e) {
      LOG.warn(e.getMessage());
    }
  }));
}
项目:educational-plugin    文件:EduAdaptiveStepicConnector.java   
public static StudyCheckResult checkCodeTask(@NotNull Project project, @NotNull Task task, @NotNull StepicUser user) {
  int attemptId = -1;
  try {
    attemptId = getAttemptId(task);
  }
  catch (IOException e) {
    LOG.warn(e.getMessage());
  }
  if (attemptId != -1) {
    Course course = task.getLesson().getCourse();
    Language courseLanguage = course.getLanguageById();
    final Editor editor = StudyUtils.getSelectedEditor(project);
    if (editor != null) {
      String commentPrefix = LanguageCommenters.INSTANCE.forLanguage(courseLanguage).getLineCommentPrefix();
      final String answer = commentPrefix + PYCHARM_COMMENT + editor.getDocument().getText();
      String defaultLanguage = EduPluginConfigurator.INSTANCE.forLanguage(courseLanguage).getStepikDefaultLanguage();
      final StepicWrappers.SubmissionToPostWrapper submissionToPost =
        new StepicWrappers.SubmissionToPostWrapper(String.valueOf(attemptId), defaultLanguage, answer);
      return doAdaptiveCheck(submissionToPost, attemptId, user.getId());
    }
  }
  else {
    LOG.warn("Got an incorrect attempt id: " + attemptId);
  }
  return new StudyCheckResult(StudyStatus.Unchecked, StudyCheckAction.FAILED_CHECK_LAUNCH);
}
项目:educational-plugin    文件:Task.java   
@NotNull
public String getTestsText(@NotNull final Project project) {
  final Course course = getLesson().getCourse();
  final Language language = course.getLanguageById();
  final EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
  final VirtualFile taskDir = getTaskDir(project);
  if (taskDir != null) {
    final VirtualFile file = taskDir.findChild(configurator.getTestFileName());
    if (file == null) return "";
    final Document document = FileDocumentManager.getInstance().getDocument(file);
    if (document != null) {
      return document.getImmutableCharSequence().toString();
    }
  }

  return "";
}
项目:intellij-ce-playground    文件:FindDialog.java   
private void updateFileTypeForEditorComponent(@NotNull ComboBox inputComboBox) {
  final Component editorComponent = inputComboBox.getEditor().getEditorComponent();

  if (editorComponent instanceof EditorTextField) {
    boolean isRegexp = myCbRegularExpressions.isSelectedWhenSelectable();
    FileType fileType = PlainTextFileType.INSTANCE;
    if (isRegexp) {
      Language regexpLanguage = Language.findLanguageByID("RegExp");
      if (regexpLanguage != null) {
        LanguageFileType regexpFileType = regexpLanguage.getAssociatedFileType();
        if (regexpFileType != null) {
          fileType = regexpFileType;
        }
      }
    }
    String fileName = isRegexp ? "a.regexp" : "a.txt";
    final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(fileName, fileType, ((EditorTextField)editorComponent).getText(), -1, true);

    ((EditorTextField)editorComponent).setNewDocumentAndFileType(fileType, PsiDocumentManager.getInstance(myProject).getDocument(file));
  }
}
项目:mule-intellij-plugins    文件:WeaveEditor.java   
@Nullable
public static Language substituteLanguage(@NotNull Project project, @NotNull VirtualFile file) {
    Language language = null;

    if (file != null) {
        //logger.debug("*** VFile is " + file);
        String newDataType = file.getUserData(WeaveEditor.newFileDataTypeKey);
        //logger.debug("*** newDataType is " + newDataType);
        if (newDataType != null) {
            language = WeaveEditor.getLanguage(newDataType);
            //logger.debug("*** Resolved Language is " + language);
        }
    }

    return language;
}
项目:intellij-ce-playground    文件:CodeInsightUtilCore.java   
public static <T extends PsiElement> T findElementInRange(@NotNull PsiFile file,
                                                           int startOffset,
                                                           int endOffset,
                                                           @NotNull Class<T> klass,
                                                           @NotNull Language language) {
  PsiElement element1 = file.getViewProvider().findElementAt(startOffset, language);
  PsiElement element2 = file.getViewProvider().findElementAt(endOffset - 1, language);
  if (element1 instanceof PsiWhiteSpace) {
    startOffset = element1.getTextRange().getEndOffset();
    element1 = file.getViewProvider().findElementAt(startOffset, language);
  }
  if (element2 instanceof PsiWhiteSpace) {
    endOffset = element2.getTextRange().getStartOffset();
    element2 = file.getViewProvider().findElementAt(endOffset - 1, language);
  }
  if (element2 == null || element1 == null) return null;
  final PsiElement commonParent = PsiTreeUtil.findCommonParent(element1, element2);
  final T element =
    ReflectionUtil.isAssignable(klass, commonParent.getClass())
    ? (T)commonParent : PsiTreeUtil.getParentOfType(commonParent, klass);
  if (element == null || element.getTextRange().getStartOffset() != startOffset || element.getTextRange().getEndOffset() != endOffset) {
    return null;
  }
  return element;
}
项目:intellij-ce-playground    文件:HtmlConditionalCommentInjector.java   
@Override
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement host) {
  Pair<ASTNode, ASTNode> pair = parseConditionalCommentBoundaries(host);
  if (pair == null) {
    return;
  }
  final TextRange textRange = host.getTextRange();
  final int startOffset = textRange.getStartOffset();
  Language language = host.getParent().getLanguage();
  ASTNode conditionalStart = pair.first;
  ASTNode conditionalEnd = pair.second;
  TextRange range = new UnfairTextRange(conditionalStart.getTextRange().getEndOffset() - startOffset, conditionalEnd.getStartOffset() - startOffset);
  if (range.getStartOffset() < range.getEndOffset()) {
    registrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost)host, range).doneInjecting();
  }
}
项目:intellij-ce-playground    文件:FileManagerImpl.java   
public static void clearPsiCaches(FileViewProvider provider) {
  if (provider instanceof SingleRootFileViewProvider) {
    for (PsiFile root : ((SingleRootFileViewProvider)provider).getCachedPsiFiles()) {
      if (root instanceof PsiFileImpl) {
        ((PsiFileImpl)root).clearCaches();
      }
    }
  } else {
    for (Language language : provider.getLanguages()) {
      final PsiFile psi = provider.getPsi(language);
      if (psi instanceof PsiFileImpl) {
        ((PsiFileImpl)psi).clearCaches();
      }
    }
  }
}
项目:intellij-ce-playground    文件:IElementType.java   
protected IElementType(@NotNull @NonNls String debugName, @Nullable Language language, boolean register) {
  myDebugName = debugName;
  myLanguage = language == null ? Language.ANY : language;
  if (register) {
    synchronized (lock) {
      myIndex = size++;
      LOG.assertTrue(myIndex < MAX_INDEXED_TYPES, "Too many element types registered. Out of (short) range.");
      IElementType[] newRegistry =
        myIndex >= ourRegistry.length ? ArrayUtil.realloc(ourRegistry, ourRegistry.length * 3 / 2 + 1, FACTORY) : ourRegistry;
      newRegistry[myIndex] = this;
      ourRegistry = newRegistry;
    }
  }
  else {
    myIndex = -1;
  }
}
项目:rythm_plugin    文件:RythmFileViewProvider.java   
@Override
protected PsiFile createFile(@NotNull Language lang) {
    ParserDefinition parserDefinition = getDefinition(lang);
    if (parserDefinition == null) {
        return null;
    }
    if (lang.is(getTemplateDataLanguage())) {
        PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
        file.setContentElementType(getTemplateDataElementType(getBaseLanguage()));
        return file;
    } else if (lang.isKindOf(getBaseLanguage())) {
        return parserDefinition.createFile(this);
    } else {
        return null;
    }
}
项目:intellij-ce-playground    文件:XmlBraceMatcher.java   
@Override
public int getBraceTokenGroupId(IElementType tokenType) {
  final Language l = tokenType.getLanguage();
  PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(l);

  if (matcher != null) {
    BracePair[] pairs = matcher.getPairs();
    for (BracePair pair : pairs) {
      if (pair.getLeftBraceType() == tokenType || pair.getRightBraceType() == tokenType ) {
        return l.hashCode();
      }
    }
  }
  if (tokenType instanceof IXmlLeafElementType) {
    return tokenType == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER || tokenType == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER
           ? XML_VALUE_DELIMITER_GROUP
           : XML_TAG_TOKEN_GROUP;
  }
  else{
    return BraceMatchingUtil.UNDEFINED_TOKEN_GROUP;
  }
}
项目:intellij-ce-playground    文件:RecursiveTokenizingVisitor.java   
@Override
public void visitElement(PsiElement element) {
  Language language = element.getLanguage();
  if (language != myLastLanguage) {
    myLastLanguage = language;
    myLastProfile = StructuralSearchUtil.getProfileByPsiElement(element);
  }
  if (myLastProfile != null) {
    language = myLastProfile.getLanguage(element);
  }
  if (myAcceptableLanguages == null || myAcceptableLanguages.contains(language)) {
    Tokenizer tokenizer = StructuralSearchUtil.getTokenizerForLanguage(language);
    if (tokenizer != null) {
      myLanguages.add(language.getID());
      if (!tokenizer.visit(element, this)) {
        return;
      }
    }
  }
  super.visitElement(element);
}
项目:intellij-ce-playground    文件:LowLevelSearchUtil.java   
private static void diagnoseInvalidRange(@NotNull PsiElement scope,
                                         PsiFile file,
                                         FileViewProvider viewProvider,
                                         CharSequence buffer,
                                         TextRange range) {
  String msg = "Range for element: '" + scope + "' = " + range + " is out of file '" + file + "' range: " + file.getTextRange();
  msg += "; file contents length: " + buffer.length();
  msg += "\n file provider: " + viewProvider;
  Document document = viewProvider.getDocument();
  if (document != null) {
    msg += "\n committed=" + PsiDocumentManager.getInstance(file.getProject()).isCommitted(document);
  }
  for (Language language : viewProvider.getLanguages()) {
    final PsiFile root = viewProvider.getPsi(language);
    msg += "\n root " + language + " length=" + root.getTextLength() + (root instanceof PsiFileImpl
                                                                        ? "; contentsLoaded=" + ((PsiFileImpl)root).isContentsLoaded() : "");
  }

  LOG.error(msg);
}
项目:intellij-ce-playground    文件:CodeCompletionHandlerBase.java   
private static boolean shouldSkipAutoPopup(Editor editor, PsiFile psiFile) {
  int offset = editor.getCaretModel().getOffset();
  int psiOffset = Math.max(0, offset - 1);

  PsiElement elementAt = InjectedLanguageUtil.findInjectedElementNoCommit(psiFile, psiOffset);
  if (elementAt == null) {
    elementAt = psiFile.findElementAt(psiOffset);
  }
  if (elementAt == null) return true;

  Language language = PsiUtilCore.findLanguageFromElement(elementAt);

  for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
    final ThreeState result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset);
    if (result != ThreeState.UNSURE) {
      LOG.debug(confidence + " has returned shouldSkipAutopopup=" + result);
      return result == ThreeState.YES;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:PythonTemplateIndentOptionsProvider.java   
@Nullable
@Override
public final IndentOptions getIndentOptions(@NotNull final CodeStyleSettings settings,
                                            @NotNull final PsiFile file) {
  final Language language = file.getLanguage();
  if (!(language instanceof PythonTemplateLanguage)) {
    return null; // We only care about python template files
  }

  // This template language has no settings, lets use parent language then
  final Language templateDataLanguage = PyTemplatesUtil.getTemplateDataLanguage(file, null);
  if (templateDataLanguage == null) {
    return null; // No template data language
  }
  return settings.getIndentOptions(templateDataLanguage.getAssociatedFileType());
}
项目:GoJetPlugin    文件:JetFileType.java   
private static LanguageFileType getAssociatedFileType(VirtualFile file, Project project) {
    if (project == null) {
        return null;
    }
    Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(file);

    LanguageFileType associatedFileType = null;
    if (language != null) {
        associatedFileType = language.getAssociatedFileType();
    }

    if (language == null || associatedFileType == null) {
        associatedFileType = JetLanguage.getDefaultTemplateLang();
    }
    return associatedFileType;
}
项目:intellij-ce-playground    文件:RenameUtil.java   
public static boolean isValidName(final Project project, final PsiElement psiElement, final String newName) {
  if (newName == null || newName.length() == 0) {
    return false;
  }
  final Condition<String> inputValidator = RenameInputValidatorRegistry.getInputValidator(psiElement);
  if (inputValidator != null) {
    return inputValidator.value(newName);
  }
  if (psiElement instanceof PsiFile || psiElement instanceof PsiDirectory) {
    return newName.indexOf('\\') < 0 && newName.indexOf('/') < 0;
  }
  if (psiElement instanceof PomTargetPsiElement) {
    return !StringUtil.isEmptyOrSpaces(newName);
  }

  final PsiFile file = psiElement.getContainingFile();
  final Language elementLanguage = psiElement.getLanguage();

  final Language fileLanguage = file == null ? null : file.getLanguage();
  Language language = fileLanguage == null ? elementLanguage : fileLanguage.isKindOf(elementLanguage) ? fileLanguage : elementLanguage;

  return LanguageNamesValidation.INSTANCE.forLanguage(language).isIdentifier(newName.trim(), project);
}
项目:intellij-ce-playground    文件:MultiplePsiFilesPerDocumentFileViewProvider.java   
@Override
@Nullable
public PsiReference findReferenceAt(int offset) {
  TextRange minRange = new TextRange(0, getContents().length());
  PsiReference ret = null;
  for (final Language language : getLanguages()) {
    final PsiElement psiRoot = getPsi(language);
    final PsiReference reference = SharedPsiElementImplUtil.findReferenceAt(psiRoot, offset, language);
    if (reference == null) continue;
    final TextRange textRange = reference.getRangeInElement().shiftRight(reference.getElement().getTextRange().getStartOffset());
    if (minRange.contains(textRange) && !textRange.contains(minRange)) {
      minRange = textRange;
      ret = reference;
    }
  }
  return ret;
}
项目:intellij-ce-playground    文件:TemporaryPlacesInjector.java   
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement context) {
  if (!(context instanceof PsiLanguageInjectionHost) || !((PsiLanguageInjectionHost)context).isValidHost()) return;
  PsiLanguageInjectionHost host = (PsiLanguageInjectionHost)context;

  PsiFile containingFile = context.getContainingFile();
  InjectedLanguage injectedLanguage = myRegistry.getLanguageFor(host, containingFile);
  Language language = injectedLanguage != null ? injectedLanguage.getLanguage() : null;
  if (language == null) return;

  final ElementManipulator<PsiLanguageInjectionHost> manipulator = ElementManipulators.getManipulator(host);
  if (manipulator == null) return;
  List<Trinity<PsiLanguageInjectionHost, InjectedLanguage,TextRange>> trinities =
    Collections.singletonList(Trinity.create(host, injectedLanguage, manipulator.getRangeInElement(host)));
  InjectorUtils.registerInjection(language, trinities, containingFile, registrar);
  InjectorUtils.registerSupport(myRegistry.getLanguageInjectionSupport(), false, registrar);
}
项目:intellij-ce-playground    文件:TodoIndex.java   
@Override
public boolean acceptInput(@NotNull final VirtualFile file) {
  if (!file.isInLocalFileSystem()) {
    return false; // do not index TODOs in library sources
  }

  final FileType fileType = file.getFileType();

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    return commentTokens != null;
  }

  return PlatformIdTableBuilding.isTodoIndexerRegistered(fileType) ||
         fileType instanceof CustomSyntaxTableFileType;
}
项目:intellij-ce-playground    文件:GenericInlineHandler.java   
public static void collectConflicts(final PsiReference reference,
                                    final PsiElement element,
                                    final Map<Language, InlineHandler.Inliner> inliners,
                                    final MultiMap<PsiElement, String> conflicts) {
  final PsiElement referenceElement = reference.getElement();
  if (referenceElement == null) return;
  final Language language = referenceElement.getLanguage();
  final InlineHandler.Inliner inliner = inliners.get(language);
  if (inliner != null) {
    final MultiMap<PsiElement, String> refConflicts = inliner.getConflicts(reference, element);
    if (refConflicts != null) {
      for (PsiElement psiElement : refConflicts.keySet()) {
        conflicts.putValues(psiElement, refConflicts.get(psiElement));
      }
    }
  }
  else {
    conflicts.putValue(referenceElement, "Cannot inline reference from " + language.getDisplayName());
  }
}
项目:intellij-spring-assistant    文件:YamlDocumentationProvider.java   
DocumentationProxyElement(@NotNull final PsiManager manager, @NotNull final Language language,
    @NotNull final MetadataNode target, boolean requestedForTargetValue,
    @Nullable String value) {
  super(manager, language);
  this.target = target;
  this.requestedForTargetValue = requestedForTargetValue;
  this.value = value;
}
项目:intellij-spring-assistant    文件:PropertiesDocumentationProvider.java   
DocumentationProxyElement(@NotNull final PsiManager manager, @NotNull final Language language,
    @NotNull final MetadataNode target, boolean requestedForTargetValue,
    @Nullable String value) {
  super(manager, language);
  this.target = target;
  this.requestedForTargetValue = requestedForTargetValue;
  this.value = value;
}
项目:AppleScript-IDEA    文件:AppleScriptJSInjector.java   
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
  if (context instanceof AppleScriptStringLiteralExpression) {
    AppleScriptCommandHandlerCall asCommand = PsiTreeUtil.getContextOfType(context, AppleScriptCommandHandlerCall.class);
    if (asCommand != null && asCommand.getCommandName().equalsIgnoreCase("do javascript")) {
      Collection<Language> javascript = Language.findInstancesByMimeType("javascript");
      if (javascript.isEmpty()) return;

      registrar.startInjecting(javascript.iterator().next()).addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(1, context.getTextLength() - 1)).doneInjecting();
    }
  }
}
项目:magento2-phpstorm-plugin    文件:LineMarkerXmlTagDecorator.java   
@Override
@NotNull
@Contract(
        pure = true
)
public Language getLanguage() {
    return xmlTag.getLanguage();
}
项目:bamboo-soy    文件:SoyFileViewProviderFactory.java   
@NotNull
@Override
public FileViewProvider createFileViewProvider(
    @NotNull VirtualFile virtualFile,
    Language language,
    @NotNull PsiManager psiManager,
    boolean eventSystemEnabled) {
  assert language.isKindOf(SoyLanguage.INSTANCE);
  return new SoyFileViewProvider(psiManager, virtualFile, eventSystemEnabled);
}
项目:hybris-integration-intellij-idea-plugin    文件:ImportProjectProgressModalWindow.java   
private void disableWrapOnType(final Language impexLanguage) {
    final CodeStyleScheme currentScheme = CodeStyleSchemes.getInstance().getCurrentScheme();
    final CodeStyleSettings codeStyleSettings = currentScheme.getCodeStyleSettings();
    if (impexLanguage != null) {
        CommonCodeStyleSettings langSettings = codeStyleSettings.getCommonSettings(impexLanguage);
        if (langSettings != null) {
            langSettings.WRAP_ON_TYPING = CommonCodeStyleSettings.WrapOnTyping.NO_WRAP.intValue;
        }
    }
}
项目:educational-plugin    文件:EduIntellijUtils.java   
public static void nameTaskFileAfterContainingClass(@NotNull Task task,
                                                    @NotNull TaskFile taskFile,
                                                    @NotNull Project project) {
  Language language = task.getLesson().getCourse().getLanguageById();
  if (language.getAssociatedFileType() == null) {
    LOG.warn("Cannot rename task file. Unable to find associated file type for language: " + language.getID());
    return;
  }
  task.getTaskFiles().remove(taskFile.name);
  taskFile.name = publicClassName(project, taskFile, language.getAssociatedFileType()) + "." + language.getAssociatedFileType().getDefaultExtension();
  task.taskFiles.put(taskFile.name, taskFile);
}
项目:educational-plugin    文件:EduAdaptiveStepicConnector.java   
private static String getCodeTemplateForTask(@NotNull Language language,
                                             @Nullable LinkedTreeMap codeTemplates) {
  if (codeTemplates != null) {
    final String languageString = EduPluginConfigurator.INSTANCE.forLanguage(language).getStepikDefaultLanguage();
    return (String)codeTemplates.get(languageString);
  }

  return null;
}
项目:educational-plugin    文件:EduAdaptiveStepicConnector.java   
@Nullable
private static String getTaskFileName(@NotNull Language language) {
  // This is a hacky way to how we should name task file.
  // It's assumed that if test's name is capitalized we need to capitalize task file name too.
  String testFileName = EduPluginConfigurator.INSTANCE.forLanguage(language).getTestFileName();
  boolean capitalize = !testFileName.isEmpty() && Character.isUpperCase(testFileName.charAt(0));

  LanguageFileType type = language.getAssociatedFileType();
  if (type == null) {
    LOG.warn("Failed to create task file name: associated file type for " + language + " is null");
    return null;
  }

  return (capitalize ? StringUtil.capitalize(TASK_NAME) : TASK_NAME) + "." + type.getDefaultExtension();
}