@Nullable private static Commenter findCommenter(Editor editor, PsiFile file, final int line) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter(); } Document document = editor.getDocument(); int lineStartOffset = document.getLineStartOffset(line); int lineEndOffset = document.getLineEndOffset(line) - 1; final CharSequence charSequence = document.getCharsSequence(); lineStartOffset = CharArrayUtil.shiftForward(charSequence, lineStartOffset, " \t"); lineEndOffset = CharArrayUtil.shiftBackward(charSequence, lineEndOffset < 0 ? 0 : lineEndOffset, " \t"); final Language lineStartLanguage = PsiUtilCore.getLanguageAtOffset(file, lineStartOffset); final Language lineEndLanguage = PsiUtilCore.getLanguageAtOffset(file, lineEndOffset); return CommentByBlockCommentHandler.getCommenter(file, editor, lineStartLanguage, lineEndLanguage); }
@Nullable private Commenter findCommenter(final int line) { final FileType fileType = myFile.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter(); } int lineStartOffset = myDocument.getLineStartOffset(line); int lineEndOffset = myDocument.getLineEndOffset(line) - 1; final CharSequence charSequence = myDocument.getCharsSequence(); lineStartOffset = CharArrayUtil.shiftForward(charSequence, lineStartOffset, " \t"); lineEndOffset = CharArrayUtil.shiftBackward(charSequence, lineEndOffset < 0 ? 0 : lineEndOffset, " \t"); final Language lineStartLanguage = PsiUtilBase.getLanguageAtOffset(myFile, lineStartOffset); final Language lineEndLanguage = PsiUtilBase.getLanguageAtOffset(myFile, lineEndOffset); return CommentByBlockCommentHandler.getCommenter(myFile, myEditor, lineStartLanguage, lineEndLanguage); }
private static void init(final AbstractFileType abstractFileType) { SyntaxTable table = abstractFileType.getSyntaxTable(); CompletionUtil.registerCompletionData(abstractFileType,new SyntaxTableCompletionData(table)); if (!isEmpty(table.getStartComment()) && !isEmpty(table.getEndComment()) || !isEmpty(table.getLineComment())) { abstractFileType.setCommenter(new MyCommenter(abstractFileType)); } if (table.isHasBraces() || table.isHasBrackets() || table.isHasParens()) { BraceMatchingUtil.registerBraceMatcher(abstractFileType,new CustomFileTypeBraceMatcher()); } TypedHandler.registerQuoteHandler(abstractFileType, new CustomFileTypeQuoteHandler()); }
@RequiredReadAction @Nullable @Override public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor) { if (file.getFileType() != PlainTextFileType.INSTANCE && !(file.getFileType() instanceof AbstractFileType)) return null; final String extension = file.getExtension(); if (extension == null) { return null; } if (myEnabledExtensions.contains(extension) || UnknownFeaturesCollector.getInstance(myProject).isIgnored(createFileFeatureForIgnoring(file))) return null; UnknownExtension fileFeatureForChecking = new UnknownExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP.getName(), file.getName()); List<IdeaPluginDescriptor> allPlugins = PluginsAdvertiserHolder.getLoadedPluginDescriptors(); Set<IdeaPluginDescriptor> byFeature = PluginsAdvertiser.findByFeature(allPlugins, fileFeatureForChecking); if (!byFeature.isEmpty()) { return createPanel(file, byFeature, allPlugins); } return null; }
public void testInsertDeleteQuotes() throws Exception { configureByFile(BASE_PATH + "InsertDeleteQuote.cs"); EditorTestUtil.performTypingAction(getEditor(), '"'); checkResultByFile(BASE_PATH + "InsertDeleteQuote_after.cs"); configureByFile(BASE_PATH+"InsertDeleteQuote_after.cs"); EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR); checkResultByFile(BASE_PATH+"InsertDeleteQuote.cs"); FileType extension = FileTypeManager.getInstance().getFileTypeByExtension("pl"); assertTrue("Test is not set up correctly:"+extension, extension instanceof AbstractFileType); configureByFile(BASE_PATH + "InsertDeleteQuote.pl"); EditorTestUtil.performTypingAction(getEditor(), '"'); checkResultByFile(BASE_PATH + "InsertDeleteQuote_after.pl"); configureByFile(BASE_PATH+"InsertDeleteQuote_after.pl"); EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR); checkResultByFile(BASE_PATH+"InsertDeleteQuote.pl"); configureByFile(BASE_PATH + "InsertDeleteQuote.aj"); EditorTestUtil.performTypingAction(getEditor(), '"'); checkResultByFile(BASE_PATH + "InsertDeleteQuote_after.aj"); configureByFile(BASE_PATH+"InsertDeleteQuote_after.aj"); EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR); checkResultByFile(BASE_PATH+"InsertDeleteQuote.aj"); }
@Override public void applyEditorTo(AbstractFileType type) throws ConfigurationException { if (myFileTypeName.getText().trim().length() == 0) { throw new ConfigurationException(IdeBundle.message("error.name.cannot.be.empty"), CommonBundle.getErrorTitle()); } else if (myFileTypeDescr.getText().trim().length() == 0) { myFileTypeDescr.setText(myFileTypeName.getText()); } type.setName(myFileTypeName.getText()); type.setDescription(myFileTypeDescr.getText()); type.setSyntaxTable(getSyntaxTable()); }
@Override protected boolean isValidFor(@NotNull Project project, @NotNull Editor editor, @NotNull Caret caret, @NotNull final PsiFile file) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter() != null; } Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(file.getLanguage()); if (commenter == null) commenter = LanguageCommenters.INSTANCE.forLanguage(file.getViewProvider().getBaseLanguage()); if (commenter == null) return false; return commenter.getBlockCommentPrefix() != null && commenter.getBlockCommentSuffix() != null; }
@Override protected boolean isValidFor(@NotNull Project project, @NotNull Editor editor, @NotNull Caret caret, @NotNull final PsiFile file) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter() != null; } if (LanguageCommenters.INSTANCE.forLanguage(file.getLanguage()) != null || LanguageCommenters.INSTANCE.forLanguage(file.getViewProvider().getBaseLanguage()) != null) return true; PsiElement host = InjectedLanguageManager.getInstance(project).getInjectionHost(file); return host != null && LanguageCommenters.INSTANCE.forLanguage(host.getLanguage()) != null; }
@Nullable private static Commenter findCommenter(PsiFile file, Editor editor, Caret caret) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter(); } Language lang = PsiUtilBase.getLanguageInEditor(caret, file.getProject()); return getCommenter(file, editor, lang, lang); }
private static void init(final AbstractFileType abstractFileType) { SyntaxTable table = abstractFileType.getSyntaxTable(); if (!isEmpty(table.getStartComment()) && !isEmpty(table.getEndComment()) || !isEmpty(table.getLineComment())) { abstractFileType.setCommenter(new MyCommenter(abstractFileType)); } if (table.isHasBraces() || table.isHasBrackets() || table.isHasParens()) { BraceMatchingUtil.registerBraceMatcher(abstractFileType, CustomFileTypeBraceMatcher.createBraceMatcher()); } TypedHandler.registerQuoteHandler(abstractFileType, new CustomFileTypeQuoteHandler()); }
@Override @Nullable public SyntaxHighlighter create(@NotNull final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { if (fileType instanceof AbstractFileType) { return new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable()); } return null; }
public void applyEditorTo(AbstractFileType type) throws ConfigurationException { if (myFileTypeName.getText().trim().length() == 0) { throw new ConfigurationException(IdeBundle.message("error.name.cannot.be.empty"), CommonBundle.getErrorTitle()); } else if (myFileTypeDescr.getText().trim().length() == 0) { myFileTypeDescr.setText(myFileTypeName.getText()); } type.setName(myFileTypeName.getText()); type.setDescription(myFileTypeDescr.getText()); type.setSyntaxTable(getSyntaxTable()); }
@Override protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull final PsiFile file) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter() != null; } Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(file.getLanguage()); if (commenter == null) commenter = LanguageCommenters.INSTANCE.forLanguage(file.getViewProvider().getBaseLanguage()); if (commenter == null) return false; return commenter.getBlockCommentPrefix() != null && commenter.getBlockCommentSuffix() != null; }
@Override protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull final PsiFile file) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter() != null; } return LanguageCommenters.INSTANCE.forLanguage(file.getLanguage()) != null || LanguageCommenters.INSTANCE.forLanguage(file.getViewProvider().getBaseLanguage()) != null; }
@Nullable private static Commenter findCommenter(PsiFile file, Editor editor) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter(); } Language lang = PsiUtilBase.getLanguageInEditor(editor, file.getProject()); return getCommenter(file, editor, lang, lang); }
@Override @Nullable public SyntaxHighlighter create(final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { if (fileType instanceof AbstractFileType) { return new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable()); } return null; }
@Nullable private static Commenter findCommenter(@Nonnull Editor editor, @Nonnull PsiFile file, final int line) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter(); } final Language lineStartLanguage = getLineStartLanguage(editor, file, line); final Language lineEndLanguage = getLineEndLanguage(file, editor, line); return CommentByBlockCommentHandler.getCommenter(file, editor, lineStartLanguage, lineEndLanguage); }
@Override protected boolean isValidFor(@Nonnull Project project, @Nonnull Editor editor, @Nonnull Caret caret, @Nonnull final PsiFile file) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter() != null; } Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(file.getLanguage()); if (commenter == null) commenter = LanguageCommenters.INSTANCE.forLanguage(file.getViewProvider().getBaseLanguage()); if (commenter == null) return false; return commenter.getBlockCommentPrefix() != null && commenter.getBlockCommentSuffix() != null; }
@Override protected boolean isValidFor(@Nonnull Project project, @Nonnull Editor editor, @Nonnull Caret caret, @Nonnull final PsiFile file) { final FileType fileType = file.getFileType(); if (fileType instanceof AbstractFileType) { return ((AbstractFileType)fileType).getCommenter() != null; } if (LanguageCommenters.INSTANCE.forLanguage(file.getLanguage()) != null || LanguageCommenters.INSTANCE.forLanguage(file.getViewProvider().getBaseLanguage()) != null) return true; PsiElement host = InjectedLanguageManager.getInstance(project).getInjectionHost(file); return host != null && LanguageCommenters.INSTANCE.forLanguage(host.getLanguage()) != null; }
@Override public void initFileType(final FileType fileType) { if (fileType instanceof AbstractFileType) { init(((AbstractFileType)fileType)); } }
@Override public SchemesManager<FileType, AbstractFileType> getSchemesManager() { return SchemesManager.EMPTY; }
public abstract SchemesManager<FileType, AbstractFileType> getSchemesManager();