当前位置: 首页>>代码示例>>Java>>正文


Java PsiUtil.isLanguageLevel5OrHigher方法代码示例

本文整理汇总了Java中com.intellij.psi.util.PsiUtil.isLanguageLevel5OrHigher方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.isLanguageLevel5OrHigher方法的具体用法?Java PsiUtil.isLanguageLevel5OrHigher怎么用?Java PsiUtil.isLanguageLevel5OrHigher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.PsiUtil的用法示例。


在下文中一共展示了PsiUtil.isLanguageLevel5OrHigher方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAvailable

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
  PsiVariable psiVariable = getVariable(element);
  if (psiVariable == null || psiVariable instanceof PsiResourceVariable) return false;
  if (psiVariable.getLanguage() != JavaLanguage.INSTANCE) return false;
  if (psiVariable.getTypeElement() == null) return false;
  if (!PsiUtil.isLanguageLevel5OrHigher(psiVariable)) return false;
  final PsiType psiType = psiVariable.getType();
  final PsiClass psiTypeClass = PsiUtil.resolveClassInType(psiType);
  if (psiTypeClass != null) {
    final String qualifiedName = psiTypeClass.getQualifiedName();
    if (qualifiedName != null) { //is already atomic
      if (myFromToMap.values().contains(qualifiedName) ||
          qualifiedName.equals(AtomicReference.class.getName()) ||
          qualifiedName.equals(AtomicReferenceArray.class.getName())) {
        return false;
      }
    }
  }
  else if (!myFromToMap.containsKey(psiType)) {
    return false;
  }
  return AllowedApiFilterExtension.isClassAllowed(AtomicReference.class.getName(), element);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ConvertFieldToAtomicIntention.java

示例2: buildErrorString

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
@NotNull
public String buildErrorString(Object... infos) {
  final PsiVariable variable = (PsiVariable)infos[0];
  final String name = variable.getName();
  final String expectedType = s_expectedTypes.get(name);
  if (PsiUtil.isLanguageLevel5OrHigher(variable)) {
    final String boxedType = s_boxingClasses.get(expectedType);
    if (boxedType != null) {
      return InspectionGadgetsBundle.message(
        "standard.variable.names.problem.descriptor2",
        expectedType, boxedType);
    }
  }
  return InspectionGadgetsBundle.message(
    "standard.variable.names.problem.descriptor", expectedType);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:StandardVariableNamesInspectionBase.java

示例3: wrapWithNewExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static TypeConversionDescriptor wrapWithNewExpression(PsiType to, PsiType from, PsiExpression initializer) {
  final String boxedTypeName = from instanceof PsiPrimitiveType ? ((PsiPrimitiveType)from).getBoxedTypeName() : from.getCanonicalText();
  return new TypeConversionDescriptor("$qualifier$", "new " +
                                                     to.getCanonicalText() +
                                                     "() {\n" +
                                                     "@Override \n" +
                                                     "protected " +
                                                     boxedTypeName +
                                                     " initialValue() {\n" +
                                                     "  return " +
                                                     (PsiUtil.isLanguageLevel5OrHigher(initializer)
                                                      ? initializer.getText()
                                                      : (from instanceof PsiPrimitiveType ? "new " +
                                                                                            ((PsiPrimitiveType)from).getBoxedTypeName() +
                                                                                            "(" +
                                                                                            initializer.getText() +
                                                                                            ")" : initializer.getText())) +
                                                     ";\n" +
                                                     "}\n" +
                                                     "}", initializer);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ThreadLocalConversionRule.java

示例4: satisfiedBy

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public boolean satisfiedBy(@NotNull PsiElement element) {
  if (!(element instanceof PsiParameterList)) {
    return false;
  }
  if (!PsiUtil.isLanguageLevel5OrHigher(element)) {
    return false;
  }
  final PsiParameterList parameterList = (PsiParameterList)element;
  if (!(element.getParent() instanceof PsiMethod)) {
    return false;
  }
  if (parameterList.getParametersCount() == 0) {
    return false;
  }
  final PsiParameter[] parameters = parameterList.getParameters();
  final PsiParameter lastParameter =
    parameters[parameters.length - 1];
  if (lastParameter.isVarArgs()) {
    return false;
  }
  final PsiType type = lastParameter.getType();
  return type instanceof PsiArrayType;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:MakeMethodVarargsPredicate.java

示例5: toPrimitive

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static String toPrimitive(String replaceByArg, PsiType from, PsiElement context) {
  return PsiUtil.isLanguageLevel5OrHigher(context)
         ? replaceByArg
         : from instanceof PsiPrimitiveType ? "((" +
                                              ((PsiPrimitiveType)from).getBoxedTypeName() +
                                              ")" +
                                              replaceByArg +
                                              ")." +
                                              from.getCanonicalText() +
                                              "Value()" : "((" + from.getCanonicalText() + ")" + replaceByArg + ")";
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ThreadLocalConversionRule.java

示例6: isAvailable

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project,
                           @NotNull PsiFile file,
                           @NotNull PsiElement startElement,
                           @NotNull PsiElement endElement) {
  if (!startElement.isValid()) return false;
  if (!PsiUtil.isLanguageLevel5OrHigher(startElement)) return false;
  final PsiModifierListOwner myModifierListOwner = (PsiModifierListOwner)startElement;

  return !AnnotationUtil.isAnnotated(myModifierListOwner, myAnnotation, false, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:AddAnnotationPsiFix.java

示例7: visitVariable

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitVariable(@NotNull PsiVariable variable) {
  super.visitVariable(variable);
  final String variableName = variable.getName();
  final String expectedType = s_expectedTypes.get(variableName);
  if (expectedType == null) {
    return;
  }
  final PsiType type = variable.getType();
  final String typeText = type.getCanonicalText();
  if (expectedType.equals(typeText)) {
    return;
  }
  if (PsiUtil.isLanguageLevel5OrHigher(variable)) {
    final PsiPrimitiveType unboxedType =
      PsiPrimitiveType.getUnboxedType(type);
    if (unboxedType != null) {
      final String unboxedTypeText =
        unboxedType.getCanonicalText();
      if (expectedType.equals(unboxedTypeText)) {
        return;
      }
    }
  }
  if (ignoreParameterNameSameAsSuper &&
      isVariableNamedSameAsSuper(variable)) {
    return;
  }
  registerVariableError(variable, variable);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:StandardVariableNamesInspectionBase.java

示例8: buildErrorString

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
@Override
protected String buildErrorString(Object... infos) {
  final PsiPackageStatement packageStatement = (PsiPackageStatement)infos[0];
  if (PsiUtil.isLanguageLevel5OrHigher(packageStatement)) {
    return InspectionGadgetsBundle.message("missing.package.info.problem.descriptor", packageStatement.getPackageName());
  }
  else {
    return InspectionGadgetsBundle.message("missing.package.html.problem.descriptor", packageStatement.getPackageName());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:MissingPackageInfoInspectionBase.java

示例9: isAvailable

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static boolean isAvailable(DataContext dataContext) {
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
  if (project == null || view == null) {
    return false;
  }
  final PsiDirectory[] directories = view.getDirectories();
  if (directories.length == 0) {
    return false;
  }
  final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final JavaDirectoryService directoryService = JavaDirectoryService.getInstance();
  final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
  for (PsiDirectory directory : directories) {
    if (projectFileIndex.isUnderSourceRootOfType(directory.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
        PsiUtil.isLanguageLevel5OrHigher(directory)) {
      final PsiPackage aPackage = directoryService.getPackage(directory);
      if (aPackage != null) {
        final String qualifiedName = aPackage.getQualifiedName();
        if (StringUtil.isEmpty(qualifiedName) || nameHelper.isQualifiedName(qualifiedName)) {
          return true;
        }
      }
    }

  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:CreatePackageInfoAction.java

示例10: toBoxed

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static String toBoxed(String replaceByArg, PsiType from, PsiElement context) {
  return PsiUtil.isLanguageLevel5OrHigher(context)
         ? replaceByArg
         : from instanceof PsiPrimitiveType ? "new " + ((PsiPrimitiveType)from).getBoxedTypeName() +
                                              "(" +
                                              replaceByArg +
                                              ")"
                                              : replaceByArg;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ThreadLocalConversionRule.java

示例11: getType

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
/**
 * JLS 15.25
 */
@Override
public PsiType getType() {
  PsiExpression expr1 = getThenExpression();
  PsiExpression expr2 = getElseExpression();
  PsiType type1 = expr1 == null ? null : expr1.getType();
  PsiType type2 = expr2 == null ? null : expr2.getType();
  if (type1 == null) return type2;
  if (type2 == null) return type1;

  if (type1.equals(type2)) return type1;
  final int typeRank1 = TypeConversionUtil.getTypeRank(type1);
  final int typeRank2 = TypeConversionUtil.getTypeRank(type2);

  // bug in JLS3, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6888770
  if (type1 instanceof PsiClassType && type2.equals(PsiPrimitiveType.getUnboxedType(type1))) return type2;
  if (type2 instanceof PsiClassType && type1.equals(PsiPrimitiveType.getUnboxedType(type2))) return type1;

  if (TypeConversionUtil.isNumericType(typeRank1) && TypeConversionUtil.isNumericType(typeRank2)){
    if (typeRank1 == TypeConversionUtil.BYTE_RANK && typeRank2 == TypeConversionUtil.SHORT_RANK) {
      return type2 instanceof PsiPrimitiveType ? type2 : PsiPrimitiveType.getUnboxedType(type2);
    }
    if (typeRank1 == TypeConversionUtil.SHORT_RANK && typeRank2 == TypeConversionUtil.BYTE_RANK) {
      return type1 instanceof PsiPrimitiveType ? type1 : PsiPrimitiveType.getUnboxedType(type1);
    }
    if (typeRank2 == TypeConversionUtil.INT_RANK && (typeRank1 == TypeConversionUtil.BYTE_RANK || typeRank1 == TypeConversionUtil.SHORT_RANK || typeRank1 == TypeConversionUtil.CHAR_RANK)){
      if (TypeConversionUtil.areTypesAssignmentCompatible(type1, expr2)) return type1;
    }
    if (typeRank1 == TypeConversionUtil.INT_RANK && (typeRank2 == TypeConversionUtil.BYTE_RANK || typeRank2 == TypeConversionUtil.SHORT_RANK || typeRank2 == TypeConversionUtil.CHAR_RANK)){
      if (TypeConversionUtil.areTypesAssignmentCompatible(type2, expr1)) return type2;
    }
    return TypeConversionUtil.binaryNumericPromotion(type1, type2);
  }
  if (TypeConversionUtil.isNullType(type1) && !(type2 instanceof PsiPrimitiveType)) return type2;
  if (TypeConversionUtil.isNullType(type2) && !(type1 instanceof PsiPrimitiveType)) return type1;

  if (PsiUtil.isLanguageLevel8OrHigher(this) && 
      PsiPolyExpressionUtil.isPolyExpression(this) && 
      !MethodCandidateInfo.ourOverloadGuard.currentStack().contains(PsiUtil.skipParenthesizedExprUp(this.getParent()))) {
    //15.25.3 Reference Conditional Expressions 
    // The type of a poly reference conditional expression is the same as its target type.
    return InferenceSession.getTargetType(this);
  }

  if (TypeConversionUtil.isAssignable(type1, type2, false)) return type1;
  if (TypeConversionUtil.isAssignable(type2, type1, false)) return type2;
  if (!PsiUtil.isLanguageLevel5OrHigher(this)) {
    return null;
  }
  if (TypeConversionUtil.isPrimitiveAndNotNull(type1)) {
    type1 = ((PsiPrimitiveType)type1).getBoxedType(this);
    if (type1 == null) return null;
  }
  if (TypeConversionUtil.isPrimitiveAndNotNull(type2)) {
    type2 = ((PsiPrimitiveType)type2).getBoxedType(this);
    if (type2 == null) return null;
  }

  if (type1 instanceof PsiLambdaParameterType || type2 instanceof PsiLambdaParameterType) return null;
  final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(type1, type2, getManager());
  return leastUpperBound != null ? PsiUtil.captureToplevelWildcards(leastUpperBound, this) : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:PsiConditionalExpressionImpl.java

示例12: isValidInContext

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean isValidInContext(PsiElement element) {
  return element instanceof PsiMethod ||
         (element instanceof PsiClass && PsiUtil.isLanguageLevel5OrHigher(element));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:ParamDocTagInfo.java

示例13: visitLiteralExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitLiteralExpression(PsiLiteralExpression expression) {
  Object value = expression.getValue();
  if (!(value instanceof String)) return;
  String stringValue = (String)value;
  if (stringValue.trim().isEmpty()) {
    return;
  }

  Set<PsiModifierListOwner> nonNlsTargets = new THashSet<PsiModifierListOwner>();
  if (canBeI18ned(myManager.getProject(), expression, stringValue, nonNlsTargets)) {
    PsiField parentField = PsiTreeUtil.getParentOfType(expression, PsiField.class);
    if (parentField != null) {
      nonNlsTargets.add(parentField);
    }

    final String description = CodeInsightBundle.message("inspection.i18n.message.general.with.value", "#ref");

    List<LocalQuickFix> fixes = new ArrayList<LocalQuickFix>();
    if (I18nizeConcatenationQuickFix.getEnclosingLiteralConcatenation(expression) != null) {
      fixes.add(I18N_CONCATENATION_QUICK_FIX);
    }
    fixes.add(I18N_QUICK_FIX);

    if (!isNotConstantFieldInitializer(expression)) {
      fixes.add(createIntroduceConstantFix());
    }

    final Project project = expression.getManager().getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    if (PsiUtil.isLanguageLevel5OrHigher(expression)) {
      for (PsiModifierListOwner element : nonNlsTargets) {
        if (!AnnotationUtil.isAnnotated(element, AnnotationUtil.NLS, true, false)) {
          if (!element.getManager().isInProject(element) ||
              facade.findClass(AnnotationUtil.NON_NLS, element.getResolveScope()) != null) {
            fixes.add(new AddAnnotationFix(AnnotationUtil.NON_NLS, element));
          }
        }
      }
    }

    LocalQuickFix[] farr = fixes.toArray(new LocalQuickFix[fixes.size()]);
    final ProblemDescriptor problem = myManager.createProblemDescriptor(expression,
                                                                        description, myOnTheFly, farr,
                                                                        ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
    myProblems.add(problem);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:49,代码来源:I18nInspection.java

示例14: shouldInspect

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean shouldInspect(PsiFile file) {
  return PsiUtil.isLanguageLevel5OrHigher(file);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:MissingDeprecatedAnnotationInspection.java


注:本文中的com.intellij.psi.util.PsiUtil.isLanguageLevel5OrHigher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。