use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class GrIntroduceFieldProcessor method initializeInMethod.
void initializeInMethod(@NotNull GrVariable field, @NotNull List<PsiElement> replaced) {
final PsiElement _scope = myContext.getScope();
final PsiElement scope = _scope instanceof GroovyScriptClass ? ((GroovyScriptClass) _scope).getContainingFile() : _scope;
final PsiElement place = replaced.get(0);
final GrMember member = GrIntroduceFieldHandler.getContainer(place, scope);
GrStatementOwner container = member instanceof GrMethod ? ((GrMethod) member).getBlock() : member instanceof GrClassInitializer ? ((GrClassInitializer) member).getBlock() : place.getContainingFile() instanceof GroovyFile ? ((GroovyFile) place.getContainingFile()) : null;
assert container != null;
final PsiElement anchor;
if (mySettings.removeLocalVar()) {
GrVariable variable = myLocalVariable;
anchor = PsiTreeUtil.getParentOfType(variable, GrStatement.class);
} else {
anchor = GrIntroduceHandlerBase.findAnchor(replaced.toArray(new PsiElement[replaced.size()]), container);
GrIntroduceHandlerBase.assertStatement(anchor, myContext.getScope());
}
initializeInMethodInner(field, container, (GrStatement) anchor, replaced.get(0));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class GroovyRefactoringSupportProvider method isMemberInplaceRenameAvailable.
@Override
public boolean isMemberInplaceRenameAvailable(@NotNull PsiElement element, @Nullable PsiElement context) {
if (context == null || context.getContainingFile() instanceof GroovyFile)
return false;
PsiElement parent = context.getParent();
//don't try to inplace rename aliased imported references
if (parent instanceof GrReferenceElement) {
GroovyResolveResult result = ((GrReferenceElement) parent).advancedResolve();
PsiElement fileResolveContext = result.getCurrentFileResolveContext();
if (fileResolveContext instanceof GrImportStatement && ((GrImportStatement) fileResolveContext).isAliasedImport()) {
return false;
}
}
return element instanceof GrMember;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class ClosureGenerator method getOwner.
@NonNls
@NotNull
private CharSequence getOwner(@NotNull GrClosableBlock closure) {
final GroovyPsiElement context = PsiTreeUtil.getParentOfType(closure, GrMember.class, GroovyFile.class);
LOG.assertTrue(context != null);
final PsiClass contextClass;
if (context instanceof GroovyFile) {
contextClass = ((GroovyFile) context).getScriptClass();
} else if (context instanceof PsiClass) {
contextClass = (PsiClass) context;
} else if (context instanceof GrMember) {
if (((GrMember) context).hasModifierProperty(PsiModifier.STATIC)) {
//no context class
contextClass = null;
} else {
contextClass = ((GrMember) context).getContainingClass();
}
} else {
contextClass = null;
}
if (contextClass == null)
return "null";
final PsiElement implicitClass = GenerationUtil.getWrappingImplicitClass(closure);
if (implicitClass == null) {
return "this";
} else {
final StringBuilder buffer = new StringBuilder();
GenerationUtil.writeThisReference(contextClass, buffer, this.context);
return buffer;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class FieldAnnotationChecker method checkScriptField.
private static void checkScriptField(AnnotationHolder holder, GrAnnotation annotation) {
final PsiAnnotationOwner owner = annotation.getOwner();
final GrMember container = PsiTreeUtil.getParentOfType(((PsiElement) owner), GrMember.class);
if (container != null) {
if (container.getContainingClass() instanceof GroovyScriptClass) {
holder.createErrorAnnotation(annotation, GroovyBundle.message("annotation.field.can.only.be.used.within.a.script.body"));
} else {
holder.createErrorAnnotation(annotation, GroovyBundle.message("annotation.field.can.only.be.used.within.a.script"));
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class GroovySuppressableInspectionTool method getElementToolSuppressedIn.
@Nullable
public static PsiElement getElementToolSuppressedIn(final PsiElement place, @NotNull String toolId) {
if (place == null)
return null;
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
final PsiElement statement = PsiUtil.findEnclosingStatement(place);
if (statement != null) {
PsiElement prev = statement.getPrevSibling();
while (prev != null && StringUtil.isEmpty(prev.getText().trim())) {
prev = prev.getPrevSibling();
}
if (prev instanceof PsiComment) {
String text = prev.getText();
Matcher matcher = SuppressionUtil.SUPPRESS_IN_LINE_COMMENT_PATTERN.matcher(text);
if (matcher.matches() && SuppressionUtil.isInspectionToolIdMentioned(matcher.group(1), toolId)) {
return prev;
}
}
}
GrMember member = null;
GrDocComment docComment = PsiTreeUtil.getParentOfType(place, GrDocComment.class);
if (docComment != null) {
GrDocCommentOwner owner = docComment.getOwner();
if (owner instanceof GrMember) {
member = (GrMember) owner;
}
}
if (member == null) {
member = PsiTreeUtil.getNonStrictParentOfType(place, GrMember.class);
}
while (member != null) {
GrModifierList modifierList = member.getModifierList();
for (String ids : getInspectionIdsSuppressedInAnnotation(modifierList)) {
if (SuppressionUtil.isInspectionToolIdMentioned(ids, toolId)) {
return modifierList;
}
}
member = PsiTreeUtil.getParentOfType(member, GrMember.class);
}
return null;
} finally {
accessToken.finish();
}
}
Aggregations