-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
195 additions
and
14 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...sis/src/com/python/pydev/analysis/refactoring/quick_fixes/DummyMarkerInfoForAnalysis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.python.pydev.analysis.refactoring.quick_fixes; | ||
|
||
import org.python.pydev.core.IMarkerInfoForAnalysis; | ||
|
||
public class DummyMarkerInfoForAnalysis implements IMarkerInfoForAnalysis { | ||
|
||
public Object message; | ||
public Object flake8MessageId; | ||
public int length; | ||
public int offset; | ||
public Integer pyDevAnalysisType; | ||
public Object pyLintMessageId; | ||
|
||
public DummyMarkerInfoForAnalysis(int pyDevAnalysisType, int offset, int length) { | ||
this.pyDevAnalysisType = pyDevAnalysisType; | ||
this.offset = offset; | ||
this.length = length; | ||
} | ||
|
||
@Override | ||
public Object getPyLintMessageIdAttribute() { | ||
return pyLintMessageId; | ||
} | ||
|
||
@Override | ||
public Integer getPyDevAnalisysType() { | ||
return pyDevAnalysisType; | ||
} | ||
|
||
@Override | ||
public boolean hasPosition() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getOffset() { | ||
return offset; | ||
} | ||
|
||
@Override | ||
public int getLength() { | ||
return length; | ||
} | ||
|
||
@Override | ||
public void delete() { | ||
|
||
} | ||
|
||
@Override | ||
public Object getFlake8MessageId() { | ||
return flake8MessageId; | ||
} | ||
|
||
@Override | ||
public Object getMessage() { | ||
return message; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipantWithMarkersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* Copyright (c) 2005-2013 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Eclipse Public License (EPL). | ||
* Please see the license.txt included with this distribution for details. | ||
* Any modifications to this file must keep this entire header intact. | ||
*/ | ||
package com.python.pydev.refactoring.tdd; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.jface.text.Document; | ||
import org.python.pydev.ast.codecompletion.PyCodeCompletion; | ||
import org.python.pydev.ast.codecompletion.revisited.CodeCompletionTestsBase; | ||
import org.python.pydev.ast.codecompletion.revisited.modules.CompiledModule; | ||
import org.python.pydev.ast.refactoring.AbstractPyRefactoring; | ||
import org.python.pydev.core.IAnalysisPreferences; | ||
import org.python.pydev.core.IMarkerInfoForAnalysis; | ||
import org.python.pydev.core.TestDependent; | ||
import org.python.pydev.core.docutils.PySelection; | ||
import org.python.pydev.core.structure.CompletionRecursionException; | ||
import org.python.pydev.plugin.nature.PythonNature; | ||
import org.python.pydev.shared_core.callbacks.ICallback; | ||
import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle; | ||
|
||
import com.python.pydev.analysis.AnalysisPreferences; | ||
import com.python.pydev.analysis.refactoring.quick_fixes.DummyMarkerInfoForAnalysis; | ||
import com.python.pydev.analysis.refactoring.refactorer.Refactorer; | ||
|
||
/** | ||
* @author Fabio | ||
* | ||
*/ | ||
public class TddCodeGenerationQuickFixParticipantWithMarkersTest extends CodeCompletionTestsBase { | ||
|
||
public static void main(String[] args) { | ||
|
||
try { | ||
//DEBUG_TESTS_BASE = true; | ||
TddCodeGenerationQuickFixParticipantWithMarkersTest test = new TddCodeGenerationQuickFixParticipantWithMarkersTest(); | ||
test.setUp(); | ||
test.testCreateClass(); | ||
test.tearDown(); | ||
System.out.println("Finished"); | ||
|
||
junit.textui.TestRunner.run(TddCodeGenerationQuickFixParticipantWithMarkersTest.class); | ||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/* | ||
* @see TestCase#setUp() | ||
*/ | ||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
AbstractPyRefactoring.setPyRefactoring(new Refactorer()); | ||
CompiledModule.COMPILED_MODULES_ENABLED = false; | ||
this.restorePythonPath(TestDependent.getCompletePythonLib(true, isPython3Test()) + | ||
"|" + TestDependent.PYTHON2_PIL_PACKAGES + | ||
"|" | ||
+ TestDependent.TEST_PYSRC_TESTING_LOC + | ||
"configobj-4.6.0-py2.6.egg", false); | ||
|
||
this.restorePythonPath(false); | ||
codeCompletion = new PyCodeCompletion(); | ||
TddCodeGenerationQuickFixWithoutMarkersParticipant.onGetTddPropsError = new ICallback<Boolean, Exception>() { | ||
|
||
@Override | ||
public Boolean call(Exception e) { | ||
throw new RuntimeException("Error:" + org.python.pydev.shared_core.log.Log.getExceptionStr(e)); | ||
} | ||
}; | ||
PyCodeCompletion.onCompletionRecursionException = new ICallback<Object, CompletionRecursionException>() { | ||
|
||
@Override | ||
public Object call(CompletionRecursionException e) { | ||
throw new RuntimeException( | ||
"Recursion error:" + org.python.pydev.shared_core.log.Log.getExceptionStr(e)); | ||
} | ||
|
||
}; | ||
} | ||
|
||
/* | ||
* @see TestCase#tearDown() | ||
*/ | ||
@Override | ||
public void tearDown() throws Exception { | ||
CompiledModule.COMPILED_MODULES_ENABLED = true; | ||
super.tearDown(); | ||
AbstractPyRefactoring.setPyRefactoring(null); | ||
PyCodeCompletion.onCompletionRecursionException = null; | ||
} | ||
|
||
public void testCreateClass() throws Exception { | ||
int usedGrammar = GRAMMAR_TO_USE_FOR_PARSING; | ||
GRAMMAR_TO_USE_FOR_PARSING = PythonNature.LATEST_GRAMMAR_PY3_VERSION; | ||
try { | ||
String mod1Contents = "" + | ||
"class Foo(object):\n" + | ||
" def m1(self):\n" + | ||
" NewClass"; | ||
|
||
Document doc = new Document(mod1Contents); | ||
|
||
TddQuickFixFromMarkersParticipant participant = new TddQuickFixFromMarkersParticipant(); | ||
int offset = mod1Contents.length(); | ||
PySelection ps = new PySelection(doc, offset); | ||
int markerStart = mod1Contents.indexOf("NewClass"); | ||
int markerLen = "NewClass".length(); | ||
|
||
IMarkerInfoForAnalysis markerInfo = new DummyMarkerInfoForAnalysis( | ||
IAnalysisPreferences.TYPE_UNDEFINED_VARIABLE, markerStart, markerLen); | ||
IAnalysisPreferences analysisPreferences = new AnalysisPreferences(null); | ||
String line = ps.getLine(); | ||
List<ICompletionProposalHandle> props = new ArrayList<>(); | ||
participant.addProps(markerInfo, analysisPreferences, line, ps, offset, nature, null, props); | ||
|
||
} finally { | ||
GRAMMAR_TO_USE_FOR_PARSING = usedGrammar; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters