Java Code Examples for com.intellij.lang.LanguageParserDefinitions

The following are top voted examples for showing how to use com.intellij.lang.LanguageParserDefinitions. 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: TodoIndex.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 2
Project: intellij-ce-playground   File: CoreStubTreeLoader.java   Source Code and License 6 votes vote down vote up
@Override
public boolean canHaveStub(VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    Language l = ((LanguageFileType)fileType).getLanguage();
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) return false;
    final IFileElementType elementType = parserDefinition.getFileNodeType();
    return elementType instanceof IStubFileElementType && ((IStubFileElementType)elementType).shouldBuildStubFor(file);
  }
  else if (fileType.isBinary()) {
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    return builder != null && builder.acceptsFile(file);
  }
  return false;
}
 
Example 3
Project: intellij-ce-playground   File: CumulativeStubVersion.java   Source Code and License 6 votes vote down vote up
public static int getCumulativeVersion() {
  int version = VERSION;
  for (final FileType fileType : FileTypeRegistry.getInstance().getRegisteredFileTypes()) {
    if (fileType instanceof LanguageFileType) {
      Language l = ((LanguageFileType)fileType).getLanguage();
      ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
      if (parserDefinition != null) {
        final IFileElementType type = parserDefinition.getFileNodeType();
        if (type instanceof IStubFileElementType) {
          version += ((IStubFileElementType)type).getStubVersion();
        }
      }
    }

    BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    if (builder != null) {
      version += builder.getStubVersion();
    }
  }
  return version;
}
 
Example 4
Project: intellij-ce-playground   File: IndentsPass.java   Source Code and License 6 votes vote down vote up
private boolean isComment(int offset) {
  final HighlighterIterator it = myEditor.getHighlighter().createIterator(offset);
  IElementType tokenType = it.getTokenType();
  Language language = tokenType.getLanguage();
  TokenSet comments = myComments.get(language);
  if (comments == null) {
    ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    if (definition != null) {
      comments = definition.getCommentTokens();
    }
    if (comments == null) {
      return false;
    }
    else {
      myComments.put(language, comments);
    }
  }
  return comments.contains(tokenType);
}
 
Example 5
Project: intellij-ce-playground   File: StubUpdatingIndex.java   Source Code and License 6 votes vote down vote up
public static boolean canHaveStub(@NotNull VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    final Language l = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) {
      return false;
    }

    final IFileElementType elementType = parserDefinition.getFileNodeType();
    if (elementType instanceof IStubFileElementType) {
      if (((IStubFileElementType)elementType).shouldBuildStubFor(file)) {
        return true;
      }
      if (IndexingStamp.isFileIndexedStateCurrent(file, INDEX_ID)) {
        return true;
      }
    }
  }
  final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
  return builder != null && builder.acceptsFile(file);
}
 
Example 6
Project: intellij-ce-playground   File: MultiHostRegistrarImpl.java   Source Code and License 6 votes vote down vote up
@Override
@NotNull
public MultiHostRegistrar startInjecting(@NotNull Language language) {
  escapers = new SmartList<LiteralTextEscaper<? extends PsiLanguageInjectionHost>>();
  shreds = new SmartList<PsiLanguageInjectionHost.Shred>();
  outChars = new StringBuilder();

  if (!cleared) {
    clear();
    throw new IllegalStateException("Seems you haven't called doneInjecting()");
  }

  if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null) {
    ReferenceInjector injector = ReferenceInjector.findById(language.getID());
    if (injector == null) {
      throw new UnsupportedOperationException("Cannot inject language '" + language + "' since its getParserDefinition() returns null");
    }
    myLanguage = null;
    myReferenceInjector = injector;
  }
  myLanguage = language;

  return this;
}
 
Example 7
Project: intellij-ce-playground   File: TextOccurrencesUtil.java   Source Code and License 6 votes vote down vote up
private static boolean processStringLiteralsContainingIdentifier(@NotNull String identifier, @NotNull SearchScope searchScope, PsiSearchHelper helper, final Processor<PsiElement> processor) {
  TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, int offsetInElement) {
      final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
      final ASTNode node = element.getNode();
      if (definition != null && node != null && definition.getStringLiteralElements().contains(node.getElementType())) {
        return processor.process(element);
      }
      return true;
    }
  };

  return helper.processElementsWithWord(occurenceProcessor,
                                 searchScope,
                                 identifier,
                                 UsageSearchContext.IN_STRINGS,
                                 true);
}
 
Example 8
Project: intellij-ce-playground   File: XmlWrongClosingTagNameInspection.java   Source Code and License 6 votes vote down vote up
private static void registerProblemStart(@NotNull final AnnotationHolder holder,
                                    @NotNull final XmlTag tag,
                                    @NotNull final XmlToken start,
                                    @NotNull final XmlToken end) {
  PsiElement context = tag.getContainingFile().getContext();
  if (context != null) {
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
    if (parserDefinition != null) {
      ASTNode contextNode = context.getNode();
      if (contextNode != null && contextNode.getChildren(parserDefinition.getStringLiteralElements()) != null) {
        // TODO: we should check for concatenations here
        return;
      }
    }
  }
  final String tagName = tag.getName();
  final String endTokenText = end.getText();

  final RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false);
  final RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true);

  final Annotation annotation = holder.createErrorAnnotation(start, XmlErrorMessages.message("tag.has.wrong.closing.tag.name"));
  annotation.registerFix(renameEndAction);
  annotation.registerFix(renameStartAction);
}
 
Example 9
Project: intellij-ce-playground   File: XmlWrongClosingTagNameInspection.java   Source Code and License 6 votes vote down vote up
private static void registerProblemEnd(@NotNull final AnnotationHolder holder,
                                       @NotNull final XmlTag tag,
                                       @NotNull final XmlToken end) {
  PsiElement context = tag.getContainingFile().getContext();
  if (context != null) {
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
    if (parserDefinition != null) {
      ASTNode contextNode = context.getNode();
      if (contextNode != null && contextNode.getChildren(parserDefinition.getStringLiteralElements()) != null) {
        // TODO: we should check for concatenations here
        return;
      }
    }
  }
  final String tagName = tag.getName();
  final String endTokenText = end.getText();

  final RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false);
  final RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true);

  final Annotation annotation = holder.createErrorAnnotation(end, XmlErrorMessages.message("wrong.closing.tag.name"));
  annotation.registerFix(new RemoveExtraClosingTagIntentionAction());
  annotation.registerFix(renameEndAction);
  annotation.registerFix(renameStartAction);
}
 
Example 10
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 11
Project: tools-idea   File: CoreStubTreeLoader.java   Source Code and License 6 votes vote down vote up
@Override
public boolean canHaveStub(VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    Language l = ((LanguageFileType)fileType).getLanguage();
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) return false;
    final IFileElementType elementType = parserDefinition.getFileNodeType();
    return elementType instanceof IStubFileElementType && ((IStubFileElementType)elementType).shouldBuildStubFor(file);
  }
  else if (fileType.isBinary()) {
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    return builder != null && builder.acceptsFile(file);
  }
  return false;
}
 
Example 12
Project: tools-idea   File: TypedHandler.java   Source Code and License 6 votes vote down vote up
private static boolean isInsideStringLiteral(final Editor editor, final PsiFile file) {
  int offset = editor.getCaretModel().getOffset();
  PsiElement element = file.findElementAt(offset);
  if (element == null) return false;
  final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
  if (definition != null) {
    final TokenSet stringLiteralElements = definition.getStringLiteralElements();
    final ASTNode node = element.getNode();
    if (node == null) return false;
    final IElementType elementType = node.getElementType();
    if (stringLiteralElements.contains(elementType)) {
      return true;
    }
    PsiElement parent = element.getParent();
    if (parent != null) {
      ASTNode parentNode = parent.getNode();
      if (parentNode != null && stringLiteralElements.contains(parentNode.getElementType())) {
        return true;
      }
    }
  }
  return false;
}
 
Example 13
Project: tools-idea   File: StubUpdatingIndex.java   Source Code and License 6 votes vote down vote up
public static boolean canHaveStub(@NotNull VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    final Language l = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) {
      return false;
    }

    final IFileElementType elementType = parserDefinition.getFileNodeType();
    if (elementType instanceof IStubFileElementType) {
      if (((IStubFileElementType)elementType).shouldBuildStubFor(file)) {
        return true;
      }
      final ID indexId = IndexInfrastructure.getStubId(INDEX_ID, file.getFileType());
      if (IndexingStamp.isFileIndexed(file, indexId, IndexInfrastructure.getIndexCreationStamp(indexId))) {
        return true;
      }
    }
  }
  final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
  return builder != null && builder.acceptsFile(file);
}
 
Example 14
Project: tools-idea   File: StubUpdatingIndex.java   Source Code and License 6 votes vote down vote up
private static Map<FileType, Integer> computeVersionMap() {
  Map<FileType, Integer> map = new HashMap<FileType, Integer>();
  for (final FileType fileType : FileTypeManager.getInstance().getRegisteredFileTypes()) {
    if (fileType instanceof LanguageFileType) {
      Language l = ((LanguageFileType)fileType).getLanguage();
      ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
      if (parserDefinition != null) {
        final IFileElementType type = parserDefinition.getFileNodeType();
        if (type instanceof IStubFileElementType) {
          map.put(fileType, ((IStubFileElementType)type).getStubVersion());
        }
      }
    }
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    if (builder != null) {
      map.put(fileType, builder.getStubVersion());
    }
  }
  return map;
}
 
Example 15
Project: tools-idea   File: TodoIndex.java   Source Code and License 6 votes vote down vote up
@Override
public boolean acceptInput(final VirtualFile file) {
  if (!(file.getFileSystem() instanceof LocalFileSystem)) {
    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;
}
 
Example 16
Project: tools-idea   File: MultiHostRegistrarImpl.java   Source Code and License 6 votes vote down vote up
@Override
@NotNull
public MultiHostRegistrar startInjecting(@NotNull Language language) {
  escapers = new SmartList<LiteralTextEscaper<? extends PsiLanguageInjectionHost>>();
  shreds = new SmartList<PsiLanguageInjectionHost.Shred>();
  outChars = new StringBuilder();

  if (!cleared) {
    clear();
    throw new IllegalStateException("Seems you haven't called doneInjecting()");
  }

  if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null) {
    throw new UnsupportedOperationException("Cannot inject language '" + language + "' since its getParserDefinition() returns null");
  }
  myLanguage = language;

  return this;
}
 
Example 17
Project: tools-idea   File: TextOccurrencesUtil.java   Source Code and License 6 votes vote down vote up
private static boolean processStringLiteralsContainingIdentifier(@NotNull String identifier, @NotNull SearchScope searchScope, PsiSearchHelper helper, final Processor<PsiElement> processor) {
  TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {
    @Override
    public boolean execute(PsiElement element, int offsetInElement) {
      final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
      final ASTNode node = element.getNode();
      if (definition != null && node != null && definition.getStringLiteralElements().contains(node.getElementType())) {
        return processor.process(element);
      }
      return true;
    }
  };

  return helper.processElementsWithWord(occurenceProcessor,
                                 searchScope,
                                 identifier,
                                 UsageSearchContext.IN_STRINGS,
                                 true);
}
 
Example 18
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 19
Project: idea-gitignore   File: IgnoreFile.java   Source Code and License 6 votes vote down vote up
/** Builds a new instance of {@link IgnoreFile}. */
public IgnoreFile(@NotNull FileViewProvider viewProvider, @NotNull IgnoreFileType fileType) {
    super(viewProvider);

    this.fileType = fileType;
    this.language = findLanguage(fileType.getLanguage(), viewProvider);

    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(this.language);
    if (parserDefinition == null) {
        throw new RuntimeException(
                "PsiFileBase: language.getParserDefinition() returned null for: " + this.language
        );
    }
    this.parserDefinition = parserDefinition;

    final IFileElementType nodeType = parserDefinition.getFileNodeType();
    init(nodeType, nodeType);
}
 
Example 20
Project: idea-doT   File: DotFileViewProvider.java   Source Code and License 6 votes vote down vote up
@Override
protected PsiFile createFile(@NotNull Language lang) {
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    if (parserDefinition == null) {
        return null;
    }

    Language templateDataLanguage = getTemplateDataLanguage(myManager, myFile);
    if (lang == templateDataLanguage) {
        PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
        file.setContentElementType(new TemplateDataElementType("Dot_TEMPLATE_DATA", templateDataLanguage, DotTokenTypes.CONTENT, DotTokenTypes.OUTER_ELEMENT_TYPE));
        return file;
    } else if (lang == DotLanguage.INSTANCE) {
        return parserDefinition.createFile(this);
    } else {
        return null;
    }
}
 
Example 21
Project: consulo-javaee   File: JspFileViewProviderImpl.java   Source Code and License 6 votes vote down vote up
@Nullable
@Override
protected PsiFile createFile(@NotNull final Language lang)
{
	if(lang == getBaseLanguage())
	{
		return LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this);
	}

	if(lang == JavaLanguage.INSTANCE)
	{
		return new JspJavaFileImpl(this);
	}

	if(lang == getTemplateDataLanguage())
	{
		PsiFileImpl file = (PsiFileImpl) LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this);
		file.setContentElementType(JspTemplateTokens.HTML_TEMPLATE_DATA);
		return file;
	}
	return null;
}
 
Example 22
Project: consulo   File: DefaultASTLeafFactory.java   Source Code and License 6 votes vote down vote up
@Nonnull
@Override
public LeafElement createLeaf(@Nonnull IElementType type, @Nonnull LanguageVersion languageVersion, @Nonnull CharSequence text) {
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(type.getLanguage());
  if(parserDefinition != null) {
    if(parserDefinition.getCommentTokens(languageVersion).contains(type)) {
      return new PsiCoreCommentImpl(type, text);
    }
  }

  // this is special case, then type is WHITE_SPACE, but no parser definition
  if(type == TokenType.WHITE_SPACE) {
    return new PsiWhiteSpaceImpl(text);
  }

  if (type instanceof ILeafElementType) {
    return (LeafElement)((ILeafElementType)type).createLeafNode(text);
  }
  return new LeafPsiElement(type, text);
}
 
Example 23
Project: consulo   File: CoreStubTreeLoader.java   Source Code and License 6 votes vote down vote up
@Override
public boolean canHaveStub(VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    Language l = ((LanguageFileType)fileType).getLanguage();
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) return false;
    final IFileElementType elementType = parserDefinition.getFileNodeType();
    return elementType instanceof IStubFileElementType && ((IStubFileElementType)elementType).shouldBuildStubFor(file);
  }
  else if (fileType.isBinary()) {
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    return builder != null && builder.acceptsFile(file);
  }
  return false;
}
 
Example 24
Project: consulo   File: IndentsPass.java   Source Code and License 6 votes vote down vote up
private boolean isComment(int offset) {
  final HighlighterIterator it = myEditor.getHighlighter().createIterator(offset);
  IElementType tokenType = it.getTokenType();
  Language language = tokenType.getLanguage();
  TokenSet comments = myComments.get(language);
  if (comments == null) {
    ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    if (definition != null) {
      comments = definition.getCommentTokens(LanguageVersionUtil.findLanguageVersion(language, myFile));
    }
    if (comments == null) {
      return false;
    }
    else {
      myComments.put(language, comments);
    }
  }
  return comments.contains(tokenType);
}
 
Example 25
Project: consulo   File: StubUpdatingIndex.java   Source Code and License 6 votes vote down vote up
public static boolean canHaveStub(@Nonnull VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    final Language l = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) {
      return false;
    }

    final IFileElementType elementType = parserDefinition.getFileNodeType();
    if (elementType instanceof IStubFileElementType) {
      if (((IStubFileElementType)elementType).shouldBuildStubFor(file)) {
        return true;
      }
      FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
      if (file instanceof NewVirtualFile &&
          fileBasedIndex instanceof FileBasedIndexImpl &&
          ((FileBasedIndexImpl)fileBasedIndex).getIndex(INDEX_ID).isIndexedStateForFile(((NewVirtualFile)file).getId(), file)) {
        return true;
      }
    }
  }
  final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
  return builder != null && builder.acceptsFile(file);
}
 
Example 26
Project: consulo   File: StubVersionMap.java   Source Code and License 6 votes vote down vote up
private static Object getVersionOwner(FileType fileType) {
  Object owner = null;
  if (fileType instanceof LanguageFileType) {
    Language l = ((LanguageFileType)fileType).getLanguage();
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition != null) {
      final IFileElementType type = parserDefinition.getFileNodeType();
      if (type instanceof IStubFileElementType) {
        owner = type;
      }
    }
  }

  BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
  if (builder != null) {
    owner = builder;
  }
  return owner;
}
 
Example 27
Project: consulo   File: TextOccurrencesUtil.java   Source Code and License 6 votes vote down vote up
private static boolean processStringLiteralsContainingIdentifier(@Nonnull String identifier,
                                                                 @Nonnull SearchScope searchScope,
                                                                 PsiSearchHelper helper,
                                                                 final Processor<PsiElement> processor) {
  TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {
    @Override
    public boolean execute(PsiElement element, int offsetInElement) {
      final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
      final ASTNode node = element.getNode();
      if (definition != null &&
          node != null &&
          definition.getStringLiteralElements(element.getLanguageVersion()).contains(node.getElementType())) {
        return processor.process(element);
      }
      return true;
    }
  };

  return helper.processElementsWithWord(occurenceProcessor, searchScope, identifier, UsageSearchContext.IN_STRINGS, true);
}
 
Example 28
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 29
Project: consulo-javascript   File: JSChangeUtil.java   Source Code and License 6 votes vote down vote up
private static ASTNode insertWhitespaceIfNeeded(ASTNode anchorNode, final ASTNode elementNode, final ASTNode parentNode,
		final ASTNode insertionPlaceNode) throws IncorrectOperationException
{
	ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(parentNode.getPsi().getLanguage());
	final TokenSet comments = parserDef.getCommentTokens(parentNode.getPsi().getLanguage().getVersions()[0]);
	final TokenSet whitespaces = parserDef.getWhitespaceTokens(parentNode.getPsi().getLanguage().getVersions()[0]);

	if(anchorNode != null && ((!whitespaces.contains(anchorNode.getElementType()) && !whitespaces.contains(elementNode.getElementType())) ||
			comments.contains(anchorNode.getElementType()) ||
			comments.contains(elementNode.getElementType()) ||
			elementNode.getPsi() instanceof PsiComment))
	{
		String commentString = " ";
		if(comments.contains(anchorNode.getElementType()) ||
				comments.contains(elementNode.getElementType()) ||
				elementNode.getPsi() instanceof PsiComment)
		{
			commentString = "\n";
		}

		final ASTNode wsNode = PsiParserFacade.SERVICE.getInstance(parentNode.getPsi().getProject()).createWhiteSpaceFromText(commentString).getNode();
		parentNode.addChild(wsNode, insertionPlaceNode);
		anchorNode = wsNode;
	}
	return anchorNode;
}
 
Example 30
Project: rythm_plugin   File: RythmFileViewProvider.java   Source Code and License 5 votes vote down vote up
private ParserDefinition getDefinition(Language lang) {
    ParserDefinition parserDefinition;
    if (lang.isKindOf(getBaseLanguage())) {
        parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang.is(getBaseLanguage()) ? lang : getBaseLanguage());
    } else {
        parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    }
    return parserDefinition;
}
 
Example 31
Project: GoJetPlugin   File: JetFileViewProvider.java   Source Code and License 5 votes vote down vote up
@Nullable
@Override
protected PsiFile createFile(@NotNull Language lang) {
    if (lang == myTemplateDataLanguage) {
        PsiFileImpl file = (PsiFileImpl) LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this);
        file.setContentElementType(TEMPLATE_DATA);
        return file;
    } else if (lang == JetLanguage.INSTANCE) {
        return LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this);
    } else {
        return null;
    }
}
 
Example 32
Project: intellij-ce-playground   File: JspIndexPatternBuilder.java   Source Code and License 5 votes vote down vote up
@Override
public TokenSet getCommentTokenSet(@NotNull final PsiFile file) {
  final JspFile jspFile = JspPsiUtil.getJspFile(file);
  TokenSet commentTokens = TokenSet.orSet(JavaIndexPatternBuilder.XML_COMMENT_BIT_SET, StdTokenSets.COMMENT_BIT_SET);
  final ParserDefinition parserDefinition =
    LanguageParserDefinitions.INSTANCE.forLanguage(jspFile.getViewProvider().getTemplateDataLanguage());
  if (parserDefinition != null) {
    commentTokens = TokenSet.orSet(commentTokens, parserDefinition.getCommentTokens());
  }
  return commentTokens;
}
 
Example 33
Project: intellij-ce-playground   File: ShiftIndentInsideHelper.java   Source Code and License 5 votes vote down vote up
private static  boolean isComment(final ASTNode node) {
  final PsiElement psiElement = SourceTreeToPsiMap.treeElementToPsi(node);
  if (psiElement instanceof PsiComment) return true;
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(psiElement.getLanguage());
  if (parserDefinition == null) return false;
  final TokenSet commentTokens = parserDefinition.getCommentTokens();
  return commentTokens.contains(node.getElementType());
}
 
Example 34
Project: intellij-ce-playground   File: PlatformIdTableBuilding.java   Source Code and License 5 votes vote down vote up
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = ourTodoIndexers.get(fileType);

  if (indexer != null) {
    return indexer;
  }

  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType)fileType).isSameFileType()) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer =
      new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), 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);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, virtualFile);
    }
  }

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

  return null;
}
 
Example 35
Project: intellij-ce-playground   File: SkipAutopopupInStrings.java   Source Code and License 5 votes vote down vote up
public static boolean isInStringLiteral(PsiElement element) {
  ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(PsiUtilCore.findLanguageFromElement(element));
  if (definition == null) {
    return false;
  }

  return isStringLiteral(element, definition) || isStringLiteral(element.getParent(), definition) ||
          isStringLiteralWithError(element, definition) || isStringLiteralWithError(element.getParent(), definition);
}
 
Example 36
Project: intellij-ce-playground   File: StructuralSearchProfileBase.java   Source Code and License 5 votes vote down vote up
protected boolean isStringLiteral(PsiElement element) {
  if (element == null) return false;
  final ASTNode astNode = element.getNode();
  if (astNode == null) {
    return false;
  }
  final IElementType elementType = astNode.getElementType();
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
  if (parserDefinition != null) {
    final TokenSet literals = parserDefinition.getStringLiteralElements();
    return literals.contains(elementType);
  }
  return false;
}
 
Example 37
Project: intellij-ce-playground   File: StructuralSearchProfileBase.java   Source Code and License 5 votes vote down vote up
private void doVisitElement(PsiElement element) {
  CompiledPattern pattern = myGlobalVisitor.getContext().getPattern();

  if (myGlobalVisitor.getCodeBlockLevel() == 0) {
    initTopLevelElement(element);
    return;
  }

  if (canBePatternVariable(element) && pattern.isRealTypedVar(element)) {
    myGlobalVisitor.handle(element);
    final MatchingHandler handler = pattern.getHandler(element);
    handler.setFilter(new NodeFilter() {
      public boolean accepts(PsiElement other) {
        return canBePatternVariableValue(other);
      }
    });

    super.visitElement(element);

    return;
  }

  super.visitElement(element);

  if (myGlobalVisitor.getContext().getSearchHelper().doOptimizing() && element instanceof LeafElement) {
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
    if (parserDefinition != null) {
      String text = element.getText();

      // todo: support variables inside comments
      boolean flag = true;
      if (StringUtil.isJavaIdentifier(text) && flag) {
        myGlobalVisitor.processTokenizedName(text, true, GlobalCompilingVisitor.OccurenceKind.CODE);
      }
    }
  }
}
 
Example 38
Project: intellij-ce-playground   File: SingleRootFileViewProvider.java   Source Code and License 5 votes vote down vote up
@Nullable
protected PsiFile createFile(@NotNull Language lang) {
  if (lang != getBaseLanguage()) return null;
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
  if (parserDefinition != null) {
    return parserDefinition.createFile(this);
  }
  return null;
}
 
Example 39
Project: intellij-ce-playground   File: CacheUtil.java   Source Code and License 5 votes vote down vote up
public static boolean isInComments(final IElementType tokenType) {
  final Language language = tokenType.getLanguage();
  boolean inComments = false;

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

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

    if (commentTokens.contains(tokenType)) {
      inComments = true;
    }
  }
  return inComments;
}
 
Example 40
Project: intellij-ce-playground   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) {
    tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInCommentsOnly() ? definition.getCommentTokens(): TokenSet.EMPTY);
    tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInStringLiteralsOnly() ? definition.getStringLiteralElements() : TokenSet.EMPTY);
  }
  return tokensOfInterest;
}
 
Example 41
Project: intellij-ce-playground   File: RegExpElementImpl.java   Source Code and License 5 votes vote down vote up
public static boolean isLiteralExpression(@Nullable PsiElement context) {
  if (context == null) return false;
  final ASTNode astNode = context.getNode();
  if (astNode == null) {
    return false;
  }
  final IElementType elementType = astNode.getElementType();
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
  return parserDefinition.getStringLiteralElements().contains(elementType);
}
 
Example 42
Project: intellij-ce-playground   File: XmlCoreEnvironment.java   Source Code and License 5 votes vote down vote up
public ApplicationEnvironment(CoreApplicationEnvironment appEnvironment) {
  appEnvironment.registerFileType(HtmlFileType.INSTANCE, "html;htm;sht;shtm;shtml");
  appEnvironment.registerFileType(XHtmlFileType.INSTANCE, "xhtml");
  appEnvironment.registerFileType(DTDFileType.INSTANCE, "dtd;ent;mod;elt");

  appEnvironment.registerFileType(XmlFileType.INSTANCE, "xml;xsd;tld;xsl;jnlp;wsdl;jhm;ant;xul;xslt;rng;fxml");

  SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(XMLLanguage.INSTANCE, new XmlSyntaxHighlighterFactory());
  SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(DTDLanguage.INSTANCE, new DtdSyntaxHighlighterFactory());
  SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(HTMLLanguage.INSTANCE, new HtmlSyntaxHighlighterFactory());
  SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(XHTMLLanguage.INSTANCE, new XhtmlSyntaxHighlighterFactory());

  appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, XMLLanguage.INSTANCE, new XMLParserDefinition());
  appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, DTDLanguage.INSTANCE, new DTDParserDefinition());
  appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, HTMLLanguage.INSTANCE, new HTMLParserDefinition());
  appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, XHTMLLanguage.INSTANCE, new XHTMLParserDefinition());

  appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlIdIndexer());
  appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlIdIndexer());
  appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlTodoIndexer());
  appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlTodoIndexer());
  appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, XHtmlFileType.INSTANCE, new XHtmlTodoIndexer());

  appEnvironment.addExtension(MetaDataContributor.EP_NAME, new XmlApplicationComponent());
  appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlNamespaceIndex());
  appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new SchemaTypeInheritanceIndex());
  appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlTagNamesIndex());
  appEnvironment.addExtension(StandardResourceProvider.EP_NAME, new InternalResourceProvider());

  appEnvironment.registerApplicationComponent(PathMacros.class, new PathMacrosImpl());
  appEnvironment.registerApplicationService(ExternalResourceManager.class, new ExternalResourceManagerExImpl());
  appEnvironment.registerApplicationService(XmlFoldingSettings.class, new XmlFoldingSettings());
  Language[] myLanguages = new Language[]{XMLLanguage.INSTANCE, HTMLLanguage.INSTANCE, XHTMLLanguage.INSTANCE, DTDLanguage.INSTANCE};
  for (Language myLanguage : myLanguages) {
    appEnvironment.addExplicitExtension(LanguageFolding.INSTANCE, myLanguage, new XmlFoldingBuilder());
    appEnvironment.addExplicitExtension(LanguageFindUsages.INSTANCE, myLanguage, new XmlFindUsagesProvider());
    appEnvironment.addExplicitExtension(LanguageASTFactory.INSTANCE, myLanguage, new XmlASTFactory());
  }
}
 
Example 43
Project: intellij-ce-playground   File: GradleEditorValueExtractor.java   Source Code and License 5 votes vote down vote up
@Override
public void visitReferenceExpression(GrReferenceExpression expression) {
  if (expression.getParent() instanceof GrMethodCallExpression) {
    // This is a reference expression which points to the method name. We're not interested in it, so, just return.
    return;
  }
  GrExpression qualifier = expression.getQualifierExpression();
  if (qualifier == null) {
    myContext.addCachedVariable(expression.getText(), expression.getTextRange());
    return;
  }
  myContext.rememberVariableQualifier(qualifier.getText());
  PsiElement dotToken = expression.getDotToken();
  if (dotToken == null) {
    return;
  }
  ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.findSingle(GroovyLanguage.INSTANCE);
  for (PsiElement e = dotToken.getNextSibling(); e != null; e = e.getNextSibling()) {
    ASTNode node = e.getNode();
    if (node == null) {
      if (e instanceof PsiWhiteSpace) {
        continue;
      }
      e.accept(myVisitor);
      return;
    }
    IElementType type = node.getElementType();
    if (type == GroovyTokenTypes.mIDENT) {
      myContext.addCachedVariable(e.getText(), e.getTextRange());
    }
    else if (parserDefinition.getWhitespaceTokens().contains(type) || parserDefinition.getCommentTokens().contains(type)) {
      continue;
    }
    else {
      e.accept(myVisitor);
    }
    return;
  }
}
 
Example 44
Project: intellij-ce-playground   File: PropertiesCoreEnvironment.java   Source Code and License 5 votes vote down vote up
public ApplicationEnvironment(CoreApplicationEnvironment appEnvironment) {
  appEnvironment.registerFileType(PropertiesFileType.INSTANCE, "properties");
  appEnvironment.addExplicitExtension(SyntaxHighlighterFactory.LANGUAGE_FACTORY, PropertiesLanguage.INSTANCE,
                                      new PropertiesSyntaxHighlighterFactory());
  appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesParserDefinition());
  appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlPropertiesIndex());
  appEnvironment.addExtension(StubIndexExtension.EP_NAME, new PropertyKeyIndex());

  appEnvironment.registerApplicationService(PropertiesQuickFixFactory.class, new EmptyPropertiesQuickFixFactory());
  appEnvironment.registerApplicationService(PropertiesRefactoringSettings.class, new PropertiesRefactoringSettings());
  appEnvironment.addExplicitExtension(LanguageAnnotators.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesAnnotator());
  appEnvironment.addExplicitExtension(LanguageFindUsages.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesFindUsagesProvider());

  appEnvironment.addExplicitExtension(LanguageASTFactory.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesASTFactory());
  appEnvironment.addExplicitExtension(LanguageFolding.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesFoldingBuilder());
  appEnvironment.addExplicitExtension(ElementManipulators.INSTANCE, PropertyImpl.class, new PropertyManipulator());
  appEnvironment.addExplicitExtension(ElementManipulators.INSTANCE, PropertyKeyImpl.class, new PropertyKeyManipulator());
  appEnvironment.addExplicitExtension(ElementManipulators.INSTANCE, PropertyValueImpl.class, new PropertyValueManipulator());

  final StubElementTypeHolderEP stubElementTypeHolderBean = new StubElementTypeHolderEP();
  stubElementTypeHolderBean.holderClass = PropertiesElementTypes.class.getName();
  appEnvironment.addExtension(StubElementTypeHolderEP.EP_NAME, stubElementTypeHolderBean);

  appEnvironment.addExplicitExtension(LanguageCommenters.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesCommenter());
  appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, PropertiesFileType.INSTANCE, new PropertiesIdIndexer());
  appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, PropertiesFileType.INSTANCE, new PropertiesTodoIndexer());

  appEnvironment.addExtension(IconProvider.EXTENSION_POINT_NAME, new XmlPropertiesIconProvider());
}
 
Example 45
Project: epigraph   File: EpigraphPsiUtil.java   Source Code and License 5 votes vote down vote up
public static @NotNull <T extends PsiElement> T parseText(
    @NotNull String text,
    @NotNull IElementType rootElementType,
    @NotNull Class<T> rootElementClass,
    @NotNull ParserDefinition parserDefinition,
    @Nullable ErrorProcessor errorProcessor) {

  LanguageParserDefinitions.INSTANCE.addExplicitExtension(
      parserDefinition.getFileNodeType().getLanguage(),
      parserDefinition
  );

  PsiParser parser = parserDefinition.createParser(model.first);
  Lexer lexer = parserDefinition.createLexer(model.first);
  PsiBuilderImpl psiBuilder = new PsiBuilderImpl(
      model.first,
      null,
      parserDefinition,
      lexer,
      new CharTableImpl(),
      text,
      null,
      null
  );

  ASTNode astNode = parser.parse(rootElementType, psiBuilder);
  T res = astNode.getPsi(rootElementClass);
  collectErrors(res, errorProcessor);

  return res;
}
 
Example 46
Project: tools-idea   File: JavaCoreApplicationEnvironment.java   Source Code and License 5 votes vote down vote up
public JavaCoreApplicationEnvironment(Disposable parentDisposable) {
  super(parentDisposable);

  registerFileType(JavaClassFileType.INSTANCE, "class");
  registerFileType(JavaFileType.INSTANCE, "java");
  registerFileType(ArchiveFileType.INSTANCE, "jar;zip");

  addExplicitExtension(FileTypeFileViewProviders.INSTANCE, JavaClassFileType.INSTANCE,  new ClassFileViewProviderFactory());
  addExplicitExtension(BinaryFileStubBuilders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileStubBuilder());
  
  addExplicitExtension(LanguageASTFactory.INSTANCE, JavaLanguage.INSTANCE, new CoreJavaASTFactory());
  addExplicitExtension(LanguageParserDefinitions.INSTANCE, JavaLanguage.INSTANCE, new JavaParserDefinition());
  addExplicitExtension(LanguageConstantExpressionEvaluator.INSTANCE, JavaLanguage.INSTANCE, new PsiExpressionEvaluator());

  registerExtensionPoint(Extensions.getRootArea(), ClsStubBuilderFactory.EP_NAME, ClsStubBuilderFactory.class);
  registerExtensionPoint(Extensions.getRootArea(), PsiAugmentProvider.EP_NAME, PsiAugmentProvider.class);
  registerExtensionPoint(Extensions.getRootArea(), JavaMainMethodProvider.EP_NAME, JavaMainMethodProvider.class);
  addExtension(ClsStubBuilderFactory.EP_NAME, new DefaultClsStubBuilderFactory());

  myApplication.registerService(PsiPackageImplementationHelper.class, new CorePsiPackageImplementationHelper());

  myApplication.registerService(EmptySubstitutor.class, new EmptySubstitutorImpl());
  myApplication.registerService(JavaDirectoryService.class, createJavaDirectoryService());
  myApplication.registerService(JavaVersionService.class, new JavaVersionService());

  addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiPackage.class, new PackagePresentationProvider());
  addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiClass.class, new ClassPresentationProvider());
  addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiMethod.class, new MethodPresentationProvider());
  addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiField.class, new FieldPresentationProvider());
  addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiLocalVariable.class, new VariablePresentationProvider());
  addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiParameter.class, new VariablePresentationProvider());
}
 
Example 47
Project: tools-idea   File: JspIndexPatternBuilder.java   Source Code and License 5 votes vote down vote up
@Override
public TokenSet getCommentTokenSet(final PsiFile file) {
  final JspFile jspFile = JspPsiUtil.getJspFile(file);
  TokenSet commentTokens = TokenSet.orSet(JavaIndexPatternBuilder.XML_COMMENT_BIT_SET, StdTokenSets.COMMENT_BIT_SET);
  final ParserDefinition parserDefinition =
    LanguageParserDefinitions.INSTANCE.forLanguage(jspFile.getViewProvider().getTemplateDataLanguage());
  if (parserDefinition != null) {
    commentTokens = TokenSet.orSet(commentTokens, parserDefinition.getCommentTokens());
  }
  return commentTokens;
}
 
Example 48
Project: tools-idea   File: ShiftIndentInsideHelper.java   Source Code and License 5 votes vote down vote up
private static  boolean isComment(final ASTNode node) {
  final PsiElement psiElement = SourceTreeToPsiMap.treeElementToPsi(node);
  if (psiElement instanceof PsiComment) return true;
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(psiElement.getLanguage());
  if (parserDefinition == null) return false;
  final TokenSet commentTokens = parserDefinition.getCommentTokens();
  return commentTokens.contains(node.getElementType());
}
 
Example 49
Project: tools-idea   File: SkipAutopopupInStrings.java   Source Code and License 5 votes vote down vote up
public static boolean isInStringLiteral(PsiElement element) {
  ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(PsiUtilBase.findLanguageFromElement(element));
  if (definition == null) {
    return false;
  }

  return isStringLiteral(element, definition) || isStringLiteral(element.getParent(), definition) ||
          isStringLiteralWithError(element, definition) || isStringLiteralWithError(element.getParent(), definition);
}
 
Example 50
Project: tools-idea   File: SingleRootFileViewProvider.java   Source Code and License 5 votes vote down vote up
@Nullable
protected PsiFile createFile(@NotNull Language lang) {
  if (lang != getBaseLanguage()) return null;
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
  if (parserDefinition != null) {
    return parserDefinition.createFile(this);
  }
  return null;
}
 
Example 51
Project: tools-idea   File: CacheUtil.java   Source Code and License 5 votes vote down vote up
public static boolean isInComments(final IElementType tokenType) {
  final Language language = tokenType.getLanguage();
  boolean inComments = false;

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

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

    if (commentTokens.contains(tokenType)) {
      inComments = true;
    }
  }
  return inComments;
}
 
Example 52
Project: tools-idea   File: PlatformIdTableBuilding.java   Source Code and License 5 votes vote down vote up
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = ourTodoIndexers.get(fileType);

  if (indexer != null) {
    return indexer;
  }

  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer =
      new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), 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);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, virtualFile);
    }
  }

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

  return null;
}
 
Example 53
Project: tools-idea   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) {
    tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInCommentsOnly() ? definition.getCommentTokens(): TokenSet.EMPTY);
    tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInStringLiteralsOnly() ? definition.getStringLiteralElements() : TokenSet.EMPTY);
  }
  return tokensOfInterest;
}
 
Example 54
Project: tools-idea   File: RegExpElementImpl.java   Source Code and License 5 votes vote down vote up
public static boolean isLiteralExpression(@Nullable PsiElement context) {
  if (context == null) return false;
  final ASTNode astNode = context.getNode();
  if (astNode == null) {
    return false;
  }
  final IElementType elementType = astNode.getElementType();
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
  return parserDefinition.getStringLiteralElements().contains(elementType);
}
 
Example 55
Project: tools-idea   File: XmlCoreEnvironment.java   Source Code and License 5 votes vote down vote up
public ApplicationEnvironment(CoreApplicationEnvironment appEnvironment) {
  appEnvironment.registerFileType(HtmlFileType.INSTANCE, "html;htm;sht;shtm;shtml");
  appEnvironment.registerFileType(XHtmlFileType.INSTANCE, "xhtml");
  appEnvironment.registerFileType(DTDFileType.INSTANCE, "dtd;ent;mod;elt");

  appEnvironment.registerFileType(XmlFileType.INSTANCE, "xml;xsd;tld;xsl;jnlp;wsdl;jhm;ant;xul;xslt;rng;fxml");

  appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, XMLLanguage.INSTANCE, new XMLParserDefinition());
  appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, DTDLanguage.INSTANCE, new DTDParserDefinition());
  appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, HTMLLanguage.INSTANCE, new HTMLParserDefinition());
  appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, XHTMLLanguage.INSTANCE, new XHTMLParserDefinition());

  XmlASTFactory astFactory = new XmlASTFactory();
  appEnvironment.addExplicitExtension(LanguageASTFactory.INSTANCE, XMLLanguage.INSTANCE, astFactory);
  appEnvironment.addExplicitExtension(LanguageASTFactory.INSTANCE, HTMLLanguage.INSTANCE, astFactory);
  appEnvironment.addExplicitExtension(LanguageASTFactory.INSTANCE, XHTMLLanguage.INSTANCE, astFactory);
  appEnvironment.addExplicitExtension(LanguageASTFactory.INSTANCE, DTDLanguage.INSTANCE, astFactory);

  appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlIdIndexer());
  appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlIdIndexer());

  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), StartTagEndTokenProvider.EP_NAME, StartTagEndTokenProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlSuppressionProvider.EP_NAME, XmlSuppressionProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlFileNSInfoProvider.EP_NAME, XmlFileNSInfoProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlSchemaProvider.EP_NAME, XmlSchemaProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), ImplicitNamespaceDescriptorProvider.EP_NAME, ImplicitNamespaceDescriptorProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlElementDescriptorProvider.EP_NAME, XmlElementDescriptorProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), Html5SchemaProvider.EP_NAME, Html5SchemaProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlAttributeDescriptorsProvider.EP_NAME, XmlAttributeDescriptorsProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlExtension.EP_NAME, XmlExtension.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), HtmlEmbeddedTokenTypesProvider.EXTENSION_POINT_NAME, HtmlEmbeddedTokenTypesProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), StandardResourceProvider.EP_NAME, StandardResourceProvider.class);
  CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), StandardResourceEP.EP_NAME, StandardResourceEP.class);

  appEnvironment.addExtension(MetaDataContributor.EP_NAME, new XmlApplicationComponent());
  appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlNamespaceIndex());
  appEnvironment.addExtension(StandardResourceProvider.EP_NAME, new InternalResourceProvider());

  appEnvironment.registerApplicationService(ExternalResourceManager.class, createExternalResourceManager());
}
 
Example 56
Project: intellij-latte   File: LatteFileViewProvider.java   Source Code and License 5 votes vote down vote up
@Nullable
protected PsiFile createFile(@NotNull Language lang) {
	ParserDefinition parser = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
	if (parser == null) {
		return null;
	} else if (lang == XMLLanguage.INSTANCE || lang == HTMLLanguage.INSTANCE) {
		PsiFileImpl file = (PsiFileImpl) parser.createFile(this);
		file.setContentElementType(templateDataElement);
		return file;
	} else {
		return lang == this.getBaseLanguage() ? parser.createFile(this) : null;
	}
}
 
Example 57
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 58
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 59
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 60
Project: consulo   File: SkipAutopopupInStrings.java   Source Code and License 5 votes vote down vote up
public static boolean isInStringLiteral(PsiElement element) {
  LanguageVersion languageVersion = PsiUtilCore.findLanguageVersionFromElement(element);

  ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(languageVersion.getLanguage());
  if (definition == null) {
    return false;
  }

  return isStringLiteral(element, definition, languageVersion) || isStringLiteral(element.getParent(), definition, languageVersion) ||
          isStringLiteralWithError(element, definition, languageVersion) || isStringLiteralWithError(element.getParent(), definition, languageVersion);
}