本文整理汇总了Java中com.intellij.openapi.projectRoots.JavaVersionService类的典型用法代码示例。如果您正苦于以下问题:Java JavaVersionService类的具体用法?Java JavaVersionService怎么用?Java JavaVersionService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaVersionService类属于com.intellij.openapi.projectRoots包,在下文中一共展示了JavaVersionService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTopLevelClass
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
private static PsiClass getTopLevelClass(@NotNull PsiElement place, PsiClass memberClass) {
PsiClass lastClass = null;
Boolean isAtLeast17 = null;
for (PsiElement placeParent = place; placeParent != null; placeParent = placeParent.getContext()) {
if (placeParent instanceof PsiClass && !(placeParent instanceof PsiAnonymousClass)) {
final boolean isTypeParameter = placeParent instanceof PsiTypeParameter;
if (isTypeParameter && isAtLeast17 == null) {
isAtLeast17 = JavaVersionService.getInstance().isAtLeast(placeParent, JavaSdkVersion.JDK_1_7);
}
if (!isTypeParameter || isAtLeast17) {
PsiClass aClass = (PsiClass)placeParent;
if (memberClass != null && aClass.isInheritor(memberClass, true)) return aClass;
lastClass = aClass;
}
}
}
return lastClass;
}
示例2: isAccessible
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Override
public boolean isAccessible() {
Boolean Accessible = myAccessible;
boolean accessible = true;
if(Accessible == null) {
if (myPlace != null && myCandidate instanceof PsiMember) {
final PsiMember member = (PsiMember)myCandidate;
accessible = JavaPsiFacade.getInstance(myPlace.getProject()).getResolveHelper()
.isAccessible(member, member.getModifierList(), myPlace, myAccessClass, myCurrentFileResolveContext);
if (accessible && member.hasModifierProperty(PsiModifier.PRIVATE) && myPlace instanceof PsiReferenceExpression && JavaVersionService.getInstance().isAtLeast(myPlace, JavaSdkVersion.JDK_1_7)) {
accessible = !isAccessedThroughTypeParameterBound();
}
}
myAccessible = accessible;
}
else {
accessible = Accessible;
}
return accessible;
}
示例3: getTooltip
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Override
public String getTooltip(MemberInfo memberInfo) {
if (checkForProblems(memberInfo) == OK) return null;
if (!(memberInfo.getMember() instanceof PsiField)) return CodeInsightBundle.message("generate.equals.hashcode.internal.error");
final PsiField field = (PsiField)memberInfo.getMember();
if (!JavaVersionService.getInstance().isAtLeast(field, JavaSdkVersion.JDK_1_5)) {
final PsiType type = field.getType();
if (PsiAdapter.isNestedArray(type)) {
return CodeInsightBundle .message("generate.equals.warning.equals.for.nested.arrays.not.supported");
}
if (GenerateEqualsHelper.isArrayOfObjects(type)) {
return CodeInsightBundle.message("generate.equals.warning.generated.equals.could.be.incorrect");
}
}
return null;
}
示例4: isAccessible
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Override
public boolean isAccessible(){
if(myAccessProblem == null){
boolean accessProblem = false;
if (myPlace != null && myCandidate instanceof PsiMember) {
final PsiMember member = (PsiMember)myCandidate;
accessProblem = !JavaPsiFacade.getInstance(myPlace.getProject()).getResolveHelper()
.isAccessible(member, member.getModifierList(), myPlace, myAccessClass, myCurrentFileResolveContext);
if (!accessProblem && member.hasModifierProperty(PsiModifier.PRIVATE) && myPlace instanceof PsiReferenceExpression && JavaVersionService.getInstance().isAtLeast(myPlace, JavaSdkVersion.JDK_1_7)) {
accessProblem = isAccessedThroughTypeParameterBound();
}
}
myAccessProblem = accessProblem ? Boolean.TRUE : Boolean.FALSE;
}
return !myAccessProblem.booleanValue();
}
示例5: isAccessible
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Override
public boolean isAccessible()
{
Boolean Accessible = myAccessible;
boolean accessible = true;
if(Accessible == null)
{
if(myPlace != null && myCandidate instanceof PsiMember)
{
final PsiMember member = (PsiMember) myCandidate;
accessible = JavaPsiFacade.getInstance(myPlace.getProject()).getResolveHelper().isAccessible(member, member.getModifierList(), myPlace, myAccessClass, myCurrentFileResolveContext);
if(accessible && member.hasModifierProperty(PsiModifier.PRIVATE) && myPlace instanceof PsiReferenceExpression && JavaVersionService.getInstance().isAtLeast(myPlace, JavaSdkVersion
.JDK_1_7))
{
accessible = !isAccessedThroughTypeParameterBound();
}
}
myAccessible = accessible;
}
else
{
accessible = Accessible;
}
return accessible;
}
示例6: getTooltip
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Override
public String getTooltip(MemberInfo memberInfo)
{
if(checkForProblems(memberInfo) == OK)
{
return null;
}
if(!(memberInfo.getMember() instanceof PsiField))
{
return CodeInsightBundle.message("generate.equals.hashcode.internal.error");
}
final PsiField field = (PsiField) memberInfo.getMember();
if(!JavaVersionService.getInstance().isAtLeast(field, JavaSdkVersion.JDK_1_5))
{
final PsiType type = field.getType();
if(PsiAdapter.isNestedArray(type))
{
return CodeInsightBundle.message("generate.equals.warning.equals.for.nested.arrays.not.supported");
}
if(GenerateEqualsHelper.isArrayOfObjects(type))
{
return CodeInsightBundle.message("generate.equals.warning.generated.equals.could.be.incorrect");
}
}
return null;
}
示例7: checkForProblems
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Override
public int checkForProblems(@NotNull MemberInfo member)
{
if(!(member.getMember() instanceof PsiField))
{
return ERROR;
}
final PsiField field = (PsiField) member.getMember();
final PsiType type = field.getType();
if(!JavaVersionService.getInstance().isAtLeast(field, JavaSdkVersion.JDK_1_5))
{
if(PsiAdapter.isNestedArray(type))
{
return ERROR;
}
if(GenerateEqualsHelper.isArrayOfObjects(type))
{
return WARNING;
}
}
return OK;
}
示例8: isTypeArgumentsApplicable
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
private boolean isTypeArgumentsApplicable(Computable<PsiSubstitutor> computable) {
final PsiMethod psiMethod = getElement();
PsiTypeParameter[] typeParams = psiMethod.getTypeParameters();
if (myTypeArguments != null && typeParams.length != myTypeArguments.length && !PsiUtil.isLanguageLevel7OrHigher(psiMethod)){
return typeParams.length == 0 && JavaVersionService.getInstance().isAtLeast(psiMethod, JavaSdkVersion.JDK_1_7);
}
return GenericsUtil.isTypeArgumentsApplicable(typeParams, computable.compute(), getParent());
}
示例9: getJavaVersion
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
public static int getJavaVersion(@NotNull PsiElement element) {
JavaSdkVersion sdkVersion = JavaVersionService.getInstance().getJavaSdkVersion(element);
if (sdkVersion == null) {
sdkVersion = JavaSdkVersion.fromLanguageLevel(PsiUtil.getLanguageLevel(element));
}
int version = 0;
switch (sdkVersion) {
case JDK_1_0:
case JDK_1_1:
version = 1;
break;
case JDK_1_2:
version = 2;
break;
case JDK_1_3:
version = 3;
break;
case JDK_1_4:
version = 4;
break;
case JDK_1_5:
version = 5;
break;
case JDK_1_6:
version = 6;
break;
case JDK_1_7:
version = 7;
break;
case JDK_1_8:
version = 8;
break;
case JDK_1_9:
version = 9;
break;
}
return version;
}
示例10: visitClass
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Override public void visitClass(PsiClass aClass) {
// Don't go into classes (anonymous, locals).
if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
final Module module = ModuleUtilCore.findModuleForPsiElement(aClass);
final LanguageLevel effectiveLanguageLevel = module != null ? getEffectiveLanguageLevel(module) : null;
if (effectiveLanguageLevel != null && !effectiveLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
final JavaSdkVersion version = JavaVersionService.getInstance().getJavaSdkVersion(aClass);
if (version != null && version.isAtLeast(JavaSdkVersion.JDK_1_8)) {
final List<PsiMethod> methods = new ArrayList<PsiMethod>();
for (HierarchicalMethodSignature methodSignature : aClass.getVisibleSignatures()) {
final PsiMethod method = methodSignature.getMethod();
if (ourDefaultMethods.contains(getSignature(method))) {
methods.add(method);
}
}
if (!methods.isEmpty()) {
PsiElement element2Highlight = aClass.getNameIdentifier();
if (element2Highlight == null) {
element2Highlight = aClass;
}
myHolder.registerProblem(element2Highlight,
methods.size() == 1 ? InspectionsBundle.message("inspection.1.8.problem.single.descriptor", methods.get(0).getName(), getJdkName(effectiveLanguageLevel))
: InspectionsBundle.message("inspection.1.8.problem.descriptor", methods.size(), getJdkName(effectiveLanguageLevel)),
QuickFixFactory.getInstance().createImplementMethodsFix(aClass));
}
}
}
}
}
示例11: checkAccessStaticFieldFromEnumConstructor
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Nullable
static HighlightInfo checkAccessStaticFieldFromEnumConstructor(@NotNull PsiReferenceExpression expr, @NotNull JavaResolveResult result) {
final PsiElement resolved = result.getElement();
if (!(resolved instanceof PsiField)) return null;
if (!((PsiModifierListOwner)resolved).hasModifierProperty(PsiModifier.STATIC)) return null;
if (expr.getParent() instanceof PsiSwitchLabelStatement) return null;
final PsiMember constructorOrInitializer = PsiUtil.findEnclosingConstructorOrInitializer(expr);
if (constructorOrInitializer == null) return null;
if (constructorOrInitializer.hasModifierProperty(PsiModifier.STATIC)) return null;
final PsiClass aClass = constructorOrInitializer instanceof PsiEnumConstantInitializer ?
(PsiClass)constructorOrInitializer : constructorOrInitializer.getContainingClass();
if (aClass == null || !(aClass.isEnum() || aClass instanceof PsiEnumConstantInitializer)) return null;
final PsiField field = (PsiField)resolved;
if (aClass instanceof PsiEnumConstantInitializer) {
if (field.getContainingClass() != aClass.getSuperClass()) return null;
} else if (field.getContainingClass() != aClass) return null;
if (!JavaVersionService.getInstance().isAtLeast(field, JavaSdkVersion.JDK_1_6)) {
final PsiType type = field.getType();
if (type instanceof PsiClassType && ((PsiClassType)type).resolve() == aClass) return null;
}
if (PsiUtil.isCompileTimeConstant(field)) return null;
String description = JavaErrorMessages.message(
"illegal.to.access.static.member.from.enum.constructor.or.instance.initializer",
HighlightMessageUtil.getSymbolName(resolved, result.getSubstitutor())
);
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expr).descriptionAndTooltip(description).create();
}
示例12: isMemberEnabled
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Override
public boolean isMemberEnabled(MemberInfo member) {
if (!(member.getMember() instanceof PsiField)) return false;
final PsiField field = (PsiField)member.getMember();
final PsiType type = field.getType();
return JavaVersionService.getInstance().isAtLeast(field, JavaSdkVersion.JDK_1_5) || !PsiAdapter.isNestedArray(type);
}
示例13: checkForProblems
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
@Override
public int checkForProblems(@NotNull MemberInfo member) {
if (!(member.getMember() instanceof PsiField)) return ERROR;
final PsiField field = (PsiField)member.getMember();
final PsiType type = field.getType();
if (!JavaVersionService.getInstance().isAtLeast(field, JavaSdkVersion.JDK_1_5)) {
if (PsiAdapter.isNestedArray(type)) return ERROR;
if (GenerateEqualsHelper.isArrayOfObjects(type)) return WARNING;
}
return OK;
}
示例14: preferVarargs
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
private static int preferVarargs(CandidateInfo info) {
final int level = ((MethodCandidateInfo)info).getApplicabilityLevel();
if (level == MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY) {
final PsiMethod psiMethod = (PsiMethod)info.getElement();
if (psiMethod != null && psiMethod.isVarArgs() && JavaVersionService.getInstance().isAtLeast(psiMethod, JavaSdkVersion.JDK_1_7)) {
return level + 1;
}
}
return level;
}
示例15: JavaCoreApplicationEnvironment
import com.intellij.openapi.projectRoots.JavaVersionService; //导入依赖的package包/类
public JavaCoreApplicationEnvironment(Disposable parentDisposable) {
super(parentDisposable);
registerFileType(JavaClassFileType.INSTANCE, "class");
registerFileType(JavaFileType.INSTANCE, "java");
registerFileType(ArchiveFileType.INSTANCE, "jar;zip");
addExplicitExtension(FileTypeFileViewProviders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileViewProviderFactory());
addExplicitExtension(BinaryFileStubBuilders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileStubBuilder());
addExplicitExtension(LanguageASTFactory.INSTANCE, JavaLanguage.INSTANCE, new CoreJavaASTFactory());
addExplicitExtension(LanguageParserDefinitions.INSTANCE, JavaLanguage.INSTANCE, new JavaParserDefinition());
addExplicitExtension(LanguageConstantExpressionEvaluator.INSTANCE, JavaLanguage.INSTANCE, new PsiExpressionEvaluator());
registerExtensionPoint(Extensions.getRootArea(), ClsStubBuilderFactory.EP_NAME, ClsStubBuilderFactory.class);
registerExtensionPoint(Extensions.getRootArea(), PsiAugmentProvider.EP_NAME, PsiAugmentProvider.class);
registerExtensionPoint(Extensions.getRootArea(), JavaMainMethodProvider.EP_NAME, JavaMainMethodProvider.class);
addExtension(ClsStubBuilderFactory.EP_NAME, new DefaultClsStubBuilderFactory());
myApplication.registerService(PsiPackageImplementationHelper.class, new CorePsiPackageImplementationHelper());
myApplication.registerService(EmptySubstitutor.class, new EmptySubstitutorImpl());
myApplication.registerService(JavaDirectoryService.class, createJavaDirectoryService());
myApplication.registerService(JavaVersionService.class, new JavaVersionService());
addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiPackage.class, new PackagePresentationProvider());
addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiClass.class, new ClassPresentationProvider());
addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiMethod.class, new MethodPresentationProvider());
addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiField.class, new FieldPresentationProvider());
addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiLocalVariable.class, new VariablePresentationProvider());
addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiParameter.class, new VariablePresentationProvider());
}