本文整理汇总了Java中com.intellij.psi.util.PsiUtil.getLanguageLevel方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.getLanguageLevel方法的具体用法?Java PsiUtil.getLanguageLevel怎么用?Java PsiUtil.getLanguageLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtil
的用法示例。
在下文中一共展示了PsiUtil.getLanguageLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEffectiveLanguageLevel
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
@Override
public LanguageLevel getEffectiveLanguageLevel(@Nullable VirtualFile virtualFile) {
if (virtualFile == null) return PsiUtil.getLanguageLevel(myProject);
final VirtualFile folder = virtualFile.getParent();
if (folder != null) {
final LanguageLevel level = folder.getUserData(LanguageLevel.KEY);
if (level != null) return level;
}
final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
Module module = index.getModuleForFile(virtualFile);
if (module != null && index.isInSourceContent(virtualFile)) {
return EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module);
}
LanguageLevel classesLanguageLevel = getClassesLanguageLevel(virtualFile);
return classesLanguageLevel != null ? classesLanguageLevel : PsiUtil.getLanguageLevel(myProject);
}
示例2: VariableResolverProcessor
import com.intellij.psi.util.PsiUtil; //导入方法依赖的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;
}
示例3: fun
import com.intellij.psi.util.PsiUtil; //导入方法依赖的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());
}
示例4: isInSuper
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
protected boolean isInSuper(PsiElement member) {
if (!(member instanceof PsiMember)) return false;
final PsiManager manager = member.getManager();
if (InheritanceUtil.isInheritorOrSelf(mySuper, ((PsiMember)member).getContainingClass(), true)) return true;
if (member instanceof PsiField) {
final PsiClass containingClass = ((PsiField) member).getContainingClass();
LanguageLevel languageLevel = PsiUtil.getLanguageLevel(member);
if (manager.areElementsEquivalent(containingClass, JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().getArrayClass(languageLevel))) {
return true;
}
} else if (member instanceof PsiMethod) {
return mySuper.findMethodBySignature((PsiMethod) member, true) != null;
}
return false;
}
示例5: JavaMethodResolveHelper
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public JavaMethodResolveHelper(@NotNull final PsiElement argumentList, PsiFile containingFile, @Nullable final PsiType[] argumentTypes) {
myArgumentTypes = argumentTypes;
final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(argumentList);
final PsiConflictResolver resolver = argumentTypes == null ? DuplicateConflictResolver.INSTANCE : new JavaMethodsConflictResolver(argumentList, argumentTypes,
languageLevel);
myProcessor = new MethodResolverProcessor(argumentList, containingFile, new PsiConflictResolver[]{resolver}) {
@Override
protected MethodCandidateInfo createCandidateInfo(@NotNull final PsiMethod method, @NotNull final PsiSubstitutor substitutor,
final boolean staticProblem,
final boolean accessible, final boolean varargs) {
return JavaMethodResolveHelper.this
.createCandidateInfo(method, substitutor, staticProblem, myCurrentFileContext, !accessible, argumentList, argumentTypes,
languageLevel);
}
@Override
protected boolean isAccepted(final PsiMethod candidate) {
return !candidate.isConstructor();
}
};
}
示例6: MethodResolverProcessor
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public MethodResolverProcessor(@NotNull PsiCallExpression place,
@NotNull PsiExpressionList argumentList,
@NotNull PsiFile placeFile){
this(place, placeFile, new PsiConflictResolver[]{new JavaMethodsConflictResolver(argumentList, PsiUtil.getLanguageLevel(placeFile))});
setArgumentList(argumentList);
obtainTypeArguments(place);
}
示例7: getSwitchExpression
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
public static PsiExpression getSwitchExpression(PsiIfStatement statement, int minimumBranches, boolean nullSafe) {
final PsiExpression condition = statement.getCondition();
final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(statement);
final PsiExpression possibleSwitchExpression = determinePossibleSwitchExpressions(condition, languageLevel, nullSafe);
if (!canBeSwitchExpression(possibleSwitchExpression, languageLevel)) {
return null;
}
int branchCount = 0;
while (true) {
branchCount++;
if (!canBeMadeIntoCase(statement.getCondition(), possibleSwitchExpression, languageLevel, false)) {
break;
}
final PsiStatement elseBranch = statement.getElseBranch();
if (!(elseBranch instanceof PsiIfStatement)) {
if (elseBranch != null) {
branchCount++;
}
if (branchCount < minimumBranches) {
return null;
}
return possibleSwitchExpression;
}
statement = (PsiIfStatement)elseBranch;
}
return null;
}
示例8: processTypeDeclarations
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static void processTypeDeclarations(PsiType type, PsiElement place, PsiScopeProcessor processor) {
if (type instanceof PsiArrayType) {
LanguageLevel languageLevel = PsiUtil.getLanguageLevel(place);
final PsiClass arrayClass = JavaPsiFacade.getInstance(place.getProject()).getElementFactory().getArrayClass(languageLevel);
final PsiTypeParameter[] arrayTypeParameters = arrayClass.getTypeParameters();
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
if (arrayTypeParameters.length > 0) {
substitutor = substitutor.put(arrayTypeParameters[0], ((PsiArrayType)type).getComponentType());
}
arrayClass.processDeclarations(processor, ResolveState.initial().put(PsiSubstitutor.KEY, substitutor), arrayClass, place);
}
else if (type instanceof PsiIntersectionType) {
for (PsiType psiType : ((PsiIntersectionType)type).getConjuncts()) {
processTypeDeclarations(psiType, place, processor);
}
}
else if (type instanceof PsiDisjunctionType) {
final PsiType lub = ((PsiDisjunctionType)type).getLeastUpperBound();
processTypeDeclarations(lub, place, processor);
}
else {
final JavaResolveResult result = PsiUtil.resolveGenericsClassInType(type);
final PsiClass clazz = (PsiClass)result.getElement();
if (clazz != null) {
clazz.processDeclarations(processor, ResolveState.initial().put(PsiSubstitutor.KEY, result.getSubstitutor()), clazz, place);
}
}
}
示例9: processDeclarations
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
@NotNull ResolveState state,
PsiElement lastParent,
@NotNull PsiElement place) {
if (isEnum()) {
if (!PsiClassImplUtil.processDeclarationsInEnum(processor, state, myInnersCache)) return false;
}
LanguageLevel level = processor instanceof MethodsProcessor ? ((MethodsProcessor)processor).getLanguageLevel() : PsiUtil.getLanguageLevel(place);
return PsiClassImplUtil.processDeclarationsInClass(this, processor, state, null, lastParent, place, level, false);
}
示例10: createMemberValueFromText
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static PsiAnnotationMemberValue createMemberValueFromText(@NotNull String text,
@NotNull PsiManager manager,
@NotNull ClsElementImpl parent) {
LanguageLevel level = PsiUtil.getLanguageLevel(parent);
DummyHolder holder = DummyHolderFactory.createHolder(manager, new JavaDummyElement(text, ANNOTATION_VALUE, level), null);
PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiAnnotationMemberValue)) {
LOG.error("Could not parse initializer:'" + text + "'");
return null;
}
return getMemberValue(element, parent);
}
示例11: inferConstraint
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
protected static Pair<PsiType, ConstraintType> inferConstraint(PsiTypeParameter typeParameter,
PsiExpression innerMethodCall,
int parameterIdx,
PsiType innerReturnType,
JavaResolveResult result,
final PsiSubstitutor substitutor) {
final PsiElement element = result.getElement();
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod)element;
final PsiParameter[] parameters = method.getParameterList().getParameters();
PsiParameter parameter = null;
if (parameters.length > parameterIdx) {
parameter = parameters[parameterIdx];
}
else if (method.isVarArgs()) {
parameter = parameters[parameters.length - 1];
}
if (parameter != null) {
final PsiParameter finalParameter = parameter;
PsiType type = PsiResolveHelper.ourGuard.doPreventingRecursion(innerMethodCall, true, new Computable<PsiType>() {
@Override
public PsiType compute() {
return substitutor.substitute(finalParameter.getType());
}
});
final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(finalParameter);
final Pair<PsiType, ConstraintType> constraint =
new PsiOldInferenceHelper(element.getManager()).getSubstitutionForTypeParameterConstraint(typeParameter, innerReturnType, type, false, languageLevel);
if (constraint != null) return constraint;
}
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:ProcessCandidateParameterTypeInferencePolicy.java
示例12: MethodReferenceConflictResolver
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private MethodReferenceConflictResolver(PsiMethodReferenceExpressionImpl referenceExpression,
PsiMethodReferenceUtil.QualifierResolveResult qualifierResolveResult,
@Nullable MethodSignature signature, boolean varArgs) {
super(referenceExpression, signature != null ? signature.getParameterTypes() : PsiType.EMPTY_ARRAY, PsiUtil.getLanguageLevel(referenceExpression));
myReferenceExpression = referenceExpression;
myQualifierResolveResult = qualifierResolveResult;
myFunctionalMethodVarArgs = varArgs;
mySignature = signature;
}
示例13: MethodCandidateInfo
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public MethodCandidateInfo(@NotNull PsiElement candidate,
PsiSubstitutor substitutor,
boolean accessProblem,
boolean staticsProblem,
PsiElement argumentList,
PsiElement currFileContext,
@Nullable PsiType[] argumentTypes,
PsiType[] typeArguments) {
this(candidate, substitutor, accessProblem, staticsProblem, argumentList, currFileContext, argumentTypes, typeArguments,
PsiUtil.getLanguageLevel(argumentList));
}
示例14: isCodeBlockRedundant
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static PsiExpression isCodeBlockRedundant(PsiExpression expression, PsiElement body) {
if (body instanceof PsiCodeBlock) {
PsiExpression psiExpression = LambdaUtil.extractSingleExpressionFromBody(body);
if (psiExpression != null && !findCommentsOutsideExpression(body, psiExpression)) {
if (LambdaUtil.isExpressionStatementExpression(psiExpression)) {
final PsiElement parent = PsiUtil.skipParenthesizedExprUp(expression.getParent());
if (parent instanceof PsiExpressionList) {
final PsiElement gParent = parent.getParent();
if (gParent instanceof PsiCallExpression) {
final CandidateInfo[] candidates = PsiResolveHelper.SERVICE.getInstance(gParent.getProject())
.getReferencedMethodCandidates((PsiCallExpression)gParent, false, true);
if (candidates.length > 1) {
final List<CandidateInfo> info = new ArrayList<CandidateInfo>(Arrays.asList(candidates));
final LanguageLevel level = PsiUtil.getLanguageLevel(parent);
final JavaMethodsConflictResolver conflictResolver = new JavaMethodsConflictResolver((PsiExpressionList)parent, level);
final PsiExpressionList argumentList = ((PsiCallExpression)gParent).getArgumentList();
if (argumentList == null) {
return null;
}
conflictResolver.checkParametersNumber(info, argumentList.getExpressions().length, false);
conflictResolver.checkSpecifics(info, MethodCandidateInfo.ApplicabilityLevel.VARARGS, level);
if (info.size() > 1) {
return null;
}
}
}
}
}
return psiExpression;
}
}
return null;
}
示例15: PostHighlightingVisitor
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
PostHighlightingVisitor(@NotNull PsiFile file,
@NotNull Document document,
@NotNull RefCountHolder refCountHolder) throws ProcessCanceledException {
myProject = file.getProject();
myFile = file;
myDocument = document;
myCurrentEntryIndex = -1;
myLanguageLevel = PsiUtil.getLanguageLevel(file);
final FileViewProvider viewProvider = myFile.getViewProvider();
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
VirtualFile virtualFile = viewProvider.getVirtualFile();
myInLibrary = fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile);
myRefCountHolder = refCountHolder;
ApplicationManager.getApplication().assertReadAccessAllowed();
InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
myDeadCodeKey = HighlightDisplayKey.find(UnusedDeclarationInspectionBase.SHORT_NAME);
myDeadCodeInspection = (UnusedDeclarationInspectionBase)profile.getUnwrappedTool(UnusedDeclarationInspectionBase.SHORT_NAME, myFile);
LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || myDeadCodeInspection != null);
myUnusedSymbolInspection = myDeadCodeInspection != null ? myDeadCodeInspection.getSharedLocalInspectionTool() : null;
myDeadCodeInfoType = myDeadCodeKey == null
? HighlightInfoType.UNUSED_SYMBOL
: new HighlightInfoType.HighlightInfoTypeImpl(profile.getErrorLevel(myDeadCodeKey, myFile).getSeverity(),
HighlightInfoType.UNUSED_SYMBOL.getAttributesKey());
}