diff --git a/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java b/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java index cec7c4a148b2..c4d13696308f 100644 --- a/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java +++ b/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package com.intellij.ide.highlighter; import com.intellij.lexer.JavaHighlightingLexer; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.HighlighterColors; -import com.intellij.openapi.editor.SyntaxHighlighterColors; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; import com.intellij.pom.java.LanguageLevel; @@ -39,21 +38,11 @@ public class JavaFileHighlighter extends SyntaxHighlighterBase { private static final Map ourMap1; private static final Map ourMap2; - private final LanguageLevel myLanguageLevel; - - public JavaFileHighlighter() { - this(LanguageLevel.HIGHEST); - } - - public JavaFileHighlighter(LanguageLevel languageLevel) { - myLanguageLevel = languageLevel; - } - static { ourMap1 = new HashMap(); ourMap2 = new HashMap(); - fillMap(ourMap1, ElementType.KEYWORD_BIT_SET, JavaHighlightingColors .KEYWORD); + fillMap(ourMap1, ElementType.KEYWORD_BIT_SET, JavaHighlightingColors.KEYWORD); fillMap(ourMap1, ElementType.LITERAL_BIT_SET, JavaHighlightingColors.KEYWORD); fillMap(ourMap1, ElementType.OPERATION_BIT_SET, JavaHighlightingColors.OPERATION_SIGN); @@ -96,25 +85,28 @@ public class JavaFileHighlighter extends SyntaxHighlighterBase { ourMap1.put(JavaDocTokenType.DOC_TAG_NAME, JavaHighlightingColors.DOC_COMMENT); ourMap2.put(JavaDocTokenType.DOC_TAG_NAME, JavaHighlightingColors.DOC_COMMENT_TAG); - IElementType[] javaDocMarkup = new IElementType[]{XmlTokenType.XML_START_TAG_START, - XmlTokenType.XML_END_TAG_START, - XmlTokenType.XML_TAG_END, - XmlTokenType.XML_EMPTY_ELEMENT_END, - XmlTokenType.TAG_WHITE_SPACE, - XmlTokenType.XML_TAG_NAME, - XmlTokenType.XML_NAME, - XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN, - XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER, - XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER, - XmlTokenType.XML_CHAR_ENTITY_REF, - XmlTokenType.XML_EQ}; - + IElementType[] javaDocMarkup = { + XmlTokenType.XML_START_TAG_START, XmlTokenType.XML_END_TAG_START, XmlTokenType.XML_TAG_END, XmlTokenType.XML_EMPTY_ELEMENT_END, + XmlTokenType.TAG_WHITE_SPACE, XmlTokenType.XML_TAG_NAME, XmlTokenType.XML_NAME, XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN, + XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER, XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER, XmlTokenType.XML_CHAR_ENTITY_REF, + XmlTokenType.XML_EQ + }; for (IElementType idx : javaDocMarkup) { ourMap1.put(idx, JavaHighlightingColors.DOC_COMMENT); ourMap2.put(idx, JavaHighlightingColors.DOC_COMMENT_MARKUP); } } + private final LanguageLevel myLanguageLevel; + + public JavaFileHighlighter() { + this(LanguageLevel.HIGHEST); + } + + public JavaFileHighlighter(@NotNull LanguageLevel languageLevel) { + myLanguageLevel = languageLevel; + } + @NotNull public Lexer getHighlightingLexer() { return new JavaHighlightingLexer(myLanguageLevel); diff --git a/java/openapi/src/com/intellij/openapi/module/LanguageLevelUtil.java b/java/openapi/src/com/intellij/openapi/module/LanguageLevelUtil.java index 1fa919bef956..39028e7a26da 100644 --- a/java/openapi/src/com/intellij/openapi/module/LanguageLevelUtil.java +++ b/java/openapi/src/com/intellij/openapi/module/LanguageLevelUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,43 +15,26 @@ */ package com.intellij.openapi.module; -import com.intellij.openapi.projectRoots.JavaSdk; -import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author yole */ public class LanguageLevelUtil extends EffectiveLanguageLevelUtil { - private LanguageLevelUtil() { - } + private LanguageLevelUtil() { } @NotNull - public static LanguageLevel getLanguageLevelForFile(final VirtualFile file) { + public static LanguageLevel getLanguageLevelForFile(@Nullable VirtualFile file) { if (file == null) return LanguageLevel.HIGHEST; if (file.isDirectory()) { - final LanguageLevel ll = file.getUserData(LanguageLevel.KEY); - return ll != null ? ll : LanguageLevel.HIGHEST; + LanguageLevel languageLevel = file.getUserData(LanguageLevel.KEY); + return languageLevel != null ? languageLevel : LanguageLevel.HIGHEST; } return getLanguageLevelForFile(file.getParent()); } - - /** - * @deprecated use {@link com.intellij.openapi.projectRoots.JavaSdkVersion#getMaxLanguageLevel()} instead - */ - public static LanguageLevel getDefaultLanguageLevel(@NotNull String versionString) { - JavaSdkVersion version = JavaSdk.getInstance().getVersion(versionString); - return version != null ? version.getMaxLanguageLevel() : LanguageLevel.JDK_1_3; - } - - /** - * @deprecated use {@link com.intellij.openapi.projectRoots.JavaSdkVersion#isAtLeast(com.intellij.openapi.projectRoots.JavaSdkVersion)} instead - */ - public static boolean isOfVersionOrHigher(@NotNull String versionString, String checkedVersion) { - return JavaSdk.getInstance().compareTo(versionString, checkedVersion) >= 0; - } } diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java index a3fcf0749ed1..a6cf7a35de95 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java +++ b/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,23 +17,23 @@ package com.intellij.openapi.fileTypes; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; /** * Controls the syntax highlighting of a file. * - * @see com.intellij.openapi.fileTypes.SyntaxHighlighterFactory#getSyntaxHighlighter(com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile) - * @see com.intellij.openapi.fileTypes.SyntaxHighlighterFactory#getSyntaxHighlighter(com.intellij.lang.Language, com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile) + * @see SyntaxHighlighterFactory#getSyntaxHighlighter(com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile) + * @see SyntaxHighlighterFactory#getSyntaxHighlighter(com.intellij.lang.Language, com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile) */ public interface SyntaxHighlighter { /** * @deprecated - * @see com.intellij.openapi.fileTypes.SyntaxHighlighterFactory#getSyntaxHighlighter(com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile) - * @see com.intellij.openapi.fileTypes.SyntaxHighlighterFactory#getSyntaxHighlighter(com.intellij.lang.Language, com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile) + * @see SyntaxHighlighterFactory#getSyntaxHighlighter(com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile) + * @see SyntaxHighlighterFactory#getSyntaxHighlighter(com.intellij.lang.Language, com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile) */ - @Deprecated SyntaxHighlighterProvider PROVIDER = new FileTypeExtensionFactory(SyntaxHighlighterProvider.class, "com.intellij.syntaxHighlighter").get(); + SyntaxHighlighterProvider PROVIDER = + new FileTypeExtensionFactory(SyntaxHighlighterProvider.class, "com.intellij.syntaxHighlighter").get(); /** * Returns the lexer used for highlighting the file. The lexer is invoked incrementally when the file is changed, so it must be diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java index bc27f5975396..ad697f946707 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java +++ b/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,45 +13,45 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * @author max - */ package com.intellij.openapi.fileTypes; import com.intellij.lang.Language; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * @author max + */ public abstract class SyntaxHighlighterFactory { public static final SyntaxHighlighterLanguageFactory LANGUAGE_FACTORY = new SyntaxHighlighterLanguageFactory(); /** * Returns syntax highlighter for the given language. - * @param lang a {@code Language} to get highlighter for - * @param project might be necessary to gather various project settings from - * @param virtualFile might be necessary to collect file specific settings + * + * @param language a {@code Language} to get highlighter for + * @param project might be necessary to gather various project settings from + * @param file might be necessary to collect file specific settings * @return {@code SyntaxHighlighter} interface implementation for the given file type */ - public static SyntaxHighlighter getSyntaxHighlighter(@NotNull Language lang, @Nullable Project project, @Nullable final VirtualFile virtualFile) { - return LANGUAGE_FACTORY.forLanguage(lang).getSyntaxHighlighter(project, virtualFile); + public static SyntaxHighlighter getSyntaxHighlighter(@NotNull Language language, @Nullable Project project, @Nullable VirtualFile file) { + return LANGUAGE_FACTORY.forLanguage(language).getSyntaxHighlighter(project, file); } /** * Returns syntax highlighter for the given file type. * Note: it is recommended to use {@link #getSyntaxHighlighter(Language, Project, VirtualFile)} in most cases, * and use this method only when you are do not know the language you use. + * * @param fileType a file type to use to select appropriate highlighter - * @param project might be necessary to gather various project settings from - * @param virtualFile might be necessary to collect file specific settings + * @param project might be necessary to gather various project settings from + * @param file might be necessary to collect file specific settings * @return {@code SyntaxHighlighter} interface implementation for the given file type */ @Nullable - public static SyntaxHighlighter getSyntaxHighlighter(final FileType fileType, final @Nullable Project project, final @Nullable VirtualFile virtualFile) { - return SyntaxHighlighter.PROVIDER.create(fileType, project, virtualFile); + public static SyntaxHighlighter getSyntaxHighlighter(FileType fileType, @Nullable Project project, @Nullable VirtualFile file) { + return SyntaxHighlighter.PROVIDER.create(fileType, project, file); } /** @@ -61,7 +61,7 @@ public abstract class SyntaxHighlighterFactory { *

* Default implementation doesn't highlight anything. * - * @param project might be necessary to gather various project settings from. + * @param project might be necessary to gather various project settings from. * @param virtualFile might be necessary to collect file specific settings * @return SyntaxHighlighter interface implementation for this particular language. */ diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java index daee8d0e0e23..2fff109a3193 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,14 +57,13 @@ public class EditorHighlighterFactoryImpl extends EditorHighlighterFactory { } @Override - public EditorHighlighter createEditorHighlighter(@NotNull final VirtualFile vFile, @NotNull final EditorColorsScheme settings, @Nullable final Project project) { - final FileType fileType = vFile.getFileType(); + public EditorHighlighter createEditorHighlighter(@NotNull VirtualFile vFile, @NotNull EditorColorsScheme settings, @Nullable Project project) { + FileType fileType = vFile.getFileType(); if (fileType instanceof LanguageFileType) { LanguageFileType substFileType = substituteFileType(((LanguageFileType)fileType).getLanguage(), vFile, project); if (substFileType != null) { - final EditorHighlighter editorHighlighter = FileTypeEditorHighlighterProviders.INSTANCE.forFileType(substFileType).getEditorHighlighter(project, - fileType, - vFile, settings); + EditorHighlighterProvider provider = FileTypeEditorHighlighterProviders.INSTANCE.forFileType(substFileType); + EditorHighlighter editorHighlighter = provider.getEditorHighlighter(project, fileType, vFile, settings); boolean isPlain = editorHighlighter.getClass() == LexerEditorHighlighter.class && ((LexerEditorHighlighter) editorHighlighter).isPlain(); if (!isPlain) { @@ -74,9 +73,8 @@ public class EditorHighlighterFactoryImpl extends EditorHighlighterFactory { return FileTypeEditorHighlighterProviders.INSTANCE.forFileType(fileType).getEditorHighlighter(project, fileType, vFile, settings); } - final ContentBasedFileSubstitutor[] processors = Extensions.getExtensions(ContentBasedFileSubstitutor.EP_NAME); SyntaxHighlighter highlighter = null; - for (ContentBasedFileSubstitutor processor : processors) { + for (ContentBasedFileSubstitutor processor : Extensions.getExtensions(ContentBasedFileSubstitutor.EP_NAME)) { boolean applicable; try { applicable = processor.isApplicable(project, vFile); @@ -97,16 +95,14 @@ public class EditorHighlighterFactoryImpl extends EditorHighlighterFactory { @Nullable private static LanguageFileType substituteFileType(Language language, VirtualFile vFile, Project project) { + LanguageFileType fileType = null; if (vFile != null && project != null) { - final Language substLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, vFile, project); + Language substLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, vFile, project); if (substLanguage != language) { - final FileType fileType = substLanguage.getAssociatedFileType(); - if (fileType instanceof LanguageFileType) { - return (LanguageFileType) fileType; - } + fileType = substLanguage.getAssociatedFileType(); } } - return null; + return fileType; } @Override