use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement in project intellij-community by JetBrains.
the class GrDisjunctionTypeElementImpl method deleteChildInternal.
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
final PsiElement psi = child.getPsi();
if (psi instanceof GrTypeElement) {
PsiElement next = PsiUtil.skipWhitespacesAndComments(psi.getNextSibling(), true);
if (next != null) {
if (next.getNode().getElementType() == GroovyTokenTypes.mBOR) {
super.deleteChildInternal(next.getNode());
}
} else {
PsiElement prev = PsiUtil.skipWhitespacesAndComments(psi.getPrevSibling(), false);
if (prev != null) {
if (prev.getNode().getElementType() == GroovyTokenTypes.mBOR) {
super.deleteChildInternal(prev.getNode());
}
}
}
}
super.deleteChildInternal(child);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement in project intellij-community by JetBrains.
the class GrMethodBaseImpl method getNamedParameters.
@Override
@NotNull
public Map<String, NamedArgumentDescriptor> getNamedParameters() {
final GrMethodStub stub = getStub();
if (stub != null) {
String[] namedParameters = stub.getNamedParameters();
if (namedParameters.length == 0)
return Collections.emptyMap();
Map<String, NamedArgumentDescriptor> result = ContainerUtil.newHashMap();
for (String parameter : namedParameters) {
result.put(parameter, GrNamedArgumentSearchVisitor.CODE_NAMED_ARGUMENTS_DESCR);
}
return result;
}
GrOpenBlock body = getBlock();
if (body == null)
return Collections.emptyMap();
GrParameter[] parameters = getParameters();
if (parameters.length == 0)
return Collections.emptyMap();
GrParameter firstParameter = parameters[0];
PsiType type = firstParameter.getTypeGroovy();
GrTypeElement typeElement = firstParameter.getTypeElementGroovy();
if (type != null && typeElement != null && type.getPresentableText() != null && !type.getPresentableText().endsWith("Map")) {
return Collections.emptyMap();
}
GrNamedArgumentSearchVisitor visitor = new GrNamedArgumentSearchVisitor(firstParameter.getNameIdentifierGroovy().getText());
body.accept(visitor);
return visitor.getResult();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement in project intellij-community by JetBrains.
the class GrVariableStubBase method getTypeElement.
@Nullable
public GrTypeElement getTypeElement() {
String typeText = getTypeText();
if (typeText == null)
return null;
GrTypeElement typeElement = SoftReference.dereference(myTypeElement);
if (typeElement == null) {
typeElement = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(typeText, getPsi());
myTypeElement = new SoftReference<>(typeElement);
}
return typeElement;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement in project intellij-community by JetBrains.
the class GroovyTypeCastSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
if (e instanceof GrTypeCastExpression) {
GrTypeCastExpression castExpression = ((GrTypeCastExpression) e);
GrTypeElement type = castExpression.getCastTypeElement();
TextRange range = type.getTextRange();
if (range.contains(cursorOffset)) {
PsiElement leftParen = castExpression.getLeftParen();
PsiElement rightParen = castExpression.getRightParen();
if (leftParen.getTextOffset() < rightParen.getTextOffset()) {
range = new TextRange(leftParen.getTextRange().getStartOffset(), rightParen.getTextRange().getEndOffset());
result.add(range);
}
}
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement in project intellij-community by JetBrains.
the class GroovyCreateFieldFromUsageHelper method setupTemplateImpl.
@Override
public Template setupTemplateImpl(PsiField f, Object expectedTypes, PsiClass targetClass, Editor editor, PsiElement context, boolean createConstantField, PsiSubstitutor substitutor) {
GrVariableDeclaration fieldDecl = (GrVariableDeclaration) f.getParent();
GrField field = (GrField) fieldDecl.getVariables()[0];
TemplateBuilderImpl builder = new TemplateBuilderImpl(fieldDecl);
Project project = context.getProject();
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
if (expectedTypes instanceof TypeConstraint[]) {
GrTypeElement typeElement = fieldDecl.getTypeElementGroovy();
assert typeElement != null;
ChooseTypeExpression expr = new ChooseTypeExpression((TypeConstraint[]) expectedTypes, PsiManager.getInstance(project), typeElement.getResolveScope());
builder.replaceElement(typeElement, expr);
} else if (expectedTypes instanceof ExpectedTypeInfo[]) {
new GuessTypeParameters(factory).setupTypeElement(field.getTypeElement(), (ExpectedTypeInfo[]) expectedTypes, substitutor, builder, context, targetClass);
}
if (createConstantField) {
field.setInitializerGroovy(factory.createExpressionFromText("0", null));
builder.replaceElement(field.getInitializerGroovy(), new EmptyExpression());
}
fieldDecl = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(fieldDecl);
Template template = builder.buildTemplate();
TextRange range = fieldDecl.getTextRange();
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
if (expectedTypes instanceof ExpectedTypeInfo[]) {
if (((ExpectedTypeInfo[]) expectedTypes).length > 1)
template.setToShortenLongNames(false);
}
return template;
}
Aggregations