Java Code Examples for consulo.lang.LanguageVersion

The following are top voted examples for showing how to use consulo.lang.LanguageVersion. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: consulo-unity3d   File: ShaderLabParser.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public ASTNode parse(@NotNull IElementType root, @NotNull PsiBuilder b, @NotNull LanguageVersion languageVersion)
{
	ShaderLabParserBuilder builder = new ShaderLabParserBuilder(b);

	PsiBuilder.Marker mark = builder.mark();

	if(!ShaderLabRoles.Shader.tryParse(builder))
	{
		builder.error("Shader expected");
	}

	while(!builder.eof())
	{
		doneError(builder, "Unexpected token");
	}
	mark.done(root);
	return builder.getTreeBuilt();
}
 
Example 2
Project: consulo-csharp   File: CSharpLanguageVersionResolver.java   Source Code and License 6 votes vote down vote up
@RequiredReadAction
@NotNull
@Override
public LanguageVersion getLanguageVersion(@NotNull Language language, @Nullable PsiElement element)
{
	if(element == null)
	{
		return CSharpLanguageVersionHelper.getInstance().getHighestVersion();
	}
	Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(element);
	if(moduleForPsiElement == null)
	{
		return CSharpLanguageVersionHelper.getInstance().getHighestVersion();
	}
	CSharpSimpleModuleExtension extension = ModuleUtilCore.getExtension(moduleForPsiElement, CSharpSimpleModuleExtension.class);
	if(extension == null)
	{
		return CSharpLanguageVersionHelper.getInstance().getHighestVersion();
	}
	return CSharpLanguageVersionHelper.getInstance().getWrapper(extension.getLanguageVersion());
}
 
Example 3
Project: consulo-csharp   File: CSharpLanguageVersionResolver.java   Source Code and License 6 votes vote down vote up
@NotNull
@RequiredReadAction
@Override
public LanguageVersion getLanguageVersion(@NotNull Language language, @Nullable Project project, @Nullable VirtualFile virtualFile)
{
	if(project == null || virtualFile == null)
	{
		return CSharpLanguageVersionHelper.getInstance().getHighestVersion();
	}
	Module moduleForPsiElement = ModuleUtilCore.findModuleForFile(virtualFile, project);
	if(moduleForPsiElement == null)
	{
		return CSharpLanguageVersionHelper.getInstance().getHighestVersion();
	}
	CSharpSimpleModuleExtension extension = ModuleUtilCore.getExtension(moduleForPsiElement, CSharpSimpleModuleExtension.class);
	if(extension == null)
	{
		return CSharpLanguageVersionHelper.getInstance().getHighestVersion();
	}
	return CSharpLanguageVersionHelper.getInstance().getWrapper(extension.getLanguageVersion());
}
 
Example 4
Project: consulo-csharp   File: CSharpFileFactory.java   Source Code and License 6 votes vote down vote up
@NotNull
private static IElementType createElementType(String id, BiConsumer<PsiBuilder, LanguageVersion> consumer)
{
	return new IFileElementType(id, CSharpLanguage.INSTANCE)
	{
		@Override
		protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi)
		{
			final Project project = psi.getProject();
			final Language languageForParser = getLanguageForParser(psi);
			final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY);
			final LanguageVersion languageVersion = tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion;
			final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, languageVersion, chameleon.getChars());
			consumer.accept(builder, languageVersion);
			while(!builder.eof())
			{
				builder.advanceLexer();
			}
			return builder.getTreeBuilt();
		}
	};
}
 
Example 5
Project: consulo-csharp   File: CSharpParsingTestCase.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public LanguageVersion resolveLanguageVersion(@NotNull FileType fileType)
{
	String name = getName();
	try
	{
		Method declaredMethod = getClass().getDeclaredMethod(name);
		SetLanguageVersion annotation = declaredMethod.getAnnotation(SetLanguageVersion.class);
		if(annotation != null)
		{
			return CSharpLanguageVersionHelper.getInstance().getWrapper(annotation.version());
		}
		else
		{
			throw new IllegalArgumentException("Missed @SetLanguageVersion");
		}
	}
	catch(NoSuchMethodException e)
	{
		throw new Error(e);
	}
}
 
Example 6
Project: consulo   File: PsiViewerDialog.java   Source Code and License 6 votes vote down vote up
private void updateVersionsCombo(@Nullable final String lastUsed) {
  final Object source = getSource();
  List<LanguageVersion> items = new ArrayList<LanguageVersion>();
  if (source instanceof LanguageFileType) {
    final Language baseLang = ((LanguageFileType)source).getLanguage();
    LanguageVersion[] versions = baseLang.getVersions();

    Collections.addAll(items, versions);
  }
  myDialectComboBox.setModel(new CollectionComboBoxModel(items));

  final int size = items.size();
  final boolean visible = size > 1;
  myDialectLabel.setVisible(visible);
  myDialectComboBox.setVisible(visible);
  if (visible && (myCurrentFile != null || lastUsed != null)) {
    String currentLaversion = myCurrentFile != null ? myCurrentFile.getLanguageVersion().getName() : lastUsed;
    for (int i = 0; i < size; ++i) {
      if (currentLaversion.equals(items.get(i).getName())) {
        myDialectComboBox.setSelectedIndex(i);
        return;
      }
    }
    myDialectComboBox.setSelectedIndex(size > 0 ? 0 : -1);
  }
}
 
Example 7
Project: consulo-tasks   File: JqlParser.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder, LanguageVersion languageVersion) {
  //builder.setDebugMode(true);
  PsiBuilder.Marker rootMarker = builder.mark();
  // Parser should accept empty string
  if (!builder.eof()) {
    parseQuery(builder);
    while (!builder.eof()) {
      builder.error("Illegal query part");
      builder.advanceLexer();
    }
  }
  rootMarker.done(root);
  return builder.getTreeBuilt();
}
 
Example 8
Project: consulo-javascript   File: JavaScriptLanguageVersionResolver.java   Source Code and License 6 votes vote down vote up
@NotNull
@RequiredReadAction
@Override
public LanguageVersion getLanguageVersion(@NotNull Language language, @Nullable Project project, @Nullable VirtualFile virtualFile)
{
	if(project == null || virtualFile == null)
	{
		return StandardJavaScriptVersions.getInstance().getDefaultVersion();
	}

	FileType fileType = virtualFile.getFileType();
	if(fileType instanceof JavaScriptFileTypeWithVersion)
	{
		return ((JavaScriptFileTypeWithVersion) fileType).getLanguageVersion(project, virtualFile);
	}

	return StandardJavaScriptVersions.getInstance().getDefaultVersion();
}
 
Example 9
Project: consulo   File: CommentUtilCore.java   Source Code and License 6 votes vote down vote up
public static boolean isCommentToken(@Nonnull IElementType tokenType, @Nonnull LanguageVersion languageVersion) {
  final Language language = tokenType.getLanguage();
  if(language != languageVersion.getLanguage()) {
    return false;
  }

  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);

  if (parserDefinition != null) {
    final TokenSet commentTokens = parserDefinition.getCommentTokens(languageVersion);

    if (commentTokens.contains(tokenType)) {
      return true;
    }
  }
  return false;
}
 
Example 10
Project: consulo-javascript   File: StandardJavaScriptVersionsImpl.java   Source Code and License 6 votes vote down vote up
@NotNull
public List<JavaScriptLanguageVersion> getValidLanguageVersions()
{
	List<JavaScriptLanguageVersion> list = new ArrayList<>();
	LanguageVersion[] versions = JavaScriptLanguage.INSTANCE.getVersions();
	for(LanguageVersion version : versions)
	{
		if(version instanceof StandardJavaScriptVersions.Marker)
		{
			list.add((BaseJavaScriptLanguageVersion) version);
		}
	}

	ContainerUtil.sort(list, (o1, o2) -> ((Marker) o1).getWeight() - ((Marker) o2).getWeight());
	return list;
}
 
Example 11
Project: consulo-javascript   File: JavaScriptFileType.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public LanguageVersion getLanguageVersion(@Nullable Project project, @Nullable VirtualFile virtualFile)
{
	if(virtualFile == null || project == null)
	{
		return StandardJavaScriptVersions.getInstance().getDefaultVersion();
	}
	Module moduleForFile = ModuleUtilCore.findModuleForFile(virtualFile, project);
	if(moduleForFile == null)
	{
		return StandardJavaScriptVersions.getInstance().getDefaultVersion();
	}
	JavaScriptModuleExtension<?> extension = ModuleUtilCore.getExtension(moduleForFile, JavaScriptModuleExtension.class);
	if(extension != null)
	{
		return extension.getLanguageVersion();
	}
	return StandardJavaScriptVersions.getInstance().getDefaultVersion();
}
 
Example 12
Project: consulo-xml   File: BaseHtmlLexer.java   Source Code and License 6 votes vote down vote up
@Nullable
protected IElementType getCurrentStylesheetElementType()
{
	LanguageVersion languageVersion = getStyleLanguageVersion();
	if(languageVersion != null)
	{
		for(EmbeddedTokenTypesProvider provider : EmbeddedTokenTypesProvider.EXTENSION_POINT_NAME.getExtensions())
		{
			if(provider.isMyVersion(languageVersion))
			{
				return provider.getElementType();
			}
		}
	}
	return null;
}
 
Example 13
Project: consulo   File: PsiFileFactoryImpl.java   Source Code and License 6 votes vote down vote up
@Nullable
public PsiElement createElementFromText(@Nullable final String text,
                                        @Nonnull final Language language,
                                        @Nonnull final LanguageVersion languageVersion,
                                        @Nonnull final IElementType type,
                                        @Nullable final PsiElement context) {
  if (text == null) return null;
  final DummyHolder result = DummyHolderFactory.createHolder(myManager, language, context);
  final FileElement holder = result.getTreeElement();

  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
  if (parserDefinition == null) {
    throw new AssertionError("No parser definition for " + language);
  }
  final Project project = myManager.getProject();
  final Lexer lexer = parserDefinition.createLexer(languageVersion);
  final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, holder, lexer, language, languageVersion, text);
  final ASTNode node = parserDefinition.createParser(languageVersion).parse(type, builder, languageVersion);
  holder.rawAddChildren((TreeElement)node);
  markGenerated(result);
  return node.getPsi();
}
 
Example 14
Project: consulo   File: PsiFileFactoryImpl.java   Source Code and License 6 votes vote down vote up
@Nullable
@Override
public PsiFile createFileFromText(@Nonnull String name,
                                  @Nonnull LanguageVersion languageVersion,
                                  @Nonnull CharSequence text,
                                  boolean physical,
                                  boolean markAsCopy,
                                  boolean noSizeLimit,
                                  @Nullable VirtualFile original) {
  LightVirtualFile virtualFile = new LightVirtualFile(name, languageVersion.getLanguage(), text);
  if (original != null) virtualFile.setOriginalFile(original);
  virtualFile.putUserData(LanguageVersion.KEY, languageVersion);
  if (noSizeLimit) {
    SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
  }
  return trySetupPsiForFile(virtualFile, languageVersion.getLanguage(), languageVersion, physical, markAsCopy);
}
 
Example 15
Project: consulo-nodejs   File: NodeJSModuleExtensionPanel.java   Source Code and License 5 votes vote down vote up
@RequiredDispatchThread
public NodeJSModuleExtensionPanel(final NodeJSMutableModuleExtension extension, Runnable runnable)
{
	super(new VerticalFlowLayout(true, false));

	add(ModuleExtensionSdkBoxBuilder.createAndDefine(extension, runnable).build());

	List<JavaScriptLanguageVersion> validLanguageVersions = StandardJavaScriptVersions.getInstance().getValidLanguageVersions();

	ComboBox languageVersionComboBox = new ComboBox(new CollectionComboBoxModel(validLanguageVersions, extension.getLanguageVersion()));
	languageVersionComboBox.addItemListener(new ItemListener()
	{
		@Override
		public void itemStateChanged(ItemEvent e)
		{
			if(e.getStateChange() == ItemEvent.SELECTED)
			{
				//noinspection unchecked
				extension.setLanguageVersion((LanguageVersion) e.getItem());
			}
		}
	});
	languageVersionComboBox.setRenderer(new ColoredListCellRenderer<BaseJavaScriptLanguageVersion>()
	{
		@Override
		protected void customizeCellRenderer(JList list, BaseJavaScriptLanguageVersion value, int index, boolean selected, boolean hasFocus)
		{
			append(value.getPresentableName());
		}
	});

	add(LabeledComponent.create(languageVersionComboBox, "Language Version"));
}
 
Example 16
Project: consulo-csharp   File: CSharpPreprocessorParser.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public ASTNode parse(@NotNull IElementType elementType, @NotNull PsiBuilder builder, @NotNull LanguageVersion languageVersion)
{
	PsiBuilder.Marker mark = builder.mark();

	while(!builder.eof())
	{
		PreprocessorParsing.parse(builder);
	}

	mark.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 17
Project: consulo-csharp   File: CSharpBuilderWrapper.java   Source Code and License 5 votes vote down vote up
public CSharpBuilderWrapper(PsiBuilder delegate, LanguageVersion languageVersion)
{
	super(delegate);
	myLanguageVersion = languageVersion;

	Set<String> variables = delegate.getUserData(CSharpFileStubElementType.PREPROCESSOR_VARIABLES);
	putUserData(CSharpFileStubElementType.PREPROCESSOR_VARIABLES, variables == null ? Collections.<String>emptySet() : variables);
}
 
Example 18
Project: consulo-csharp   File: CSharpParser.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public ASTNode parse(@NotNull IElementType elementType, @NotNull PsiBuilder builder, @NotNull LanguageVersion languageVersion)
{
	//builder.setDebugMode(true);
	CSharpBuilderWrapper builderWrapper = new CSharpBuilderWrapper(builder, languageVersion);

	PsiBuilder.Marker marker = builderWrapper.mark();

	DeclarationParsing.parseAll(builderWrapper, true, false);

	marker.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 19
Project: consulo-csharp   File: CSharpPreprocessorElements.java   Source Code and License 5 votes vote down vote up
@Override
protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi)
{
	final Project project = psi.getProject();
	final Language languageForParser = getLanguageForParser(psi);
	final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY);
	final LanguageVersion languageVersion = tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion;
	final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new _CSharpMacroLexer(), languageForParser, languageVersion, chameleon.getChars());
	final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(languageForParser).createParser(languageVersion);
	return parser.parse(this, builder, languageVersion).getFirstChildNode();
}
 
Example 20
Project: consulo-csharp   File: CSharpFragmentFactory.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public ASTNode parse(@NotNull IElementType elementType, @NotNull PsiBuilder builder, @NotNull LanguageVersion languageVersion)
{
	PsiBuilder.Marker mark = builder.mark();
	ExpressionParsing.parse(new CSharpBuilderWrapper(builder, languageVersion), ModifierSet.EMPTY);
	while(!builder.eof())
	{
		builder.error("Unexpected token");
		builder.advanceLexer();
	}
	mark.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 21
Project: consulo-csharp   File: CSharpFragmentFactory.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public ASTNode parse(@NotNull IElementType elementType, @NotNull PsiBuilder builder, @NotNull LanguageVersion languageVersion)
{
	PsiBuilder.Marker mark = builder.mark();
	SharedParsingHelpers.parseType(new CSharpBuilderWrapper(builder, languageVersion), SharedParsingHelpers.VAR_SUPPORT);
	while(!builder.eof())
	{
		builder.error("Unexpected token");
		builder.advanceLexer();
	}
	mark.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 22
Project: consulo-csharp   File: CSharpFragmentFactory.java   Source Code and License 5 votes vote down vote up
@Override
protected ASTNode doParseContents(@NotNull final ASTNode chameleon, @NotNull final PsiElement psi)
{
	final Project project = psi.getProject();
	final Language languageForParser = getLanguageForParser(psi);
	final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY);
	final LanguageVersion languageVersion = tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion;
	final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, languageVersion,
			chameleon.getChars());

	return ourExpressionParser.parse(this, builder, languageVersion).getFirstChildNode();
}
 
Example 23
Project: consulo-csharp   File: CSharpFragmentFactory.java   Source Code and License 5 votes vote down vote up
@Override
protected ASTNode doParseContents(@NotNull final ASTNode chameleon, @NotNull final PsiElement psi)
{
	final Project project = psi.getProject();
	final Language languageForParser = getLanguageForParser(psi);
	final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY);
	final LanguageVersion languageVersion = tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion;
	final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, languageVersion,
			chameleon.getChars());

	return ourTypeParser.parse(this, builder, languageVersion).getFirstChildNode();
}
 
Example 24
Project: consulo-csharp   File: CSharpDocParser.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public ASTNode parse(@NotNull IElementType root, @NotNull PsiBuilder builder, @NotNull LanguageVersion languageVersion)
{
	builder.enforceCommentTokens(TokenSet.EMPTY);

	final PsiBuilder.Marker file = builder.mark();
	new CSharpDocParsing(builder).parse();
	file.done(root);
	return builder.getTreeBuilt();
}
 
Example 25
Project: consulo-csharp   File: CSharpDocElements.java   Source Code and License 5 votes vote down vote up
@Override
@RequiredReadAction
protected ASTNode doParseContents(@NotNull final ASTNode chameleon, @NotNull final PsiElement psi)
{
	final Project project = psi.getProject();
	CSharpDocLanguage docLanguage = CSharpDocLanguage.INSTANCE;
	final LanguageVersion languageVersion = LanguageVersionUtil.findDefaultVersion(docLanguage);
	DeprecatedCSharpDocLexer docLexer = new DeprecatedCSharpDocLexer();
	final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, docLexer, docLanguage, languageVersion, chameleon.getChars());
	final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(docLanguage).createParser(languageVersion);
	return parser.parse(this, builder, languageVersion).getFirstChildNode();
}
 
Example 26
Project: consulo-lua   File: LuaDocParser.java   Source Code and License 5 votes vote down vote up
@NotNull
public ASTNode parse(IElementType root, PsiBuilder builder, LanguageVersion languageVersion) {
  PsiBuilder.Marker rootMarker = builder.mark();
  new LuaDocParsing().parse(builder);
  rootMarker.done(root);
  return builder.getTreeBuilt();
}
 
Example 27
Project: consulo   File: BlockSupportImpl.java   Source Code and License 5 votes vote down vote up
@Nonnull
public static DiffLog mergeTrees(@Nonnull final PsiFileImpl fileImpl,
                                 @Nonnull final ASTNode oldRoot,
                                 @Nonnull final ASTNode newRoot,
                                 @Nonnull ProgressIndicator indicator,
                                 @Nonnull CharSequence lastCommittedText) {
  if (newRoot instanceof FileElement) {
    ((FileElement)newRoot).setCharTable(fileImpl.getTreeElement().getCharTable());
  }

  try {
    newRoot.putUserData(TREE_TO_BE_REPARSED, Pair.create(oldRoot, lastCommittedText));
    newRoot.putUserData(LanguageVersion.KEY, fileImpl.getLanguageVersion());

    if (isReplaceWholeNode(fileImpl, newRoot)) {
      DiffLog treeChangeEvent = replaceElementWithEvents((CompositeElement)oldRoot, (CompositeElement)newRoot);
      fileImpl.putUserData(TREE_DEPTH_LIMIT_EXCEEDED, Boolean.TRUE);

      return treeChangeEvent;
    }
    newRoot.getFirstChildNode();  // maybe reparsed in PsiBuilderImpl and have thrown exception here
  }
  catch (ReparsedSuccessfullyException e) {
    // reparsed in PsiBuilderImpl
    return e.getDiffLog();
  }
  finally {
    newRoot.putUserData(TREE_TO_BE_REPARSED, null);
  }

  final ASTShallowComparator comparator = new ASTShallowComparator(indicator);
  final ASTStructure treeStructure = createInterruptibleASTStructure(newRoot, indicator);

  DiffLog diffLog = new DiffLog();
  diffTrees(oldRoot, diffLog, comparator, treeStructure, indicator, lastCommittedText);
  return diffLog;
}
 
Example 28
Project: consulo   File: InjectionRegistrarImpl.java   Source Code and License 5 votes vote down vote up
private static void checkForCorrectContextElement(@Nonnull List<PlaceInfo> placeInfos,
                                                  @Nonnull PsiElement contextElement,
                                                  @Nonnull LanguageVersion language,
                                                  @Nonnull PsiFile hostPsiFile,
                                                  @Nonnull VirtualFile hostVirtualFile,
                                                  @Nonnull DocumentEx hostDocument) {
  boolean isAncestor = false;
  for (PlaceInfo info : placeInfos) {
    isAncestor |= PsiTreeUtil.isAncestor(contextElement, info.host, false);
  }
  assert isAncestor : exceptionContext("Context element " + contextElement.getTextRange() + ": '" + contextElement + "'; " + " must be the parent of at least one of injection hosts", language,
                                       hostPsiFile, hostVirtualFile, hostDocument, placeInfos);
}
 
Example 29
Project: consulo-css   File: CssParser.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public ASTNode parse(@NotNull IElementType rootElementType, @NotNull PsiBuilder builder, @NotNull LanguageVersion languageVersion)
{
	PsiBuilder.Marker mark = builder.mark();
	parseRoot(builder);
	mark.done(rootElementType);
	return builder.getTreeBuilt();
}
 
Example 30
Project: consulo-play   File: PlayBaseTemplateParser.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder, LanguageVersion languageVersion)
{
	//builder.setDebugMode(true);

	PsiBuilder.Marker marker = builder.mark();

	parseInner(builder);

	marker.done(root);

	return builder.getTreeBuilt();
}
 
Example 31
Project: consulo   File: PsiUtilCore.java   Source Code and License 5 votes vote down vote up
@Nonnull
public static LanguageVersion findLanguageVersionFromElement(final PsiElement elt) {
  if (elt.getFirstChild() == null) { //is leaf
    final PsiElement parent = elt.getParent();
    if (parent != null) {
      return parent.getLanguageVersion();
    }
  }

  return elt.getLanguageVersion();
}
 
Example 32
Project: consulo-xml   File: XmlASTLeafFactory.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public LeafElement createLeaf(@NotNull IElementType type, @NotNull LanguageVersion languageVersion, @NotNull CharSequence text) {
  if (type instanceof IXmlLeafElementType) {
    if (type == XML_REAL_WHITE_SPACE) {
      return new PsiWhiteSpaceImpl(text);
    }
    return new XmlTokenImpl(type, text);
  }

  return null;
}
 
Example 33
Project: consulo   File: FindManagerImpl.java   Source Code and License 5 votes vote down vote up
private static TokenSet addTokenTypesForLanguage(FindModel model, Language lang, TokenSet tokensOfInterest) {
  ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
  if (definition != null) {
    for (LanguageVersion languageVersion : lang.getVersions()) {
      tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInCommentsOnly() ? definition.getCommentTokens(languageVersion) : TokenSet.EMPTY);
      tokensOfInterest =
              TokenSet.orSet(tokensOfInterest, model.isInStringLiteralsOnly() ? definition.getStringLiteralElements(languageVersion) : TokenSet.EMPTY);
    }
  }
  return tokensOfInterest;
}
 
Example 34
Project: consulo-java   File: ManifestLanguageVersionResolver.java   Source Code and License 5 votes vote down vote up
@RequiredReadAction
@NotNull
@Override
public LanguageVersion getLanguageVersion(@NotNull Language language, @Nullable Project project, @Nullable VirtualFile virtualFile)
{
	if(virtualFile == null)
	{
		return ManifestLanguageVersion.Manifest;
	}
	return virtualFile.getFileType() == BndFileType.INSTANCE ? ManifestLanguageVersion.Bnd : ManifestLanguageVersion.Manifest;
}
 
Example 35
Project: consulo   File: SandParser.java   Source Code and License 5 votes vote down vote up
@Nonnull
@Override
public ASTNode parse(@Nonnull IElementType root, @Nonnull PsiBuilder builder, @Nonnull LanguageVersion languageVersion) {
  PsiBuilder.Marker mark = builder.mark();
  while (!builder.eof()) {
    boolean find = false;
    for (Pair<IElementType, IElementType> pair : myPairs) {
      if (builder.getTokenType() == pair.getFirst()) {
        PsiBuilder.Marker defMark = builder.mark();
        builder.advanceLexer();

        if (!PsiBuilderUtil.expect(builder, SandTokens.IDENTIFIER)) {
          builder.error("Identifier expected");
        }
        defMark.done(pair.getSecond());
        find = true;
      }
    }

    if(!find) {
      builder.error("Expected start token");
      builder.advanceLexer();
    }
  }
  mark.done(root);
  return builder.getTreeBuilt();
}
 
Example 36
Project: consulo-javascript   File: JavaScriptQuickFixFactory.java   Source Code and License 5 votes vote down vote up
@NotNull
public static JavaScriptQuickFixFactory byElement(PsiElement element)
{
	LanguageVersion languageVersion = element.getLanguageVersion();
	if(languageVersion instanceof BaseJavaScriptLanguageVersion)
	{
		JavaScriptQuickFixFactory quickFixFactory = EP.findSingle(languageVersion.getName());
		if(quickFixFactory != null)
		{
			return quickFixFactory;
		}
	}
	return ourDefaultImpl;
}
 
Example 37
Project: consulo   File: SandFile.java   Source Code and License 5 votes vote down vote up
@Nonnull
@Override
public FileType getFileType() {
  LanguageVersion languageVersion = getLanguageVersion();
  if(languageVersion instanceof BaseSandLanguageVersion) {
    return ((BaseSandLanguageVersion)languageVersion).getFileType();
  }
  return SandFileType.INSTANCE;
}
 
Example 38
Project: consulo-javascript   File: ClientJavaScriptModuleExtensionPanel.java   Source Code and License 5 votes vote down vote up
public ClientJavaScriptModuleExtensionPanel(final JavaScriptMutableModuleExtension<?> extension)
{
	super(new VerticalFlowLayout(true, false));

	List<JavaScriptLanguageVersion> validLanguageVersions = StandardJavaScriptVersions.getInstance().getValidLanguageVersions();

	ComboBox languageVersionComboBox = new ComboBox(new CollectionComboBoxModel(validLanguageVersions, extension.getLanguageVersion()));
	languageVersionComboBox.addItemListener(new ItemListener()
	{
		@Override
		public void itemStateChanged(ItemEvent e)
		{
			if(e.getStateChange() == ItemEvent.SELECTED)
			{
				//noinspection unchecked
				extension.setLanguageVersion((LanguageVersion) e.getItem());
			}
		}
	});
	languageVersionComboBox.setRenderer(new ColoredListCellRenderer<BaseJavaScriptLanguageVersion>()
	{
		@Override
		protected void customizeCellRenderer(@NotNull JList list, BaseJavaScriptLanguageVersion value, int index, boolean selected, boolean hasFocus)
		{
			append(value.getPresentableName());
		}
	});

	add(LabeledComponent.left(languageVersionComboBox, "Language Version"));
}
 
Example 39
Project: consulo   File: PlatformIdTableBuilding.java   Source Code and License 5 votes vote down vote up
@javax.annotation.Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, Project project, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType)fileType).isSameFileType()) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), project, virtualFile), getTodoIndexer(sft.getFileType(), project, virtualFile));
  }
  else {
    extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
  }
  if (extIndexer != null) {
    return extIndexer;
  }

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    LanguageVersion languageVersion = LanguageVersionUtil.findLanguageVersion(lang, project, virtualFile);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens(languageVersion) : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, languageVersion, virtualFile, project);
    }
  }

  if (fileType instanceof CustomSyntaxTableFileType) {
    return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, null, virtualFile, project);
  }

  return null;
}
 
Example 40
Project: consulo   File: OneFileAtProjectTestCase.java   Source Code and License 5 votes vote down vote up
@Nonnull
protected LanguageVersion resolveLanguageVersion(@Nonnull FileType fileType) {
  if(fileType instanceof LanguageFileType) {
    return LanguageVersionUtil.findDefaultVersion(((LanguageFileType)fileType).getLanguage());
  }
  throw new IllegalArgumentException(fileType.getName() + " is not extends 'LanguageFileType'");
}