|
From: <mir...@us...> - 2007-02-08 09:41:06
|
Revision: 1939
http://svn.sourceforge.net/rubyeclipse/?rev=1939&view=rev
Author: mirkostocker
Date: 2007-02-08 01:41:02 -0800 (Thu, 08 Feb 2007)
Log Message:
-----------
fix for refactoring with syntax errors somewhere in the project
Modified Paths:
--------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/RefactoringConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/encapsulatefield/EncapsulateFieldConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/mergewithexternalclassparts/MergeWithExternalClassPartsConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/RenameClassConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentWithIncluding.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/TS_All.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TS_Core.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/conditionchecks/temp_to_field_checker_test_2.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/conditionchecks/temp_to_field_checker_test_7.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/renamelocalvariable/conditionchecks/rename_local_condition_test_2.test_properties
Added Paths:
-----------
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TC_RefactoringConditionChecker.java
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeProvider.java 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeProvider.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -62,9 +62,13 @@
import org.jruby.ast.types.INameNode;
import org.jruby.common.NullWarnings;
import org.jruby.lexer.yacc.LexerSource;
+import org.jruby.lexer.yacc.SourcePosition;
+import org.jruby.lexer.yacc.SyntaxException;
import org.jruby.parser.DefaultRubyParser;
+import org.jruby.parser.LocalStaticScope;
import org.jruby.parser.RubyParserConfiguration;
import org.jruby.parser.RubyParserPool;
+import org.jruby.runtime.DynamicScope;
import org.rubypeople.rdt.refactoring.nodewrapper.AttrAccessorNodeWrapper;
import org.rubypeople.rdt.refactoring.nodewrapper.FieldNodeWrapper;
import org.rubypeople.rdt.refactoring.nodewrapper.MethodCallNodeWrapper;
@@ -86,20 +90,38 @@
children.add((Node) it.next());
return children;
}
-
- public static RootNode getRootNode(String fileName, String fileContent) {
- if(fileContent == null) {
- return null;
+
+ public static boolean hasSyntaxErrors(String fileName, String fileContent) {
+ try {
+ parseFile(fileName, fileContent);
+ return false;
+ } catch(SyntaxException e) {
+ return true;
}
+ }
+
+ private static RootNode parseFile(String fileName, String fileContent) {
Reader reader = new InputStreamReader(new ByteArrayInputStream(fileContent.getBytes()));
DefaultRubyParser parser;
parser = RubyParserPool.getInstance().borrowParser();
parser.setWarnings(new NullWarnings());
LexerSource lexerSource = new LexerSource(fileName, reader);
- RootNode rootNode = (RootNode) parser.parse(new RubyParserConfiguration(), lexerSource).getAST();
- return rootNode;
+ return (RootNode) parser.parse(new RubyParserConfiguration(), lexerSource).getAST();
}
+ public static RootNode getRootNode(String fileName, String fileContent) {
+ if(fileContent == null) {
+ return null;
+ }
+
+ try {
+ return parseFile(fileName, fileContent);
+ } catch(SyntaxException e) {
+// treat files with syntax errors as empty
+ return new RootNode(new SourcePosition(), new DynamicScope(new LocalStaticScope(null), null), null);
+ }
+ }
+
public static Collection<Node> getAttributeNodes(Node parent) {
Collection<Node> attrNodes = getSubNodes(parent, InstAsgnNode.class, InstVarNode.class);
attrNodes.addAll(getAttrListNodes(parent));
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/RefactoringConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/RefactoringConditionChecker.java 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/RefactoringConditionChecker.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -51,7 +51,6 @@
init(config);
}
}
-
public boolean shouldPerform(boolean onlyInternalErrors) {
if(!onlyInternalErrors && shouldPerform(true)) {
@@ -59,6 +58,7 @@
}
return messages.get(IRefactoringConditionChecker.ERRORS).isEmpty();
}
+
public boolean shouldPerform() {
return shouldPerform(false);
}
@@ -66,9 +66,22 @@
public Map<String, Collection<String>> getFinalMessages() {
initMessages();
checkFinalConditions();
+ checkForSyntaxErrors();
return messages;
}
+ private void checkForSyntaxErrors() {
+ boolean syntaxError = false;
+ for(String file : docProvider.getFileNames()) {
+ if(NodeProvider.hasSyntaxErrors(file, docProvider.getFileContent(file))) {
+ syntaxError = true;
+ }
+ }
+ if (syntaxError) {
+ addWarning("There is a syntax error somewhere in the project, the refactoring might not work on these files.");
+ }
+ }
+
private void initMessages() {
messages = new LinkedHashMap<String, Collection<String>>();
messages.put(IRefactoringConditionChecker.ERRORS, new ArrayList<String>());
@@ -92,7 +105,7 @@
String fileName = null;
try {
fileName = docProvider.getActiveFileName();
- if(docProvider.getRootNode().getBodyNode() == null) {
+ if(docProvider.getActiveFileContent().equals("")) {
addError("Nothing to do in empty document.");
}
for(String aktFileName : docProvider.getFileNames()) {
@@ -102,26 +115,26 @@
} catch(SyntaxException se) {
String activeFileName = docProvider.getActiveFileName();
if(fileName == null || fileName.equals(activeFileName)) {
- addError("There is a syntax error in your document, refactoring is not possible.");
- } else {
- addError("There is a syntax error in the document " + fileName + ", refactoring is not possible.");
+ addError("There is a syntax error in the current file, refactoring is not possible.");
}
}
+
+ if(NodeProvider.hasSyntaxErrors(docProvider.getActiveFileName(), docProvider.getActiveFileContent())) {
+ addError("There is a syntax error in the current file, refactoring is not possible.");
+ }
}
-
+
protected void addError(String message) {
- Collection<String> errors = messages.get(IRefactoringConditionChecker.ERRORS);
- errors.add(message);
+ messages.get(IRefactoringConditionChecker.ERRORS).add(message);
}
protected void addWarning(String message) {
- Collection<String> warnings = messages.get(IRefactoringConditionChecker.WARNING);
- warnings.add(message);
+ messages.get(IRefactoringConditionChecker.WARNING).add(message);
}
protected abstract void checkInitialConditions();
- protected void checkFinalConditions() {
+ protected void checkFinalConditions() {
}
protected abstract void init(Object configObj);
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/encapsulatefield/EncapsulateFieldConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/encapsulatefield/EncapsulateFieldConditionChecker.java 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/encapsulatefield/EncapsulateFieldConditionChecker.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -71,8 +71,7 @@
}
private INameNode findSelectedInstNode(int caretPosition) {
- Node instNode = SelectionNodeProvider.getSelectedNodeOfType(rootNode, caretPosition, InstVarNode.class, InstAsgnNode.class, SymbolNode.class);
- return (INameNode) instNode;
+ return (INameNode) SelectionNodeProvider.getSelectedNodeOfType(rootNode, caretPosition, InstVarNode.class, InstAsgnNode.class, SymbolNode.class);
}
public void checkFinalConditions() {
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/mergewithexternalclassparts/MergeWithExternalClassPartsConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/mergewithexternalclassparts/MergeWithExternalClassPartsConditionChecker.java 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/mergewithexternalclassparts/MergeWithExternalClassPartsConditionChecker.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -60,5 +60,4 @@
addError("There is no class in the current file that has external parts to merge.");
}
}
-
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/RenameClassConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/RenameClassConditionChecker.java 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/RenameClassConditionChecker.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -56,10 +56,6 @@
}
@Override
- protected void checkFinalConditions() {
- }
-
- @Override
protected void checkInitialConditions() {
if (config.getSelectedNode() == null) {
addError("Please select the name of a class declaration.");
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentProvider.java 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentProvider.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -57,11 +57,7 @@
public RootNode getRootNode() {
return NodeProvider.getRootNode(getActiveFileName(), getActiveFileContent());
}
-//
-// public ScopeNode getRootNodeWithEnclosingScopeNode() {
-// return NodeProvider.getRootNodeWithEnclosingScopeNode(getActiveFileName(), getActiveFileContent());
-// }
-
+
public Collection<Node> getAllNodes() {
return NodeProvider.getAllNodes(getRootNode());
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentWithIncluding.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentWithIncluding.java 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentWithIncluding.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -35,6 +35,7 @@
import org.jruby.ast.FCallNode;
import org.jruby.ast.Node;
import org.jruby.ast.StrNode;
+import org.jruby.lexer.yacc.SyntaxException;
import org.rubypeople.rdt.refactoring.classnodeprovider.ClassNodeProvider;
import org.rubypeople.rdt.refactoring.core.NodeProvider;
import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
@@ -128,7 +129,11 @@
}
private Collection<FCallNode> getRequires(DocumentProvider doc) {
- return NodeProvider.getLoadAndRequireNodes(doc.getRootNode());
+ try {
+ return NodeProvider.getLoadAndRequireNodes(doc.getRootNode());
+ } catch(SyntaxException e) {
+ return new ArrayList<FCallNode>();
+ }
}
private boolean fileIsInResultSet(String fileName) {
Modified: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/TS_All.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/TS_All.java 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/TS_All.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -48,6 +48,7 @@
import org.rubypeople.rdt.refactoring.tests.core.movemethod.TS_MoveMethod;
import org.rubypeople.rdt.refactoring.tests.core.overridemethod.TS_OverrideMethod;
import org.rubypeople.rdt.refactoring.tests.core.pushdown.TS_PushDown;
+import org.rubypeople.rdt.refactoring.tests.core.rename.TS_Rename;
import org.rubypeople.rdt.refactoring.tests.core.renameclass.TS_RenameClass;
import org.rubypeople.rdt.refactoring.tests.core.renamefield.TS_RenameField;
import org.rubypeople.rdt.refactoring.tests.core.renamelocalvariable.TS_RenameLocalVariable;
@@ -84,6 +85,7 @@
suite.addTest(TS_InlineClass.suite());
suite.addTest(TS_MoveMethod.suite());
suite.addTest(TS_MoveField.suite());
+ suite.addTest(TS_Rename.suite());
return suite;
}
Added: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TC_RefactoringConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TC_RefactoringConditionChecker.java (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TC_RefactoringConditionChecker.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -0,0 +1,44 @@
+package org.rubypeople.rdt.refactoring.tests.core;
+
+import junit.framework.TestCase;
+
+import org.rubypeople.rdt.refactoring.core.IRefactoringConditionChecker;
+import org.rubypeople.rdt.refactoring.core.RefactoringConditionChecker;
+import org.rubypeople.rdt.refactoring.documentprovider.IDocumentProvider;
+import org.rubypeople.rdt.refactoring.documentprovider.StringDocumentProvider;
+
+public class TC_RefactoringConditionChecker extends TestCase {
+ private final class TestConditionChecker extends RefactoringConditionChecker {
+ private TestConditionChecker(IDocumentProvider provider, Object config) {
+ super(provider, config);
+ }
+
+ @Override
+ protected void init(Object configObj) {
+ }
+
+ @Override
+ protected void checkInitialConditions() {
+ }
+ }
+
+ public void testSyntaxErrors() {
+
+ RefactoringConditionChecker checker = new TestConditionChecker(new StringDocumentProvider("class Test; en"), null);
+ assertEquals(1, checker.getInitialMessages().get(IRefactoringConditionChecker.ERRORS).size());
+ assertEquals(0, checker.getInitialMessages().get(IRefactoringConditionChecker.WARNING).size());
+ }
+
+ public void testSyntaxErrorsInIncludes() {
+
+ StringDocumentProvider stringDocumentProvider = new StringDocumentProvider("class Test; end");
+ stringDocumentProvider.addFile("other", "class Test; en");
+
+ RefactoringConditionChecker checker = new TestConditionChecker(stringDocumentProvider, null);
+ assertEquals(0, checker.getInitialMessages().get(IRefactoringConditionChecker.ERRORS).size());
+ assertEquals(0, checker.getInitialMessages().get(IRefactoringConditionChecker.WARNING).size());
+
+ assertEquals(0, checker.getFinalMessages().get(IRefactoringConditionChecker.ERRORS).size());
+ assertEquals(1, checker.getFinalMessages().get(IRefactoringConditionChecker.WARNING).size());
+ }
+}
Modified: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TS_Core.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TS_Core.java 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TS_Core.java 2007-02-08 09:41:02 UTC (rev 1939)
@@ -32,12 +32,15 @@
import junit.framework.TestSuite;
import org.rubypeople.rdt.refactoring.tests.FileTestSuite;
+import org.rubypeople.rdt.refactoring.tests.core.nodewrapper.TS_NodeWrapper;
public class TS_Core extends FileTestSuite {
public static Test suite() {
TestSuite suite = createSuite("Core", "enclosing_nodes_test.*rb", TC_SelectionNodeProvider.class);
suite.addTestSuite(TC_NodeProvider.class);
+ suite.addTest(TS_NodeWrapper.suite());
+ suite.addTestSuite(TC_RefactoringConditionChecker.class);
return suite;
}
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/conditionchecks/temp_to_field_checker_test_2.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/conditionchecks/temp_to_field_checker_test_2.test_properties 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/conditionchecks/temp_to_field_checker_test_2.test_properties 2007-02-08 09:41:02 UTC (rev 1939)
@@ -2,5 +2,5 @@
isClassField=false
newName=d
cursorPosition=7
-initialError0=There is a syntax error in your document, refactoring is not possible.
+initialError0=There is a syntax error in the current file, refactoring is not possible.
Modified: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/conditionchecks/temp_to_field_checker_test_7.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/conditionchecks/temp_to_field_checker_test_7.test_properties 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/conditionchecks/temp_to_field_checker_test_7.test_properties 2007-02-08 09:41:02 UTC (rev 1939)
@@ -2,4 +2,4 @@
isClassField=false
newName=d
cursorPosition=4
-initialError0=There is a syntax error in your document, refactoring is not possible.
\ No newline at end of file
+initialError0=There is a syntax error in the current file, refactoring is not possible.
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/renamelocalvariable/conditionchecks/rename_local_condition_test_2.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/renamelocalvariable/conditionchecks/rename_local_condition_test_2.test_properties 2007-02-07 22:00:20 UTC (rev 1938)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/renamelocalvariable/conditionchecks/rename_local_condition_test_2.test_properties 2007-02-08 09:41:02 UTC (rev 1939)
@@ -1,2 +1,2 @@
cursorPosition=0
-initialError0=There is a syntax error in your document, refactoring is not possible.
\ No newline at end of file
+initialError0=There is a syntax error in the current file, refactoring is not possible.
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|