本文整理汇总了Java中com.intellij.psi.util.PsiUtil类的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil类的具体用法?Java PsiUtil怎么用?Java PsiUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiUtil类属于com.intellij.psi.util包,在下文中一共展示了PsiUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isStructuralType
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private boolean isStructuralType( PsiTypeElement typeElem )
{
if( typeElem != null )
{
PsiClass psiClass = PsiUtil.resolveClassInType( typeElem.getType() );
if( psiClass == null )
{
return false;
}
PsiAnnotation structuralAnno = psiClass.getModifierList() == null
? null
: psiClass.getModifierList().findAnnotation( "manifold.ext.api.Structural" );
if( structuralAnno != null )
{
return true;
}
}
return false;
}
示例2: visitAssertStatement
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Override
public void visitAssertStatement(PsiAssertStatement statement) {
super.visitAssertStatement(statement);
final PsiExpression assertCondition =
statement.getAssertCondition();
final PsiExpression expression =
ParenthesesUtils.stripParentheses(assertCondition);
if (expression == null) {
return;
}
if (BoolUtils.isFalse(expression)) {
return;
}
if (!PsiUtil.isConstantExpression(expression)) {
return;
}
registerError(expression);
}
示例3: getBoxedPropertyType
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Nullable
private static String getBoxedPropertyType(PsiElement declaration) {
PsiType attrType = null;
if (declaration instanceof PsiField) {
attrType = JavaFxPsiUtil.getWrappedPropertyType((PsiField)declaration, declaration.getProject(), JavaFxCommonClassNames.ourWritableMap);
} else if (declaration instanceof PsiMethod) {
final PsiParameter[] parameters = ((PsiMethod)declaration).getParameterList().getParameters();
final boolean isStatic = ((PsiMethod)declaration).hasModifierProperty(PsiModifier.STATIC);
if (isStatic && parameters.length == 2 || !isStatic && parameters.length == 1) {
attrType = parameters[parameters.length - 1].getType();
}
}
String boxedQName = null;
if (attrType instanceof PsiPrimitiveType) {
boxedQName = ((PsiPrimitiveType)attrType).getBoxedTypeName();
} else if (PsiPrimitiveType.getUnboxedType(attrType) != null) {
final PsiClass attrClass = PsiUtil.resolveClassInType(attrType);
boxedQName = attrClass != null ? attrClass.getQualifiedName() : null;
}
return boxedQName;
}
示例4: getIteratedType
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private static PsiType getIteratedType(PsiElement parent, PsiType collection) {
if (parent instanceof GrReferenceExpression) {
final GrExpression qualifier = ((GrReferenceExpression)parent).getQualifier();
if (qualifier != null) {
return ClosureParameterEnhancer.findTypeForIteration(qualifier, parent);
}
}
final PsiType iterable = PsiUtil.extractIterableTypeParameter(collection, true);
if (iterable != null && parent instanceof GrExpression) {
return PsiImplUtil.normalizeWildcardTypeByPosition(iterable, (GrExpression)parent);
}
else {
return iterable;
}
}
示例5: getVariablesVisibleAt
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@NotNull public static PsiVariable[] getVariablesVisibleAt(@Nullable final PsiElement place, String prefix) {
if (place == null) {
return new PsiVariable[0];
}
final Set<String> usedNames = ContainerUtil.newHashSet();
final List<PsiVariable> list = new ArrayList<PsiVariable>();
VariablesProcessor varproc = new VariablesProcessor(prefix, true, list) {
@Override
public boolean execute(@NotNull PsiElement pe, @NotNull ResolveState state) {
if (pe instanceof PsiVariable) {
if (!usedNames.add(((PsiVariable)pe).getName())) {
return false;
}
//exclude variables that are initialized in 'place'
final PsiExpression initializer = ((PsiVariable)pe).getInitializer();
if (initializer != null && PsiTreeUtil.isAncestor(initializer, place, false)) return true;
}
return pe instanceof PsiField && !PsiUtil.isAccessible((PsiField)pe, place, null) || super.execute(pe, state);
}
};
PsiScopesUtil.treeWalkUp(varproc, place, null);
return varproc.getResultsAsArray();
}
示例6: inferIteratorType
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private PsiType inferIteratorType(GroovyResolveResult iteratorMethodResult, GrExpression tupleInitializer) {
PsiElement method = iteratorMethodResult.getElement();
if (method instanceof PsiMethod) {
return iteratorMethodResult.getSubstitutor().substitute(((PsiMethod)method).getReturnType());
}
else {
PsiType initializerType = tupleInitializer.getType();
PsiType iterableParam = PsiUtil.extractIterableTypeParameter(initializerType, false);
JavaPsiFacade facade = JavaPsiFacade.getInstance(context.project);
PsiClass iterableClass = facade.findClass(CommonClassNames.JAVA_UTIL_ITERATOR, tupleInitializer.getResolveScope());
if (iterableClass != null && iterableParam != null) {
return facade.getElementFactory().createType(iterableClass, iterableParam);
}
else {
return facade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_ITERATOR, tupleInitializer);
}
}
}
示例7: hasStaticInitializer
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private static boolean hasStaticInitializer(PsiField field) {
if (field.hasModifierProperty(PsiModifier.STATIC)) {
final PsiExpression initializer = field.getInitializer();
if (initializer == null) {
return false;
}
final PsiType fieldType = field.getType();
final PsiType stringType = TypeUtils.getStringType(field);
if (field.hasModifierProperty(PsiModifier.FINAL) && (fieldType instanceof PsiPrimitiveType || fieldType.equals(stringType))) {
return !PsiUtil.isConstantExpression(initializer);
}
else {
return true;
}
}
return false;
}
示例8: visitConditionalExpression
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Override
public void visitConditionalExpression(PsiConditionalExpression expression) {
super.visitConditionalExpression(expression);
final PsiExpression condition = PsiUtil.skipParenthesizedExprDown(expression.getCondition());
if (!(condition instanceof PsiBinaryExpression)) {
return;
}
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)condition;
final PsiReferenceExpression referenceExpression = extractVariableReference(binaryExpression);
if (referenceExpression == null) {
return;
}
final IElementType tokenType = binaryExpression.getOperationTokenType();
if (tokenType == JavaTokenType.EQEQ) {
if (checkVariableUsage(referenceExpression, expression.getThenExpression(), expression.getElseExpression())) {
registerError(referenceExpression, Boolean.FALSE);
}
}
else if (tokenType == JavaTokenType.NE) {
if (checkVariableUsage(referenceExpression, expression.getElseExpression(), expression.getThenExpression())) {
registerError(referenceExpression, Boolean.FALSE);
}
}
}
示例9: isReferencedForWrite
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
boolean isReferencedForWrite(@NotNull PsiVariable variable) {
Collection<PsiReference> array;
synchronized (myLocalRefsMap) {
array = myLocalRefsMap.get(variable);
}
if (array.isEmpty()) return false;
for (PsiReference ref : array) {
final PsiElement refElement = ref.getElement();
if (!(refElement instanceof PsiExpression)) { // possible with incomplete code
return true;
}
if (PsiUtil.isAccessedForWriting((PsiExpression)refElement)) {
return true;
}
}
return false;
}
示例10: addExprTypesByDerivedClasses
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private void addExprTypesByDerivedClasses(LinkedHashSet<PsiType> set, PsiExpression expr) {
PsiType type = expr.getType();
if (!(type instanceof PsiClassType)) return;
PsiClass refClass = PsiUtil.resolveClassInType(type);
if (refClass == null) return;
PsiManager manager = PsiManager.getInstance(myProject);
PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(5);
ClassInheritorsSearch.search(refClass, true).forEach(new PsiElementProcessorAdapter<PsiClass>(processor));
if (processor.isOverflow()) return;
for (PsiClass derivedClass : processor.getCollection()) {
if (derivedClass instanceof PsiAnonymousClass) continue;
PsiType derivedType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(derivedClass);
set.add(derivedType);
}
}
示例11: registerSwapFixes
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private static void registerSwapFixes(final PsiExpression[] expressions, final PsiCall callExpression, final List<PsiCall> permutations,
MethodCandidateInfo candidate, final int incompatibilitiesCount, final int minIncompatibleIndex,
final int maxIncompatibleIndex) throws IncorrectOperationException {
PsiMethod method = candidate.getElement();
PsiSubstitutor substitutor = candidate.getSubstitutor();
if (incompatibilitiesCount >= 3) return; // no way we can fix it by swapping
for (int i = minIncompatibleIndex; i < maxIncompatibleIndex; i++) {
for (int j = i+1; j <= maxIncompatibleIndex; j++) {
ArrayUtil.swap(expressions, i, j);
if (PsiUtil.isApplicable(method, substitutor, expressions)) {
PsiCall copy = (PsiCall)callExpression.copy();
PsiExpression[] copyExpressions = copy.getArgumentList().getExpressions();
copyExpressions[i].replace(expressions[i]);
copyExpressions[j].replace(expressions[j]);
JavaResolveResult result = copy.resolveMethodGenerics();
if (result.getElement() != null && result.isValidResult()) {
permutations.add(copy);
if (permutations.size() > 1) return;
}
}
ArrayUtil.swap(expressions, i, j);
}
}
}
示例12: checkExpression
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private void checkExpression(PsiExpression expression) {
expression = PsiUtil.deparenthesizeExpression(expression);
if (negate) {
if (expression instanceof PsiPrefixExpression) {
final PsiPrefixExpression prefixExpression =
(PsiPrefixExpression)expression;
final IElementType tokenType =
prefixExpression.getOperationTokenType();
if (tokenType != JavaTokenType.EXCL) {
return;
}
expression = PsiUtil.deparenthesizeExpression(
prefixExpression.getOperand());
checkInstanceOfExpression(expression);
}
}
else {
checkInstanceOfExpression(expression);
}
if (expression instanceof PsiPolyadicExpression) {
final PsiPolyadicExpression binaryExpression =
(PsiPolyadicExpression)expression;
visitPolyadicExpression(binaryExpression);
}
}
示例13: createInitialStates
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Nullable
private Collection<DfaMemoryState> createInitialStates(@NotNull PsiElement psiBlock, InstructionVisitor visitor) {
PsiClass containingClass = PsiTreeUtil.getParentOfType(psiBlock, PsiClass.class);
if (containingClass != null && PsiUtil.isLocalOrAnonymousClass(containingClass)) {
final PsiElement parent = containingClass.getParent();
final PsiCodeBlock block = DfaPsiUtil.getTopmostBlockInSameClass(parent);
if ((parent instanceof PsiNewExpression || parent instanceof PsiDeclarationStatement) && block != null) {
final RunnerResult result = analyzeMethod(block, visitor);
if (result == RunnerResult.OK) {
final Collection<DfaMemoryState> closureStates = myNestedClosures.get(DfaPsiUtil.getTopmostBlockInSameClass(psiBlock));
if (!closureStates.isEmpty()) {
return closureStates;
}
}
return null;
}
}
return Collections.singletonList(createMemoryState());
}
示例14: addBound
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
public boolean addBound(PsiType classType, InferenceBound inferenceBound) {
if (inferenceBound == InferenceBound.EQ &&
PsiUtil.resolveClassInClassTypeOnly(classType) == this) {
return false;
}
List<PsiType> list = myBounds.get(inferenceBound);
if (list == null) {
list = new ArrayList<PsiType>();
myBounds.put(inferenceBound, list);
}
final int idx = list.indexOf(classType);
if (idx < 0) {
list.add(classType);
return true;
}
return false;
}
示例15: chooseAndImplement
import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
protected static void chooseAndImplement(PsiClass psiClass, Project project, @NotNull PsiClass targetClass, Editor editor) {
boolean hasNonTrivialConstructor = false;
final PsiMethod[] constructors = psiClass.getConstructors();
for (PsiMethod constructor : constructors) {
if (constructor.getParameterList().getParametersCount() > 0) {
hasNonTrivialConstructor = true;
break;
}
}
if (hasNonTrivialConstructor) {
final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(psiClass, targetClass, PsiSubstitutor.EMPTY);
final List<PsiMethodMember> baseConstructors = new ArrayList<PsiMethodMember>();
for (PsiMethod baseConstr : constructors) {
if (PsiUtil.isAccessible(project, baseConstr, targetClass, targetClass)) {
baseConstructors.add(new PsiMethodMember(baseConstr, substitutor));
}
}
final int offset = editor.getCaretModel().getOffset();
CreateConstructorMatchingSuperFix.chooseConstructor2Delegate(project, editor,
substitutor,
baseConstructors, constructors, targetClass);
editor.getCaretModel().moveToOffset(offset);
}
OverrideImplementUtil.chooseAndImplementMethods(project, editor, targetClass);
}