Search in sources :

Example 21 with PsiParameter

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

the class GroovyGenerateMethodMissingHandler method chooseOriginalMembers.

@Nullable
@Override
protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) {
    final PsiMethod[] missings = aClass.findMethodsByName("methodMissing", true);
    PsiMethod method = null;
    for (PsiMethod missing : missings) {
        final PsiParameter[] parameters = missing.getParameterList().getParameters();
        if (parameters.length == 2) {
            if (isNameParam(parameters[0])) {
                method = missing;
            }
        }
    }
    if (method != null) {
        String text = GroovyCodeInsightBundle.message("generate.method.missing.already.defined.warning");
        if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.method.missing.already.defined.title"), Messages.getQuestionIcon()) == Messages.YES) {
            final PsiMethod finalMethod = method;
            if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {

                @Override
                public Boolean compute() {
                    try {
                        finalMethod.delete();
                        return Boolean.TRUE;
                    } catch (IncorrectOperationException e) {
                        LOG.error(e);
                        return Boolean.FALSE;
                    }
                }
            }).booleanValue()) {
                return null;
            }
        } else {
            return null;
        }
    }
    return new ClassMember[1];
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiMethod(com.intellij.psi.PsiMethod) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ClassMember(com.intellij.codeInsight.generation.ClassMember) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with PsiParameter

use of com.intellij.psi.PsiParameter in project kotlin by JetBrains.

the class JavaValueParameterImpl method getName.

@Override
@Nullable
public Name getName() {
    PsiParameter psi = getPsi();
    if (psi instanceof ClsParameterImpl && ((ClsParameterImpl) psi).isAutoGeneratedName()) {
        return null;
    }
    String name = psi.getName();
    return name == null ? null : Name.identifier(name);
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) ClsParameterImpl(com.intellij.psi.impl.compiled.ClsParameterImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with PsiParameter

use of com.intellij.psi.PsiParameter in project kotlin by JetBrains.

the class DateFormatDetector method specifiesLocale.

private static boolean specifiesLocale(@NonNull PsiMethod method) {
    PsiParameterList parameterList = method.getParameterList();
    PsiParameter[] parameters = parameterList.getParameters();
    for (PsiParameter parameter : parameters) {
        PsiType type = parameter.getType();
        if (type.getCanonicalText().equals(LOCALE_CLS)) {
            return true;
        }
    }
    return false;
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiParameterList(com.intellij.psi.PsiParameterList) PsiType(com.intellij.psi.PsiType)

Example 24 with PsiParameter

use of com.intellij.psi.PsiParameter in project kotlin by JetBrains.

the class UnsafeBroadcastReceiverDetector method checkOnReceive.

private static void checkOnReceive(@NonNull JavaContext context, @NonNull PsiMethod method) {
    // Search for call to getAction but also search for references to aload_2,
    // which indicates that the method is making use of the received intent in
    // some way.
    //
    // If the onReceive method doesn't call getAction but does make use of
    // the received intent, it is possible that it is passing it to another
    // method that might be performing the getAction check, so we warn that the
    // finding may be a false positive. (An alternative option would be to not
    // report a finding at all in this case.)
    PsiParameter parameter = method.getParameterList().getParameters()[1];
    OnReceiveVisitor visitor = new OnReceiveVisitor(context.getEvaluator(), parameter);
    context.getUastContext().getMethodBody(method).accept(visitor);
    if (!visitor.getCallsGetAction()) {
        String report;
        if (!visitor.getUsesIntent()) {
            report = "This broadcast receiver declares an intent-filter for a protected " + "broadcast action string, which can only be sent by the system, " + "not third-party applications. However, the receiver's onReceive " + "method does not appear to call getAction to ensure that the " + "received Intent's action string matches the expected value, " + "potentially making it possible for another actor to send a " + "spoofed intent with no action string or a different action " + "string and cause undesired behavior.";
        } else {
            // An alternative implementation option is to not report a finding at all in
            // this case, if we are worried about false positives causing confusion or
            // resulting in developers ignoring other lint warnings.
            report = "This broadcast receiver declares an intent-filter for a protected " + "broadcast action string, which can only be sent by the system, " + "not third-party applications. However, the receiver's onReceive " + "method does not appear to call getAction to ensure that the " + "received Intent's action string matches the expected value, " + "potentially making it possible for another actor to send a " + "spoofed intent with no action string or a different action " + "string and cause undesired behavior. In this case, it is " + "possible that the onReceive method passed the received Intent " + "to another method that checked the action string. If so, this " + "finding can safely be ignored.";
        }
        Location location = context.getNameLocation(method);
        context.report(ACTION_STRING, method, location, report);
    }
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) Location(com.android.tools.klint.detector.api.Location)

Example 25 with PsiParameter

use of com.intellij.psi.PsiParameter in project kotlin by JetBrains.

the class ViewConstructorDetector method isXmlConstructor.

// ---- Implements JavaScanner ----
private static boolean isXmlConstructor(@NonNull JavaEvaluator evaluator, @NonNull PsiMethod method) {
    // Accept
    //   android.content.Context
    //   android.content.Context,android.util.AttributeSet
    //   android.content.Context,android.util.AttributeSet,int
    PsiParameterList parameterList = method.getParameterList();
    int argumentCount = parameterList.getParametersCount();
    if (argumentCount == 0 || argumentCount > 3) {
        return false;
    }
    PsiParameter[] parameters = parameterList.getParameters();
    if (!evaluator.typeMatches(parameters[0].getType(), CLASS_CONTEXT)) {
        return false;
    }
    if (argumentCount == 1) {
        return true;
    }
    if (!evaluator.typeMatches(parameters[1].getType(), CLASS_ATTRIBUTE_SET)) {
        return false;
    }
    //noinspection SimplifiableIfStatement
    if (argumentCount == 2) {
        return true;
    }
    return PsiType.INT.equals(parameters[2].getType());
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiParameterList(com.intellij.psi.PsiParameterList)

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