Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
1d69ef88
Commit
1d69ef88
authored
9 years ago
by
Dmitry Trofimov
Browse files
Options
Download
Email Patches
Plain Diff
Use PyFunction.getTypeComment() method
parent
f5abd508
Branches unavailable
Tags unavailable
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/src/com/jetbrains/python/inspections/PyMissingTypeHintsInspection.java
+1
-37
...ains/python/inspections/PyMissingTypeHintsInspection.java
with
1 addition
and
37 deletions
+1
-37
python/src/com/jetbrains/python/inspections/PyMissingTypeHintsInspection.java
+
1
-
37
View file @
1d69ef88
...
...
@@ -23,7 +23,6 @@ import com.intellij.lang.ASTNode;
import
com.intellij.openapi.project.Project
;
import
com.intellij.psi.PsiElementVisitor
;
import
com.intellij.psi.util.PsiTreeUtil
;
import
com.jetbrains.python.PyTokenTypes
;
import
com.jetbrains.python.codeInsight.intentions.PyAnnotateTypesIntention
;
import
com.jetbrains.python.inspections.quickfix.PyQuickFixUtil
;
import
com.jetbrains.python.psi.PyElementVisitor
;
...
...
@@ -43,7 +42,7 @@ public class PyMissingTypeHintsInspection extends PyInspection{
return
new
PyElementVisitor
()
{
@Override
public
void
visitPyFunction
(
PyFunction
function
)
{
if
(!(
typeCommentExists
(
function
)
||
typeAnnotationsExist
(
function
)))
{
if
(!(
function
.
getTypeComment
()
!=
null
||
typeAnnotationsExist
(
function
)))
{
ASTNode
nameNode
=
function
.
getNameNode
();
if
(
nameNode
!=
null
)
{
holder
.
registerProblem
(
nameNode
.
getPsi
(),
"Type hinting is missing for function definition"
,
new
AddTypeHintsQuickFix
(
function
.
getName
()));
...
...
@@ -53,41 +52,6 @@ public class PyMissingTypeHintsInspection extends PyInspection{
};
}
private
static
boolean
typeCommentExists
(
PyFunction
function
)
{
ASTNode
node
=
function
.
getStatementList
().
getNode
().
getFirstChildNode
();
while
(
node
!=
null
&&
node
.
getElementType
()
!=
PyTokenTypes
.
END_OF_LINE_COMMENT
)
{
node
=
node
.
getTreeNext
();
}
if
(
node
!=
null
)
{
return
isTypeComment
(
node
);
}
node
=
function
.
getStatementList
().
getPrevSibling
().
getNode
();
while
(
node
!=
null
&&
node
.
getElementType
()
!=
PyTokenTypes
.
COLON
&&
node
.
getElementType
()
!=
PyTokenTypes
.
END_OF_LINE_COMMENT
)
{
node
=
node
.
getTreePrev
();
}
if
(
node
!=
null
&&
node
.
getElementType
()
==
PyTokenTypes
.
END_OF_LINE_COMMENT
)
{
return
isTypeComment
(
node
);
}
return
false
;
}
private
static
boolean
isTypeComment
(
ASTNode
node
)
{
String
commentText
=
node
.
getText
();
int
startInd
=
commentText
.
indexOf
(
'#'
);
if
(
startInd
!=
-
1
)
{
commentText
=
commentText
.
substring
(
startInd
+
1
).
trim
();
if
(
commentText
.
startsWith
(
"type:"
))
{
return
true
;
}
}
return
false
;
}
private
static
boolean
typeAnnotationsExist
(
PyFunction
function
)
{
for
(
PyParameter
param:
function
.
getParameterList
().
getParameters
())
{
PyNamedParameter
namedParameter
=
param
.
getAsNamed
();
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help