use of com.intellij.psi.PsiParameter in project Conductor by bluelinelabs.
the class ControllerIssueDetector method checkClass.
@Override
public void checkClass(JavaContext context, PsiClass declaration) {
final JavaEvaluator evaluator = context.getEvaluator();
if (evaluator.isAbstract(declaration)) {
return;
}
if (!evaluator.isPublic(declaration)) {
String message = String.format("This Controller class should be public (%1$s)", declaration.getQualifiedName());
context.report(ISSUE, declaration, context.getLocation(declaration), message);
return;
}
if (declaration.getContainingClass() != null && !evaluator.isStatic(declaration)) {
String message = String.format("This Controller inner class should be static (%1$s)", declaration.getQualifiedName());
context.report(ISSUE, declaration, context.getLocation(declaration), message);
return;
}
boolean hasDefaultConstructor = false;
boolean hasBundleConstructor = false;
PsiMethod[] constructors = declaration.getConstructors();
for (PsiMethod constructor : constructors) {
if (evaluator.isPublic(constructor)) {
PsiParameter[] parameters = constructor.getParameterList().getParameters();
if (parameters.length == 0) {
hasDefaultConstructor = true;
break;
} else if (parameters.length == 1 && parameters[0].getType().equalsToText(SdkConstants.CLASS_BUNDLE) || parameters[0].getType().equalsToText("Bundle")) {
hasBundleConstructor = true;
break;
}
}
}
if (constructors.length > 0 && !hasDefaultConstructor && !hasBundleConstructor) {
String message = String.format("This Controller needs to have either a public default constructor or a" + " public single-argument constructor that takes a Bundle. (`%1$s`)", declaration.getQualifiedName());
context.report(ISSUE, declaration, context.getLocation(declaration), message);
}
}
use of com.intellij.psi.PsiParameter in project intellij-community by JetBrains.
the class GroovyGeneratePropertyMissingHandler method chooseOriginalMembers.
@Nullable
@Override
protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) {
final PsiMethod[] missings = aClass.findMethodsByName("propertyMissing", true);
PsiMethod getter = null;
PsiMethod setter = null;
for (PsiMethod missing : missings) {
final PsiParameter[] parameters = missing.getParameterList().getParameters();
if (parameters.length == 1) {
if (isNameParam(parameters[0])) {
getter = missing;
}
} else if (parameters.length == 2) {
if (isNameParam(parameters[0])) {
setter = missing;
}
}
}
if (setter != null && getter != null) {
String text = GroovyCodeInsightBundle.message("generate.property.missing.already.defined.warning");
if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.property.missing.already.defined.title"), Messages.getQuestionIcon()) == Messages.YES) {
final PsiMethod finalGetter = getter;
final PsiMethod finalSetter = setter;
if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
try {
finalSetter.delete();
finalGetter.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 intellij-community by JetBrains.
the class GrInplaceParameterIntroducer method updateTitle.
@Override
protected void updateTitle(@Nullable GrVariable variable, String value) {
if (getPreviewEditor() == null || variable == null)
return;
final PsiElement declarationScope = ((PsiParameter) variable).getDeclarationScope();
if (declarationScope instanceof PsiMethod) {
final PsiMethod psiMethod = (PsiMethod) declarationScope;
final StringBuilder buf = new StringBuilder();
buf.append(psiMethod.getName()).append(" (");
boolean frst = true;
final List<TextRange> ranges2Remove = new ArrayList<>();
TextRange addedRange = null;
int i = 0;
for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) {
if (frst) {
frst = false;
} else {
buf.append(", ");
}
int startOffset = buf.length();
/*if (myMustBeFinal || myPanel.isGenerateFinal()) {
buf.append("final ");
}*/
buf.append(parameter.getType().getPresentableText()).append(" ").append(variable == parameter ? value : parameter.getName());
int endOffset = buf.length();
if (variable == parameter) {
addedRange = new TextRange(startOffset, endOffset);
} else if (myParametersToRemove.contains(i)) {
ranges2Remove.add(new TextRange(startOffset, endOffset));
}
i++;
}
assert addedRange != null;
buf.append(")");
setPreviewText(buf.toString());
final MarkupModel markupModel = DocumentMarkupModel.forDocument(getPreviewEditor().getDocument(), myProject, true);
markupModel.removeAllHighlighters();
for (TextRange textRange : ranges2Remove) {
markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), 0, getTestAttributesForRemoval(), HighlighterTargetArea.EXACT_RANGE);
}
markupModel.addRangeHighlighter(addedRange.getStartOffset(), addedRange.getEndOffset(), 0, getTextAttributesForAdd(), HighlighterTargetArea.EXACT_RANGE);
//revalidate();
}
}
use of com.intellij.psi.PsiParameter in project intellij-community by JetBrains.
the class LocalVarAnalyzer method searchForVarsToWrap.
public static Result searchForVarsToWrap(GroovyPsiElement root, Result analyzedVars, ExpressionContext context) {
LocalVarAnalyzer visitor = new LocalVarAnalyzer();
root.accept(visitor);
Map<PsiVariable, String> varToName = analyzedVars == null ? new HashMap<>() : analyzedVars.varToName;
Set<PsiVariable> toWrap = analyzedVars == null ? new HashSet<>() : analyzedVars.toWrap;
Set<PsiVariable> toMakeFinal = analyzedVars == null ? new HashSet<>() : analyzedVars.toMakeFinal;
for (PsiVariable v : visitor.touched) {
if (visitor.rewritten.contains(v)) {
toWrap.add(v);
if (v instanceof PsiParameter) {
varToName.put(v, GenerationUtil.suggestVarName(v.getType(), root, context));
} else {
varToName.put(v, v.getName());
}
} else {
toMakeFinal.add(v);
varToName.put(v, v.getName());
}
}
return analyzedVars == null ? new Result(toMakeFinal, toWrap, varToName) : analyzedVars;
}
use of com.intellij.psi.PsiParameter in project intellij-community by JetBrains.
the class ChainCompletionLookupElementUtil method fillMethodParameters.
public static String fillMethodParameters(final PsiMethod method, @Nullable final TIntObjectHashMap<SubLookupElement> replaceElements) {
final TIntObjectHashMap<SubLookupElement> notNullReplaceElements = replaceElements == null ? new TIntObjectHashMap<>(0) : replaceElements;
final PsiParameter[] parameters = method.getParameterList().getParameters();
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < parameters.length; i++) {
if (i != 0) {
sb.append(", ");
}
final PsiParameter parameter = parameters[i];
final SubLookupElement replaceElement = notNullReplaceElements.get(i);
if (replaceElement != null) {
sb.append(replaceElement.getInsertString());
} else {
sb.append(parameter.getName());
}
}
return sb.toString();
}
Aggregations