Search in sources :

Example 11 with PsiParameter

use of com.intellij.psi.PsiParameter in project intellij-community by JetBrains.

the class RemoveUnusedParameterFix method getNewParametersInfo.

@NotNull
public static ParameterInfoImpl[] getNewParametersInfo(PsiMethod method, PsiParameter parameterToRemove) {
    List<ParameterInfoImpl> result = new ArrayList<>();
    PsiParameter[] parameters = method.getParameterList().getParameters();
    for (int i = 0; i < parameters.length; i++) {
        PsiParameter parameter = parameters[i];
        if (!Comparing.equal(parameter, parameterToRemove)) {
            result.add(new ParameterInfoImpl(i, parameter.getName(), parameter.getType()));
        }
    }
    return result.toArray(new ParameterInfoImpl[result.size()]);
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) ArrayList(java.util.ArrayList) ParameterInfoImpl(com.intellij.refactoring.changeSignature.ParameterInfoImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PsiParameter

use of com.intellij.psi.PsiParameter in project intellij-community by JetBrains.

the class UnassignedVariableAccessInspection method check.

@Override
protected void check(@NotNull GrControlFlowOwner owner, @NotNull ProblemsHolder problemsHolder) {
    Instruction[] flow = owner.getControlFlow();
    ReadWriteVariableInstruction[] reads = ControlFlowBuilderUtil.getReadsWithoutPriorWrites(flow, true);
    for (ReadWriteVariableInstruction read : reads) {
        PsiElement element = read.getElement();
        if (element instanceof GroovyPsiElement && !(element instanceof GrClosableBlock)) {
            String name = read.getVariableName();
            GroovyPsiElement property = ResolveUtil.resolveProperty((GroovyPsiElement) element, name);
            if (property != null && !(property instanceof PsiParameter) && !(property instanceof PsiField) && PsiTreeUtil.isAncestor(owner, property, false) && !(myIgnoreBooleanExpressions && isBooleanCheck(element))) {
                problemsHolder.registerProblem(element, GroovyInspectionBundle.message("unassigned.access.tooltip", name));
            }
        }
    }
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) PsiParameter(com.intellij.psi.PsiParameter) ReadWriteVariableInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariableInstruction) PsiField(com.intellij.psi.PsiField) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) Instruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction) ReadWriteVariableInstruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariableInstruction) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 13 with PsiParameter

use of com.intellij.psi.PsiParameter in project qi4j-sdk by Qi4j.

the class AbstractInjectionAnnotationDeclarationOnFieldAndConstructorInspection method checkMethod.

@Override
public final ProblemDescriptor[] checkMethod(@NotNull PsiMethod method, @NotNull InspectionManager manager, boolean isOnTheFly) {
    PsiParameterList parameterList = method.getParameterList();
    PsiParameter[] parameters = parameterList.getParameters();
    if (method.isConstructor()) {
        List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
        for (PsiParameter parameter : parameters) {
            PsiAnnotation annotation = getAnnotationToCheck(parameter);
            if (annotation != null) {
                ProblemDescriptor[] descriptors = verifyAnnotationDeclaredCorrectly(parameter, annotation, manager);
                if (descriptors != null) {
                    problems.addAll(asList(descriptors));
                }
            }
        }
        return problems.toArray(new ProblemDescriptor[problems.size()]);
    } else {
        List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
        for (PsiParameter parameter : parameters) {
            PsiAnnotation annotationToCheck = getAnnotationToCheck(parameter);
            if (annotationToCheck != null) {
                String message = getInjectionAnnotationValidDeclarationMessage();
                AbstractFix removeAnnotationFix = createRemoveAnnotationFix(annotationToCheck);
                ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(annotationToCheck, message, removeAnnotationFix, GENERIC_ERROR_OR_WARNING);
                problems.add(problemDescriptor);
            }
        }
        return problems.toArray(new ProblemDescriptor[problems.size()]);
    }
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) AbstractFix(org.qi4j.ide.plugin.idea.common.inspections.AbstractFix) PsiParameterList(com.intellij.psi.PsiParameterList) PsiAnnotation(com.intellij.psi.PsiAnnotation) LinkedList(java.util.LinkedList)

Example 14 with PsiParameter

use of com.intellij.psi.PsiParameter in project intellij-community by JetBrains.

the class ParametersMatcher method matchParameters.

private static MatchResult matchParameters(final PsiMethod method, final ChainCompletionContext context, final Set<String> additionalExcludedNames) {
    int matched = 0;
    int unMatched = 0;
    boolean hasTarget = false;
    for (final PsiParameter parameter : method.getParameterList().getParameters()) {
        final PsiType type = parameter.getType();
        final String canonicalText = type.getCanonicalText();
        if (context.contains(canonicalText) || type instanceof PsiPrimitiveType) {
            matched++;
        } else {
            unMatched++;
        }
        if (context.getTarget().getClassQName().equals(canonicalText) || additionalExcludedNames.contains(canonicalText)) {
            hasTarget = true;
        }
    }
    return new MatchResult(matched, unMatched, hasTarget);
}
Also used : PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiParameter(com.intellij.psi.PsiParameter) PsiType(com.intellij.psi.PsiType)

Example 15 with PsiParameter

use of com.intellij.psi.PsiParameter in project intellij-community by JetBrains.

the class JavaMethodDescriptor method getParameters.

@Override
public List<ParameterInfoImpl> getParameters() {
    final ArrayList<ParameterInfoImpl> result = new ArrayList<>();
    final PsiParameter[] parameters = myMethod.getParameterList().getParameters();
    for (int i = 0; i < parameters.length; i++) {
        PsiParameter parameter = parameters[i];
        ParameterInfoImpl info = new ParameterInfoImpl(i, parameter.getName(), parameter.getType());
        info.defaultValue = "";
        result.add(info);
    }
    return result;
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) ArrayList(java.util.ArrayList)

Aggregations

PsiParameter (com.intellij.psi.PsiParameter)26 PsiMethod (com.intellij.psi.PsiMethod)6 PsiElement (com.intellij.psi.PsiElement)5 PsiType (com.intellij.psi.PsiType)5 ArrayList (java.util.ArrayList)5 PsiParameterList (com.intellij.psi.PsiParameterList)4 Nullable (org.jetbrains.annotations.Nullable)3 ClassMember (com.intellij.codeInsight.generation.ClassMember)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiField (com.intellij.psi.PsiField)2 PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)2 PsiVariable (com.intellij.psi.PsiVariable)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (com.android.annotations.Nullable)1 ResourceUrl (com.android.ide.common.resources.ResourceUrl)1 ResourceType (com.android.resources.ResourceType)1 Location (com.android.tools.klint.detector.api.Location)1 JavaEvaluator (com.android.tools.lint.client.api.JavaEvaluator)1 AddAnnotationPsiFix (com.intellij.codeInsight.intention.AddAnnotationPsiFix)1