本文整理汇总了Java中com.intellij.pom.java.LanguageLevel类的典型用法代码示例。如果您正苦于以下问题:Java LanguageLevel类的具体用法?Java LanguageLevel怎么用?Java LanguageLevel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LanguageLevel类属于com.intellij.pom.java包,在下文中一共展示了LanguageLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Override
protected void setUp() throws Exception
{
super.setUp();
IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory();
TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder = factory.createLightFixtureBuilder( getProjectDescriptor() );
IdeaProjectTestFixture fixture = fixtureBuilder.getFixture();
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( fixture, new TempDirTestFixtureImpl() );
myFixture.setUp();
myFixture.setTestDataPath( getTestDataPath() );
myModule = myFixture.getModule();
LanguageLevelProjectExtension.getInstance( getProject() ).setLanguageLevel( LanguageLevel.JDK_1_8 );
}
示例2: checkFunctionalInterface
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Nullable
static HighlightInfo checkFunctionalInterface(@NotNull PsiAnnotation annotation, @NotNull LanguageLevel languageLevel) {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && Comparing.strEqual(annotation.getQualifiedName(), CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE)) {
final PsiAnnotationOwner owner = annotation.getOwner();
if (owner instanceof PsiModifierList) {
final PsiElement parent = ((PsiModifierList)owner).getParent();
if (parent instanceof PsiClass) {
final String errorMessage = LambdaHighlightingUtil.checkInterfaceFunctional((PsiClass)parent, ((PsiClass)parent).getName() + " is not a functional interface");
if (errorMessage != null) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(annotation).descriptionAndTooltip(errorMessage).create();
}
}
}
}
return null;
}
示例3: getJdkHomePath
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Nullable
public static String getJdkHomePath(@NotNull LanguageLevel langLevel) {
Collection<String> jdkHomePaths = new ArrayList<String>(JavaSdk.getInstance().suggestHomePaths());
if (jdkHomePaths.isEmpty()) {
return null;
}
// prefer jdk path of getJavaHome(), since we have to allow access to it in tests
// see AndroidProjectDataServiceTest#testImportData()
final List<String> list = new ArrayList<String>();
String javaHome = SystemProperties.getJavaHome();
if (javaHome != null && !javaHome.isEmpty()) {
for (Iterator<String> it = jdkHomePaths.iterator(); it.hasNext(); ) {
final String path = it.next();
if (path != null && javaHome.startsWith(path)) {
it.remove();
list.add(path);
}
}
}
list.addAll(jdkHomePaths);
return getBestJdkHomePath(list, langLevel);
}
示例4: parseFragment
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Nullable
public static ASTNode parseFragment(final ASTNode chameleon, final ParserWrapper wrapper, final boolean eatAll, final LanguageLevel level) {
final PsiElement psi = (chameleon.getTreeParent() != null ? chameleon.getTreeParent().getPsi() : chameleon.getPsi());
assert psi != null : chameleon;
final Project project = psi.getProject();
final PsiBuilderFactory factory = PsiBuilderFactory.getInstance();
final Lexer lexer = chameleon.getElementType() == JavaDocElementType.DOC_COMMENT
? JavaParserDefinition.createDocLexer(level) : JavaParserDefinition.createLexer(level);
final PsiBuilder builder = factory.createBuilder(project, chameleon, lexer, chameleon.getElementType().getLanguage(), chameleon.getChars());
setLanguageLevel(builder, level);
final PsiBuilder.Marker root = builder.mark();
wrapper.parse(builder);
if (!builder.eof()) {
if (!eatAll) throw new AssertionError("Unexpected tokens");
final PsiBuilder.Marker extras = builder.mark();
while (!builder.eof()) builder.advanceLexer();
extras.error(JavaErrorMessages.message("unexpected.tokens"));
}
root.done(chameleon.getElementType());
return builder.getTreeBuilt().getFirstChildNode();
}
示例5: updateJdk
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
private static void updateJdk(
Project project,
BlazeContext context,
ProjectViewSet projectViewSet,
BlazeProjectData blazeProjectData) {
LanguageLevel javaLanguageLevel =
JavaLanguageLevelHelper.getJavaLanguageLevel(
projectViewSet, blazeProjectData, LanguageLevel.JDK_1_7);
final Sdk sdk = Jdks.chooseOrCreateJavaSdk(javaLanguageLevel);
if (sdk == null) {
String msg =
String.format(
"Unable to find a JDK %1$s installed.\n", javaLanguageLevel.getPresentableText());
msg +=
"After configuring a suitable JDK in the \"Project Structure\" dialog, "
+ "sync the project again.";
IssueOutput.error(msg).submit(context);
return;
}
setProjectSdkAndLanguageLevel(project, sdk, javaLanguageLevel);
}
示例6: visitConditionalExpression
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Override
public void visitConditionalExpression(PsiConditionalExpression expression) {
super.visitConditionalExpression(expression);
if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) && PsiPolyExpressionUtil.isPolyExpression(expression)) {
final PsiExpression thenExpression = expression.getThenExpression();
final PsiExpression elseExpression = expression.getElseExpression();
if (thenExpression != null && elseExpression != null) {
final PsiType conditionalType = expression.getType();
if (conditionalType != null) {
final PsiExpression[] sides = {thenExpression, elseExpression};
for (PsiExpression side : sides) {
final PsiType sideType = side.getType();
if (sideType != null && !TypeConversionUtil.isAssignable(conditionalType, sideType)) {
myHolder.add(HighlightUtil.checkAssignability(conditionalType, sideType, side, side));
}
}
}
}
}
}
示例7: isApplicableTo
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
private boolean isApplicableTo(@NotNull PsiType[] types2AtSite,
@NotNull PsiMethod method1,
@NotNull LanguageLevel languageLevel,
boolean varargsPosition,
@NotNull PsiSubstitutor methodSubstitutor1,
@NotNull PsiMethod method2,
PsiSubstitutor siteSubstitutor1) {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && method1.getTypeParameters().length > 0 && myArgumentsList instanceof PsiExpressionList) {
final PsiElement parent = myArgumentsList.getParent();
if (parent instanceof PsiCallExpression) {
return InferenceSession.isMoreSpecific(method2, method1, siteSubstitutor1, ((PsiExpressionList)myArgumentsList).getExpressions(), myArgumentsList, varargsPosition);
}
}
final PsiUtil.ApplicabilityChecker applicabilityChecker = languageLevel.isAtLeast(LanguageLevel.JDK_1_8)
? new PsiUtil.ApplicabilityChecker() {
@Override
public boolean isApplicable(PsiType left, PsiType right,
boolean allowUncheckedConversion, int argId) {
return isTypeMoreSpecific(left, right, argId);
}
}
: PsiUtil.ApplicabilityChecker.ASSIGNABILITY_CHECKER;
final int applicabilityLevel = PsiUtil.getApplicabilityLevel(method1, methodSubstitutor1, types2AtSite, languageLevel, false, varargsPosition, applicabilityChecker);
return applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
}
示例8: chooseOrCreateJavaSdk
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Nullable
public static Sdk chooseOrCreateJavaSdk(@Nullable LanguageLevel langLevel) {
if (langLevel == null) {
langLevel = DEFAULT_LANG_LEVEL;
}
for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) {
if (isApplicableJdk(sdk, langLevel)) {
return sdk;
}
}
String jdkHomePath = getJdkHomePath(langLevel);
if (jdkHomePath != null) {
return createJdk(jdkHomePath);
}
return null;
}
示例9: LanguageLevelCombo
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
public LanguageLevelCombo(String defaultItem) {
myDefaultItem = defaultItem;
for (LanguageLevel level : LanguageLevel.values()) {
addItem(level);
}
setRenderer(new ColoredListCellRendererWrapper() {
@Override
protected void doCustomize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof LanguageLevel) {
append(((LanguageLevel)value).getPresentableText());
}
else if (value instanceof String) { // default for SDK or project
append((String)value);
LanguageLevel defaultLevel = getDefaultLevel();
if (defaultLevel != null) {
append(" (" + defaultLevel.getPresentableText() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
}
}
}
});
}
示例10: visitLocalVariable
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Override
public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
if (index >= myIgnoreCount) {
// long and double variables increase the index by 2, not by 1
int paramIndex = (index - myIgnoreCount == myUsedParamSize) ? myUsedParamCount : index - myIgnoreCount;
if (paramIndex >= myParamCount) return;
if (ClsParsingUtil.isJavaIdentifier(name, LanguageLevel.HIGHEST)) {
PsiParameterStubImpl parameterStub = myParamStubs[paramIndex];
if (parameterStub != null) {
parameterStub.setName(name);
}
}
myUsedParamCount = paramIndex + 1;
if ("D".equals(desc) || "J".equals(desc)) {
myUsedParamSize += 2;
}
else {
myUsedParamSize++;
}
}
}
示例11: testLanguageLevelChange
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
public void testLanguageLevelChange() {
//noinspection unused
PsiFile psiFile = myFixture.addFileToProject("Foo.java", "class Foo {}");
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
PlatformTestUtil.tryGcSoftlyReachableObjects();
PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass("Foo", scope);
assertNotNull(psiClass);
long count = PsiManager.getInstance(getProject()).getModificationTracker().getJavaStructureModificationCount();
IdeaTestUtil.setModuleLanguageLevel(myFixture.getModule(), LanguageLevel.JDK_1_3);
assertTrue(count != PsiManager.getInstance(getProject()).getModificationTracker().getJavaStructureModificationCount());
psiClass = (JavaPsiFacade.getInstance(getProject()).findClass("Foo", scope));
assertNotNull(psiClass);
assertTrue(psiClass.isValid());
}
示例12: VariableResolverProcessor
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
public VariableResolverProcessor(@NotNull PsiJavaCodeReferenceElement place, @NotNull PsiFile placeFile) {
super(place.getReferenceName(), ourFilter, new PsiConflictResolver[]{new JavaVariableConflictResolver()}, new SmartList<CandidateInfo>(), place, placeFile);
PsiClass access = null;
PsiElement qualifier = place.getQualifier();
if (qualifier instanceof PsiExpression) {
final JavaResolveResult accessClass = PsiUtil.getAccessObjectClass((PsiExpression)qualifier);
final PsiElement element = accessClass.getElement();
if (element instanceof PsiTypeParameter) {
PsiElementFactory factory = JavaPsiFacade.getInstance(placeFile.getProject()).getElementFactory();
final PsiClassType type = factory.createType((PsiTypeParameter)element);
final PsiType accessType = accessClass.getSubstitutor().substitute(type);
if (accessType instanceof PsiArrayType) {
LanguageLevel languageLevel = PsiUtil.getLanguageLevel(placeFile);
access = factory.getArrayClass(languageLevel);
}
else if (accessType instanceof PsiClassType) {
access = ((PsiClassType)accessType).resolve();
}
}
else if (element instanceof PsiClass) {
access = (PsiClass)element;
}
}
myAccessClass = access;
}
示例13: fun
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Override
@Nullable
public PsiType fun(final PsiMethodCallExpression call) {
PsiReferenceExpression methodExpression = call.getMethodExpression();
PsiType theOnly = null;
final JavaResolveResult[] results = methodExpression.multiResolve(false);
LanguageLevel languageLevel = PsiUtil.getLanguageLevel(call);
for (int i = 0; i < results.length; i++) {
final PsiType type = getResultType(call, methodExpression, results[i], languageLevel);
if (type == null) {
return null;
}
if (i == 0) {
theOnly = type;
}
else if (!theOnly.equals(type)) {
return null;
}
}
return PsiClassImplUtil.correctType(theOnly, call.getResolveScope());
}
示例14: setUpModule
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Override
protected void setUpModule() {
super.setUpModule();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
final String modulePath = getTestAppPath();
final String srcPath = modulePath + File.separator + "src";
VirtualFile moduleDir = LocalFileSystem.getInstance().findFileByPath(modulePath.replace(File.separatorChar, '/'));
VirtualFile srcDir = LocalFileSystem.getInstance().findFileByPath(srcPath.replace(File.separatorChar, '/'));
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
PsiTestUtil.removeAllRoots(myModule, rootManager.getSdk());
PsiTestUtil.addContentRoot(myModule, moduleDir);
PsiTestUtil.addSourceRoot(myModule, srcDir);
IdeaTestUtil.setModuleLanguageLevel(myModule, LanguageLevel.JDK_1_8);
PsiTestUtil.setCompilerOutputPath(myModule, VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(myModuleOutputDir.getAbsolutePath())), false);
}
});
}
示例15: value
import com.intellij.pom.java.LanguageLevel; //导入依赖的package包/类
@Override
public boolean value(PsiElement expression) {
if (!(expression instanceof PsiExpression)) return false;
PsiType type = ((PsiExpression)expression).getType();
if (type == null) return false;
if (PsiType.INT.isAssignableFrom(type)) return true;
if (type instanceof PsiClassType) {
PsiClass psiClass = ((PsiClassType)type).resolve();
if (psiClass != null && psiClass.isEnum()) return true;
}
if (type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
PsiFile containingFile = expression.getContainingFile();
if (containingFile instanceof PsiJavaFile) {
LanguageLevel level = ((PsiJavaFile)containingFile).getLanguageLevel();
if (level.isAtLeast(LanguageLevel.JDK_1_7)) return true;
}
}
return false;
}