-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type info action #92
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add an interface e.g. MatabTypedExpr
and add mixins for different expressions that will implement this interface. E.g. one mixin for binary expressions, one mixin for literal expression.
Then you'll be able to show type info for all expressions not only references.
fun MatlabFunctionDeclaration.isConstructor(): MatlabClassDeclaration? { | ||
val classDeclaration = this.parentOfTypes(MatlabClassDeclaration::class) ?: return null | ||
val className = classDeclaration.getChildOfType(IDENTIFIER)?.text ?: return null | ||
val functionName = this.getChildOfType(IDENTIFIER)?.text ?: return null | ||
return if (className == functionName) classDeclaration else null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use MatlabClassDeclarationImpl.getName
method instead of searching for identifier
fun getTypeFromBinaryExpr(expr: MatlabBinaryExpr): MatlabType { | ||
val left = getTypeFromExpr(expr.left) | ||
val right = getTypeFromExpr(expr.right) | ||
return when (expr) { | ||
is MatlabAndExpr, is MatlabOrExpr, is MatlabMatrixAndExpr, is MatlabMatrixOrExpr, is MatlabUnaryNegationExpr, is MatlabEqualExpr, | ||
is MatlabNotEqualExpr, is MatlabLessExpr, is MatlabLessOrEqualExpr, is MatlabMoreExpr, is MatlabMoreOrEqualExpr -> MatlabTypeBool() | ||
is MatlabPlusExpr, is MatlabMinusExpr, is MatlabMulExpr, is MatlabRdivExpr, is MatlabLdivExpr, is MatlabPowExpr, | ||
is MatlabElementWiseMulExpr, is MatlabElementWiseLdivExpr, is MatlabElementWiseRdivExpr, is MatlabElementWisePowExpr -> { | ||
when { | ||
left is MatlabTypeScalar && right is MatlabTypeScalar -> MatlabTypeScalar() | ||
left is MatlabTypeMatrix && right is MatlabTypeMatrix -> MatlabTypeMatrix() | ||
left is MatlabTypeMatrix && right is MatlabTypeScalar || right is MatlabTypeMatrix && left is MatlabTypeScalar -> MatlabTypeMatrix() | ||
else -> MatlabTypeUnknown() | ||
} | ||
} | ||
is MatlabUnaryPlusExpr, is MatlabUnaryMinExpr -> { | ||
when (left) { | ||
is MatlabTypeScalar -> MatlabTypeScalar() | ||
is MatlabTypeMatrix -> MatlabTypeMatrix() | ||
else -> MatlabTypeUnknown() | ||
} | ||
} | ||
else -> MatlabTypeUnknown() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved to binary expression class. Maybe create a mixin for it?
return SyntaxTraverser.psiApi() | ||
.parents(elementAt) | ||
.takeWhile { it !is PsiFile } | ||
.filter(MatlabRefExpr::class.java) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are able to get type of all expressions not only reference expressions
Ok, I thought about mixins and getting type for all expressions (not only for references), but I don't know, how can I cash in this case because ResolveCashe is only for references |
Probably it's okay not to cache types of these elements |
…arators to avoid test fails on Windows
No description provided.