Java Code Examples for com.intellij.lang.Language#findLanguageByID()

The following examples show how to use com.intellij.lang.Language#findLanguageByID() . These examples are extracted from open source projects. 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
@Override
    public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement psiElement) {
        String productCode = INSTANCE.getBuild().getProductCode();
        if (NutzCons.IDEA_VERSION.equals(productCode)) {
            final Language SQL_LANGUAGE = Language.findLanguageByID("SQL");
            if (DomUtil.isNutzSqlFile(psiElement.getContainingFile())) {
                if (psiElement instanceof XmlTag) {
                    XmlTag tag = (XmlTag) psiElement;
                    if (SQL_TAG.equals(tag.getName())) {
                        registrarInjecting(SQL_LANGUAGE, registrar, DomUtil.findXmlTexts(psiElement.getChildren()), null, null);
                    }
//                else if (EXP_TAG.equals(tag.getName())) {
//                    registrarInjecting(XMLLanguage.INSTANCE, registrar, DomUtil.findXmlTexts(psiElement.getChildren()), "<!--", "-->");
//                }
                }
            }
        }
    }
 
Example 2
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement psiElement) {
    String productCode = INSTANCE.getBuild().getProductCode();
    if (NutzCons.IDEA_VERSION.equals(productCode)) {
        //旗舰版才支持该功能
        final Language SQL_LANGUAGE = Language.findLanguageByID("SQL");
        if (psiElement.getParent() != null && psiElement.getParent().getParent() != null) {
            PsiElement parent = psiElement.getParent().getParent().getParent();
            if (parent != null && parent instanceof PsiAnnotation) {
                String qualifiedName = ((PsiAnnotation) parent).getQualifiedName();
                if (NutzCons.SQLS.contains(qualifiedName)) {
                    registrar.startInjecting(SQL_LANGUAGE);
                    registrar.addPlace(null, null, (PsiLanguageInjectionHost) psiElement, ElementManipulators.getValueTextRange(psiElement));
                    registrar.doneInjecting();
                }
            }
        }
    }
}
 
Example 3
Source Project: dbunit-extractor   File: SQLInjector.java    License: MIT License 6 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host,
                                 @NotNull final InjectedLanguagePlaces places) {
    final boolean isSelectQuery = host.getText().trim().toUpperCase().startsWith("SELECT");
    final boolean isDataSetFile = host.getContainingFile().getText().startsWith("<dataset>");
    if (isDataSetFile && isSelectQuery) {
        final Language language = Language.findLanguageByID("SQL");
        if (language != null) {
            try {
                places.addPlace(language, TextRange.from(0, host.getTextLength()), null, null);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 4
private static PsiElement generateCPP(Project project, TaskData taskData) {
	VirtualFile parent = FileUtils.findOrCreateByRelativePath(project.getBaseDir(), FileUtils.getDirectory(taskData.getCppPath()));
	PsiDirectory psiParent = PsiManager.getInstance(project).findDirectory(parent);
	if (psiParent == null) {
		throw new NotificationException("Couldn't open parent directory as PSI");
	}

	Language objC = Language.findLanguageByID("ObjectiveC");
	if (objC == null) {
		throw new NotificationException("Language not found");
	}

	PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(
			FileUtils.getFilename(taskData.getCppPath()),
			objC,
			getTaskContent(project, taskData.getClassName())
	);
	if (file == null) {
		throw new NotificationException("Couldn't generate file");
	}
	return ApplicationManager.getApplication().runWriteAction(
			(Computable<PsiElement>) () -> psiParent.add(file)
	);

}
 
Example 5
Source Project: consulo   File: InspectionManagerEx.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public static SuppressIntentionAction[] getSuppressActions(@Nonnull InspectionToolWrapper toolWrapper) {
  final InspectionProfileEntry tool = toolWrapper.getTool();
  if (tool instanceof CustomSuppressableInspectionTool) {
    return ((CustomSuppressableInspectionTool)tool).getSuppressActions(null);
  }
  final List<LocalQuickFix> actions = new ArrayList<LocalQuickFix>(Arrays.asList(tool.getBatchSuppressActions(null)));
  if (actions.isEmpty()) {
    final Language language = Language.findLanguageByID(toolWrapper.getLanguage());
    if (language != null) {
      final List<InspectionSuppressor> suppressors = LanguageInspectionSuppressors.INSTANCE.allForLanguage(language);
      for (InspectionSuppressor suppressor : suppressors) {
        final SuppressQuickFix[] suppressActions = suppressor.getSuppressActions(null, tool.getShortName());
        Collections.addAll(actions, suppressActions);
      }
    }
  }
  return ContainerUtil.map2Array(actions, SuppressIntentionAction.class, new Function<LocalQuickFix, SuppressIntentionAction>() {
    @Override
    public SuppressIntentionAction fun(final LocalQuickFix fix) {
      return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction((SuppressQuickFix)fix);
    }
  });
}
 
Example 6
protected TemplateLanguageErrorFilter(
  final @Nonnull TokenSet templateExpressionStartTokens,
  final @Nonnull Class templateFileViewProviderClass,
  final @Nonnull String... knownSubLanguageNames)
{
  myTemplateExpressionStartTokens = TokenSet.create(templateExpressionStartTokens.getTypes());
  myTemplateFileViewProviderClass = templateFileViewProviderClass;

  List<String> knownSubLanguageList = new ArrayList<String>(Arrays.asList(knownSubLanguageNames));
  knownSubLanguageList.add("JavaScript");
  knownSubLanguageList.add("CSS");
  knownLanguageSet = new HashSet<Language>();
  for (String name : knownSubLanguageList) {
    final Language language = Language.findLanguageByID(name);
    if (language != null) {
      knownLanguageSet.add(language);
    }
  }
}
 
Example 7
private void injectLanguage(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectedLanguagePlaces, String scriptingName) {
    final Language requiredLanguage = Language.findLanguageByID(scriptingName);
    if (requiredLanguage != null) {
        final TextRange range = TextRange.from(0, host.getTextRange().getLength());
        injectedLanguagePlaces.addPlace(requiredLanguage, range, null, null);
    }
}
 
Example 8
private void injectLanguage(String langPrefix, @NotNull String languageId,
                            @NotNull PsiLanguageInjectionHost host,
                            @NotNull InjectedLanguagePlaces injectedLanguagePlaces) {
    // Find the required Language
    final Language requiredLanguage = Language.findLanguageByID(languageId);
    if (requiredLanguage == null) {
        return;
    }
    final TextRange textRange = ((XmlAttributeValue) host).getValueTextRange();
    final int length = getLanguagePrefix(langPrefix).length() + 1;
    final TextRange expressionTextRange = TextRange.from(length, textRange.getLength() - length);
    injectedLanguagePlaces.addPlace(requiredLanguage, expressionTextRange, null, null);
}
 
Example 9
Source Project: nosql4idea   File: QueryPanel.java    License: Apache License 2.0 5 votes vote down vote up
private EditorHighlighter createHighlighter(EditorColorsScheme settings) {
    Language language = Language.findLanguageByID("JSON");
    if (language == null) {
        language = Language.ANY;
    }
    return new LexerEditorHighlighter(PlainTextSyntaxHighlighterFactory.getSyntaxHighlighter(language, null, null), settings);
}
 
Example 10
Source Project: consulo   File: InspectionsFilter.java    License: Apache License 2.0 5 votes vote down vote up
public boolean matches(final Tools tools) {
  if (myShowOnlyCleanupInspections && !tools.getTool().isCleanupTool()) {
    return false;
  }

  if (mySuitableInspectionsStates != null && mySuitableInspectionsStates != tools.isEnabled()) {
    return false;
  }

  if (myAvailableOnlyForAnalyze != isAvailableOnlyForAnalyze(tools)) {
    return false;
  }

  if (!mySuitableSeverities.isEmpty()) {
    boolean suitable = false;
    for (final ScopeToolState state : tools.getTools()) {
      if (mySuitableInspectionsStates != null && mySuitableInspectionsStates != state.isEnabled()) {
        continue;
      }
      if (mySuitableSeverities.contains(tools.getDefaultState().getLevel().getSeverity())) {
        suitable = true;
        break;
      }
    }
    if (!suitable) {
      return false;
    }
  }

  if(mySuitableLanguages.isEmpty()) {
    return true;
  }
  final String languageId = tools.getDefaultState().getTool().getLanguage();
  Language language  = languageId == null ? null : Language.findLanguageByID(languageId);
  return language != null && mySuitableLanguages.contains(language);
}
 
Example 11
public void readExternal(@Nonnull Element element) throws InvalidDataException {
  synchronized (this) {
    initCommonSettingsMap();
    for (Element commonSettingsElement : element.getChildren(COMMON_SETTINGS_TAG)) {
      final String languageId = commonSettingsElement.getAttributeValue(LANGUAGE_ATTR);
      if (!StringUtil.isEmpty(languageId)) {
        Language target = Language.findLanguageByID(languageId);
        boolean isKnownLanguage = target != null;
        if (isKnownLanguage) {
          final LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(target);
          if (provider != null) {
            CommonCodeStyleSettings settings = safelyGetDefaults(provider);
            if (settings != null) {
              settings.readExternal(commonSettingsElement);
              init(settings, target);
            }
          }
          else {
            isKnownLanguage = false;
          }
        }
        if (!isKnownLanguage) {
          myUnknownSettingsMap.put(languageId, JDOMUtil.internElement(commonSettingsElement));
        }
      }
    }
    initNonReadSettings();
  }
}
 
Example 12
Source Project: consulo   File: FileElementInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
PsiElement restoreElement(@Nonnull SmartPointerManagerImpl manager) {
  Language language = Language.findLanguageByID(myLanguageId);
  if (language == null) return null;
  PsiFile file = SelfElementInfo.restoreFileFromVirtual(myVirtualFile, myProject, language);
  return file != null && file.getClass().getName().equals(myFileClassName) ? file : null;
}
 
Example 13
Source Project: consulo   File: Identikit.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public PsiElement findPsiElement(@Nonnull PsiFile file, int startOffset, int endOffset) {
  Language fileLanguage = Language.findLanguageByID(myFileLanguageId);
  if (fileLanguage == null) return null;   // plugin has been unloaded
  Language actualLanguage = fileLanguage != Language.ANY ? fileLanguage : file.getViewProvider().getBaseLanguage();
  PsiFile actualLanguagePsi = file.getViewProvider().getPsi(actualLanguage);
  if (actualLanguagePsi == null) {
    return null; // the file has changed its language or dialect, so we can't restore
  }
  return findInside(actualLanguagePsi, startOffset, endOffset);
}
 
Example 14
Source Project: idea-php-typo3-plugin   File: FluidConfig.java    License: MIT License 4 votes vote down vote up
@NotNull
public static Language getCommenterLanguage() {
    final Language id = Language.findLanguageByID(getStringPropertyValue(COMMENTER_LANGUAGE_ID));
    return id == null ? HTMLLanguage.INSTANCE : id;
}
 
Example 15
@Nullable
public Language getLanguage() {
    return Language.findLanguageByID(this.language);
}
 
Example 16
Source Project: consulo   File: CachedAnnotators.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Collection<Annotator> initialValue(@Nonnull String languageId) {
  Language language = Language.findLanguageByID(languageId);
  return language == null ? ContainerUtil.<Annotator>emptyList() : LanguageAnnotators.INSTANCE.allForLanguage(language);
}
 
Example 17
Source Project: consulo   File: LanguagePointerImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected Language compute() {
  return Language.findLanguageByID(myId);
}
 
Example 18
Source Project: consulo   File: Identikit.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public Language getFileLanguage() {
  return Language.findLanguageByID(myFileLanguageId);
}
 
Example 19
Source Project: consulo   File: XExpressionState.java    License: Apache License 2.0 4 votes vote down vote up
public XExpression toXExpression() {
  checkConverted();
  return new XExpressionImpl(myExpression, Language.findLanguageByID(myLanguage), myCustomInfo);
}
 
Example 20
@Nls
@Override
public String getDisplayName() {
  Language languageByID = Language.findLanguageByID(myExtensionPoint.getKey());
  return languageByID == null ? myExtensionPoint.getKey() : languageByID.getDisplayName();
}