use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class MultipleRepositoryUrlsFix method doFix.
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
List<GrCallExpression> statements = MultipleRepositoryUrlsInspection.findUrlCallExpressions(myClosure);
if (statements.size() <= 1)
return;
statements.remove(0);
List<PsiElement> elements = new ArrayList<>(statements);
for (GrCallExpression statement : statements) {
PsiElement newLineCandidate = statement.getNextSibling();
if (PsiUtil.isNewLine(newLineCandidate)) {
elements.add(newLineCandidate);
}
}
myClosure.removeElements(elements.toArray(new PsiElement[elements.size()]));
GrClosableBlock closableBlock = PsiTreeUtil.getParentOfType(myClosure, GrClosableBlock.class);
if (closableBlock == null)
return;
GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(project);
for (GrCallExpression statement : statements) {
closableBlock.addStatementBefore(elementFactory.createStatementFromText(myRepoType + '{' + statement.getText() + '}'), null);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class CustomAnnotationChecker method checkAnnotationValueByType.
public static void checkAnnotationValueByType(@NotNull AnnotationHolder holder, @NotNull GrAnnotationMemberValue value, @Nullable PsiType ltype, boolean skipArrays) {
final GlobalSearchScope resolveScope = value.getResolveScope();
final PsiManager manager = value.getManager();
if (value instanceof GrExpression) {
final PsiType rtype;
if (value instanceof GrClosableBlock) {
rtype = PsiType.getJavaLangClass(manager, resolveScope);
} else {
rtype = ((GrExpression) value).getType();
}
if (rtype != null && !checkAnnoTypeAssignable(ltype, rtype, value, skipArrays)) {
holder.createErrorAnnotation(value, GroovyBundle.message("cannot.assign", rtype.getPresentableText(), ltype.getPresentableText()));
}
} else if (value instanceof GrAnnotation) {
final PsiElement resolved = ((GrAnnotation) value).getClassReference().resolve();
if (resolved instanceof PsiClass) {
final PsiClassType rtype = JavaPsiFacade.getElementFactory(value.getProject()).createType((PsiClass) resolved, PsiSubstitutor.EMPTY);
if (!checkAnnoTypeAssignable(ltype, rtype, value, skipArrays)) {
holder.createErrorAnnotation(value, GroovyBundle.message("cannot.assign", rtype.getPresentableText(), ltype.getPresentableText()));
}
}
} else if (value instanceof GrAnnotationArrayInitializer) {
if (ltype instanceof PsiArrayType) {
final PsiType componentType = ((PsiArrayType) ltype).getComponentType();
final GrAnnotationMemberValue[] initializers = ((GrAnnotationArrayInitializer) value).getInitializers();
for (GrAnnotationMemberValue initializer : initializers) {
checkAnnotationValueByType(holder, initializer, componentType, false);
}
} else {
final PsiType rtype = TypesUtil.getTupleByAnnotationArrayInitializer((GrAnnotationArrayInitializer) value);
if (!checkAnnoTypeAssignable(ltype, rtype, value, skipArrays)) {
holder.createErrorAnnotation(value, GroovyBundle.message("cannot.assign", rtype.getPresentableText(), ltype.getPresentableText()));
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GroovyAnnotator method checkAnnotationAttributeValue.
private boolean checkAnnotationAttributeValue(@Nullable GrAnnotationMemberValue value, @NotNull PsiElement toHighlight) {
if (value == null)
return false;
if (value instanceof GrLiteral)
return false;
if (value instanceof GrClosableBlock)
return false;
if (value instanceof GrAnnotation)
return false;
if (value instanceof GrReferenceExpression) {
PsiElement resolved = ((GrReferenceExpression) value).resolve();
if (resolved instanceof PsiClass)
return false;
if (resolved instanceof PsiEnumConstant)
return false;
if (resolved == null && isClassReference(value))
return false;
if (resolved instanceof GrAccessorMethod)
resolved = ((GrAccessorMethod) resolved).getProperty();
if (resolved instanceof PsiField) {
GrExpression initializer;
try {
if (resolved instanceof GrField) {
initializer = ((GrField) resolved).getInitializerGroovy();
} else {
final PsiExpression _initializer = ((PsiField) resolved).getInitializer();
initializer = _initializer != null ? (GrExpression) ExpressionConverter.getExpression(_initializer, GroovyLanguage.INSTANCE, value.getProject()) : null;
}
} catch (IncorrectOperationException e) {
initializer = null;
}
if (initializer != null) {
return checkAnnotationAttributeValue(initializer, toHighlight);
}
}
}
if (value instanceof GrAnnotationArrayInitializer) {
for (GrAnnotationMemberValue expression : ((GrAnnotationArrayInitializer) value).getInitializers()) {
if (checkAnnotationAttributeValue(expression, toHighlight))
return true;
}
return false;
}
if (value instanceof GrUnaryExpression) {
final IElementType tokenType = ((GrUnaryExpression) value).getOperationTokenType();
if (tokenType == GroovyTokenTypes.mMINUS || tokenType == GroovyTokenTypes.mPLUS) {
return checkAnnotationAttributeValue(((GrUnaryExpression) value).getOperand(), toHighlight);
}
}
myHolder.createErrorAnnotation(toHighlight, GroovyBundle.message("expected.0.to.be.inline.constant", value.getText()));
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GrUnnecessarySemicolonInspection method isSemicolonNecessary.
private static boolean isSemicolonNecessary(@NotNull PsiElement semicolon) {
if (semicolon.getParent() instanceof GrTraditionalForClause)
return true;
PsiElement prevSibling = PsiUtil.skipSet(semicolon, false, BACKWARD_SET);
PsiElement nextSibling = PsiUtil.skipSet(semicolon, true, FORWARD_SET);
return prevSibling instanceof GrStatement && (nextSibling instanceof GrStatement || nextSibling != null && nextSibling.getNextSibling() instanceof GrClosableBlock);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class UnassignedVariableAccessInspection method check.
@Override
protected void check(@NotNull GrControlFlowOwner owner, @NotNull ProblemsHolder problemsHolder) {
Instruction[] flow = owner.getControlFlow();
ReadWriteVariableInstruction[] reads = ControlFlowBuilderUtil.getReadsWithoutPriorWrites(flow, true);
for (ReadWriteVariableInstruction read : reads) {
PsiElement element = read.getElement();
if (element instanceof GroovyPsiElement && !(element instanceof GrClosableBlock)) {
String name = read.getVariableName();
GroovyPsiElement property = ResolveUtil.resolveProperty((GroovyPsiElement) element, name);
if (property != null && !(property instanceof PsiParameter) && !(property instanceof PsiField) && PsiTreeUtil.isAncestor(owner, property, false) && !(myIgnoreBooleanExpressions && isBooleanCheck(element))) {
problemsHolder.registerProblem(element, GroovyInspectionBundle.message("unassigned.access.tooltip", name));
}
}
}
}
Aggregations