use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class PsiImplUtil method getQualifierType.
@Nullable
public static PsiType getQualifierType(@NotNull GrReferenceExpression ref) {
final GrExpression rtQualifier = getRuntimeQualifier(ref);
if (rtQualifier != null) {
return rtQualifier.getType();
}
PsiClass containingClass = null;
final GrMember member = PsiTreeUtil.getParentOfType(ref, GrMember.class);
if (member == null) {
final PsiFile file = ref.getContainingFile();
if (file instanceof GroovyFileBase && ((GroovyFileBase) file).isScript()) {
containingClass = ((GroovyFileBase) file).getScriptClass();
} else {
return null;
}
} else if (member instanceof GrMethod) {
if (!member.hasModifierProperty(PsiModifier.STATIC)) {
containingClass = member.getContainingClass();
}
}
if (containingClass != null) {
final PsiClassType categoryType = GdkMethodUtil.getCategoryType(containingClass);
if (categoryType != null) {
return categoryType;
}
return JavaPsiFacade.getElementFactory(ref.getProject()).createType(containingClass);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class PsiImplUtil method inferReturnType.
@Nullable
public static PsiType inferReturnType(PsiElement position) {
final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(position);
if (flowOwner == null)
return null;
final PsiElement parent = flowOwner.getContext();
if (flowOwner instanceof GrOpenBlock && parent instanceof GrMethod) {
final GrMethod method = (GrMethod) parent;
if (method.isConstructor())
return null;
return method.getReturnType();
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class ControlFlowBuilder method visitOpenBlock.
@Override
public void visitOpenBlock(@NotNull GrOpenBlock block) {
final PsiElement parent = block.getParent();
final PsiElement lbrace = block.getLBrace();
if (lbrace != null && parent instanceof GrMethod) {
for (GrParameter parameter : ((GrMethod) parent).getParameters()) {
if (myPolicy.isVariableInitialized(parameter)) {
addNode(new ReadWriteVariableInstruction(parameter.getName(), parameter, ReadWriteVariableInstruction.WRITE));
}
}
}
super.visitOpenBlock(block);
if (!(block.getParent() instanceof GrBlockStatement && block.getParent().getParent() instanceof GrLoopStatement)) {
final GrStatement[] statements = block.getStatements();
if (statements.length > 0) {
handlePossibleReturn(statements[statements.length - 1]);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class ControlFlowBuilder method collectUsedVariableWithoutInitialization.
private static Set<ReadWriteVariableInstruction> collectUsedVariableWithoutInitialization(GrTypeDefinition typeDefinition) {
final Set<ReadWriteVariableInstruction> vars = ContainerUtil.newLinkedHashSet();
typeDefinition.acceptChildren(new GroovyRecursiveElementVisitor() {
private void collectVars(Instruction[] flow) {
ReadWriteVariableInstruction[] reads = ControlFlowBuilderUtil.getReadsWithoutPriorWrites(flow, false);
Collections.addAll(vars, reads);
}
@Override
public void visitField(@NotNull GrField field) {
GrExpression initializer = field.getInitializerGroovy();
if (initializer != null) {
Instruction[] flow = new ControlFlowBuilder(field.getProject()).buildControlFlow(initializer);
collectVars(flow);
}
}
@Override
public void visitMethod(@NotNull GrMethod method) {
GrOpenBlock block = method.getBlock();
if (block != null) {
collectVars(block.getControlFlow());
}
}
@Override
public void visitClassInitializer(@NotNull GrClassInitializer initializer) {
GrOpenBlock block = initializer.getBlock();
collectVars(block.getControlFlow());
}
});
return vars;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GroovyPsiElementFactoryImpl method createMethodFromText.
@Override
@NotNull
public GrMethod createMethodFromText(String methodText, @Nullable PsiElement context) {
if (methodText == null)
throw new IncorrectOperationException("Method text not provided");
GroovyFile file = createGroovyFile(methodText, false, context);
GrTopStatement[] definitions = file.getTopStatements();
if (definitions.length != 1) {
throw new IncorrectOperationException("Can't create method from text: '" + file.getText() + "'");
}
GrTopStatement definition = definitions[0];
if (!(definition instanceof GrMethod)) {
throw new IncorrectOperationException("Can't create method from text: '" + file.getText() + "'");
}
return ((GrMethod) definition);
}
Aggregations