use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class ConvertConcatenationToGstringIntention method containsMultilineStrings.
private static boolean containsMultilineStrings(GrExpression expr) {
final Ref<Boolean> result = Ref.create(false);
expr.accept(new GroovyRecursiveElementVisitor() {
@Override
public void visitLiteralExpression(@NotNull GrLiteral literal) {
if (GrStringUtil.isMultilineStringLiteral(literal) && literal.getText().contains("\n")) {
result.set(true);
}
}
@Override
public void visitElement(@NotNull GroovyPsiElement element) {
if (!result.get()) {
super.visitElement(element);
}
}
});
return result.get();
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class GrIntroduceFieldDialog method canBeInitializedOutsideBlock.
private static boolean canBeInitializedOutsideBlock(@NotNull GrIntroduceContext context, @NotNull PsiClass clazz) {
final StringPartInfo part = context.getStringPart();
GrExpression expression = context.getExpression();
if (expression != null) {
expression = (GrExpression) PsiUtil.skipParentheses(expression, false);
if (expression == null)
return false;
if (expression instanceof GrReferenceExpression) {
final PsiElement resolved = ((GrReferenceExpression) expression).resolve();
if (PsiUtil.isLocalVariable(resolved)) {
expression = ((GrVariable) resolved).getInitializerGroovy();
if (expression == null)
return false;
}
}
ExpressionChecker visitor = new ExpressionChecker(clazz, expression);
expression.accept(visitor);
return visitor.isResult();
}
if (part != null) {
for (GrStringInjection injection : part.getInjections()) {
GroovyPsiElement scope = injection.getExpression() != null ? injection.getExpression() : injection.getClosableBlock();
assert scope != null;
ExpressionChecker visitor = new ExpressionChecker(clazz, scope);
scope.accept(visitor);
if (!visitor.isResult()) {
return visitor.isResult();
}
}
return true;
} else {
return false;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class GroovyParameterInfoHandler method getCurrentParameterIndex.
private static int getCurrentParameterIndex(GroovyPsiElement place, int offset) {
if (place instanceof GrArgumentList) {
GrArgumentList list = (GrArgumentList) place;
int idx = (list.getNamedArguments().length > 0) ? 1 : 0;
for (PsiElement child = list.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getTextRange().contains(offset)) {
if (child instanceof GrNamedArgument)
return 0;
return idx;
}
if (child.getNode().getElementType() == GroovyTokenTypes.mCOMMA)
idx++;
if (isNamedArgWithPriorComma(child))
idx--;
}
}
return -1;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class GroovyChangeContextUtil method encodeContextInfo.
public static void encodeContextInfo(PsiElement element, PsiElement scope) {
if (!(element instanceof GroovyPsiElement))
return;
if (PsiUtil.isThisReference(element)) {
GrReferenceExpression thisExpr = (GrReferenceExpression) element;
final PsiClass containingClass = PsiTreeUtil.getParentOfType(thisExpr, PsiClass.class);
element.putCopyableUserData(KEY_ENCODED, KEY_ENCODED);
thisExpr.putCopyableUserData(QUALIFIER_CLASS_KEY, containingClass);
} else if (element instanceof GrReferenceExpression) {
GrReferenceExpression refExpr = (GrReferenceExpression) element;
final GrExpression qualifier = refExpr.getQualifierExpression();
if (qualifier == null) {
PsiElement refElement = refExpr.resolve();
element.putCopyableUserData(KEY_ENCODED, KEY_ENCODED);
if (refElement != null && !PsiTreeUtil.isContextAncestor(scope, refElement, false)) {
if (refElement instanceof GrAccessorMethod)
refElement = ((GrAccessorMethod) refElement).getProperty();
if (refElement instanceof PsiClass) {
refExpr.putCopyableUserData(REF_TO_CLASS, (PsiClass) refElement);
} else if (refElement instanceof PsiMember) {
refExpr.putCopyableUserData(REF_TO_MEMBER, (PsiMember) refElement);
}
}
}
} else if (element instanceof GrCodeReferenceElement) {
final PsiElement resolvedElement = ((GrCodeReferenceElement) element).resolve();
element.putCopyableUserData(KEY_ENCODED, KEY_ENCODED);
if (resolvedElement instanceof PsiClass && !PsiTreeUtil.isContextAncestor(scope, resolvedElement, false)) {
element.putCopyableUserData(REF_TO_CLASS, (PsiClass) resolvedElement);
}
}
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
encodeContextInfo(child, scope);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class GroovyNameSuggestionProvider method getSuggestedNames.
@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, @Nullable PsiElement nameSuggestionContext, Set<String> result) {
if (nameSuggestionContext == null)
nameSuggestionContext = element;
if (element instanceof GrVariable && nameSuggestionContext instanceof GroovyPsiElement) {
final PsiType type = ((GrVariable) element).getTypeGroovy();
if (type != null) {
final String[] names = GroovyNameSuggestionUtil.suggestVariableNameByType(type, new DefaultGroovyVariableNameValidator((GroovyPsiElement) nameSuggestionContext));
result.addAll(Arrays.asList(names));
return new SuggestedNameInfo(names) {
@Override
public void nameChosen(String name) {
JavaStatisticsManager.incVariableNameUseCount(name, JavaCodeStyleManager.getInstance(element.getProject()).getVariableKind((GrVariable) element), ((GrVariable) element).getName(), type);
}
};
}
}
return null;
}
Aggregations