|
From: <caw...@us...> - 2007-04-20 16:53:09
|
Revision: 2346
http://svn.sourceforge.net/rubyeclipse/?rev=2346&view=rev
Author: cawilliams
Date: 2007-04-20 09:52:46 -0700 (Fri, 20 Apr 2007)
Log Message:
-----------
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/MarkerUtility.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RdtWarnings.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java 2007-04-20 13:18:24 UTC (rev 2345)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java 2007-04-20 16:52:46 UTC (rev 2346)
@@ -56,7 +56,6 @@
import org.rubypeople.rdt.internal.core.builder.MassIndexUpdaterJob;
import org.rubypeople.rdt.internal.core.builder.RubyBuilder;
import org.rubypeople.rdt.internal.core.parser.RubyParser;
-import org.rubypeople.rdt.internal.core.search.indexing.IndexManager;
import org.rubypeople.rdt.internal.core.symbols.ISymbolFinder;
import org.rubypeople.rdt.internal.core.symbols.SymbolIndex;
import org.rubypeople.rdt.internal.core.util.MementoTokenizer;
@@ -245,6 +244,13 @@
* @see #getDefaultOptions()
* @since 0.9.0
*/
+ public static final String COMPILER_PB_UNREACHABLE_CODE = PLUGIN_ID + ".compiler.problem.unreachableCode"; //$NON-NLS-1$
+
+ /**
+ * Possible configurable option ID.
+ * @see #getDefaultOptions()
+ * @since 0.9.0
+ */
public static final String CODEASSIST_CAMEL_CASE_MATCH = PLUGIN_ID + ".codeComplete.camelCaseMatch"; //$NON-NLS-1$
// FIXME Rename to CORE_INCOMPLETE_LOADPATH
@@ -1331,39 +1337,76 @@
return newContainerEntry(path, LoadpathEntry.NO_EXTRA_ATTRIBUTES, isExported);
}
+ /**
+ * Returns the Ruby model element corresponding to the given handle identifier
+ * generated by <code>IRubyElement.getHandleIdentifier()</code>, or
+ * <code>null</code> if unable to create the associated element.
+ *
+ * @param handleIdentifier the given handle identifier
+ * @return the Ruby element corresponding to the handle identifier
+ */
+ public static IRubyElement create(String handleIdentifier) {
+ return create(handleIdentifier, DefaultWorkingCopyOwner.PRIMARY);
+ }
+
+ /**
+ * Returns the Ruby model element corresponding to the given handle identifier
+ * generated by <code>IRubyElement.getHandleIdentifier()</code>, or
+ * <code>null</code> if unable to create the associated element.
+ * If the returned Ruby element is an <code>ICompilationUnit</code>, its owner
+ * is the given owner if such a working copy exists, otherwise the compilation unit
+ * is a primary compilation unit.
+ *
+ * @param handleIdentifier the given handle identifier
+ * @param owner the owner of the returned compilation unit, ignored if the returned
+ * element is not a compilation unit
+ * @return the Ruby element corresponding to the handle identifier
+ * @since 3.0
+ */
+ public static IRubyElement create(String handleIdentifier, WorkingCopyOwner owner) {
+ if (handleIdentifier == null) {
+ return null;
+ }
+ MementoTokenizer memento = new MementoTokenizer(handleIdentifier);
+ RubyModel model = RubyModelManager.getRubyModelManager().getRubyModel();
+ return model.getHandleFromMemento(memento, owner);
+ }
+
/**
- * Returns the Ruby model element corresponding to the given handle identifier
- * generated by <code>IRubyElement.getHandleIdentifier()</code>, or
- * <code>null</code> if unable to create the associated element.
- *
- * @param handleIdentifier the given handle identifier
- * @return the Ruby element corresponding to the handle identifier
+ * Creates and returns a new loadpath entry of kind <code>CPE_SOURCE</code>
+ * for the project's source folder identified by the given absolute
+ * workspace-relative path but excluding all source files with paths
+ * matching any of the given patterns.
+ * <p>
+ * The convenience method is fully equivalent to:
+ * <pre>
+ * newSourceEntry(path, new IPath[] {}, exclusionPatterns, null);
+ * </pre>
+ * </p>
+ *
+ * @param path the absolute workspace-relative path of a source folder
+ * @param exclusionPatterns the possibly empty list of exclusion patterns
+ * represented as relative paths
+ * @return a new source loadpath entry
+ * @see #newSourceEntry(IPath, IPath[], IPath[], IPath)
+ * @since 2.1
*/
- public static IRubyElement create(String handleIdentifier) {
- return create(handleIdentifier, DefaultWorkingCopyOwner.PRIMARY);
+ public static ILoadpathEntry newSourceEntry(IPath path, IPath[] exclusionPatterns) {
+ return newSourceEntry(path, LoadpathEntry.INCLUDE_ALL, exclusionPatterns, LoadpathEntry.NO_EXTRA_ATTRIBUTES);
}
/**
- * Returns the Ruby model element corresponding to the given handle identifier
- * generated by <code>IRubyElement.getHandleIdentifier()</code>, or
- * <code>null</code> if unable to create the associated element.
- * If the returned Ruby element is an <code>ICompilationUnit</code>, its owner
- * is the given owner if such a working copy exists, otherwise the compilation unit
- * is a primary compilation unit.
+ * Creates and returns a compilation unit element for
+ * the given source file (i.e. a file with one of the {@link RubyCore#getRubyLikeExtensions()
+ * Java-like extensions}). Returns <code>null</code> if unable
+ * to recognize the compilation unit.
*
- * @param handleIdentifier the given handle identifier
- * @param owner the owner of the returned compilation unit, ignored if the returned
- * element is not a compilation unit
- * @return the Ruby element corresponding to the handle identifier
- * @since 3.0
+ * @param file the given source file
+ * @return a compilation unit element for the given source file, or <code>null</code> if unable
+ * to recognize the compilation unit
*/
- public static IRubyElement create(String handleIdentifier, WorkingCopyOwner owner) {
- if (handleIdentifier == null) {
- return null;
- }
- MementoTokenizer memento = new MementoTokenizer(handleIdentifier);
- RubyModel model = RubyModelManager.getRubyModelManager().getRubyModel();
- return model.getHandleFromMemento(memento, owner);
+ public static IRubyScript createRubyScriptFrom(IFile file) {
+ return RubyModelManager.createRubyScriptFrom(file, null/*unknown ruby project*/);
}
-}
\ No newline at end of file
+}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java 2007-04-20 13:18:24 UTC (rev 2345)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java 2007-04-20 16:52:46 UTC (rev 2346)
@@ -30,6 +30,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
@@ -72,6 +73,7 @@
import org.rubypeople.rdt.core.IProblemRequestor;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.IRubyModelMarker;
import org.rubypeople.rdt.core.IRubyProject;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.ISourceFolder;
@@ -87,6 +89,7 @@
import org.rubypeople.rdt.internal.compiler.util.HashtableOfObjectToInt;
import org.rubypeople.rdt.internal.core.buffer.BufferManager;
import org.rubypeople.rdt.internal.core.builder.RubyBuilder;
+import org.rubypeople.rdt.internal.core.parser.MarkerUtility;
import org.rubypeople.rdt.internal.core.search.RubyWorkspaceScope;
import org.rubypeople.rdt.internal.core.search.indexing.IndexManager;
import org.rubypeople.rdt.internal.core.util.Messages;
@@ -604,7 +607,17 @@
}
public void acceptProblem(IProblem problem) {
- if (this.problemRequestor == null) return;
+ // Don't accept the problem if a marker already exists for this same problem...
+ try {
+ IResource resource = workingCopy.getUnderlyingResource();
+ IMarker marker = MarkerUtility.markerExists(resource, problem.getMessage(), problem.getSourceLineNumber(), IRubyModelMarker.RUBY_MODEL_PROBLEM_MARKER);
+ if (marker != null) return;
+ } catch (RubyModelException e) {
+ // ignore
+ } catch (CoreException e) {
+ // ignore
+ }
+ if (this.problemRequestor == null) return;
this.problemRequestor.acceptProblem(problem);
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java 2007-04-20 13:18:24 UTC (rev 2345)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java 2007-04-20 16:52:46 UTC (rev 2346)
@@ -1153,7 +1153,7 @@
}
protected Instruction handleNode(Node visited) {
- return null;
+ return visitNode(visited);
}
/* (non-Javadoc)
@@ -1188,7 +1188,6 @@
@Override
protected Instruction visitNode(Node iVisited) {
- // TODO Auto-generated method stub
return null;
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/MarkerUtility.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/MarkerUtility.java 2007-04-20 13:18:24 UTC (rev 2345)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/MarkerUtility.java 2007-04-20 16:52:46 UTC (rev 2346)
@@ -70,12 +70,14 @@
public static void createProblemMarker(IResource underlyingResource, IProblem problem) {
try {
- IMarker marker = underlyingResource.createMarker(IRubyModelMarker.RUBY_MODEL_PROBLEM_MARKER);
+ IMarker marker = markerExists(underlyingResource, problem.getMessage(), problem.getSourceLineNumber(), IRubyModelMarker.RUBY_MODEL_PROBLEM_MARKER);
+ if (marker != null) return;
Map<String, Comparable> map = new HashMap<String, Comparable>();
int severity;
if(problem.isWarning()) severity = IMarker.SEVERITY_WARNING;
else if(problem.isError()) severity = IMarker.SEVERITY_ERROR;
else severity = IMarker.SEVERITY_INFO;
+ marker = underlyingResource.createMarker(IRubyModelMarker.RUBY_MODEL_PROBLEM_MARKER);
map.put(IMarker.SEVERITY, new Integer(severity));
map.put(IMarker.MESSAGE, problem.getMessage());
map.put(IMarker.USER_EDITABLE, Boolean.FALSE);
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RdtWarnings.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RdtWarnings.java 2007-04-20 13:18:24 UTC (rev 2345)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RdtWarnings.java 2007-04-20 16:52:46 UTC (rev 2346)
@@ -9,19 +9,21 @@
import org.eclipse.core.resources.IFile;
import org.jruby.lexer.yacc.ISourcePosition;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.compiler.CategorizedProblem;
/**
* @author Chris
*/
public class RdtWarnings implements IRdtWarnings {
- private List<Warning> warnings;
+ private List<CategorizedProblem> warnings;
public RdtWarnings() {
- warnings = new ArrayList<Warning>();
+ warnings = new ArrayList<CategorizedProblem>();
}
- public List<Warning> getWarnings() {
+ public List<CategorizedProblem> getWarnings() {
return Collections.unmodifiableList(warnings);
}
@@ -54,6 +56,16 @@
if (message.startsWith("Useless")) {
return ;
}
+ if (message.equals("Statement not reached.")) { // TODO Categorize problems that JRuby provides in one place
+ String value = RubyCore.getOption(RubyCore.COMPILER_PB_UNREACHABLE_CODE);
+ if (value == null || value.equals(RubyCore.WARNING)) {
+ warnings.add(new Warning(position, message));
+ }
+ if (value != null && value.equals(RubyCore.ERROR)) {
+ warnings.add(new Error(position, message));
+ }
+ return;
+ }
warnings.add(new Warning(position, message));
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java 2007-04-20 13:18:24 UTC (rev 2345)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java 2007-04-20 16:52:46 UTC (rev 2346)
@@ -13,6 +13,7 @@
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.core.WorkingCopyOwner;
import org.rubypeople.rdt.core.search.IRubySearchConstants;
@@ -239,18 +240,23 @@
return RubyModelManager.getRubyModelManager().getWorkspaceScope();
}
- public static Collection<? extends IType> findType(String typeName) {
- SearchPattern pattern = SearchPattern.createPattern(IRubyElement.TYPE, typeName, IRubySearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
+ public static Collection<? extends IType> findType(String simpleTypeName) {
+ SearchPattern pattern = SearchPattern.createPattern(IRubyElement.TYPE, "*", IRubySearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
SearchParticipant[] participants = new SearchParticipant[] {getDefaultSearchParticipant()};
IRubySearchScope scope = createWorkspaceScope();
TypeRequestor requestor = new TypeRequestor();
try {
new BasicSearchEngine().search(pattern, participants, scope, requestor, null);
} catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ RubyCore.log(e);
}
- return requestor.getTypes();
+ List<IType> types = new ArrayList<IType>();
+ List<IType> matches = requestor.getTypes();
+ for (IType type : matches) {
+ if (Util.getSimpleName(type.getElementName()).equals(simpleTypeName))
+ types.add(type);
+ }
+ return types;
}
private static class TypeRequestor extends SearchRequestor {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|