Java Code Examples for com.intellij.lang.PsiBuilderFactory

The following examples show how to use com.intellij.lang.PsiBuilderFactory. 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
Source Project: consulo-csharp   Source File: CSharpFileFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private static IElementType createElementType(String id, BiConsumer<PsiBuilder, LanguageVersion> consumer)
{
	return new IFileElementType(id, CSharpLanguage.INSTANCE)
	{
		@Override
		protected ASTNode doParseContents(@Nonnull ASTNode chameleon, @Nonnull 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 2
Source Project: consulo-csharp   Source File: CSharpFileStubElementType.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Override
protected ASTNode doParseContents(@Nonnull ASTNode chameleon, @Nonnull PsiElement psi)
{
	final Project project = psi.getProject();
	final Language languageForParser = getLanguageForParser(psi);
	final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY);
	final CSharpLanguageVersionWrapper languageVersion = (CSharpLanguageVersionWrapper) (tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion);

	Set<String> defVariables = getStableDefines((PsiFile) psi);

	final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, languageVersion, chameleon.getChars());
	builder.putUserData(PREPROCESSOR_VARIABLES, defVariables);

	final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(languageForParser).createParser(languageVersion);
	return parser.parse(this, builder, languageVersion).getFirstChildNode();
}
 
Example 3
Source Project: consulo   Source File: LightApplicationBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void registerServices(@Nonnull InjectingContainerBuilder builder) {
  builder.bind(PsiBuilderFactory.class).to(PsiBuilderFactoryImpl.class);
  builder.bind(FileTypeRegistry.class).to(LightFileTypeRegistry.class);
  builder.bind(FileDocumentManager.class).to(LightFileDocumentManager.class);
  builder.bind(JobLauncher.class).to(LightJobLauncher.class);
  builder.bind(EncodingManager.class).to(LightEncodingManager.class);
  builder.bind(PathMacrosService.class).to(LightPathMacrosService.class);
  builder.bind(PathMacros.class).to(LightPathMacros.class);
  builder.bind(UISettings.class);
  builder.bind(ExpandableItemsHandlerFactory.class).to(LightExpandableItemsHandlerFactory.class);
  builder.bind(TreeUIHelper.class).to(LightTreeUIHelper.class);
  builder.bind(UiActivityMonitor.class).to(LightUiActivityMonitor.class);
  builder.bind(TreeAnchorizer.class).to(TreeAnchorizer.class);
  builder.bind(ProgressManager.class).to(CoreProgressManager.class);
}
 
Example 4
Source Project: reasonml-idea-plugin   Source File: OclParser.java    License: MIT License 5 votes vote down vote up
public static ASTNode parseOcamlNode(@NotNull ILazyParseableElementType root, @NotNull ASTNode chameleon) {
    PsiElement parentElement = chameleon.getTreeParent().getPsi();
    Project project = parentElement.getProject();

    PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new OclLexer(), root.getLanguage(), chameleon.getText());
    //builder.setDebugMode(true);
    OclParser parser = new OclParser();

    return parser.parse(root, builder).getFirstChildNode();
}
 
Example 5
Source Project: consulo-csharp   Source File: CSharpPreprocessorElements.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ASTNode doParseContents(@Nonnull ASTNode chameleon, @Nonnull 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 6
Source Project: consulo-csharp   Source File: CSharpFragmentFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ASTNode doParseContents(@Nonnull final ASTNode chameleon, @Nonnull 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 7
Source Project: consulo-csharp   Source File: CSharpFragmentFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ASTNode doParseContents(@Nonnull final ASTNode chameleon, @Nonnull 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 8
@Override
@RequiredReadAction
protected ASTNode doParseContents(@Nonnull ASTNode chameleon, @Nonnull 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());

	builder.putUserData(CSharpFileStubElementType.PREPROCESSOR_VARIABLES, collectVariableFor(psi));
	CSharpBuilderWrapper wrapper = new CSharpBuilderWrapper(builder, languageVersion);

	PsiBuilder.Marker mark = wrapper.mark();

	ModifierSet modifierSet = ModifierSet.EMPTY;
	if(psi instanceof DotNetModifierListOwner)
	{
		CSharpModifierList modifierList = (CSharpModifierList) ((DotNetModifierListOwner) psi).getModifierList();
		if(modifierList != null && modifierList.hasModifierInTree(CSharpModifier.ASYNC))
		{
			modifierSet = ModifierSet.create(CSharpSoftTokens.ASYNC_KEYWORD);
		}
	}
	parse(wrapper, modifierSet);

	while(!wrapper.eof())
	{
		PsiBuilder.Marker er = wrapper.mark();
		wrapper.advanceLexer();
		er.error("Unexpected token");
	}

	mark.done(this);

	return wrapper.getTreeBuilt().getFirstChildNode();
}
 
Example 9
Source Project: consulo-csharp   Source File: CSharpDocElements.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
protected ASTNode doParseContents(@Nonnull final ASTNode chameleon, @Nonnull 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 10
Source Project: consulo-csharp   Source File: CSharpDocElements.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ASTNode doParseContents(@Nonnull final ASTNode chameleon, @Nonnull final PsiElement psi)
{
	Project project = psi.getProject();
	Language languageForParser = getLanguageForParser(psi);
	CSharpReferenceLexer lexer = new CSharpReferenceLexer();
	PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, lexer, languageForParser, languageForParser.getVersions()[0], chameleon.getChars());
	return myParser.parse(this, builder, languageForParser.getVersions()[0]).getFirstChildNode();
}
 
Example 11
@Override
protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi) {
  final PsiBuilderFactory factory = PsiBuilderFactory.getInstance();
  final PsiBuilder psiBuilder = factory.createBuilder(getProject(), chameleon);
  final PsiBuilder builder = adapt_builder_(HaxeTokenTypes.EXPRESSION, psiBuilder, new HaxeParser());

  final PsiBuilder.Marker marker = enter_section_(builder, 0, _NONE_, "<code fragment>");
  HaxeParser.expression(builder, 1);
  while (builder.getTokenType() != null) {
    builder.advanceLexer();
  }
  marker.done(HaxeTokenTypes.EXPRESSION);
  return builder.getTreeBuilt();
}
 
Example 12
Source Project: consulo   Source File: PsiManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public PsiManagerImpl(@Nonnull Project project, @Nonnull Provider<FileIndexFacade> fileIndexFacadeProvider, @Nonnull PsiModificationTracker modificationTracker) {
  // we need to initialize PsiBuilderFactory service so it won't initialize under PsiLock from ChameleonTransform
  PsiBuilderFactory.getInstance();

  myProject = project;
  myFileIndex = fileIndexFacadeProvider;
  myModificationTracker = modificationTracker;

  myFileManager = new FileManagerImpl(this, fileIndexFacadeProvider);

  myTreeChangePreprocessors.add((PsiTreeChangePreprocessor)myModificationTracker);

  Disposer.register(project, () -> myIsDisposed = true);
}