From e0d025da15217c6dbec279f5cb3ef584b373f145 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 27 Aug 2013 17:36:08 +0200 Subject: [PATCH] initial extraction of python-community module (for now with a few cyclic dependencies) --- python/build/pycharm_build.gant | 3 +- python/build/python-build.iml | 1 + python/python-community.iml | 22 +++++ python/python.iml | 1 + .../python/PythonTokenSetContributor.java | 12 +-- .../console/PydevConsoleCommunication.java | 5 +- .../python/lexer/PyStringLiteralLexer.java | 18 ++-- python/src/icons/PythonIcons.java | 94 +++++++++++++++++++ 8 files changed, 138 insertions(+), 18 deletions(-) create mode 100644 python/python-community.iml create mode 100644 python/src/icons/PythonIcons.java diff --git a/python/build/pycharm_build.gant b/python/build/pycharm_build.gant index 2933aa245012..6ca80732d84d 100644 --- a/python/build/pycharm_build.gant +++ b/python/build/pycharm_build.gant @@ -26,7 +26,8 @@ private List pycharmPlatformApiModules() { private List pycharmImplementationModules() { //modules to put into pycharm.jar - return ["yaml", "graph", "coverage-common", "python", "python-ide", "python-openapi", "python-psi-api", "duplicates", "duplicates-xml"] + return ["yaml", "graph", "coverage-common", "python-community", "python", "python-ide", "python-openapi", "python-psi-api", + "duplicates", "duplicates-xml"] } class Paths { diff --git a/python/build/python-build.iml b/python/build/python-build.iml index 0cd30ce1abdb..8919bae949dc 100644 --- a/python/build/python-build.iml +++ b/python/build/python-build.iml @@ -10,6 +10,7 @@ + diff --git a/python/python-community.iml b/python/python-community.iml new file mode 100644 index 000000000000..6aff1acabdb7 --- /dev/null +++ b/python/python-community.iml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/python/python.iml b/python/python.iml index 5b1950305d39..6e7890b1f92d 100644 --- a/python/python.iml +++ b/python/python.iml @@ -39,6 +39,7 @@ + diff --git a/python/src/com/jetbrains/python/PythonTokenSetContributor.java b/python/src/com/jetbrains/python/PythonTokenSetContributor.java index 9f16cc9534c2..4e1165a77868 100644 --- a/python/src/com/jetbrains/python/PythonTokenSetContributor.java +++ b/python/src/com/jetbrains/python/PythonTokenSetContributor.java @@ -33,12 +33,12 @@ public class PythonTokenSetContributor implements PythonDialectsTokenSetContribu public TokenSet getNameDefinerTokens() { // FROM_IMPORT_STATEMENT is not exactly a NameDefiner but needed anyway in mypackage/__init__.py, 'from mypackage.foo import bar' makes // 'foo' name visible - return TokenSet.create(PyElementTypes.STAR_IMPORT_ELEMENT, PyElementTypes.IMPORT_ELEMENT, PyElementTypes.CLASS_DECLARATION, - PyElementTypes.GLOBAL_STATEMENT, PyElementTypes.GENERATOR_EXPRESSION, PyElementTypes.DICT_COMP_EXPRESSION, - PyElementTypes.LIST_COMP_EXPRESSION, PyElementTypes.SET_COMP_EXPRESSION, PyElementTypes.WITH_STATEMENT, - PyElementTypes.FUNCTION_DECLARATION, PyElementTypes.ASSIGNMENT_STATEMENT, PyElementTypes.EXCEPT_PART, - PyElementTypes.FOR_STATEMENT, - PyElementTypes.FROM_IMPORT_STATEMENT); + return TokenSet.create(STAR_IMPORT_ELEMENT, IMPORT_ELEMENT, CLASS_DECLARATION, + GLOBAL_STATEMENT, GENERATOR_EXPRESSION, DICT_COMP_EXPRESSION, + LIST_COMP_EXPRESSION, SET_COMP_EXPRESSION, WITH_STATEMENT, + FUNCTION_DECLARATION, ASSIGNMENT_STATEMENT, EXCEPT_PART, + FOR_STATEMENT, + FROM_IMPORT_STATEMENT); } @Override diff --git a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java index be635c4b86bd..5fee53076554 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java @@ -9,8 +9,9 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; -import com.jetbrains.django.util.VirtualFileUtil; import com.jetbrains.python.console.parsing.PythonConsoleData; import com.jetbrains.python.console.pydev.*; import com.jetbrains.python.debugger.PydevXmlUtils; @@ -173,7 +174,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl String path = (String)params.get(0); int line = Integer.parseInt((String)params.get(1)); - final VirtualFile file = VirtualFileUtil.findFile(path); + final VirtualFile file = StringUtil.isEmpty(path) ? null : LocalFileSystem.getInstance().findFileByPath(path); if (file != null) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override diff --git a/python/src/com/jetbrains/python/lexer/PyStringLiteralLexer.java b/python/src/com/jetbrains/python/lexer/PyStringLiteralLexer.java index 6bb5662e092a..26ce74bacbdc 100644 --- a/python/src/com/jetbrains/python/lexer/PyStringLiteralLexer.java +++ b/python/src/com/jetbrains/python/lexer/PyStringLiteralLexer.java @@ -110,33 +110,33 @@ public class PyStringLiteralLexer extends LexerBase { char nextChar = myBuffer.charAt(myStart + 1); mySeenEscapedSpacesOnly &= nextChar == ' '; if ((nextChar == '\n' || nextChar == ' ' && (mySeenEscapedSpacesOnly || isTrailingSpace(myStart+2)))) { - return VALID_STRING_ESCAPE_TOKEN; // escaped EOL + return StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN; // escaped EOL } if (nextChar == 'u' || nextChar == 'U') { if (isUnicodeMode()) { final int width = nextChar == 'u'? 4 : 8; // is it uNNNN or Unnnnnnnn for(int i = myStart + 2; i < myStart + width + 2; i++) { - if (i >= myEnd || !StringUtil.isHexDigit(myBuffer.charAt(i))) return INVALID_UNICODE_ESCAPE_TOKEN; + if (i >= myEnd || !StringUtil.isHexDigit(myBuffer.charAt(i))) return StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN; } - return VALID_STRING_ESCAPE_TOKEN; + return StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN; } else return myOriginalLiteralToken; // b"\u1234" is just b"\\u1234", nothing gets escaped } if (nextChar == 'x') { // \xNN is allowed both in bytes and unicode. for(int i = myStart + 2; i < myStart + 4; i++) { - if (i >= myEnd || !StringUtil.isHexDigit(myBuffer.charAt(i))) return INVALID_UNICODE_ESCAPE_TOKEN; + if (i >= myEnd || !StringUtil.isHexDigit(myBuffer.charAt(i))) return StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN; } - return VALID_STRING_ESCAPE_TOKEN; + return StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN; } if (nextChar == 'N' && isUnicodeMode()) { int i = myStart+2; - if (i >= myEnd || myBuffer.charAt(i) != '{') return INVALID_UNICODE_ESCAPE_TOKEN; + if (i >= myEnd || myBuffer.charAt(i) != '{') return StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN; i++; while(i < myEnd && myBuffer.charAt(i) != '}') i++; - if (i >= myEnd) return INVALID_UNICODE_ESCAPE_TOKEN; - return VALID_STRING_ESCAPE_TOKEN; + if (i >= myEnd) return StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN; + return StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN; } switch (nextChar) { @@ -157,7 +157,7 @@ public class PyStringLiteralLexer extends LexerBase { case '4': case '5': case '6': - case '7': return VALID_STRING_ESCAPE_TOKEN; + case '7': return StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN; } // other unrecognized escapes are just part of string, not an error diff --git a/python/src/icons/PythonIcons.java b/python/src/icons/PythonIcons.java new file mode 100644 index 000000000000..8f3784dbb63b --- /dev/null +++ b/python/src/icons/PythonIcons.java @@ -0,0 +1,94 @@ +package icons; + +import com.intellij.openapi.util.IconLoader; + +import javax.swing.*; + +/** + * NOTE THIS FILE IS AUTO-GENERATED by the build/scripts/icons.gant + * Don't repeat mistakes of others ;-) + */ +public class PythonIcons { + private static Icon load(String path) { + return IconLoader.getIcon(path, PythonIcons.class); + } + + + public static class Appengine { + public static final Icon AppEngine = load("/icons/com/jetbrains/appengine/appEngine.png"); // 16x16 + public static final Icon Required = load("/icons/com/jetbrains/appengine/required.png"); // 16x16 + + } + + public static class Django { + public static final Icon Django = load("/icons/com/jetbrains/django/django.png"); // 16x16 + public static final Icon DjangoTests = load("/icons/com/jetbrains/django/djangoTests.png"); // 16x16 + public static final Icon ModelClass = load("/icons/com/jetbrains/django/modelClass.png"); // 16x16 + public static final Icon StructureViewDjangoTagIcon = load("/icons/com/jetbrains/django/structureViewDjangoTagIcon.png"); // 16x16 + + } + + public static class Pyramid { + public static final Icon Pyramid = load("/icons/com/jetbrains/pyramid/pyramid.png"); // 16x16 + + } + + public static class Jinja2 { + public static final Icon Jinja2 = load("/icons/com/jetbrains/jinja2/jinja2.png"); // 16x16 + + } + + public static class Mako { + public static final Icon Mako = load("/icons/com/jetbrains/mako/mako.png"); // 16x16 + + } + + public static class Web2Py { + public static final Icon Web2Py = load("/icons/com/jetbrains/web2py/web2py.png"); // 16x16 + + } + + + public static class Chameleon { + public static final Icon Chameleon = load("/icons/com/jetbrains/chameleon/chameleon.png"); // 16x16 + + } + + public static class Pyqt { + public static final Icon TsFile = load("/icons/com/jetbrains/pyqt/tsFile.png"); // 16x16 + public static final Icon UiForm = load("/icons/com/jetbrains/pyqt/uiForm.png"); // 16x16 + + } + + public static class Python { + + public static class Buildout { + public static final Icon Buildout = load("/icons/com/jetbrains/python/buildout/buildout.png"); // 16x16 + + } + + public static class Debug { + public static final Icon CommandLine = load("/icons/com/jetbrains/python/debug/commandLine.png"); // 16x16 + + } + public static final Icon Dotnet = load("/icons/com/jetbrains/python/dotnet.png"); // 16x16 + public static final Icon Jython = load("/icons/com/jetbrains/python/jython.png"); // 16x16 + + public static class Nodes { + public static final Icon Cyan_dot = load("/icons/com/jetbrains/python/nodes/cyan-dot.png"); // 16x16 + public static final Icon Lock = load("/icons/com/jetbrains/python/nodes/lock.png"); // 16x16 + public static final Icon Red_inv_triangle = load("/icons/com/jetbrains/python/nodes/red-inv-triangle.png"); // 16x16 + + } + public static final Icon PropertyDeleter = load("/icons/com/jetbrains/python/propertyDeleter.png"); // 16x16 + public static final Icon PropertyGetter = load("/icons/com/jetbrains/python/propertyGetter.png"); // 16x16 + public static final Icon PropertySetter = load("/icons/com/jetbrains/python/propertySetter.png"); // 16x16 + public static final Icon Pypy = load("/icons/com/jetbrains/python/pypy.png"); // 16x16 + public static final Icon Python = load("/icons/com/jetbrains/python/python.png"); // 16x16 + public static final Icon Python_24 = load("/icons/com/jetbrains/python/python_24.png"); // 24x24 + public static final Icon PythonClosed = load("/icons/com/jetbrains/python/pythonClosed.png"); // 16x16 + public static final Icon PythonTests = load("/icons/com/jetbrains/python/pythonTests.png"); // 16x16 + public static final Icon Virtualenv = load("/icons/com/jetbrains/python/virtualenv.png"); // 16x16 + + } +}