use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class StubGenerator method writeVariableDeclarations.
@Override
public void writeVariableDeclarations(StringBuilder text, GrVariableDeclaration variableDeclaration) {
GrTypeElement typeElement = variableDeclaration.getTypeElementGroovy();
final GrModifierList modifierList = variableDeclaration.getModifierList();
final PsiNameHelper nameHelper = PsiNameHelper.getInstance(variableDeclaration.getProject());
for (final GrVariable variable : variableDeclaration.getVariables()) {
String name = variable.getName();
if (!nameHelper.isIdentifier(name)) {
//does not have a java image
continue;
}
ModifierListGenerator.writeModifiers(text, modifierList, STUB_FIELD_MODIFIERS, false);
//type
PsiType declaredType = typeElement == null ? PsiType.getJavaLangObject(variable.getManager(), variable.getResolveScope()) : typeElement.getType();
TypeWriter.writeType(text, declaredType, variableDeclaration, classNameProvider);
text.append(' ').append(name).append(" = ").append(getVariableInitializer(variable, declaredType));
text.append(";\n");
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class CodeBlockGenerator method writeTupleDeclaration.
private void writeTupleDeclaration(GrVariableDeclaration variableDeclaration, StringBuilder builder, ExpressionContext expressionContext) {
GrVariable[] variables = variableDeclaration.getVariables();
final GrExpression tupleInitializer = variableDeclaration.getTupleInitializer();
if (tupleInitializer instanceof GrListOrMap) {
for (GrVariable variable : variables) {
GenerationUtil.writeVariableSeparately(variable, builder, expressionContext);
builder.append(";\n");
}
} else if (tupleInitializer != null) {
GroovyResolveResult iteratorMethodResult = GenerationUtil.resolveMethod(tupleInitializer, "iterator", GrExpression.EMPTY_ARRAY, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, variableDeclaration);
final PsiType iteratorType = inferIteratorType(iteratorMethodResult, tupleInitializer);
final String iteratorName = genIteratorVar(variableDeclaration, builder, expressionContext, tupleInitializer, iteratorType, iteratorMethodResult);
final GrModifierList modifierList = variableDeclaration.getModifierList();
PsiType iterableTypeParameter = PsiUtil.extractIterableTypeParameter(iteratorType, false);
for (final GrVariable v : variables) {
ModifierListGenerator.writeModifiers(builder, modifierList);
final PsiType type = context.typeProvider.getVarType(v);
TypeWriter.writeType(builder, type, variableDeclaration);
builder.append(' ').append(v.getName());
builder.append(" = ");
GenerationUtil.wrapInCastIfNeeded(builder, type, iterableTypeParameter, tupleInitializer, expressionContext, new StatementWriter() {
@Override
public void writeStatement(StringBuilder builder, ExpressionContext context) {
builder.append(iteratorName).append(".hasNext() ? ").append(iteratorName).append(".next() : null");
}
});
builder.append(";\n");
}
} else {
GenerationUtil.writeSimpleVarDeclaration(variableDeclaration, builder, expressionContext);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GroovyCompletionData method suggestPrimitiveTypes.
private static boolean suggestPrimitiveTypes(PsiElement context) {
if (isInfixOperatorPosition(context))
return false;
if (isAfterForParameter(context))
return false;
final PsiElement parent = context.getParent();
if (parent == null)
return false;
PsiElement previous = PsiImplUtil.realPrevious(parent.getPrevSibling());
if (parent instanceof GrReferenceElement && parent.getParent() instanceof GrArgumentList) {
PsiElement prevSibling = context.getPrevSibling();
if (prevSibling != null && prevSibling.getNode() != null) {
if (!TokenSets.DOTS.contains(prevSibling.getNode().getElementType())) {
return true;
}
} else if (!(previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType()))) {
return true;
}
}
if (GroovyCompletionUtil.isTupleVarNameWithoutTypeDeclared(context))
return true;
if (previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType())) {
return false;
}
if (GroovyCompletionUtil.asSimpleVariable(context) || GroovyCompletionUtil.asTypedMethod(context) || GroovyCompletionUtil.asVariableInBlock(context) || asVariableAfterModifiers(context)) {
return true;
}
if ((parent instanceof GrParameter && ((GrParameter) parent).getTypeElementGroovy() == null) || parent instanceof GrReferenceElement && !(parent.getParent() instanceof GrImportStatement) && !(parent.getParent() instanceof GrPackageDefinition) && !(parent.getParent() instanceof GrArgumentList)) {
PsiElement prevSibling = context.getPrevSibling();
if (parent instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) {
ASTNode node = prevSibling.getNode();
return !TokenSets.DOTS.contains(node.getElementType());
} else {
return true;
}
}
if (PsiImplUtil.realPrevious(parent.getPrevSibling()) instanceof GrModifierList) {
return true;
}
if (PsiImplUtil.realPrevious(context.getPrevSibling()) instanceof GrModifierList) {
return true;
}
return parent instanceof GrExpression && parent.getParent() instanceof GroovyFile && GroovyCompletionUtil.isNewStatement(context, false);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList 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();
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GroovyAnnotator method visitPackageDefinition.
@Override
public void visitPackageDefinition(@NotNull GrPackageDefinition packageDefinition) {
final GrModifierList modifierList = packageDefinition.getAnnotationList();
checkAnnotationList(myHolder, modifierList, GroovyBundle.message("package.definition.cannot.have.modifiers"));
}
Aggregations