use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.
the class Java15APIUsageInspectionBase method getLastIncompatibleLanguageLevel.
public static LanguageLevel getLastIncompatibleLanguageLevel(@NotNull PsiMember member, @NotNull LanguageLevel languageLevel) {
if (member instanceof PsiAnonymousClass)
return null;
PsiClass containingClass = member.getContainingClass();
if (containingClass instanceof PsiAnonymousClass)
return null;
if (member instanceof PsiClass && !(member.getParent() instanceof PsiClass || member.getParent() instanceof PsiFile))
return null;
Set<String> forbiddenApi = getForbiddenApi(languageLevel);
String signature = getSignature(member);
if (forbiddenApi != null && signature != null) {
LanguageLevel lastIncompatibleLanguageLevel = getLastIncompatibleLanguageLevelForSignature(signature, languageLevel, forbiddenApi);
if (lastIncompatibleLanguageLevel != null)
return lastIncompatibleLanguageLevel;
}
return containingClass != null ? getLastIncompatibleLanguageLevel(containingClass, languageLevel) : null;
}
use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.
the class JavaTreeGenerator method generateTreeFor.
@Override
@Nullable
public TreeElement generateTreeFor(@NotNull PsiElement original, @NotNull final CharTable table, @NotNull final PsiManager manager) {
if (original instanceof PsiKeyword || original instanceof PsiIdentifier) {
final String text = original.getText();
return createLeafFromText(text, table, manager, original, ((PsiJavaToken) original).getTokenType());
}
if (original instanceof PsiModifierList) {
final String text = original.getText();
assert text != null : "Text is null for " + original + "; " + original.getClass();
final LanguageLevel level = PsiUtil.getLanguageLevel(original);
final DummyHolder holder = DummyHolderFactory.createHolder(original.getManager(), new JavaDummyElement(text, MOD_LIST, level), null);
final TreeElement modifierListElement = holder.getTreeElement().getFirstChildNode();
if (modifierListElement == null) {
throw new AssertionError("No modifier list for \"" + text + '\"');
}
return markGeneratedIfNeeded(original, modifierListElement);
}
if (original instanceof PsiReferenceExpression) {
TreeElement element = createReferenceExpression(original.getProject(), original.getText(), original);
PsiElement refElement = ((PsiJavaCodeReferenceElement) original).resolve();
if (refElement instanceof PsiClass) {
element.putCopyableUserData(REFERENCED_CLASS_KEY, (PsiClass) refElement);
}
return element;
}
if (original instanceof PsiJavaCodeReferenceElement) {
PsiElement refElement = ((PsiJavaCodeReferenceElement) original).resolve();
final boolean generated = refElement != null && CodeEditUtil.isNodeGenerated(refElement.getNode());
if (refElement instanceof PsiClass) {
if (refElement instanceof PsiAnonymousClass) {
PsiJavaCodeReferenceElement ref = ((PsiAnonymousClass) refElement).getBaseClassReference();
original = ref;
refElement = ref.resolve();
}
boolean isFQ = false;
if (original instanceof PsiJavaCodeReferenceElementImpl) {
int kind = ((PsiJavaCodeReferenceElementImpl) original).getKind(original.getContainingFile());
switch(kind) {
case PsiJavaCodeReferenceElementImpl.CLASS_OR_PACKAGE_NAME_KIND:
case PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND:
case PsiJavaCodeReferenceElementImpl.CLASS_IN_QUALIFIED_NEW_KIND:
isFQ = false;
break;
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_NAME_KIND:
case PsiJavaCodeReferenceElementImpl.CLASS_FQ_OR_PACKAGE_NAME_KIND:
isFQ = true;
break;
default:
LOG.assertTrue(false);
}
}
final String text = isFQ ? ((PsiClass) refElement).getQualifiedName() : original.getText();
final TreeElement element = createReference(original.getProject(), text, generated);
element.putCopyableUserData(REFERENCED_CLASS_KEY, (PsiClass) refElement);
return element;
}
return createReference(original.getProject(), original.getText(), generated);
}
if (original instanceof PsiCompiledElement) {
PsiElement sourceVersion = original.getNavigationElement();
if (sourceVersion != original) {
return ChangeUtil.generateTreeElement(sourceVersion, table, manager);
}
PsiElement mirror = ((PsiCompiledElement) original).getMirror();
return ChangeUtil.generateTreeElement(mirror, table, manager);
}
if (original instanceof PsiTypeElement) {
PsiTypeElement typeElement = (PsiTypeElement) original;
PsiType type = typeElement.getType();
if (type instanceof PsiIntersectionType) {
type = ((PsiIntersectionType) type).getRepresentative();
} else if (type instanceof PsiMethodReferenceType || type instanceof PsiLambdaExpressionType) {
type = PsiType.getJavaLangObject(manager, GlobalSearchScope.projectScope(manager.getProject()));
}
String text = type.getCanonicalText(true);
PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(original.getProject()).getParserFacade();
PsiTypeElement element = parserFacade.createTypeElementFromText(text, original);
TreeElement result = (TreeElement) element.getNode();
markGeneratedIfNeeded(original, result);
encodeInfoInTypeElement(result, type);
return result;
}
return null;
}
use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.
the class PsiJavaFileBaseImpl method getLanguageLevelInner.
private LanguageLevel getLanguageLevelInner() {
if (myOriginalFile instanceof PsiJavaFile) {
return ((PsiJavaFile) myOriginalFile).getLanguageLevel();
}
LanguageLevel forcedLanguageLevel = getUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY);
if (forcedLanguageLevel != null)
return forcedLanguageLevel;
VirtualFile virtualFile = getVirtualFile();
if (virtualFile == null)
virtualFile = getUserData(IndexingDataKeys.VIRTUAL_FILE);
final Project project = getProject();
if (virtualFile == null) {
final PsiFile originalFile = getOriginalFile();
if (originalFile instanceof PsiJavaFile && originalFile != this) {
return ((PsiJavaFile) originalFile).getLanguageLevel();
}
return LanguageLevel.HIGHEST;
}
return JavaPsiImplementationHelper.getInstance(project).getEffectiveLanguageLevel(virtualFile);
}
use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.
the class KeywordCompletionTest method testPrivateInJava9Interface.
public void testPrivateInJava9Interface() throws Exception {
LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject());
LanguageLevel oldLevel = levelProjectExtension.getLanguageLevel();
try {
levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_9);
doTest(false);
} finally {
levelProjectExtension.setLanguageLevel(oldLevel);
}
}
use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.
the class ExtractMethodTest method doTestWithJava17.
private void doTestWithJava17() throws Exception {
LanguageLevelProjectExtension projectExtension = LanguageLevelProjectExtension.getInstance(getProject());
LanguageLevel oldLevel = projectExtension.getLanguageLevel();
try {
projectExtension.setLanguageLevel(LanguageLevel.JDK_1_7);
doTest();
} finally {
projectExtension.setLanguageLevel(oldLevel);
}
}
Aggregations