本文整理汇总了Java中com.intellij.psi.util.PsiUtil.isLanguageLevel7OrHigher方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.isLanguageLevel7OrHigher方法的具体用法?Java PsiUtil.isLanguageLevel7OrHigher怎么用?Java PsiUtil.isLanguageLevel7OrHigher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtil
的用法示例。
在下文中一共展示了PsiUtil.isLanguageLevel7OrHigher方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitTypeCastExpression
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitTypeCastExpression(final PsiTypeCastExpression expression) {
if (PsiUtil.isLanguageLevel7OrHigher(expression)) return;
final PsiTypeElement type = expression.getCastType();
if (type != null) {
type.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitReferenceParameterList(final PsiReferenceParameterList list) {
super.visitReferenceParameterList(list);
if (list.getFirstChild() != null && QUALIFIER_REFERENCE.accepts(list)) {
final String message = InspectionsBundle.message("inspection.compiler.javac.quirks.qualifier.type.args.problem");
final String fixName = InspectionsBundle.message("inspection.compiler.javac.quirks.qualifier.type.args.fix");
myHolder.registerProblem(list, message, new RemoveElementQuickFix(fixName));
}
}
});
}
}
示例2: isApplicable
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean isApplicable(@NotNull PsiElement element, @NotNull Document copyDocument, int newOffset) {
if (!PsiUtil.isLanguageLevel7OrHigher(element)) return false;
PsiExpression initializer = JavaPostfixTemplatesUtils.getTopmostExpression(element);
if (initializer == null) return false;
final PsiType type = initializer.getType();
if (!(type instanceof PsiClassType)) return false;
final PsiClass aClass = ((PsiClassType)type).resolve();
Project project = element.getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project));
if (!InheritanceUtil.isInheritorOrSelf(aClass, autoCloseable, true)) return false;
return true;
}
示例3: isAvailable
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) {
if (!PsiUtil.isLanguageLevel7OrHigher(element)) return false;
final PsiLiteralExpression literalExpression = PsiTreeUtil.getParentOfType(element, PsiLiteralExpression.class, false);
if (literalExpression == null) return false;
final PsiType type = literalExpression.getType();
if (!PsiType.INT.equals(type) && !PsiType.LONG.equals(type) &&
!PsiType.FLOAT.equals(type) && !PsiType.DOUBLE.equals(type)) return false;
final String text = literalExpression.getText();
if (text == null || text.contains("_")) return false;
final String converted = LiteralFormatUtil.format(text, type);
return converted.length() != text.length();
}
示例4: satisfiedBy
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean satisfiedBy(final PsiElement element) {
if (!(element instanceof PsiLiteralExpression)) {
return false;
}
if (!PsiUtil.isLanguageLevel7OrHigher(element)) {
return false;
}
final PsiType type = ((PsiLiteralExpression)element).getType();
if (PsiType.INT.equals(type) || PsiType.LONG.equals(type)) {
final String text = element.getText();
return !(text.startsWith("0b") || text.startsWith("0B"));
}
return false;
}
示例5: getCollapsedType
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static String getCollapsedType(PsiType type, PsiElement context) {
String typeText = type.getCanonicalText();
if (PsiUtil.isLanguageLevel7OrHigher(context)) {
final int idx = typeText.indexOf('<');
if (idx >= 0) {
return typeText.substring(0, idx) + "<>";
}
}
return typeText;
}
示例6: isTypeArgumentsApplicable
import com.intellij.psi.util.PsiUtil; //导入方法依赖的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());
}
示例7: visitAnnotationArrayInitializer
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitAnnotationArrayInitializer(final PsiArrayInitializerMemberValue initializer) {
if (PsiUtil.isLanguageLevel7OrHigher(initializer)) return;
final PsiElement lastElement = PsiTreeUtil.skipSiblingsBackward(initializer.getLastChild(), PsiWhiteSpace.class, PsiComment.class);
if (lastElement != null && PsiUtil.isJavaToken(lastElement, JavaTokenType.COMMA)) {
final String message = InspectionsBundle.message("inspection.compiler.javac.quirks.anno.array.comma.problem");
final String fixName = InspectionsBundle.message("inspection.compiler.javac.quirks.anno.array.comma.fix");
myHolder.registerProblem(lastElement, message, new RemoveElementQuickFix(fixName));
}
}
示例8: isValidTypeForSwitch
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static boolean isValidTypeForSwitch(@Nullable final PsiType type, final PsiElement context) {
if (type == null) {
return false;
}
if (type instanceof PsiClassType) {
final PsiClass resolvedClass = ((PsiClassType)type).resolve();
if (resolvedClass == null) {
return false;
}
return (PsiUtil.isLanguageLevel5OrHigher(context) && resolvedClass.isEnum())
|| (PsiUtil.isLanguageLevel7OrHigher(context) && CommonClassNames.JAVA_LANG_STRING.equals(resolvedClass.getQualifiedName()));
}
return type.equals(PsiType.INT) || type.equals(PsiType.BYTE) || type.equals(PsiType.SHORT) || type.equals(PsiType.CHAR);
}
示例9: isAvailable
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
if (!(element instanceof PsiIdentifier)) {
return false;
}
if (!PsiUtil.isLanguageLevel7OrHigher(element)) {
return false;
}
final PsiElement referenceExpression = element.getParent();
if (!(referenceExpression instanceof PsiReferenceExpression)) {
return false;
}
if (!"equals".equals(((PsiReferenceExpression)referenceExpression).getReferenceName())) {
return false;
}
final PsiElement methodCallExpression = referenceExpression.getParent();
if (!(methodCallExpression instanceof PsiMethodCallExpression)) {
return false;
}
final int argumentsCount = ((PsiMethodCallExpression)methodCallExpression).getArgumentList().getExpressions().length;
if (argumentsCount != 1) {
return false;
}
final PsiMethod method = ((PsiMethodCallExpression)methodCallExpression).resolveMethod();
if (method == null) {
return false;
}
PsiClass javaLangObject = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_LANG_OBJECT, element.getResolveScope());
if (javaLangObject == null) {
return false;
}
if (javaLangObject.isEquivalentTo(method.getContainingClass())) {
return true;
}
final PsiMethod[] superMethods = method.findSuperMethods(javaLangObject);
return superMethods.length == 1;
}
示例10: findUsages
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
protected UsageInfo[] findUsages() {
GlobalSearchScope projectScope = GlobalSearchScope.projectScope(myProject);
List<UsageInfo> result = new ArrayList<UsageInfo>();
boolean hadTypeParameters = myClass.hasTypeParameters();
for (final PsiReference reference : ReferencesSearch.search(myClass, projectScope, false)) {
if (reference.getElement() instanceof PsiJavaCodeReferenceElement) {
PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)reference.getElement();
PsiElement parent = referenceElement.getParent();
if (parent instanceof PsiTypeElement && parent.getParent() instanceof PsiInstanceOfExpression) continue;
if (parent instanceof PsiNewExpression && PsiUtil.isLanguageLevel7OrHigher(parent)) {
final PsiReferenceParameterList parameterList = referenceElement.getParameterList();
if (parameterList != null) {
final PsiTypeElement[] parameterElements = parameterList.getTypeParameterElements();
if (parameterElements.length == 1 && parameterElements[0].getType() instanceof PsiDiamondType) continue;
}
}
if (parent instanceof PsiTypeElement || parent instanceof PsiNewExpression || parent instanceof PsiAnonymousClass ||
parent instanceof PsiReferenceList) {
if (!hadTypeParameters || referenceElement.getTypeParameters().length > 0) {
result.add(new UsageInfo(referenceElement));
}
}
}
}
return result.toArray(new UsageInfo[result.size()]);
}
示例11: shouldInspect
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean shouldInspect(PsiFile file) {
return PsiUtil.isLanguageLevel7OrHigher(file);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:EqualsReplaceableByObjectsCallInspection.java
示例12: doFix
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement comparisonToken = descriptor.getPsiElement();
final PsiElement parent = comparisonToken.getParent();
if (!(parent instanceof PsiBinaryExpression)) {
return;
}
final PsiBinaryExpression expression = (PsiBinaryExpression)parent;
boolean negated = false;
final IElementType tokenType = expression.getOperationTokenType();
if (JavaTokenType.NE.equals(tokenType)) {
negated = true;
}
final PsiExpression lhs = expression.getLOperand();
final PsiExpression strippedLhs =
ParenthesesUtils.stripParentheses(lhs);
if (strippedLhs == null) {
return;
}
final PsiExpression rhs = expression.getROperand();
final PsiExpression strippedRhs =
ParenthesesUtils.stripParentheses(rhs);
if (strippedRhs == null) {
return;
}
@NonNls final String expString;
if (PsiUtil.isLanguageLevel7OrHigher(expression)) {
expString = "java.util.Objects.equals(" + strippedLhs.getText() + ',' + strippedRhs.getText() + ')';
}
else if (ParenthesesUtils.getPrecedence(strippedLhs) >
ParenthesesUtils.METHOD_CALL_PRECEDENCE) {
expString = '(' + strippedLhs.getText() + ").equals(" +
strippedRhs.getText() + ')';
}
else {
expString = strippedLhs.getText() + ".equals(" +
strippedRhs.getText() + ')';
}
@NonNls final String newExpression;
if (negated) {
newExpression = '!' + expString;
}
else {
newExpression = expString;
}
PsiReplacementUtil.replaceExpressionAndShorten(expression, newExpression);
}
示例13: processIntention
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public void processIntention(PsiElement element) {
final PsiBinaryExpression exp = (PsiBinaryExpression)element;
final PsiExpression lhs = exp.getLOperand();
final PsiExpression rhs = exp.getROperand();
if (rhs == null) {
return;
}
final PsiExpression strippedLhs =
ParenthesesUtils.stripParentheses(lhs);
if (strippedLhs == null) {
return;
}
final PsiExpression strippedRhs =
ParenthesesUtils.stripParentheses(rhs);
if (strippedRhs == null) {
return;
}
final String lhsText = strippedLhs.getText();
final String rhsText = strippedRhs.getText();
final PsiJavaToken operationSign = exp.getOperationSign();
final IElementType tokenType = operationSign.getTokenType();
final String signText = operationSign.getText();
@NonNls final StringBuilder newExpression = new StringBuilder();
if (PsiUtil.isLanguageLevel7OrHigher(element) && ClassUtils.findClass("java.util.Objects", element) != null) {
if (tokenType.equals(JavaTokenType.NE)) {
newExpression.append('!');
}
newExpression.append("java.util.Objects.equals(").append(lhsText).append(',').append(rhsText).append(')');
}
else {
newExpression.append(lhsText).append("==null?").append(rhsText).append(signText).append(" null:");
if (tokenType.equals(JavaTokenType.NE)) {
newExpression.append('!');
}
if (ParenthesesUtils.getPrecedence(strippedLhs) > ParenthesesUtils.METHOD_CALL_PRECEDENCE) {
newExpression.append('(').append(lhsText).append(')');
}
else {
newExpression.append(lhsText);
}
newExpression.append(".equals(").append(rhsText).append(')');
}
PsiReplacementUtil.replaceExpressionAndShorten(exp, newExpression.toString());
}
示例14: satisfiedBy
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean satisfiedBy(PsiElement element) {
if (!PsiUtil.isLanguageLevel7OrHigher(element)) {
return false;
}
if (!(element instanceof PsiReferenceExpression)) {
return false;
}
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)element;
if (PsiUtil.isAccessedForWriting(referenceExpression)) {
return false;
}
final PsiElement target = referenceExpression.resolve();
if (!(target instanceof PsiVariable)) {
return false;
}
final PsiVariable variable = (PsiVariable)target;
if (ClassUtils.findClass("java.util.Objects", element) == null) {
return false;
}
final PsiAnnotation annotation = NullableNotNullManager.getInstance(variable.getProject()).getNotNullAnnotation(variable, true);
if (annotation != null && annotation.isWritable()) {
return true;
}
final PsiStatement referenceStatement = PsiTreeUtil.getParentOfType(referenceExpression, PsiStatement.class);
final PsiElement parent = referenceStatement != null ? referenceStatement.getParent() : null;
if (!(parent instanceof PsiCodeBlock)) {
return false;
}
final PsiCodeBlock codeBlock = (PsiCodeBlock)parent;
final PsiStatement[] statements = codeBlock.getStatements();
for (PsiStatement statement : statements) {
if (statement == referenceStatement) {
return false;
}
if (isNotNullAssertion(statement, variable) || isIfStatementNullCheck(statement, variable)) {
return true;
}
}
return false;
}