Java Code Examples for com.intellij.lang.PsiBuilderFactory

The following are top voted examples for showing how to use com.intellij.lang.PsiBuilderFactory. 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: intellij-ce-playground   File: DtdParsing.java   Source Code and License 6 votes vote down vote up
public DtdParsing(CharSequence chars,
                  final IElementType type,
                  final XmlEntityDecl.EntityContextType contextType,
                  PsiFile contextFile
) {
  this(
    type,
    contextType,
    PsiBuilderFactory.getInstance().createBuilder(
      LanguageParserDefinitions.INSTANCE.forLanguage(DTDLanguage.INSTANCE),
      new DtdLexer(false) {
        final int myInitialState = getLexerInitialState(type, contextType);
        @Override
        public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
          super.start(buffer, startOffset, endOffset, myInitialState);
        }
      }, chars
    )
  );
  if (contextFile != null) myBuilder.putUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY, contextFile);
}
 
Example 2
Project: intellij-ce-playground   File: GroovyDocTagValueTokenType.java   Source Code and License 6 votes vote down vote up
private ASTNode parseImpl(ASTNode chameleon) {
  final PsiElement parentElement = chameleon.getTreeParent().getPsi();
  final Project project = parentElement.getProject();
  final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new GroovyLexer(), getLanguage(), chameleon.getText());

  PsiBuilder.Marker rootMarker = builder.mark();
  if (BUILT_IN_TYPES.contains(chameleon.getText())) {
    builder.advanceLexer();
  } else {
    ReferenceElement.parse(builder, false, false, false, false, false);
    while (!builder.eof()) {
      builder.advanceLexer();
    }
  }
  rootMarker.done(this);
  return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 3
Project: spoofax-intellij   File: MetaborgFileElementType.java   Source Code and License 6 votes vote down vote up
@Override protected ASTNode doParseContents(final ASTNode chameleon, final PsiElement psi) {
    final Project project = psi.getProject();

    final MetaborgIdeaLanguage language = getMetaborgIdeaLanguage();
    final PsiBuilder builder =
        PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, language, chameleon.getChars());


    @Nullable final FileObject resource = getResource(psi, builder);
    final ILanguageImpl languageImpl = getLanguageImpl(resource, psi, this);

    final String text = builder.getOriginalText().toString();
    final ISpoofaxInputUnit input = unitService.inputUnit(resource, text, languageImpl, null);
    final ISpoofaxParseUnit parseResult = parseAll(input);

    final AstBuilder astBuilder =
        new AstBuilder(languageImpl, this.elementTypeProviderFactory, this.tokenTypesManager);
    final ASTNode tree = astBuilder.build(parseResult, this, builder);

    final ASTNode rootNode = tree.getFirstChildNode();

    final MetaborgFile file = (MetaborgFile) psi;
    file.putUserData(MetaborgFile.PARSE_RESULT_KEY, parseResult);

    return rootNode;
}
 
Example 4
Project: tools-idea   File: DtdParsing.java   Source Code and License 6 votes vote down vote up
public DtdParsing(CharSequence chars,
                  final IElementType type,
                  final XmlEntityDecl.EntityContextType contextType,
                  PsiFile contextFile
) {
  this(
    type,
    contextType,
    PsiBuilderFactory.getInstance().createBuilder(
      LanguageParserDefinitions.INSTANCE.forLanguage(DTDLanguage.INSTANCE),
      new DtdLexer(false) {
        final int myInitialState = getLexerInitialState(type, contextType);
        @Override
        public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
          super.start(buffer, startOffset, endOffset, myInitialState);
        }
      }, chars
    )
  );
  if (contextFile != null) myBuilder.putUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY, contextFile);
}
 
Example 5
Project: tools-idea   File: GroovyDocTagValueTokenType.java   Source Code and License 6 votes vote down vote up
private ASTNode parseImpl(ASTNode chameleon) {
  final PsiElement parentElement = chameleon.getTreeParent().getPsi();
  final Project project = parentElement.getProject();
  final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new GroovyLexer(), getLanguage(), chameleon.getText());

  PsiBuilder.Marker rootMarker = builder.mark();
  if (BUILT_IN_TYPES.contains(chameleon.getText())) {
    builder.advanceLexer();
  } else {
    ReferenceElement.parse(builder, false, false, false, false, false);
    while (!builder.eof()) {
      builder.advanceLexer();
    }
  }
  rootMarker.done(this);
  return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 6
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 7
Project: consulo-haxe   File: HaxeExpressionCodeFragmentImpl.java   Source Code and License 6 votes vote down vote up
@Override
protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi)
{
	final PsiBuilderFactory factory = PsiBuilderFactory.getInstance();
	final PsiBuilder psiBuilder = factory.createBuilder(getProject(), chameleon, LanguageVersionUtil.findDefaultVersion(getLanguage()));
	final PsiBuilder builder = adapt_builder_(HaxeTokenTypes.EXPRESSION, psiBuilder, new HaxeParser());

	final PsiBuilder.Marker marker = builder.mark();
	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 8
Project: consulo-play   File: PlayBaseTemplateGroovyExpressionElementType.java   Source Code and License 6 votes vote down vote up
@Override
public ASTNode parseContents(ASTNode chameleon)
{
	Project project = chameleon.getTreeParent().getPsi().getProject();
	PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new GroovyLexer(), GroovyFileType.GROOVY_LANGUAGE,
			LanguageVersionUtil.findDefaultVersion(GroovyFileType.GROOVY_LANGUAGE), chameleon.getText());

	PsiBuilder.Marker mark = builder.mark();
	GroovyParser.parseExpression(builder);
	if(!builder.eof())
	{
		builder.error("expression expected");

		while(!builder.eof())
		{
			builder.advanceLexer();
		}
	}
	mark.done(GroovyParserDefinition.GROOVY_FILE);

	return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 9
Project: consulo   File: PsiManagerImpl.java   Source Code and License 6 votes vote down vote up
public PsiManagerImpl(Project project,
                      FileDocumentManager fileDocumentManager,
                      PsiBuilderFactory psiBuilderFactory,
                      FileIndexFacade fileIndex,
                      MessageBus messageBus,
                      PsiModificationTracker modificationTracker) {
  myProject = project;
  myFileIndex = fileIndex;
  myMessageBus = messageBus;
  myModificationTracker = modificationTracker;

  //We need to initialize PsiBuilderFactory service so it won't initialize under PsiLock from ChameleonTransform
  @SuppressWarnings({"UnusedDeclaration", "UnnecessaryLocalVariable"}) Object used = psiBuilderFactory;

  myFileManager = new FileManagerImpl(this, fileDocumentManager, fileIndex);

  myTreeChangePreprocessors.add((PsiTreeChangePreprocessor)modificationTracker);

  Disposer.register(project, () -> myIsDisposed = true);
}
 
Example 10
Project: consulo-xml   File: DtdParsing.java   Source Code and License 6 votes vote down vote up
public DtdParsing(CharSequence chars,
                  final IElementType type,
                  final XmlEntityDecl.EntityContextType contextType,
                  PsiFile contextFile
) {
  this(
    type,
    contextType,
    PsiBuilderFactory.getInstance().createBuilder(
      LanguageParserDefinitions.INSTANCE.forLanguage(DTDLanguage.INSTANCE),
      new DtdLexer(false) {
        final int myInitialState = getLexerInitialState(type, contextType);
        @Override
        public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) {
          super.start(buffer, startOffset, endOffset, myInitialState);
        }
      }, LanguageVersionUtil.findDefaultVersion(DTDLanguage.INSTANCE), chars
    )
  );
  if (contextFile != null) myBuilder.putUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY, contextFile);
}
 
Example 11
Project: intellij-ce-playground   File: PsiManagerImpl.java   Source Code and License 5 votes vote down vote up
public PsiManagerImpl(Project project,
                      FileDocumentManager fileDocumentManager,
                      PsiBuilderFactory psiBuilderFactory,
                      FileIndexFacade fileIndex,
                      MessageBus messageBus,
                      PsiModificationTracker modificationTracker) {
  myProject = project;
  myFileIndex = fileIndex;
  myMessageBus = messageBus;
  myModificationTracker = modificationTracker;

  //We need to initialize PsiBuilderFactory service so it won't initialize under PsiLock from ChameleonTransform
  @SuppressWarnings({"UnusedDeclaration", "UnnecessaryLocalVariable"}) Object used = psiBuilderFactory;

  boolean isProjectDefault = project.isDefault();

  myFileManager = isProjectDefault ? new EmptyFileManager(this) : new FileManagerImpl(this, fileDocumentManager, fileIndex);

  myTreeChangePreprocessors.add((PsiTreeChangePreprocessor)modificationTracker);
  Collections.addAll(myTreeChangePreprocessors, Extensions.getExtensions(PsiTreeChangePreprocessor.EP_NAME, myProject));

  Disposer.register(project, new Disposable() {
    @Override
    public void dispose() {
      myIsDisposed = true;
    }
  });
}
 
Example 12
Project: squirrel-lang-idea-plugin   File: SquirrelTokenTypesSets.java   Source Code and License 5 votes vote down vote up
@Override
public ASTNode parseContents(final ASTNode chameleon) {
    final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(chameleon.getTreeParent().getPsi().getProject(),
            chameleon,
            new SquirrelDocLexer(),
            getLanguage(),
            chameleon.getChars());
    doParse(builder);
    return builder.getTreeBuilt().getFirstChildNode();
}
 
Example 13
Project: tools-idea   File: PsiManagerImpl.java   Source Code and License 5 votes vote down vote up
public PsiManagerImpl(Project project,
                      FileDocumentManager fileDocumentManager,
                      PsiBuilderFactory psiBuilderFactory,
                      FileIndexFacade excludedFileIndex,
                      MessageBus messageBus,
                      PsiModificationTracker modificationTracker) {
  myProject = project;
  myExcludedFileIndex = excludedFileIndex;
  myMessageBus = messageBus;
  myModificationTracker = modificationTracker;

  //We need to initialize PsiBuilderFactory service so it won't initialize under PsiLock from ChameleonTransform
  @SuppressWarnings({"UnusedDeclaration", "UnnecessaryLocalVariable"}) Object used = psiBuilderFactory;

  boolean isProjectDefault = project.isDefault();

  myFileManager = isProjectDefault ? new EmptyFileManager(this) : new FileManagerImpl(this, fileDocumentManager, excludedFileIndex);

  myTreeChangePreprocessors.add((PsiTreeChangePreprocessor)modificationTracker);
  Collections.addAll(myTreeChangePreprocessors, Extensions.getExtensions(PsiTreeChangePreprocessor.EP_NAME, myProject));

  Disposer.register(project, new Disposable() {
    @Override
    public void dispose() {
      myIsDisposed = true;
    }
  });
}
 
Example 14
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 15
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 16
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 17
Project: consulo-csharp   File: CSharpInjectExpressionElementType.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);
	CSharpReferenceLexer lexer = new CSharpReferenceLexer();
	PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, lexer, languageForParser, languageForParser.getVersions()[0], chameleon.getChars());
	return ourParser.parse(this, builder, languageForParser.getVersions()[0]).getFirstChildNode();
}
 
Example 18
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 19
Project: consulo-csharp   File: CSharpDocElements.java   Source Code and License 5 votes vote down vote up
@Override
protected ASTNode doParseContents(@NotNull final ASTNode chameleon, @NotNull 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 20
Project: intellij-haxe   File: HaxeExpressionCodeFragmentImpl.java   Source Code and License 5 votes vote down vote up
@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 21
Project: consulo-play   File: PlayBaseTemplateGroovyElementType.java   Source Code and License 5 votes vote down vote up
@Override
public ASTNode parseContents(ASTNode chameleon)
{
	PsiElement parentElement = chameleon.getPsi();
	Project project = JavaPsiFacade.getInstance(parentElement.getProject()).getProject();

	Language groovyLanguage = GroovyFileType.GROOVY_LANGUAGE;
	LanguageVersion defaultVersion = LanguageVersionUtil.findDefaultVersion(groovyLanguage);
	PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new GroovyLexer(), groovyLanguage, defaultVersion, chameleon.getText());

	return new GroovyParser().parse(this, builder, defaultVersion).getFirstChildNode();
}
 
Example 22
Project: consulo-javaee   File: JspJavaFileElementType.java   Source Code and License 5 votes vote down vote up
@NotNull
private PsiBuilder doParse(@NotNull ASTNode chameleon, Project project, LanguageVersion languageVersion)
{
	LanguageLevel languageLevel = LanguageLevel.HIGHEST;
	PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new JspJavaLexer(languageLevel), JavaLanguage.INSTANCE, languageVersion, chameleon.getChars());
	JavaParserUtil.setLanguageLevel(builder, languageLevel);
	PsiParser parser = new JavaInJspParser();
	parser.parse(this, builder, languageVersion);
	return builder;
}
 
Example 23
Project: consulo-css   File: CssHtmlElements.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;
	CssInlineLexer lexer = new CssInlineLexer();

	final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, lexer, languageForParser, languageVersion, chameleon.getChars());
	final CssParser parser = new CssParser();

	PsiBuilder.Marker mark = builder.mark();

	boolean inline = true;
	// if we can't parse as selector - rollback
	if(parser.parseSelectorListNew(builder) && builder.getTokenType() == CssTokens.LBRACE)
	{
		inline = false;
	}

	mark.rollbackTo();

	if(inline)
	{
		PsiBuilder.Marker rootMark = builder.mark();
		parseInlineRule(parser, builder);
		rootMark.done(CssElements.ROOT);
	}
	else
	{
		parser.parseRoot(builder);
	}

	return builder.getTreeBuilt();
}
 
Example 24
Project: consulo-javascript   File: JSTokenTypes.java   Source Code and License 5 votes vote down vote up
@Override
@RequiredReadAction
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, createLexer(), languageForParser, languageVersion, chameleon.getChars());
	final JavaScriptParser parser = (JavaScriptParser) LanguageParserDefinitions.INSTANCE.forLanguage(languageForParser).createParser(languageVersion);

	JavaScriptParsingContext parsingContext = parser.createParsingContext();
	doParse(parsingContext, builder);
	return builder.getTreeBuilt();
}
 
Example 25
Project: k-intellij-plugin   File: KParserTest.java   Source Code and License 4 votes vote down vote up
private PsiBuilder newPsiBuilder(String expression) {
  final Lexer lexer = SPEC.createLexer(null);
  final PsiBuilderFactory factory = PsiBuilderFactory.getInstance();
  return factory.createBuilder(SPEC, lexer, expression);
}
 
Example 26
Project: consulo-csharp   File: CSharpFileStubElementType.java   Source Code and License 4 votes vote down vote up
@RequiredReadAction
@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 CSharpLanguageVersionWrapper languageVersion = (CSharpLanguageVersionWrapper) (tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion);

	FileViewProvider viewProvider = ((PsiFile) psi).getViewProvider();
	VirtualFile virtualFile = viewProvider.getVirtualFile();
	if(virtualFile instanceof LightVirtualFile)
	{
		virtualFile = ((LightVirtualFile) virtualFile).getOriginalFile();
		// we need call second time, due second original file will be light
		if(virtualFile instanceof LightVirtualFile)
		{
			virtualFile = ((LightVirtualFile) virtualFile).getOriginalFile();
		}
	}
	if(virtualFile == null)
	{
		virtualFile = psi.getUserData(IndexingDataKeys.VIRTUAL_FILE);
	}

	Set<String> defVariables = Collections.emptySet();
	if(virtualFile != null)
	{
		List<String> variables = findVariables(virtualFile, project);

		if(variables != null)
		{
			defVariables = new HashSet<>(variables);
		}
	}

	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 27
Project: consulo   File: CoreApplicationEnvironment.java   Source Code and License 4 votes vote down vote up
public CoreApplicationEnvironment(@Nonnull Disposable parentDisposable) {
  myParentDisposable = parentDisposable;

  myFileTypeRegistry = new CoreFileTypeRegistry();

  myApplication = createApplication(myParentDisposable);
  ApplicationManager.setApplication(myApplication,
                                    new StaticGetter<>(myFileTypeRegistry),
                                    myParentDisposable);
  myLocalFileSystem = createLocalFileSystem();
  myJarFileSystem = createJarFileSystem();

  Extensions.registerAreaClass(ExtensionAreas.PROJECT, null);

  final MutablePicoContainer appContainer = myApplication.getPicoContainer();
  registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(DocumentImpl::new, null));

  VirtualFileSystem[] fs = {myLocalFileSystem, myJarFileSystem};
  VirtualFileManagerImpl virtualFileManager = new VirtualFileManagerImpl(fs, myApplication.getMessageBus());
  registerComponentInstance(appContainer, VirtualFileManager.class, virtualFileManager);

  registerApplicationExtensionPoint(ASTLazyFactory.EP.getExtensionPointName(), ASTLazyFactory.class);
  registerApplicationExtensionPoint(ASTLeafFactory.EP.getExtensionPointName(), ASTLeafFactory.class);
  registerApplicationExtensionPoint(ASTCompositeFactory.EP.getExtensionPointName(), ASTCompositeFactory.class);

  addExtension(ASTLazyFactory.EP.getExtensionPointName(), new DefaultASTLazyFactory());
  addExtension(ASTLeafFactory.EP.getExtensionPointName(), new DefaultASTLeafFactory());
  addExtension(ASTCompositeFactory.EP.getExtensionPointName(), new DefaultASTCompositeFactory());

  registerApplicationService(EncodingManager.class, new CoreEncodingRegistry());
  registerApplicationService(VirtualFilePointerManager.class, createVirtualFilePointerManager());
  registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
  registerApplicationService(ReferenceProvidersRegistry.class, new MockReferenceProvidersRegistry());
  registerApplicationService(StubTreeLoader.class, new CoreStubTreeLoader());
  registerApplicationService(PsiReferenceService.class, new PsiReferenceServiceImpl());
  registerApplicationService(MetaDataRegistrar.class, new MetaRegistry());

  registerApplicationService(ProgressManager.class, createProgressIndicatorProvider());

  registerApplicationService(JobLauncher.class, createJobLauncher());
  registerApplicationService(CodeFoldingSettings.class, new CodeFoldingSettings());
  registerApplicationService(CommandProcessor.class, new CoreCommandProcessor());
  myApplication.registerService(ApplicationInfo.class, ApplicationInfoImpl.class);
}