Java 类com.intellij.psi.util.PsiTypesUtil 实例源码
项目:manifold-ij
文件:TypeUtil.java
public static PsiType getDefaultParameterizedType( PsiType type, PsiManager mgr )
{
if( type.getArrayDimensions() > 0 )
{
PsiType defType = getDefaultParameterizedType( ((PsiArrayType)type).getComponentType(), mgr );
if( !defType.equals( type ) )
{
return new PsiArrayType( defType );
}
return type;
}
if( type instanceof PsiIntersectionType )
{
return makeDefaultParameterizedTypeForCompoundType( (PsiIntersectionType)type, mgr );
}
if( type instanceof PsiDisjunctionType )
{
return getDefaultParameterizedType( PsiTypesUtil.getLowestUpperBoundClassType( (PsiDisjunctionType)type ), mgr );
}
if( !isGenericType( type ) && !isParameterizedType( type ) )
{
return type;
}
type = ((PsiClassType)type).rawType();
return makeDefaultParameterizedType( type );
}
项目:intellij-ce-playground
文件:JavaLangClassMemberReference.java
@Nullable
private PsiClass getPsiClass() {
if (myContext instanceof PsiClassObjectAccessExpression) {
return PsiTypesUtil.getPsiClass(((PsiClassObjectAccessExpression)myContext).getOperand().getType());
} else if (myContext instanceof PsiMethodCallExpression) {
final PsiMethod method = ((PsiMethodCallExpression)myContext).resolveMethod();
if (method != null && "forName".equals(method.getName()) && isClass(method.getContainingClass())) {
final PsiExpression[] expressions = ((PsiMethodCallExpression)myContext).getArgumentList().getExpressions();
if (expressions.length == 1 && expressions[0] instanceof PsiLiteralExpression) {
final Object value = ((PsiLiteralExpression)expressions[0]).getValue();
if (value instanceof String) {
final Project project = myContext.getProject();
return JavaPsiFacade.getInstance(project).findClass(String.valueOf(value), GlobalSearchScope.allScope(project));
}
}
}
}
return null;
}
项目:intellij-ce-playground
文件:InlineSuperClassRefactoringProcessor.java
@Nullable
private static PsiType getPlaceExpectedType(PsiElement parent) {
PsiType type = PsiTypesUtil.getExpectedTypeByParent((PsiExpression)parent);
if (type == null) {
final PsiElement arg = PsiUtil.skipParenthesizedExprUp(parent);
final PsiElement gParent = arg.getParent();
if (gParent instanceof PsiExpressionList) {
int i = ArrayUtilRt.find(((PsiExpressionList)gParent).getExpressions(), arg);
final PsiElement pParent = gParent.getParent();
if (pParent instanceof PsiCallExpression) {
final PsiMethod method = ((PsiCallExpression)pParent).resolveMethod();
if (method != null) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (i >= parameters.length) {
if (method.isVarArgs()) {
return ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
}
} else {
return parameters[i].getType();
}
}
}
}
}
return type;
}
项目:intellij-ce-playground
文件:ExtensionPointDeclarationRelatedItemLineMarkerProvider.java
private static boolean isExtensionPointNameDeclarationField(PsiField psiField) {
// *do* allow non-public
if (!psiField.hasModifierProperty(PsiModifier.FINAL) ||
!psiField.hasModifierProperty(PsiModifier.STATIC) ||
psiField.hasModifierProperty(PsiModifier.ABSTRACT)) {
return false;
}
if (!psiField.hasInitializer()) {
return false;
}
final PsiExpression initializer = psiField.getInitializer();
if (!(initializer instanceof PsiMethodCallExpression) &&
!(initializer instanceof PsiNewExpression)) {
return false;
}
final PsiClass fieldClass = PsiTypesUtil.getPsiClass(psiField.getType());
if (fieldClass == null) {
return false;
}
return ExtensionPointName.class.getName().equals(fieldClass.getQualifiedName());
}
项目:intellij-ce-playground
文件:ExtensionPointDocumentationProvider.java
@Override
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
ExtensionPoint extensionPoint = findExtensionPoint(element);
if (extensionPoint == null) return null;
final XmlFile epDeclarationFile = (XmlFile)extensionPoint.getXmlTag().getContainingFile();
final Module epModule = ModuleUtilCore.findModuleForFile(epDeclarationFile.getVirtualFile(), element.getProject());
final String epPrefix = extensionPoint.getNamePrefix();
final PsiClass epClass = getExtensionPointClass(extensionPoint);
StringBuilder epClassText = new StringBuilder();
if (epClass != null) {
JavaDocInfoGenerator.generateType(epClassText, PsiTypesUtil.getClassType(epClass), epClass, true);
}
else {
epClassText.append("<unknown>");
}
return (epModule == null ? "" : "[" + epModule.getName() + "]") +
(epPrefix == null ? "" : " " + epPrefix) +
"<br/>" +
"<b>" + extensionPoint.getEffectiveName() + "</b>" +
" (" + epDeclarationFile.getName() + ")<br/>" +
epClassText.toString();
}
项目:intellij-ce-playground
文件:GroovyNameSuggestionUtil.java
private static void generateVariableNameByTypeInner(PsiType type, Set<String> possibleNames, NameValidator validator) {
String unboxed = PsiTypesUtil.unboxIfPossible(type.getCanonicalText());
if (unboxed != null && !unboxed.equals(type.getCanonicalText())) {
String name = generateNameForBuiltInType(unboxed);
name = validator.validateName(name, true);
if (GroovyNamesUtil.isIdentifier(name)) {
possibleNames.add(name);
}
}
else if (type instanceof PsiIntersectionType) {
for (PsiType psiType : ((PsiIntersectionType)type).getConjuncts()) {
generateByType(psiType, possibleNames, validator);
}
}
else {
generateByType(type, possibleNames, validator);
}
}
项目:tools-idea
文件:JavaColorProvider.java
@Override
public Color getColorFrom(@NotNull PsiElement element) {
if (element instanceof PsiNewExpression && element.getLanguage() == JavaLanguage.INSTANCE) {
final PsiNewExpression expr = (PsiNewExpression)element;
final PsiType type = expr.getType();
if (type != null) {
final PsiClass aClass = PsiTypesUtil.getPsiClass(type);
if (aClass != null) {
final String fqn = aClass.getQualifiedName();
if ("java.awt.Color".equals(fqn) || "javax.swing.plaf.ColorUIResource".equals(fqn)) {
return getColor(expr.getArgumentList());
}
}
}
}
return null;
}
项目:tools-idea
文件:InlineSuperClassRefactoringProcessor.java
@Nullable
private static PsiType getPlaceExpectedType(PsiElement parent) {
PsiType type = PsiTypesUtil.getExpectedTypeByParent((PsiExpression)parent);
if (type == null) {
final PsiElement arg = PsiUtil.skipParenthesizedExprUp(parent);
final PsiElement gParent = arg.getParent();
if (gParent instanceof PsiExpressionList) {
int i = ArrayUtilRt.find(((PsiExpressionList)gParent).getExpressions(), arg);
final PsiElement pParent = gParent.getParent();
if (pParent instanceof PsiCallExpression) {
final PsiMethod method = ((PsiCallExpression)pParent).resolveMethod();
if (method != null) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (i >= parameters.length) {
if (method.isVarArgs()) {
return ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
}
} else {
return parameters[i].getType();
}
}
}
}
}
return type;
}
项目:tools-idea
文件:GroovyNameSuggestionUtil.java
private static void generateVariableNameByTypeInner(PsiType type, Set<String> possibleNames, NameValidator validator) {
String unboxed = PsiTypesUtil.unboxIfPossible(type.getCanonicalText());
if (unboxed != null && !unboxed.equals(type.getCanonicalText())) {
String name = generateNameForBuiltInType(unboxed);
name = validator.validateName(name, true);
if (GroovyNamesUtil.isIdentifier(name)) {
possibleNames.add(name);
}
}
else if (type instanceof PsiIntersectionType) {
for (PsiType psiType : ((PsiIntersectionType)type).getConjuncts()) {
generateByType(psiType, possibleNames, validator);
}
}
else {
generateByType(type, possibleNames, validator);
}
}
项目:consulo-java
文件:ControlFlowAnalyzer.java
@Override
public void visitField(PsiField field)
{
PsiExpression initializer = field.getInitializer();
if(initializer != null)
{
initializeVariable(field, initializer);
}
else if(!field.hasModifier(JvmModifier.FINAL))
{
// initialize with default value
DfaVariableValue dfaVariable = myFactory.getVarFactory().createVariableValue(field, false);
addInstruction(new PushInstruction(dfaVariable, null, true));
addInstruction(new PushInstruction(myFactory.getConstFactory().createFromValue(PsiTypesUtil.getDefaultValue(field.getType()), field.getType(), null), null));
addInstruction(new AssignInstruction(null, dfaVariable));
addInstruction(new PopInstruction());
}
}
项目:consulo-java
文件:LambdaHighlightingUtil.java
@Nullable
static HighlightInfo checkParametersCompatible(PsiLambdaExpression expression, PsiParameter[] methodParameters, PsiSubstitutor substitutor)
{
final PsiParameter[] lambdaParameters = expression.getParameterList().getParameters();
String incompatibleTypesMessage = "Incompatible parameter types in lambda expression: ";
if(lambdaParameters.length != methodParameters.length)
{
incompatibleTypesMessage += "wrong number of parameters: expected " + methodParameters.length + " but found " + lambdaParameters.length;
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression.getParameterList()).descriptionAndTooltip(incompatibleTypesMessage).create();
}
boolean hasFormalParameterTypes = expression.hasFormalParameterTypes();
for(int i = 0; i < lambdaParameters.length; i++)
{
PsiParameter lambdaParameter = lambdaParameters[i];
PsiType lambdaParameterType = lambdaParameter.getType();
PsiType substitutedParamType = substitutor.substitute(methodParameters[i].getType());
if(hasFormalParameterTypes && !PsiTypesUtil.compareTypes(lambdaParameterType, substitutedParamType, true) || !TypeConversionUtil.isAssignable(substitutedParamType, lambdaParameterType))
{
final String expectedType = substitutedParamType != null ? substitutedParamType.getPresentableText() : null;
final String actualType = lambdaParameterType.getPresentableText();
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression.getParameterList()).descriptionAndTooltip(incompatibleTypesMessage + "expected " + expectedType + " " +
"but found " + actualType).create();
}
}
return null;
}
项目:consulo-java
文件:UncheckedWarningLocalInspectionBase.java
@Override
public void visitReturnStatement(PsiReturnStatement statement)
{
super.visitReturnStatement(statement);
if(IGNORE_UNCHECKED_ASSIGNMENT)
{
return;
}
final PsiType returnType = PsiTypesUtil.getMethodReturnType(statement);
if(returnType != null && !PsiType.VOID.equals(returnType))
{
final PsiExpression returnValue = statement.getReturnValue();
if(returnValue != null)
{
final PsiType valueType = returnValue.getType();
if(valueType != null)
{
final PsiElement psiElement = PsiTreeUtil.getParentOfType(statement, PsiMethod.class, PsiLambdaExpression.class);
LocalQuickFix[] fixes = psiElement instanceof PsiMethod ? new LocalQuickFix[]{QuickFixFactory.getInstance().createMethodReturnFix((PsiMethod) psiElement, valueType, true)} :
LocalQuickFix.EMPTY_ARRAY;
checkRawToGenericsAssignment(returnValue, returnValue, returnType, valueType, false, fixes);
}
}
}
}
项目:consulo-java
文件:JavaColorProvider.java
public static boolean isColorType(@Nullable PsiType type)
{
if(type != null)
{
final PsiClass aClass = PsiTypesUtil.getPsiClass(type);
if(aClass != null)
{
final String fqn = aClass.getQualifiedName();
if("java.awt.Color".equals(fqn) || "javax.swing.plaf.ColorUIResource".equals(fqn))
{
return true;
}
}
}
return false;
}
项目:consulo-java
文件:MethodReturnTypeFix.java
@Override
public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement)
{
final PsiMethod myMethod = (PsiMethod) startElement;
final PsiType myReturnType = myReturnTypePointer.getType();
if(myMethod.getManager().isInProject(myMethod) && myReturnType != null && myReturnType.isValid() && !TypeConversionUtil.isNullType(myReturnType))
{
final PsiType returnType = myMethod.getReturnType();
if(returnType != null && returnType.isValid() && !Comparing.equal(myReturnType, returnType))
{
return PsiTypesUtil.allTypeParametersResolved(myMethod, myReturnType);
}
}
return false;
}
项目:consulo-java
文件:InlineSuperClassRefactoringProcessor.java
@Nullable
private static PsiType getPlaceExpectedType(PsiElement parent) {
PsiType type = PsiTypesUtil.getExpectedTypeByParent((PsiExpression)parent);
if (type == null) {
final PsiElement arg = PsiUtil.skipParenthesizedExprUp(parent);
final PsiElement gParent = arg.getParent();
if (gParent instanceof PsiExpressionList) {
int i = ArrayUtilRt.find(((PsiExpressionList)gParent).getExpressions(), arg);
final PsiElement pParent = gParent.getParent();
if (pParent instanceof PsiCallExpression) {
final PsiMethod method = ((PsiCallExpression)pParent).resolveMethod();
if (method != null) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (i >= parameters.length) {
if (method.isVarArgs()) {
return ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
}
} else {
return parameters[i].getType();
}
}
}
}
}
return type;
}
项目:consulo-java
文件:TypeMigrationLabeler.java
private boolean typeContainsTypeParameters(@Nullable PsiType type, @NotNull Set<PsiTypeParameter> excluded)
{
if(!(type instanceof PsiClassType))
{
return false;
}
PsiTypesUtil.TypeParameterSearcher searcher = new PsiTypesUtil.TypeParameterSearcher();
type.accept(searcher);
for(PsiTypeParameter parameter : searcher.getTypeParameters())
{
if(!excluded.contains(parameter) && !myDisappearedTypeParameters.contains(parameter))
{
return true;
}
}
return false;
}
项目:jgiven-intellij-plugin
文件:TypeIsTooGenericCalculator.java
boolean typeIsTooGeneric(PsiType type) {
PsiClass clazz = PsiTypesUtil.getPsiClass(type);
if (clazz == null) {
return true;
}
String qualifiedName = clazz.getQualifiedName();
return qualifiedName == null
|| qualifiedName.startsWith("java.lang")
|| qualifiedName.startsWith("java.io")
|| qualifiedName.startsWith("java.util");
}
项目:jgiven-intellij-plugin
文件:ScenarioStateReferenceProvider.java
public List<PsiReference> findReferences(PsiField field, int maxNumberOfResults) {
PsiClass fieldClass = PsiTypesUtil.getPsiClass(field.getType());
if (fieldClass == null) {
return Collections.emptyList();
}
Project project = field.getProject();
PsiManager manager = PsiManager.getInstance(project);
JGivenUsageProvider usageProvider = new JGivenUsageProvider(scenarioStateProvider, resolutionHandler, new ReferenceFactory(manager));
StateReferenceProcessor processor = new StateReferenceProcessor(field, maxNumberOfResults, usageProvider);
SearchScope scope = GlobalSearchScope.everythingScope(project).intersectWith(javaFilesScope(project));
findPsiFields(project, (GlobalSearchScope) scope, processor);
return processor.getResults();
}
项目:data-mediator
文件:PsiUtils.java
/**
* Checks that the given type is an implementer of the given canonicalName with the given typed parameters
*
* @param type what we're checking against
* @param canonicalName the type must extend/implement this generic
* @param canonicalParamNames the type that the generic(s) must be (in this order)
* @return
*/
public static boolean isTypedClass(PsiType type, String canonicalName, String... canonicalParamNames) {
PsiClass parameterClass = PsiTypesUtil.getPsiClass(type);
if (parameterClass == null) {
return false;
}
// This is a safe cast, for if parameterClass != null, the type was checked in PsiTypesUtil#getPsiClass(...)
PsiClassType pct = (PsiClassType) type;
// Main class name doesn't match; exit early
if (!canonicalName.equals(parameterClass.getQualifiedName())) {
return false;
}
List<PsiType> psiTypes = new ArrayList<PsiType>(pct.resolveGenerics().getSubstitutor().getSubstitutionMap().values());
for (int i = 0; i < canonicalParamNames.length; i++) {
if (!isOfType(psiTypes.get(i), canonicalParamNames[i])) {
return false;
}
}
// Passed all screenings; must be a match!
return true;
}
项目:intellij-ce-playground
文件:PsiMethodCallExpressionImpl.java
@Nullable
private static PsiType getResultType(PsiMethodCallExpression call,
PsiReferenceExpression methodExpression,
JavaResolveResult result,
@NotNull final LanguageLevel languageLevel) {
final PsiMethod method = (PsiMethod)result.getElement();
if (method == null) return null;
boolean is15OrHigher = languageLevel.compareTo(LanguageLevel.JDK_1_5) >= 0;
final PsiType getClassReturnType = PsiTypesUtil.patchMethodGetClassReturnType(call, methodExpression, method,
new Condition<IElementType>() {
@Override
public boolean value(IElementType type) {
return type != JavaElementType.CLASS;
}
}, languageLevel);
if (getClassReturnType != null) {
return getClassReturnType;
}
PsiType ret = method.getReturnType();
if (ret == null) return null;
if (ret instanceof PsiClassType) {
ret = ((PsiClassType)ret).setLanguageLevel(languageLevel);
}
if (is15OrHigher) {
return captureReturnType(call, method, ret, result, languageLevel);
}
return TypeConversionUtil.erasure(ret);
}
项目:intellij-ce-playground
文件:LambdaHighlightingUtil.java
@Nullable
static HighlightInfo checkParametersCompatible(PsiLambdaExpression expression,
PsiParameter[] methodParameters,
PsiSubstitutor substitutor) {
final PsiParameter[] lambdaParameters = expression.getParameterList().getParameters();
String incompatibleTypesMessage = "Incompatible parameter types in lambda expression: ";
if (lambdaParameters.length != methodParameters.length) {
incompatibleTypesMessage += "wrong number of parameters: expected " + methodParameters.length + " but found " + lambdaParameters.length;
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(expression.getParameterList())
.descriptionAndTooltip(incompatibleTypesMessage)
.create();
}
boolean hasFormalParameterTypes = expression.hasFormalParameterTypes();
for (int i = 0; i < lambdaParameters.length; i++) {
PsiParameter lambdaParameter = lambdaParameters[i];
PsiType lambdaParameterType = lambdaParameter.getType();
PsiType substitutedParamType = substitutor.substitute(methodParameters[i].getType());
if (hasFormalParameterTypes &&!PsiTypesUtil.compareTypes(lambdaParameterType, substitutedParamType, true) ||
!TypeConversionUtil.isAssignable(substitutedParamType, lambdaParameterType)) {
final String expectedType = substitutedParamType != null ? substitutedParamType.getPresentableText() : null;
final String actualType = lambdaParameterType.getPresentableText();
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(expression.getParameterList())
.descriptionAndTooltip(incompatibleTypesMessage + "expected " + expectedType + " but found " + actualType)
.create();
}
}
return null;
}
项目:intellij-ce-playground
文件:GenerateCreateUIAction.java
private static boolean hasCreateUIMethod(PsiClass aClass) {
for (PsiMethod method : aClass.findMethodsByName("createUI", false)) {
if (method.hasModifierProperty(PsiModifier.STATIC)) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length == 1) {
final PsiType type = parameters[0].getType();
final PsiClass typeClass = PsiTypesUtil.getPsiClass(type);
return typeClass != null && "javax.swing.JComponent".equals(typeClass.getQualifiedName());
}
}
}
return false;
}
项目:intellij-ce-playground
文件:JavaColorProvider.java
public static boolean isColorType(@Nullable PsiType type) {
if (type != null) {
final PsiClass aClass = PsiTypesUtil.getPsiClass(type);
if (aClass != null) {
final String fqn = aClass.getQualifiedName();
if ("java.awt.Color".equals(fqn) || "javax.swing.plaf.ColorUIResource".equals(fqn)) {
return true;
}
}
}
return false;
}
项目:intellij-ce-playground
文件:AddReturnFix.java
private String suggestReturnValue() {
PsiType type = myMethod.getReturnType();
// first try to find suitable local variable
PsiVariable[] variables = getDeclaredVariables(myMethod);
for (PsiVariable variable : variables) {
PsiType varType = variable.getType();
if (varType.equals(type)) {
return variable.getName();
}
}
return PsiTypesUtil.getDefaultValueOfType(type);
}
项目:intellij-ce-playground
文件:UnnecessaryBoxingInspection.java
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length != 1) {
return;
}
if (!(arguments[0].getType() instanceof PsiPrimitiveType)) {
return;
}
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
@NonNls
final String referenceName = methodExpression.getReferenceName();
if (!"valueOf".equals(referenceName)) {
return;
}
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
if (!(qualifierExpression instanceof PsiReferenceExpression)) {
return;
}
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifierExpression;
final String canonicalText = referenceExpression.getCanonicalText();
if (PsiTypesUtil.unboxIfPossible(canonicalText) == canonicalText || !canBeUnboxed(expression)) {
return;
}
registerError(expression);
}
项目:intellij-ce-playground
文件:QuickfixUtil.java
public static String[] getArgumentsTypes(List<ParamInfo> listOfPairs) {
final List<String> result = new ArrayList<String>();
if (listOfPairs == null) return ArrayUtil.EMPTY_STRING_ARRAY;
for (ParamInfo listOfPair : listOfPairs) {
String type = PsiTypesUtil.unboxIfPossible(listOfPair.type);
result.add(type);
}
return ArrayUtil.toStringArray(result);
}
项目:intellij-ce-playground
文件:NonCodeMembersContributor.java
public static boolean runContributors(@NotNull PsiType qualifierType,
@NotNull PsiScopeProcessor processor,
@NotNull PsiElement place,
@NotNull ResolveState state) {
MyDelegatingScopeProcessor delegatingProcessor = new MyDelegatingScopeProcessor(processor);
ensureInit();
final PsiClass aClass = PsiTypesUtil.getPsiClass(qualifierType);
if (aClass != null) {
for (String superClassName : ClassUtil.getSuperClassesWithCache(aClass).keySet()) {
for (NonCodeMembersContributor enhancer : ourClassSpecifiedContributors.get(superClassName)) {
ProgressManager.checkCanceled();
enhancer.processDynamicElements(qualifierType, aClass, delegatingProcessor, place, state);
if (!delegatingProcessor.wantMore) {
return false;
}
}
}
}
for (NonCodeMembersContributor contributor : ourAllTypeContributors) {
ProgressManager.checkCanceled();
contributor.processDynamicElements(qualifierType, aClass, delegatingProcessor, place, state);
if (!delegatingProcessor.wantMore) {
return false;
}
}
return GroovyDslFileIndex.processExecutors(qualifierType, place, processor, state);
}
项目:intellij-ce-playground
文件:GrWithTraitTypeCalculator.java
@Nullable
@Override
protected PsiType calculateReturnType(@NotNull GrMethodCall callExpression, @NotNull PsiMethod resolvedMethod) {
if (!"withTraits".equals(resolvedMethod.getName())) return null;
if (resolvedMethod instanceof GrGdkMethod) {
resolvedMethod = ((GrGdkMethod)resolvedMethod).getStaticMethod();
}
GrExpression invokedExpression = callExpression.getInvokedExpression();
if (!(invokedExpression instanceof GrReferenceExpression)) return null;
GrExpression originalObject = ((GrReferenceExpression)invokedExpression).getQualifierExpression();
if (originalObject == null) return null;
PsiType invokedType = originalObject.getType();
if (!(invokedType instanceof PsiClassType)) return null;
PsiClass containingClass = resolvedMethod.getContainingClass();
if (containingClass == null || !GroovyCommonClassNames.DEFAULT_GROOVY_METHODS.equals(containingClass.getQualifiedName())) return null;
List<PsiClassType> traits = ContainerUtil.newArrayList();
GrExpression[] args = callExpression.getArgumentList().getExpressionArguments();
for (GrExpression arg : args) {
PsiType type = arg.getType();
PsiType classItem = PsiUtil.substituteTypeParameter(type, CommonClassNames.JAVA_LANG_CLASS, 0, false);
PsiClass psiClass = PsiTypesUtil.getPsiClass(classItem);
if (GrTraitUtil.isTrait(psiClass)) {
traits.add((PsiClassType)classItem);
}
}
return GrTraitType.createTraitClassType(callExpression, (PsiClassType)invokedType, traits, callExpression.getResolveScope());
}
项目:intellij-ce-playground
文件:GroovyOverrideImplementUtil.java
private static void setupOverridingMethodBody(Project project,
PsiMethod method,
GrMethod resultMethod,
FileTemplate template,
PsiSubstitutor substitutor) {
final PsiType returnType = substitutor.substitute(getSuperReturnType(method));
String returnTypeText = "";
if (returnType != null) {
returnTypeText = returnType.getPresentableText();
}
Properties properties = FileTemplateManager.getInstance(project).getDefaultProperties();
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnTypeText);
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, PsiTypesUtil.getDefaultValueOfType(returnType));
properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, callSuper(method, resultMethod));
JavaTemplateUtil.setClassAndMethodNameProperties(properties, method.getContainingClass(), resultMethod);
try {
String bodyText = StringUtil.replace(template.getText(properties), ";", "");
GroovyFile file = GroovyPsiElementFactory.getInstance(project).createGroovyFile("\n " + bodyText + "\n", false, null);
GrOpenBlock block = resultMethod.getBlock();
block.getNode().addChildren(file.getFirstChild().getNode(), null, block.getRBrace().getNode());
}
catch (IOException e) {
LOG.error(e);
}
}
项目:intellij-ce-playground
文件:InferLambdaParameterTypeIntention.java
@Nullable
private static String getInferredTypes(PsiType functionalInterfaceType, final PsiLambdaExpression lambdaExpression, boolean useFQN) {
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
final StringBuilder buf = new StringBuilder();
buf.append("(");
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
LOG.assertTrue(interfaceMethod != null);
final PsiParameter[] parameters = interfaceMethod.getParameterList().getParameters();
final PsiParameter[] lambdaParameters = lambdaExpression.getParameterList().getParameters();
if (parameters.length != lambdaParameters.length) return null;
for (int i = 0; i < parameters.length; i++) {
PsiParameter parameter = parameters[i];
final PsiType psiType = LambdaUtil.getSubstitutor(interfaceMethod, resolveResult).substitute(parameter.getType());
if (!PsiTypesUtil.isDenotableType(psiType)) return null;
if (psiType != null) {
buf.append(useFQN ? psiType.getCanonicalText() : psiType.getPresentableText()).append(" ").append(lambdaParameters[i].getName());
}
else {
buf.append(lambdaParameters[i].getName());
}
if (i < parameters.length - 1) {
buf.append(", ");
}
}
buf.append(")");
return buf.toString();
}
项目:SerializableParcelableGenerator
文件:PsiUtils.java
/**
* Checks that the given type is an implementer of the given canonicalName with the given typed parameters
*
* @param type what we're checking against
* @param canonicalName the type must extend/implement this generic
* @param canonicalParamNames the type that the generic(s) must be (in this order)
* @return
*/
public static boolean isTypedClass(PsiType type, String canonicalName, String... canonicalParamNames) {
PsiClass parameterClass = PsiTypesUtil.getPsiClass(type);
if (parameterClass == null) {
return false;
}
// This is a safe cast, for if parameterClass != null, the type was checked in PsiTypesUtil#getPsiClass(...)
PsiClassType pct = (PsiClassType) type;
// Main class name doesn't match; exit early
if (!canonicalName.equals(parameterClass.getQualifiedName())) {
return false;
}
List<PsiType> psiTypes = new ArrayList<PsiType>(pct.resolveGenerics().getSubstitutor().getSubstitutionMap().values());
for (int i = 0; i < canonicalParamNames.length; i++) {
if (!isOfType(psiTypes.get(i), canonicalParamNames[i])) {
return false;
}
}
// Passed all screenings; must be a match!
return true;
}
项目:tools-idea
文件:GenerateCreateUIAction.java
private static boolean hasCreateUIMethod(PsiClass aClass) {
for (PsiMethod method : aClass.findMethodsByName("createUI", false)) {
if (method.hasModifierProperty(PsiModifier.STATIC)) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length == 1) {
final PsiType type = parameters[0].getType();
final PsiClass typeClass = PsiTypesUtil.getPsiClass(type);
return typeClass != null && "javax.swing.JComponent".equals(typeClass.getQualifiedName());
}
}
}
return false;
}
项目:tools-idea
文件:AddReturnFix.java
private String suggestReturnValue() {
PsiType type = myMethod.getReturnType();
// first try to find suitable local variable
PsiVariable[] variables = getDeclaredVariables(myMethod);
for (PsiVariable variable : variables) {
PsiType varType = variable.getType();
if (varType.equals(type)) {
return variable.getName();
}
}
return PsiTypesUtil.getDefaultValueOfType(type);
}
项目:tools-idea
文件:ExtensionDomExtender.java
@Nullable
public static PsiClass getElementType(final PsiType psiType) {
final PsiType elementType;
if (psiType instanceof PsiArrayType) elementType = ((PsiArrayType)psiType).getComponentType();
else if (psiType instanceof PsiClassType) {
final PsiType[] types = ((PsiClassType)psiType).getParameters();
elementType = types.length == 1? types[0] : null;
}
else elementType = null;
return PsiTypesUtil.getPsiClass(elementType);
}
项目:tools-idea
文件:QuickfixUtil.java
public static String[] getArgumentsTypes(List<ParamInfo> listOfPairs) {
final List<String> result = new ArrayList<String>();
if (listOfPairs == null) return ArrayUtil.EMPTY_STRING_ARRAY;
for (ParamInfo listOfPair : listOfPairs) {
String type = PsiTypesUtil.unboxIfPossible(listOfPair.type);
result.add(type);
}
return ArrayUtil.toStringArray(result);
}
项目:tools-idea
文件:GroovyOverrideImplementUtil.java
private static void setupOverridingMethodBody(Project project,
PsiMethod method,
GrMethod resultMethod,
FileTemplate template,
PsiSubstitutor substitutor) {
final PsiType returnType = substitutor.substitute(getSuperReturnType(method));
String returnTypeText = "";
if (returnType != null) {
returnTypeText = returnType.getPresentableText();
}
Properties properties = FileTemplateManager.getInstance().getDefaultProperties(project);
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnTypeText);
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, PsiTypesUtil.getDefaultValueOfType(returnType));
properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, callSuper(method, resultMethod));
JavaTemplateUtil.setClassAndMethodNameProperties(properties, method.getContainingClass(), resultMethod);
try {
String bodyText = StringUtil.replace(template.getText(properties), ";", "");
final GrCodeBlock newBody = GroovyPsiElementFactory.getInstance(project).createMethodBodyFromText("\n " + bodyText + "\n");
resultMethod.setBlock(newBody);
}
catch (IOException e) {
LOG.error(e);
}
}
项目:tools-idea
文件:ChooseTypeExpression.java
private static void processSuperTypes(PsiType type, Set<LookupElement> result) {
String text = type.getCanonicalText();
String unboxed = PsiTypesUtil.unboxIfPossible(text);
if (unboxed != null && !unboxed.equals(text)) {
result.add(LookupElementBuilder.create(unboxed).bold());
}
else {
PsiTypeLookupItem item = PsiTypeLookupItem.createLookupItem(type, null, PsiTypeLookupItem.isDiamond(type), IMPORT_FIXER);
result.add(item);
}
PsiType[] superTypes = type.getSuperTypes();
for (PsiType superType : superTypes) {
processSuperTypes(superType, result);
}
}
项目:tools-idea
文件:NonCodeMembersContributor.java
public static boolean runContributors(@NotNull final PsiType qualifierType,
@NotNull PsiScopeProcessor processor,
@NotNull final PsiElement place,
@NotNull final ResolveState state) {
MyDelegatingScopeProcessor delegatingProcessor = new MyDelegatingScopeProcessor(processor);
ensureInit();
final PsiClass aClass = PsiTypesUtil.getPsiClass(qualifierType);
if (aClass != null) {
for (String superClassName : TypesUtil.getSuperClassesWithCache(aClass).keySet()) {
for (NonCodeMembersContributor enhancer : ourClassSpecifiedContributors.get(superClassName)) {
enhancer.processDynamicElements(qualifierType, aClass, delegatingProcessor, place, state);
if (!delegatingProcessor.wantMore) {
return false;
}
}
}
}
for (NonCodeMembersContributor contributor : ourAllTypeContributors) {
contributor.processDynamicElements(qualifierType, aClass, delegatingProcessor, place, state);
if (!delegatingProcessor.wantMore) {
return false;
}
}
return GroovyDslFileIndex.processExecutors(qualifierType, place, processor, state);
}
项目:lombok-intellij-plugin
文件:DelegateHandler.java
private boolean validateRecursion(PsiType psiType, ProblemBuilder builder) {
final PsiClass psiClass = PsiTypesUtil.getPsiClass(psiType);
if (null != psiClass) {
final DelegateAnnotationElementVisitor delegateAnnotationElementVisitor = new DelegateAnnotationElementVisitor(psiType, builder);
psiClass.acceptChildren(delegateAnnotationElementVisitor);
return delegateAnnotationElementVisitor.isValid();
}
return true;
}
项目:android-parcelable-intellij-plugin
文件:PsiUtils.java
/**
* Checks that the given type is an implementer of the given canonicalName with the given typed parameters
*
* @param type what we're checking against
* @param canonicalName the type must extend/implement this generic
* @param canonicalParamNames the type that the generic(s) must be (in this order)
* @return
*/
public static boolean isTypedClass(PsiType type, String canonicalName, String... canonicalParamNames) {
PsiClass parameterClass = PsiTypesUtil.getPsiClass(type);
if (parameterClass == null) {
return false;
}
// This is a safe cast, for if parameterClass != null, the type was checked in PsiTypesUtil#getPsiClass(...)
PsiClassType pct = (PsiClassType) type;
// Main class name doesn't match; exit early
if (!canonicalName.equals(parameterClass.getQualifiedName())) {
return false;
}
List<PsiType> psiTypes = new ArrayList<PsiType>(pct.resolveGenerics().getSubstitutor().getSubstitutionMap().values());
for (int i = 0; i < canonicalParamNames.length; i++) {
if (!isOfType(psiTypes.get(i), canonicalParamNames[i])) {
return false;
}
}
// Passed all screenings; must be a match!
return true;
}