mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-166614 Cannot create enum if project language level is 1.3, but modules are 1.8
This commit is contained in:
@@ -24,11 +24,11 @@ import com.intellij.ide.fileTemplates.JavaTemplateUtil;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.ui.InputValidatorEx;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -51,7 +51,7 @@ public class CreateClassAction extends JavaCreateTemplateInPackageAction<PsiClas
|
||||
.setTitle(IdeBundle.message("action.create.new.class"))
|
||||
.addKind("Class", PlatformIcons.CLASS_ICON, JavaTemplateUtil.INTERNAL_CLASS_TEMPLATE_NAME)
|
||||
.addKind("Interface", PlatformIcons.INTERFACE_ICON, JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME);
|
||||
if (LanguageLevelProjectExtension.getInstance(project).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) {
|
||||
if (PsiUtil.getLanguageLevel(directory).isAtLeast(LanguageLevel.JDK_1_5)) {
|
||||
builder.addKind("Enum", PlatformIcons.ENUM_ICON, JavaTemplateUtil.INTERNAL_ENUM_TEMPLATE_NAME);
|
||||
builder.addKind("Annotation", PlatformIcons.ANNOTATION_TYPE_ICON, JavaTemplateUtil.INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.NotNullLazyKey;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -529,7 +528,7 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
if (originalFile instanceof PsiJavaFile && originalFile != this) {
|
||||
return ((PsiJavaFile)originalFile).getLanguageLevel();
|
||||
}
|
||||
return LanguageLevelProjectExtension.getInstance(project).getLanguageLevel();
|
||||
return LanguageLevel.HIGHEST;
|
||||
}
|
||||
|
||||
return JavaPsiImplementationHelper.getInstance(project).getEffectiveLanguageLevel(virtualFile);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class JavaDirectoryServiceHeavyTest extends JavaCodeInsightFixtureTestCase {
|
||||
public void testCreatingEnumInLanguageLevel3Project() {
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_3);
|
||||
IdeaTestUtil.setModuleLanguageLevel(myModule, LanguageLevel.JDK_1_7);
|
||||
|
||||
PsiDirectory dir = getPsiManager().findDirectory(myFixture.getTempDirFixture().getFile(""));
|
||||
PsiClass createdEnum = JavaDirectoryService.getInstance().createEnum(dir, "Foo");
|
||||
assertTrue(createdEnum.isEnum());
|
||||
assertEquals(LanguageLevel.JDK_1_7, PsiUtil.getLanguageLevel(createdEnum));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user