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];
}
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);
}
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;
}
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);
}
}
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());
}
Aggregations