mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1113,6 +1113,11 @@
|
||||
<option name="EFFECT_TYPE" value="-1" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="PY.BUILTIN_NAME">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="8888c6" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="REGEXP.BRACES">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="e8bf6a" />
|
||||
|
||||
@@ -155,13 +155,14 @@ public class HotSwapManager extends AbstractProjectComponent {
|
||||
}
|
||||
|
||||
private void reloadClasses(DebuggerSession session, Map<String, HotSwapFile> classesToReload, HotSwapProgress progress) {
|
||||
if (progress.isCancelled()) {
|
||||
session.setModifiedClassesScanRequired(true);
|
||||
return;
|
||||
}
|
||||
final long newSwapTime = System.currentTimeMillis();
|
||||
new ReloadClassesWorker(session, progress).reloadClasses(classesToReload);
|
||||
setTimeStamp(session, newSwapTime);
|
||||
if (progress.isCancelled()) {
|
||||
session.setModifiedClassesScanRequired(true);
|
||||
}
|
||||
else {
|
||||
setTimeStamp(session, newSwapTime);
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<DebuggerSession, Map<String, HotSwapFile>> findModifiedClasses(List<DebuggerSession> sessions, Map<String, List<String>> generatedPaths) {
|
||||
|
||||
@@ -114,32 +114,44 @@ class ReloadClassesWorker {
|
||||
try {
|
||||
RedefineProcessor redefineProcessor = new RedefineProcessor(virtualMachineProxy);
|
||||
|
||||
int processedClassesCount = 0;
|
||||
for (final String qualifiedName : modifiedClasses.keySet()) {
|
||||
processedClassesCount++;
|
||||
int processedEntriesCount = 0;
|
||||
for (final Map.Entry<String, HotSwapFile> entry : modifiedClasses.entrySet()) {
|
||||
if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) {
|
||||
// once at least one class has been actually reloaded, do not interrupt the whole process
|
||||
break;
|
||||
}
|
||||
processedEntriesCount++;
|
||||
final String qualifiedName = entry.getKey();
|
||||
if (qualifiedName != null) {
|
||||
myProgress.setText(qualifiedName);
|
||||
myProgress.setFraction(processedClassesCount / (double)modifiedClasses.size());
|
||||
myProgress.setFraction(processedEntriesCount / (double)modifiedClasses.size());
|
||||
}
|
||||
final HotSwapFile fileDescr = modifiedClasses.get(qualifiedName);
|
||||
try {
|
||||
redefineProcessor.processClass(qualifiedName, fileDescr.file);
|
||||
redefineProcessor.processClass(qualifiedName, entry.getValue().file);
|
||||
}
|
||||
catch (IOException e) {
|
||||
reportProblem(qualifiedName, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) {
|
||||
// once at least one class has been actually reloaded, do not interrupt the whole process
|
||||
return;
|
||||
}
|
||||
|
||||
redefineProcessor.processPending();
|
||||
myProgress.setFraction(1);
|
||||
|
||||
final int partiallyRedefinedClassesCount = redefineProcessor.getPartiallyRedefinedClassesCount();
|
||||
if (partiallyRedefinedClassesCount == 0) {
|
||||
myProgress.addMessage(myDebuggerSession, MessageCategory.INFORMATION,
|
||||
DebuggerBundle.message("status.classes.reloaded", redefineProcessor.getProcessedClassesCount()));
|
||||
myProgress.addMessage(
|
||||
myDebuggerSession, MessageCategory.INFORMATION, DebuggerBundle.message("status.classes.reloaded", redefineProcessor.getProcessedClassesCount())
|
||||
);
|
||||
}
|
||||
else {
|
||||
final String message = DebuggerBundle.message("status.classes.not.all.versions.reloaded", partiallyRedefinedClassesCount,
|
||||
redefineProcessor.getProcessedClassesCount());
|
||||
final String message = DebuggerBundle.message(
|
||||
"status.classes.not.all.versions.reloaded", partiallyRedefinedClassesCount, redefineProcessor.getProcessedClassesCount()
|
||||
);
|
||||
myProgress.addMessage(myDebuggerSession, MessageCategory.WARNING, message);
|
||||
}
|
||||
|
||||
|
||||
@@ -269,8 +269,7 @@ public class HotSwapUIImpl extends HotSwapUI implements ProjectComponent {
|
||||
return result.get();
|
||||
}
|
||||
|
||||
private static void reloadModifiedClasses(final Map<DebuggerSession, Map<String, HotSwapFile>> modifiedClasses,
|
||||
final HotSwapProgressImpl progress) {
|
||||
private static void reloadModifiedClasses(final Map<DebuggerSession, Map<String, HotSwapFile>> modifiedClasses, final HotSwapProgressImpl progress) {
|
||||
ProgressManager.getInstance().runProcess(new Runnable() {
|
||||
public void run() {
|
||||
HotSwapManager.reloadModifiedClasses(modifiedClasses, progress);
|
||||
|
||||
@@ -259,13 +259,13 @@ public class PsiTreeUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends PsiElement> Collection<T> findChildrenOfType(@Nullable PsiElement element, @NotNull Class<T> aClass) {
|
||||
public static <T extends PsiElement> Collection<T> findChildrenOfType(@Nullable PsiElement element, @NotNull Class<? extends T> aClass) {
|
||||
return findChildrenOfAnyType(element, aClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends PsiElement> Collection<T> findChildrenOfAnyType(@Nullable final PsiElement element,
|
||||
@NotNull final Class<T>... classes) {
|
||||
@NotNull final Class<? extends T>... classes) {
|
||||
if (element == null) {
|
||||
return ContainerUtil.emptyList();
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 703 B After Width: | Height: | Size: 571 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -140,22 +140,12 @@ public class FontOptions extends JPanel implements OptionsPanel{
|
||||
@Override
|
||||
public void textChanged(DocumentEvent event) {
|
||||
if (myIsInSchemeChange || !SwingUtilities.isEventDispatchThread()) return;
|
||||
try {
|
||||
int fontSize = Integer.parseInt(myEditorFontSizeField.getText());
|
||||
if (fontSize < 1) fontSize = 1;
|
||||
if (fontSize > OptionsConstants.MAX_EDITOR_FONT_SIZE) fontSize = OptionsConstants.MAX_EDITOR_FONT_SIZE;
|
||||
Object selectedFont = myPrimaryCombo.getSelectedItem();
|
||||
if (selectedFont instanceof String) {
|
||||
FontPreferences fontPreferences = getFontPreferences();
|
||||
fontPreferences.register((String)selectedFont, fontSize);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// OK, ignore
|
||||
}
|
||||
finally {
|
||||
updateDescription(true);
|
||||
Object selectedFont = myPrimaryCombo.getSelectedItem();
|
||||
if (selectedFont instanceof String) {
|
||||
FontPreferences fontPreferences = getFontPreferences();
|
||||
fontPreferences.register((String)selectedFont, getFontSizeFromField());
|
||||
}
|
||||
updateDescription(true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -163,25 +153,32 @@ public class FontOptions extends JPanel implements OptionsPanel{
|
||||
@Override
|
||||
public void textChanged(DocumentEvent event) {
|
||||
if (myIsInSchemeChange) return;
|
||||
float lineSpacing = 1;
|
||||
try {
|
||||
lineSpacing = Float.parseFloat(myLineSpacingField.getText());
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// OK, ignore
|
||||
}
|
||||
finally {
|
||||
if (lineSpacing <= 0) lineSpacing = 1;
|
||||
if (lineSpacing > 30) lineSpacing = 30;
|
||||
if (getLineSpacing() != lineSpacing) {
|
||||
setCurrentLineSpacing(lineSpacing);
|
||||
}
|
||||
updateDescription(true);
|
||||
float lineSpacing = getLineSpacingFromField();
|
||||
if (getLineSpacing() != lineSpacing) {
|
||||
setCurrentLineSpacing(lineSpacing);
|
||||
}
|
||||
updateDescription(true);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private int getFontSizeFromField() {
|
||||
try {
|
||||
return Math.min(OptionsConstants.MAX_EDITOR_FONT_SIZE, Math.max(1, Integer.parseInt(myEditorFontSizeField.getText())));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return OptionsConstants.DEFAULT_EDITOR_FONT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
private float getLineSpacingFromField() {
|
||||
try {
|
||||
return Math.min(30, Math.max(1, Float.parseFloat(myLineSpacingField.getText())));
|
||||
} catch (NumberFormatException e){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void syncFontFamilies() {
|
||||
if (myIsInSchemeChange) {
|
||||
return;
|
||||
@@ -190,11 +187,18 @@ public class FontOptions extends JPanel implements OptionsPanel{
|
||||
fontPreferences.clearFonts();
|
||||
String primaryFontFamily = (String)myPrimaryCombo.getSelectedItem();
|
||||
String secondaryFontFamily = mySecondaryCombo.isEnabled() ? (String)mySecondaryCombo.getSelectedItem() : null;
|
||||
if (primaryFontFamily != null && !FontPreferences.DEFAULT_FONT_NAME.equals(primaryFontFamily)) {
|
||||
fontPreferences.addFontFamily(primaryFontFamily);
|
||||
int fontSize = getFontSizeFromField();
|
||||
if (primaryFontFamily != null ) {
|
||||
if (!FontPreferences.DEFAULT_FONT_NAME.equals(primaryFontFamily)) {
|
||||
fontPreferences.addFontFamily(primaryFontFamily);
|
||||
}
|
||||
fontPreferences.register(primaryFontFamily, fontSize);
|
||||
}
|
||||
if (secondaryFontFamily != null && !FontPreferences.DEFAULT_FONT_NAME.equals(secondaryFontFamily)) {
|
||||
fontPreferences.addFontFamily(secondaryFontFamily);
|
||||
if (secondaryFontFamily != null) {
|
||||
if (!FontPreferences.DEFAULT_FONT_NAME.equals(secondaryFontFamily)){
|
||||
fontPreferences.addFontFamily(secondaryFontFamily);
|
||||
}
|
||||
fontPreferences.register(secondaryFontFamily, fontSize);
|
||||
}
|
||||
updateDescription(true);
|
||||
}
|
||||
|
||||
+10
-2
@@ -32,23 +32,31 @@ public class CapitalizeAndUnderscoreMacro extends MacroBase {
|
||||
super("capitalizeAndUnderscore", CodeInsightBundle.message("macro.capitalizeAndUnderscore.string"));
|
||||
}
|
||||
|
||||
protected CapitalizeAndUnderscoreMacro(String name, String description) {
|
||||
super(name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) {
|
||||
String text = getTextResult(params, context, true);
|
||||
if (text != null && text.length() > 0) {
|
||||
final String[] words = NameUtil.nameToWords(text);
|
||||
boolean insertUnderscore = false;
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
for (String word : words) {
|
||||
if (insertUnderscore) {
|
||||
buf.append("_");
|
||||
} else {
|
||||
insertUnderscore = true;
|
||||
}
|
||||
buf.append(StringUtil.toUpperCase(word));
|
||||
buf.append(convertCase(word));
|
||||
}
|
||||
return new TextResult(buf.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String convertCase(String word) {
|
||||
return StringUtil.toUpperCase(word);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.template.macro;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class SnakeCaseMacro extends CapitalizeAndUnderscoreMacro {
|
||||
public SnakeCaseMacro() {
|
||||
super("snakeCase", "snakeCase(String)");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String convertCase(String word) {
|
||||
return word.toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,8 @@ public class LocalFsFinder implements FileLookup.Finder, FileLookup {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String normalize(@NotNull final String path) {
|
||||
public String normalize(@NotNull String path) {
|
||||
path = FileUtil.expandUserHome(path);
|
||||
final File file = new File(path);
|
||||
if (file.isAbsolute()) return file.getAbsolutePath();
|
||||
|
||||
|
||||
@@ -432,6 +432,7 @@
|
||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.FileNameWithoutExtensionMacro"/>
|
||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.ReplaceUnderscoresToCamelCaseMacro"/>
|
||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.CapitalizeAndUnderscoreMacro"/>
|
||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.SnakeCaseMacro"/>
|
||||
|
||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.CompleteMacro"/>
|
||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.CompleteSmartMacro"/>
|
||||
|
||||
@@ -129,7 +129,8 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent,
|
||||
"SelectionStartLine",
|
||||
"SelectionEndLine",
|
||||
"SelectionStartColumn",
|
||||
"SelectionEndColumn"
|
||||
"SelectionEndColumn",
|
||||
"PyInterpreterDirectory"
|
||||
);
|
||||
|
||||
public PathMacrosImpl() {
|
||||
|
||||
+10
-3
@@ -21,6 +21,7 @@ import com.intellij.lang.LanguageRefactoringSupport;
|
||||
import com.intellij.lang.refactoring.RefactoringSupportProvider;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -365,12 +366,18 @@ public abstract class GrIntroduceHandlerBase<Settings extends GrIntroduceSetting
|
||||
else {
|
||||
final Settings settings = showDialog(context);
|
||||
if (settings == null) return false;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(context.getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runRefactoring(context, settings);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runRefactoring(context, settings);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}, getRefactoringName(), null);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
+7
@@ -27,6 +27,7 @@ import org.intellij.plugins.intelliLang.inject.config.BaseInjection;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -79,4 +80,10 @@ public class PyLanguageInjectionSupport extends AbstractLanguageInjectionSupport
|
||||
// with multiple injection text ranges (PY-10691)
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpId() {
|
||||
return "reference.settings.language.injection.generic.python";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,6 +473,8 @@
|
||||
<postStartupActivity implementation="com.jetbrains.python.packaging.PyPIPackagesUpdater"/>
|
||||
<postStartupActivity implementation="com.jetbrains.python.testing.PyTestRunnerUpdater"/>
|
||||
|
||||
<macro implementation="com.jetbrains.python.sdk.InterpreterDirectoryMacro"/>
|
||||
|
||||
<!-- User skeletons -->
|
||||
<codeInsight.lineMarkerProvider language="Python" implementationClass="com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsLineMarkerProvider"/>
|
||||
|
||||
@@ -504,7 +506,6 @@
|
||||
<!-- Packaging -->
|
||||
<moduleService serviceInterface="com.jetbrains.python.packaging.PyPackageRequirementsSettings"
|
||||
serviceImplementation="com.jetbrains.python.packaging.PyPackageRequirementsSettings"/>
|
||||
|
||||
</extensions>
|
||||
|
||||
<extensionPoints>
|
||||
@@ -547,6 +548,7 @@
|
||||
<dumbAnnotator implementation="com.jetbrains.python.validation.DocStringAnnotator"/>
|
||||
<dumbAnnotator implementation="com.jetbrains.python.validation.PyDefinitionsAnnotator"/>
|
||||
<dumbAnnotator implementation="com.jetbrains.python.validation.GeneratorInArgumentListAnnotator"/>
|
||||
<dumbAnnotator implementation="com.jetbrains.python.validation.StarAnnotator"/>
|
||||
|
||||
<customTargetExpressionStubType implementation="com.jetbrains.python.psi.impl.stubs.PropertyStubType"/>
|
||||
<dialectsTokenSetContributor implementation="com.jetbrains.python.PythonTokenSetContributor"/>
|
||||
|
||||
@@ -85,6 +85,9 @@ public class PyImportOptimizer implements ImportOptimizer {
|
||||
}
|
||||
LanguageLevel langLevel = LanguageLevel.forElement(myFile);
|
||||
for (PyImportStatementBase importStatement : myImportBlock) {
|
||||
if (importStatement instanceof PyFromImportStatement && ((PyFromImportStatement)importStatement).isFromFuture()) {
|
||||
continue;
|
||||
}
|
||||
if (importStatement instanceof PyImportStatement && importStatement.getImportElements().length > 1) {
|
||||
for (PyImportElement importElement : importStatement.getImportElements()) {
|
||||
myMissorted = true;
|
||||
@@ -96,7 +99,7 @@ public class PyImportOptimizer implements ImportOptimizer {
|
||||
else {
|
||||
PsiElement toImport;
|
||||
if (importStatement instanceof PyFromImportStatement) {
|
||||
toImport = ((PyFromImportStatement) importStatement).resolveImportSource();
|
||||
toImport = ((PyFromImportStatement)importStatement).resolveImportSource();
|
||||
}
|
||||
else {
|
||||
toImport = importStatement.getImportElements()[0].resolve();
|
||||
@@ -140,12 +143,21 @@ public class PyImportOptimizer implements ImportOptimizer {
|
||||
addImports(myThirdPartyImports);
|
||||
addImports(myProjectImports);
|
||||
PsiElement lastElement = myImportBlock.get(myImportBlock.size()-1);
|
||||
myFile.deleteChildRange(myImportBlock.get(0), lastElement);
|
||||
myFile.deleteChildRange(findFirstNonFutureImport(), lastElement);
|
||||
for (PyImportStatementBase anImport : myBuiltinImports) {
|
||||
anImport.putCopyableUserData(PyBlock.IMPORT_GROUP_BEGIN, null);
|
||||
}
|
||||
}
|
||||
|
||||
private PyImportStatementBase findFirstNonFutureImport() {
|
||||
for (PyImportStatementBase importStatement: myImportBlock) {
|
||||
if (!(importStatement instanceof PyFromImportStatement && ((PyFromImportStatement)importStatement).isFromFuture())) {
|
||||
return importStatement;
|
||||
}
|
||||
}
|
||||
return myImportBlock.get(0);
|
||||
}
|
||||
|
||||
private static void markGroupBegin(List<PyImportStatementBase> imports) {
|
||||
if (imports.size() > 0) {
|
||||
imports.get(0).putCopyableUserData(PyBlock.IMPORT_GROUP_BEGIN, true);
|
||||
@@ -154,7 +166,7 @@ public class PyImportOptimizer implements ImportOptimizer {
|
||||
|
||||
private void addImports(final List<PyImportStatementBase> imports) {
|
||||
for (PyImportStatementBase newImport: imports) {
|
||||
myFile.addBefore(newImport, myImportBlock.get(0));
|
||||
myFile.addBefore(newImport, findFirstNonFutureImport());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.jetbrains.python.inspections;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionToolSession;
|
||||
import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -138,7 +139,7 @@ public class PyArgumentListInspection extends PyInspection {
|
||||
holder.registerProblem(arg, PyBundle.message("INSP.duplicate.star.arg"));
|
||||
}
|
||||
if (flags.contains(CallArgumentsMapping.ArgFlag.IS_POS_PAST_KWD)) {
|
||||
holder.registerProblem(arg, PyBundle.message("INSP.cannot.appear.past.keyword.arg"));
|
||||
holder.registerProblem(arg, PyBundle.message("INSP.cannot.appear.past.keyword.arg"), ProblemHighlightType.ERROR);
|
||||
}
|
||||
if (flags.contains(CallArgumentsMapping.ArgFlag.IS_UNMAPPED)) {
|
||||
holder.registerProblem(arg, PyBundle.message("INSP.unexpected.arg"));
|
||||
|
||||
@@ -835,7 +835,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
}
|
||||
|
||||
private void addCreateClassFix(String refText, PsiElement element, List<LocalQuickFix> actions) {
|
||||
if (refText.length() > 2 && Character.isUpperCase(refText.charAt(0)) && !Character.isUpperCase(refText.charAt(1)) &&
|
||||
if (refText.length() > 2 && Character.isUpperCase(refText.charAt(0)) && !refText.toUpperCase().equals(refText) &&
|
||||
PsiTreeUtil.getParentOfType(element, PyImportStatementBase.class) == null) {
|
||||
PsiElement anchor = element;
|
||||
if (element instanceof PyQualifiedExpression) {
|
||||
|
||||
+10
-5
@@ -21,14 +21,13 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.documentation.DocStringUtil;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyStringLiteralExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* Author: Alexey.Ivanov
|
||||
* Date: 24.03.2010
|
||||
* Time: 20:15:23
|
||||
* @author Alexey.Ivanov
|
||||
*/
|
||||
public class MoveFromFutureImportQuickFix implements LocalQuickFix {
|
||||
@NotNull
|
||||
@@ -46,7 +45,13 @@ public class MoveFromFutureImportQuickFix implements LocalQuickFix {
|
||||
PsiFile psiFile = problemElement.getContainingFile();
|
||||
if (psiFile instanceof PyFile) {
|
||||
PyFile file = (PyFile)psiFile;
|
||||
file.addBefore(problemElement, file.getStatements().get(0));
|
||||
PyStringLiteralExpression docString = DocStringUtil.findDocStringExpression(file);
|
||||
if (docString != null) {
|
||||
file.addAfter(problemElement, docString.getParent() /* PyExpressionStatement */);
|
||||
}
|
||||
else {
|
||||
file.addBefore(problemElement, file.getStatements().get(0));
|
||||
}
|
||||
problemElement.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +221,7 @@ public class PyStringLiteralLexer extends LexerBase {
|
||||
if (myBuffer.charAt(i) == '\\') {
|
||||
LOG.assertTrue(myState == AFTER_FIRST_QUOTE);
|
||||
i++;
|
||||
if (myIsRaw) return i;
|
||||
if (i == myBufferEnd) {
|
||||
myState = AFTER_LAST_QUOTE;
|
||||
return i;
|
||||
@@ -282,7 +283,7 @@ public class PyStringLiteralLexer extends LexerBase {
|
||||
final int quote_limit = myIsTriple ? 3 : 1;
|
||||
int qcnt = 0; // count consequent quotes
|
||||
while (i < myBufferEnd) { // scan to next \something
|
||||
if (myBuffer.charAt(i) == '\\') {
|
||||
if (myBuffer.charAt(i) == '\\' && !myIsRaw) {
|
||||
return i;
|
||||
}
|
||||
if (myState == BEFORE_FIRST_QUOTE && myBuffer.charAt(i) == myQuoteChar) {
|
||||
@@ -292,7 +293,7 @@ public class PyStringLiteralLexer extends LexerBase {
|
||||
qcnt = 0; // for last quote detection in the same pass
|
||||
}
|
||||
}
|
||||
else if (myState == AFTER_FIRST_QUOTE && myBuffer.charAt(i) == myQuoteChar) { // done?
|
||||
else if (myState == AFTER_FIRST_QUOTE && myBuffer.charAt(i) == myQuoteChar && (!myIsRaw || myBuffer.charAt(i-1) != '\\')) { // done?
|
||||
qcnt += 1;
|
||||
if (qcnt == quote_limit) {
|
||||
myState = AFTER_LAST_QUOTE;
|
||||
|
||||
@@ -772,6 +772,7 @@ public class ExpressionParsing extends Parsing {
|
||||
PsiBuilder.Marker starExpr = myBuilder.mark();
|
||||
nextToken();
|
||||
if (!parseBitwiseORExpression(isTargetExpression)) {
|
||||
myBuilder.error(message("PARSE.expected.expression"));
|
||||
starExpr.drop();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,29 +65,9 @@ public class CallArgumentsMappingImpl implements CallArgumentsMapping {
|
||||
public void mapArguments(PyCallExpression.PyMarkedCallee resolved_callee, @NotNull TypeEvalContext context) {
|
||||
PyExpression[] arguments = myArgumentList.getArguments();
|
||||
myMarkedCallee = resolved_callee;
|
||||
List<PyExpression> unmatched_args = new LinkedList<PyExpression>();
|
||||
Collections.addAll(unmatched_args, arguments);
|
||||
final List<PyExpression> unmatched_subargs = new LinkedList<PyExpression>(); // unmatched nested arguments will go here
|
||||
// detect starred args
|
||||
for (PyExpression arg : arguments) {
|
||||
if (arg instanceof PyStarArgument) {
|
||||
PyStarArgument star_arg = (PyStarArgument)arg;
|
||||
if (star_arg.isKeyword()) {
|
||||
if (myKwdArg == null) myKwdArg = star_arg;
|
||||
else {
|
||||
markArgument(arg, ArgFlag.IS_DUP_KWD);
|
||||
unmatched_args.remove(arg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (myTupleArg == null) myTupleArg = star_arg;
|
||||
else {
|
||||
markArgument(arg, ArgFlag.IS_DUP_TUPLE);
|
||||
unmatched_args.remove(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List<PyExpression> unmatched_args = verifyArguments();
|
||||
|
||||
final List<PyParameter> parameters = PyUtil.getParameters(myMarkedCallee.getCallable(), context);
|
||||
// prepare parameter slots
|
||||
Map<PyNamedParameter, PyExpression> slots = new LinkedHashMap<PyNamedParameter, PyExpression>();
|
||||
@@ -180,15 +160,8 @@ public class CallArgumentsMappingImpl implements CallArgumentsMapping {
|
||||
for (PyExpression arg : unmatched_subargs) {
|
||||
markArgument(arg, ArgFlag.IS_UNMAPPED);
|
||||
}
|
||||
// mark past-bound positional args
|
||||
i = positional_bound;
|
||||
while (i<arguments.length) {
|
||||
PyExpression arg = arguments[i];
|
||||
if (!(arg instanceof PyStarArgument) && !(arg instanceof PyKeywordArgument)) {
|
||||
markArgument(arg, ArgFlag.IS_POS_PAST_KWD);
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
|
||||
|
||||
boolean seen_named_args = false;
|
||||
// map named args to named params if possible
|
||||
Map<String, PyNamedParameter> parameter_by_name = new LinkedHashMap<String, PyNamedParameter>();
|
||||
@@ -352,6 +325,57 @@ public class CallArgumentsMappingImpl implements CallArgumentsMapping {
|
||||
}
|
||||
}
|
||||
|
||||
public List<PyExpression> verifyArguments() {
|
||||
List<PyExpression> unmatched_args = new LinkedList<PyExpression>();
|
||||
Collections.addAll(unmatched_args, myArgumentList.getArguments());
|
||||
// detect starred args
|
||||
for (PyExpression arg : myArgumentList.getArguments()) {
|
||||
if (arg instanceof PyStarArgument) {
|
||||
PyStarArgument star_arg = (PyStarArgument)arg;
|
||||
if (star_arg.isKeyword()) {
|
||||
if (myKwdArg == null) myKwdArg = star_arg;
|
||||
else {
|
||||
markArgument(arg, ArgFlag.IS_DUP_KWD);
|
||||
unmatched_args.remove(arg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (myTupleArg == null) myTupleArg = star_arg;
|
||||
else {
|
||||
markArgument(arg, ArgFlag.IS_DUP_TUPLE);
|
||||
unmatched_args.remove(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
markPastBoundPositionalArguments(myArgumentList.getArguments());
|
||||
return unmatched_args;
|
||||
}
|
||||
|
||||
private void markPastBoundPositionalArguments(PyExpression[] arguments) {
|
||||
boolean seenKwArg = false;
|
||||
boolean seenKeyword = false;
|
||||
boolean seenStar = false;
|
||||
for (PyExpression arg : arguments) {
|
||||
if (arg == myKwdArg) {
|
||||
seenKwArg = true;
|
||||
}
|
||||
else if (arg instanceof PyKeywordArgument) {
|
||||
seenKeyword = true;
|
||||
}
|
||||
else if (arg instanceof PyStarArgument) {
|
||||
seenStar = true;
|
||||
}
|
||||
|
||||
if (seenKeyword || seenKwArg || seenStar) {
|
||||
if (!(arg instanceof PyStarArgument) && (seenKwArg || !(arg instanceof PyKeywordArgument))) {
|
||||
markArgument(arg, ArgFlag.IS_POS_PAST_KWD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPositionalArg(PyExpression arg) {
|
||||
return !(arg instanceof PyKeywordArgument) && !(arg instanceof PyStarArgument);
|
||||
}
|
||||
|
||||
@@ -269,8 +269,13 @@ public class PyArgumentListImpl extends PyElementImpl implements PyArgumentList
|
||||
// following the spec: http://docs.python.org/ref/calls.html
|
||||
PyCallExpression call = getCallExpression();
|
||||
if (call != null) {
|
||||
PyCallExpression.PyMarkedCallee resolved_callee = call.resolveCallee(resolveContext, offset);
|
||||
if (resolved_callee != null) ret.mapArguments(resolved_callee, resolveContext.getTypeEvalContext());
|
||||
PyCallExpression.PyMarkedCallee resolvedCallee = call.resolveCallee(resolveContext, offset);
|
||||
if (resolvedCallee != null) {
|
||||
ret.mapArguments(resolvedCallee, resolveContext.getTypeEvalContext());
|
||||
}
|
||||
else {
|
||||
ret.verifyArguments();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.sdk;
|
||||
|
||||
import com.intellij.ide.macro.Macro;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class InterpreterDirectoryMacro extends Macro {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "PyInterpreterDirectory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "The directory containing the Python interpreter selected for the project";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String expand(DataContext dataContext) throws ExecutionCancelledException {
|
||||
Module module = LangDataKeys.MODULE.getData(dataContext);
|
||||
if (module == null) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
if (project == null) {
|
||||
return null;
|
||||
}
|
||||
Module[] modules = ModuleManager.getInstance(project).getModules();
|
||||
if (modules.length == 0) {
|
||||
return null;
|
||||
}
|
||||
module = modules[0];
|
||||
}
|
||||
Sdk sdk = PythonSdkType.findPythonSdk(module);
|
||||
if (sdk != null) {
|
||||
VirtualFile homeDir = sdk.getHomeDirectory();
|
||||
if (homeDir == null) {
|
||||
return null;
|
||||
}
|
||||
String path = PathUtil.getLocalPath(homeDir.getParent());
|
||||
if (path != null) {
|
||||
return FileUtil.toSystemDependentName(path);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationListener;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
@@ -556,16 +555,22 @@ public class PythonSdkType extends SdkType {
|
||||
|
||||
@NotNull
|
||||
public static Notification createInvalidSdkNotification(@Nullable final Project project) {
|
||||
String message = "Cannot run the project interpreter.";
|
||||
if (project != null && !project.isDisposed()) {
|
||||
message += " <a href=\"xxx\">Configure...</a>";
|
||||
}
|
||||
return new Notification("xxx",
|
||||
"Invalid Project Interpreter",
|
||||
"Cannot run the project interpreter. <a href=\"xxx\">Configure...</a>",
|
||||
message,
|
||||
NotificationType.ERROR,
|
||||
new NotificationListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(@NotNull Notification notification,
|
||||
@NotNull HyperlinkEvent event) {
|
||||
final ShowSettingsUtil settings = ShowSettingsUtil.getInstance();
|
||||
settings.showSettingsDialog(project, "Project Interpreter");
|
||||
if (project != null && !project.isDisposed()) {
|
||||
final ShowSettingsUtil settings = ShowSettingsUtil.getInstance();
|
||||
settings.showSettingsDialog(project, "Project Interpreter");
|
||||
}
|
||||
notification.expire();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.validation;
|
||||
|
||||
import com.jetbrains.python.psi.PyStarExpression;
|
||||
import com.jetbrains.python.psi.PyTargetExpression;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class StarAnnotator extends PyAnnotator {
|
||||
@Override
|
||||
public void visitPyStarExpression(PyStarExpression node) {
|
||||
super.visitPyStarExpression(node);
|
||||
if (!(node.getExpression() instanceof PyTargetExpression)) {
|
||||
getHolder().createErrorAnnotation(node, "can use starred expression only as assignment target");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
y = (<error descr="can use starred expression only as assignment target">*()</error> for _ in ())
|
||||
@@ -0,0 +1,10 @@
|
||||
"""This is a docstring."""
|
||||
|
||||
from __future__ import print_function
|
||||
#comment
|
||||
from __future__ import absolute_import
|
||||
|
||||
class A:
|
||||
pass
|
||||
|
||||
<warning descr="from __future__ imports must occur at the beginning of the file"><caret>from __future__ import with_statement</warning>
|
||||
@@ -0,0 +1,10 @@
|
||||
"""This is a docstring."""
|
||||
from __future__ import with_statement
|
||||
|
||||
from __future__ import print_function
|
||||
#comment
|
||||
from __future__ import absolute_import
|
||||
|
||||
class A:
|
||||
pass
|
||||
|
||||
@@ -42,7 +42,7 @@ f3(1, 2, <warning descr="Unexpected argument">3</warning>)
|
||||
f3(b=2, a=1)
|
||||
f3(b=1, <warning descr="Duplicate argument">b=2</warning>, a=1)
|
||||
f3(1, b=2)
|
||||
f3(a=1, <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">2</warning><warning descr="Parameter 'b' unfilled">)</warning>
|
||||
f3(a=1, <error descr="Cannot appear past keyword arguments or *arg or **kwarg">2</error><warning descr="Parameter 'b' unfilled">)</warning>
|
||||
|
||||
def f4(a, *b):
|
||||
pass
|
||||
@@ -52,4 +52,4 @@ f4(1, 2)
|
||||
f4(1, 2, 3)
|
||||
f4(1, *(2, 3))
|
||||
f4(*(1,2,3))
|
||||
f4(a=1, <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">2</warning>, <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">3</warning>)
|
||||
f4(a=1, <error descr="Cannot appear past keyword arguments or *arg or **kwarg">2</error>, <error descr="Cannot appear past keyword arguments or *arg or **kwarg">3</error>)
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
def foo(**kwargs): pass
|
||||
|
||||
two = 0
|
||||
kw = {}
|
||||
foo(**kw, <error descr="Cannot appear past keyword arguments or *arg or **kwarg">two=1</error>)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
kwargs = {'foo': 'bar'}
|
||||
|
||||
|
||||
class Foo(object):
|
||||
|
||||
@classmethod
|
||||
def test(cls):
|
||||
cls(**kwargs, <error descr="Cannot appear past keyword arguments or *arg or **kwarg">foo=1</error>)
|
||||
@@ -19,7 +19,7 @@ def f2(a, b, c=1, *d):
|
||||
f2(c=3, *(1,2))
|
||||
f2(1,2,3, *(1,2))
|
||||
f2(*(1,2), c=20)
|
||||
f2(*(1,2), <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">20</warning>) # fail: positional past *
|
||||
f2(*(1,2), <error descr="Cannot appear past keyword arguments or *arg or **kwarg">20</error>) # fail: positional past *
|
||||
|
||||
def f3(a=1, b=2, c=3, *d):
|
||||
return a,b,c,d
|
||||
|
||||
@@ -13,7 +13,7 @@ namedpast(1,2,3, foo='a') # pass
|
||||
namedpast(*args, foo='b') # pass
|
||||
namedpast(foo='c') # pass
|
||||
namedpast() # pass
|
||||
namedpast(foo='1', <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">2</warning>) # fail
|
||||
namedpast(foo='1', <error descr="Cannot appear past keyword arguments or *arg or **kwarg">2</error>) # fail
|
||||
|
||||
def a23(a, *b, c=1):
|
||||
pass
|
||||
@@ -21,7 +21,7 @@ def a23(a, *b, c=1):
|
||||
a23(1,2,3, c=10) # pass
|
||||
a23(1,2,3, c=10, <warning descr="Duplicate argument">a=1</warning>) # fail
|
||||
a23(c=10, a=1) # pass
|
||||
a23(c=10, <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">1</warning><warning descr="Parameter 'a' unfilled">)</warning> # fail
|
||||
a23(c=10, <error descr="Cannot appear past keyword arguments or *arg or **kwarg">1</error><warning descr="Parameter 'a' unfilled">)</warning> # fail
|
||||
a23(<warning descr="Multiple values resolve to positional parameter 'a'">*args</warning>, a=1) # fail
|
||||
a23(*args, c=1) # pass
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import with_statement
|
||||
import sys
|
||||
import datetime
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import with_statement
|
||||
import foo
|
||||
import sys
|
||||
from bar import *
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
x = (*)
|
||||
@@ -0,0 +1,13 @@
|
||||
PyFile:LoneStar.py
|
||||
PyAssignmentStatement
|
||||
PyTargetExpression: x
|
||||
PsiElement(Py:IDENTIFIER)('x')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(Py:EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
PyParenthesizedExpression
|
||||
PsiElement(Py:LPAR)('(')
|
||||
PsiElement(Py:MULT)('*')
|
||||
PsiErrorElement:expression expected
|
||||
<empty list>
|
||||
PsiElement(Py:RPAR)(')')
|
||||
@@ -0,0 +1 @@
|
||||
s = r'Hello\<selection>nWorld</selection>!'
|
||||
@@ -0,0 +1 @@
|
||||
s = r'Hello\nWo<caret>rld!'
|
||||
@@ -27,9 +27,7 @@ import com.jetbrains.python.psi.LanguageLevel;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
* Test actions that various inspections add.
|
||||
* User: dcheryasov
|
||||
* Date: Nov 29, 2008 12:47:08 AM
|
||||
* @author dcheryasov
|
||||
*/
|
||||
@TestDataPath("$CONTENT_ROOT/../testData/inspections/")
|
||||
public class PyQuickFixTest extends PyTestCase {
|
||||
@@ -161,6 +159,11 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
PyBundle.message("QFIX.move.from.future.import"), true, true);
|
||||
}
|
||||
|
||||
public void testFromFutureImportQuickFixDocString() { // PY-10080
|
||||
doInspectionTest("MoveFromFutureImportDocString.py", PyFromFutureImportInspection.class,
|
||||
PyBundle.message("QFIX.move.from.future.import"), true, true);
|
||||
}
|
||||
|
||||
public void testComparisonWithNoneQuickFix() {
|
||||
doInspectionTest("ComparisonWithNone.py", PyComparisonWithNoneInspection.class,
|
||||
PyBundle.message("QFIX.replace.equality"), true, true);
|
||||
|
||||
@@ -46,6 +46,10 @@ public class PySelectWordTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEscapeSequenceRaw() { // PY-10322
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
CodeInsightTestUtil.doWordSelectionTestOnDirectory(myFixture, "selectWord/" + getTestName(true), "py");
|
||||
}
|
||||
|
||||
@@ -26,4 +26,9 @@ public class PyStringLiteralLexerTest extends PyLexerTestCase {
|
||||
PyLexerTestCase.doLexerTest("u\"\\N{LATIN SMALL LETTER B}\"", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE),
|
||||
"Py:SINGLE_QUOTED_UNICODE", "VALID_STRING_ESCAPE_TOKEN", "Py:SINGLE_QUOTED_UNICODE");
|
||||
}
|
||||
|
||||
public void testRawBackslashN() {
|
||||
PyLexerTestCase.doLexerTest("r'[\\w\\']'", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_STRING), true,
|
||||
"r'[\\w\\']'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +183,10 @@ public class PythonHighlightingTest extends PyTestCase {
|
||||
doTest(false, false);
|
||||
}
|
||||
|
||||
public void testStarInGenerator() { // PY-10177
|
||||
doTest(LanguageLevel.PYTHON33, false, false);
|
||||
}
|
||||
|
||||
public void testStarArgs() { // PY-6456
|
||||
doTest(LanguageLevel.PYTHON32, true, false);
|
||||
}
|
||||
|
||||
@@ -398,6 +398,10 @@ public class PythonParsingTest extends ParsingTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLoneStar() { // PY-10177
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void doTest(LanguageLevel languageLevel) {
|
||||
LanguageLevel prev = myLanguageLevel;
|
||||
myLanguageLevel = languageLevel;
|
||||
|
||||
@@ -35,6 +35,13 @@ public abstract class PyLexerTestCase extends PlatformLiteFixture {
|
||||
}
|
||||
|
||||
public static void doLexerTest(String text, Lexer lexer, String... expectedTokens) {
|
||||
doLexerTest(text, lexer, false, expectedTokens);
|
||||
}
|
||||
|
||||
public static void doLexerTest(String text,
|
||||
Lexer lexer,
|
||||
boolean checkTokenText,
|
||||
String... expectedTokens) {
|
||||
lexer.start(text);
|
||||
int idx = 0;
|
||||
int tokenPos = 0;
|
||||
@@ -44,13 +51,13 @@ public abstract class PyLexerTestCase extends PlatformLiteFixture {
|
||||
lexer.advance();
|
||||
while (lexer.getTokenType() != null) {
|
||||
remainingTokens.append(",");
|
||||
remainingTokens.append(" \"").append(lexer.getTokenType().toString()).append("\"");
|
||||
remainingTokens.append(" \"").append(checkTokenText ? lexer.getTokenText() : lexer.getTokenType().toString()).append("\"");
|
||||
lexer.advance();
|
||||
}
|
||||
fail("Too many tokens. Following tokens: " + remainingTokens.toString());
|
||||
}
|
||||
assertEquals("Token offset mismatch at position " + idx, tokenPos, lexer.getTokenStart());
|
||||
String tokenName = lexer.getTokenType().toString();
|
||||
String tokenName = checkTokenText ? lexer.getTokenText() : lexer.getTokenType().toString();
|
||||
assertEquals("Token mismatch at position " + idx, expectedTokens[idx], tokenName);
|
||||
idx++;
|
||||
tokenPos = lexer.getTokenEnd();
|
||||
|
||||
@@ -168,4 +168,12 @@ public class PyArgumentListInspectionTest extends PyTestCase {
|
||||
public void testDictFromKeys() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testParameterWithDefaultAfterKeywordContainer() { // PY-9934
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testParameterWithDefaultAfterKeywordContainer2() { // PY-10351
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user