From 41d2352cf8aba5c26243dafa35d9d6fb324cfc0e Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Fri, 14 Dec 2012 16:50:39 +0100 Subject: [PATCH 1/3] Fixed broken highlighting for file path references ended by \\ (PY-7434). --- .../psi/PyStringLiteralFileReferenceSet.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java b/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java index 96a3dcb37e9e..0d3affcb3ecd 100644 --- a/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java +++ b/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java @@ -69,9 +69,7 @@ public class PyStringLiteralFileReferenceSet extends RootFileReferenceSet { @Override public boolean process(int startOffset, int endOffset, String value) { if ("\\".equals(value) || "/".equals(value)) { - if (myStartOffset != -1) { - addReference(startOffset); - } + addReference(startOffset); } else { if (myStartOffset == -1) { @@ -84,15 +82,18 @@ public class PyStringLiteralFileReferenceSet extends RootFileReferenceSet { } private void addReference(int startOffset) { - final FileReference ref = myFileReferenceSet.createFileReference( - new TextRange(myStartOffset, startOffset), - myIndex++, - myItem.toString()); - myReferenceList.add(ref); - myStartOffset = -1; - myItem.setLength(0); + if (myStartOffset != -1) { + final FileReference ref = myFileReferenceSet.createFileReference( + new TextRange(myStartOffset, startOffset), + myIndex++, + myItem.toString()); + myReferenceList.add(ref); + myStartOffset = -1; + myItem.setLength(0); + } } + public void finish() { addReference(myEndOffset); } From 4fc46fcc4590ffcaa49a872bacb6e79ee8c2ccf8 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Fri, 14 Dec 2012 17:20:07 +0100 Subject: [PATCH 2/3] Suppress warning. --- .../jetbrains/python/psi/PyStringLiteralFileReferenceSet.java | 1 + 1 file changed, 1 insertion(+) diff --git a/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java b/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java index 0d3affcb3ecd..fdd93c3733c1 100644 --- a/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java +++ b/python/openapi/src/com/jetbrains/python/psi/PyStringLiteralFileReferenceSet.java @@ -40,6 +40,7 @@ public class PyStringLiteralFileReferenceSet extends RootFileReferenceSet { @Override protected void reparse() { + //noinspection ConstantConditions if (myStringLiteralExpression != null) { MyTextRangeConsumer textRangeConsumer = new MyTextRangeConsumer(this); From ff428fd6f78de223ceea377bec663a75d9a0ec96 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Fri, 14 Dec 2012 18:26:32 +0100 Subject: [PATCH 3/3] Add path completion to os.path.join elements. --- .../python/psi/impl/PyPathEvaluator.java | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/impl/PyPathEvaluator.java b/python/src/com/jetbrains/python/psi/impl/PyPathEvaluator.java index 2adb08df2c81..3b0acc5cd7f2 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyPathEvaluator.java +++ b/python/src/com/jetbrains/python/psi/impl/PyPathEvaluator.java @@ -28,7 +28,7 @@ public class PyPathEvaluator { } @Nullable - public static String evaluate(PyExpression expr, String path) { + public static String evaluate(PyExpression expr, String containingFilePath) { if (expr == null) { return null; } @@ -36,27 +36,15 @@ public class PyPathEvaluator { final PyCallExpression call = (PyCallExpression)expr; final PyExpression[] args = call.getArguments(); if (call.isCalleeText(PyNames.DIRNAME) && args.length == 1) { - String argValue = evaluate(args[0], path); + String argValue = evaluate(args[0], containingFilePath); return argValue == null ? null : new File(argValue).getParent(); } else if (call.isCalleeText(PyNames.JOIN) && args.length >= 1) { - String result = null; - for (int i = 0; i