|
From: <caw...@us...> - 2007-03-13 17:39:12
|
Revision: 2144
http://svn.sourceforge.net/rubyeclipse/?rev=2144&view=rev
Author: cawilliams
Date: 2007-03-13 10:39:10 -0700 (Tue, 13 Mar 2007)
Log Message:
-----------
a good start on importing and modifying search stuff from JDT...
Modified Paths:
--------------
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/parser/IProblem.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/util/Util.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/LoadpathEntry.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/CharOperation.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Messages.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java
Added Paths:
-----------
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IRubySearchScope.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchDocument.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchEngine.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchMatch.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchParticipant.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchPattern.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchRequestor.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/SourceElementParser.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRestriction.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRule.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRuleSet.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/parser/
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/parser/ScannerHelper.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/util/HashtableOfIntValues.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/util/HashtableOfObject.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/util/SimpleLookupTable.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/util/SimpleSet.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/index/
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/index/DiskIndex.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/index/EntryResult.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/index/Index.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/index/MemoryIndex.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/AbstractSearchScope.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/IndexQueryRequestor.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/IndexSelector.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/PatternSearchJob.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchDocument.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchParticipant.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchScope.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubyWorkspaceScope.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/AddJarFileToIndex.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IIndexConstants.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexAllProject.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexBinaryFolder.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexManager.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexRequest.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/InternalSearchDocument.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/ReadWriteMonitor.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/SourceIndexer.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/InternalSearchPattern.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/PatternLocator.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/processing/
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/processing/IJob.java
branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/processing/JobManager.java
Modified: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/parser/IProblem.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/parser/IProblem.java 2007-03-13 17:32:30 UTC (rev 2143)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/parser/IProblem.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -34,6 +34,23 @@
public interface IProblem {
/**
+ * Problem Categories
+ * The high bits of a problem ID contains information about the category of a problem.
+ * For example, (problemID & TypeRelated) != 0, indicates that this problem is type related.
+ *
+ * A problem category can help to implement custom problem filters. Indeed, when numerous problems
+ * are listed, focusing on import related problems first might be relevant.
+ *
+ * When a problem is tagged as Internal, it means that no change other than a local source code change
+ * can fix the corresponding problem. A type related problem could be addressed by changing the type
+ * involved in it.
+ */
+ int TypeRelated = 0x01000000;
+
+ int ForbiddenReference = TypeRelated + 307;
+ int DiscouragedReference = TypeRelated + 280;
+
+ /**
* Answer a localized, human-readable message string which describes the
* problem.
*
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IRubySearchScope.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IRubySearchScope.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IRubySearchScope.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.core.search;
+
+import org.eclipse.core.runtime.IPath;
+import org.rubypeople.rdt.core.IRubyElement;
+
+/**
+ * An <code>IRubySearchScope</code> defines where search result should be found by a
+ * <code>SearchEngine</code>. Clients must pass an instance of this interface
+ * to the <code>search(...)</code> methods. Such an instance can be created using the
+ * following factory methods on <code>SearchEngine</code>: <code>createHierarchyScope(IType)</code>,
+ * <code>createRubySearchScope(IResource[])</code>, <code>createWorkspaceScope()</code>, or
+ * clients may choose to implement this interface.
+ */
+public interface IRubySearchScope {
+/**
+ * This constant defines the separator of the resourcePath string of the <code>encloses(String)</code>
+ * method. If present in the string, it separates the path to the jar file from the path
+ * to the .class file in the jar.
+ */
+String JAR_FILE_ENTRY_SEPARATOR = "|"; //$NON-NLS-1$
+/**
+ * Include type constant (bit mask) indicating that source folders should be considered in the search scope.
+ * @since 3.0
+ */
+int SOURCES = 1;
+/**
+ * Include type constant (bit mask) indicating that application libraries should be considered in the search scope.
+ * @since 3.0
+ */
+int APPLICATION_LIBRARIES = 2;
+/**
+ * Include type constant (bit mask) indicating that system libraries should be considered in the search scope.
+ * @since 3.0
+ */
+int SYSTEM_LIBRARIES = 4;
+/**
+ * Include type constant (bit mask) indicating that referenced projects should be considered in the search scope.
+ * @since 3.0
+ */
+int REFERENCED_PROJECTS = 8;
+/**
+ * Checks whether the resource at the given path is enclosed by this scope.
+ *
+ * @param resourcePath if the resource is contained in
+ * a JAR file, the path is composed of 2 paths separated
+ * by <code>JAR_FILE_ENTRY_SEPARATOR</code>: the first path is the full OS path
+ * to the JAR (if it is an external JAR), or the workspace relative <code>IPath</code>
+ * to the JAR (if it is an internal JAR),
+ * the second path is the path to the resource inside the JAR.
+ * @return whether the resource is enclosed by this scope
+ */
+public boolean encloses(String resourcePath);
+/**
+ * Checks whether this scope encloses the given element.
+ *
+ * @param element the given element
+ * @return <code>true</code> if the element is in this scope
+ */
+public boolean encloses(IRubyElement element);
+/**
+ * Returns the paths to the enclosing projects and JARs for this search scope.
+ * <ul>
+ * <li> If the path is a project path, this is the full path of the project
+ * (see <code>IResource.getFullPath()</code>).
+ * For example, /MyProject
+ * </li>
+ * <li> If the path is a JAR path and this JAR is internal to the workspace,
+ * this is the full path of the JAR file (see <code>IResource.getFullPath()</code>).
+ * For example, /MyProject/mylib.jar
+ * </li>
+ * <li> If the path is a JAR path and this JAR is external to the workspace,
+ * this is the full OS path to the JAR file on the file system.
+ * For example, d:\libs\mylib.jar
+ * </li>
+ * </ul>
+ *
+ * @return an array of paths to the enclosing projects and JARS.
+ */
+IPath[] enclosingProjectsAndJars();
+/**
+ * Returns whether this scope contains any <code>.class</code> files (either
+ * in folders or within JARs).
+ *
+ * @return whether this scope contains any <code>.class</code> files
+ * @deprecated Use
+ * {@link org.eclipse.jdt.core.search.SearchEngine#createRubySearchScope(IRubyElement[])}
+ * with the package fragment roots that correspond to the binaries instead.
+ */
+boolean includesBinaries();
+/**
+ * Returns whether this scope includes classpaths defined by
+ * the projects of the resources of this search scope.
+ *
+ * @return whether this scope includes classpaths
+ * @deprecated Use
+ * {@link org.eclipse.jdt.core.search.SearchEngine#createRubySearchScope(IRubyElement[])}
+ * with a Ruby project instead.
+ */
+boolean includesClasspaths();
+/**
+ * Sets whether this scope contains any <code>.class</code> files (either
+ * in folders or within JARs).
+ *
+ * @param includesBinaries whether this scope contains any <code>.class</code> files
+ * @deprecated Use
+ * {@link org.eclipse.jdt.core.search.SearchEngine#createRubySearchScope(IRubyElement[])}
+ * with the package fragment roots that correspond to the binaries instead.
+ */
+public void setIncludesBinaries(boolean includesBinaries);
+/**
+ * Sets whether this scope includes the classpaths defined by
+ * the projects of the resources of this search scope.
+ *
+ * @param includesClasspaths whether this scope includes classpaths
+ * @deprecated Use
+ * {@link org.eclipse.jdt.core.search.SearchEngine#createRubySearchScope(IRubyElement[])}
+ * with a Ruby project instead.
+ */
+public void setIncludesClasspaths(boolean includesClasspaths);
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchDocument.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchDocument.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchDocument.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.core.search;
+
+import org.rubypeople.rdt.internal.core.search.indexing.InternalSearchDocument;
+
+/**
+ * A search document encapsulates a content to be either indexed or searched in.
+ * A search particpant creates a search document.
+ * <p>
+ * This class is intended to be subclassed by clients.
+ * </p>
+ *
+ * @since 3.0
+ */
+public abstract class SearchDocument extends InternalSearchDocument {
+ private String documentPath;
+ private SearchParticipant participant;
+
+ /**
+ * Creates a new search document. The given document path is a string that uniquely identifies the document.
+ * Most of the time it is a workspace-relative path, but it can also be a file system path, or a path inside a zip file.
+ *
+ * @param documentPath the path to the document,
+ * or <code>null</code> if none
+ * @param participant the participant that creates the search document
+ */
+ protected SearchDocument(String documentPath, SearchParticipant participant) {
+ this.documentPath = documentPath;
+ this.participant = participant;
+ }
+
+ /**
+ * Adds the given index entry (category and key) coming from this
+ * document to the index. This method must be called from
+ * {@link SearchParticipant#indexDocument(SearchDocument document, org.eclipse.core.runtime.IPath indexPath)}.
+ *
+ * @param category the category of the index entry
+ * @param key the key of the index entry
+ */
+ public void addIndexEntry(char[] category, char[] key) {
+ super.addIndexEntry(category, key);
+ }
+
+ /**
+ * Returns the contents of this document.
+ * Contents may be different from actual resource at corresponding document path,
+ * in case of preprocessing.
+ * <p>
+ * This method must be implemented in subclasses.
+ * </p><p>
+ * Note: some implementation may choose to cache the contents directly on the
+ * document for performance reason. However, this could induce scalability issues due
+ * to the fact that collections of documents are manipulated throughout the search
+ * operation, and cached contents would then consume lots of memory until they are
+ * all released at once in the end.
+ * </p>
+ *
+ * @return the contents of this document,
+ * or <code>null</code> if none
+ */
+ public abstract byte[] getByteContents();
+
+ /**
+ * Returns the contents of this document.
+ * Contents may be different from actual resource at corresponding document
+ * path due to preprocessing.
+ * <p>
+ * This method must be implemented in subclasses.
+ * </p><p>
+ * Note: some implementation may choose to cache the contents directly on the
+ * document for performance reason. However, this could induce scalability issues due
+ * to the fact that collections of documents are manipulated throughout the search
+ * operation, and cached contents would then consume lots of memory until they are
+ * all released at once in the end.
+ * </p>
+ *
+ * @return the contents of this document,
+ * or <code>null</code> if none
+ */
+ public abstract char[] getCharContents();
+
+ /**
+ * Returns the encoding for this document.
+ * <p>
+ * This method must be implemented in subclasses.
+ * </p>
+ *
+ * @return the encoding for this document,
+ * or <code>null</code> if none
+ */
+ public abstract String getEncoding();
+
+ /**
+ * Returns the participant that created this document.
+ *
+ * @return the participant that created this document
+ */
+ public final SearchParticipant getParticipant() {
+ return this.participant;
+ }
+
+ /**
+ * Returns the path to the original document to publicly mention in index
+ * or search results. This path is a string that uniquely identifies the document.
+ * Most of the time it is a workspace-relative path, but it can also be a file system path,
+ * or a path inside a zip file.
+ *
+ * @return the path to the document
+ */
+ public final String getPath() {
+ return this.documentPath;
+ }
+ /**
+ * Removes all index entries from the index for the given document.
+ * This method must be called from
+ * {@link SearchParticipant#indexDocument(SearchDocument document, org.eclipse.core.runtime.IPath indexPath)}.
+ */
+ public void removeAllIndexEntries() {
+ super.removeAllIndexEntries();
+ }
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchEngine.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchEngine.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchEngine.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,15 @@
+package org.rubypeople.rdt.core.search;
+
+import org.rubypeople.rdt.internal.core.search.BasicSearchEngine;
+
+public class SearchEngine {
+ /**
+ * Returns a new default Ruby search participant.
+ *
+ * @return a new default Ruby search participant
+ * @since 3.0
+ */
+ public static SearchParticipant getDefaultSearchParticipant() {
+ return BasicSearchEngine.getDefaultSearchParticipant();
+ }
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchMatch.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchMatch.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchMatch.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,375 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.core.search;
+
+import org.eclipse.core.resources.IResource;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.search.SearchEngine;
+import org.rubypeople.rdt.core.search.SearchParticipant;
+import org.rubypeople.rdt.core.search.SearchPattern;
+import org.rubypeople.rdt.core.search.SearchRequestor;
+import org.rubypeople.rdt.internal.core.RubyElement;
+
+/**
+ * A search match represents the result of a search query.
+ *
+ * Search matches may be accurate (<code>A_ACCURATE</code>) or they might be
+ * merely potential matches (<code>A_INACCURATE</code>). The latter occurs when
+ * a compile-time problem prevents the search engine from completely resolving
+ * the match.
+ * <p>
+ * This class is intended to be instantiated and subclassed by clients.
+ * </p>
+ *
+ * @see SearchEngine#search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, org.eclipse.core.runtime.IProgressMonitor)
+ * @since 3.0
+ */
+public class SearchMatch {
+
+ /**
+ * The search result corresponds an exact match of the search pattern.
+ *
+ * @see #getAccuracy()
+ */
+ public static final int A_ACCURATE = 0;
+
+ /**
+ * The search result is potentially a match for the search pattern,
+ * but the search engine is unable to fully check it (for example, because
+ * there are errors in the code or the classpath are not correctly set).
+ *
+ * @see #getAccuracy()
+ */
+ public static final int A_INACCURATE = 1;
+
+ private Object element;
+ private int length;
+ private int offset;
+
+ private int accuracy;
+ private SearchParticipant participant;
+ private IResource resource;
+
+ private boolean insideDocComment = false;
+
+ // store the rule used while reporting the match
+ private int rule = SearchPattern.R_FULL_MATCH |
+ SearchPattern.R_EQUIVALENT_MATCH |
+ SearchPattern.R_ERASURE_MATCH;
+
+ // store other necessary information
+ private boolean raw = false;
+ private boolean implicit = false;
+
+ /**
+ * Creates a new search match.
+ * <p>
+ * Note that <code>isInsideDocComment()</code> defaults to false.
+ * </p>
+ *
+ * @param element the element that encloses or corresponds to the match,
+ * or <code>null</code> if none
+ * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
+ * @param offset the offset the match starts at, or -1 if unknown
+ * @param length the length of the match, or -1 if unknown
+ * @param participant the search participant that created the match
+ * @param resource the resource of the element, or <code>null</code> if none
+ */
+ public SearchMatch(
+ IRubyElement element,
+ int accuracy,
+ int offset,
+ int length,
+ SearchParticipant participant,
+ IResource resource) {
+ this.element = element;
+ this.offset = offset;
+ this.length = length;
+ this.accuracy = accuracy & A_INACCURATE;
+ if (accuracy > A_INACCURATE) {
+ this.rule = accuracy & ~A_INACCURATE; // accuracy may have also some rule information
+ }
+ this.participant = participant;
+ this.resource = resource;
+ }
+
+ /**
+ * Returns the accuracy of this search match.
+ *
+ * @return one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
+ */
+ public final int getAccuracy() {
+ return this.accuracy;
+ }
+
+ /**
+ * Returns the element of this search match.
+ * In case of a reference match, this is the inner-most enclosing element of the reference.
+ * In case of a declaration match, this is the declaration.
+ *
+ * @return the element of the search match, or <code>null</code> if none
+ */
+ public final Object getElement() {
+ return this.element;
+ }
+
+ /**
+ * Returns the length of this search match.
+ *
+ * @return the length of this search match, or -1 if unknown
+ */
+ public final int getLength() {
+ return this.length;
+ }
+
+ /**
+ * Returns the offset of this search match.
+ *
+ * @return the offset of this search match, or -1 if unknown
+ */
+ public final int getOffset() {
+ return this.offset;
+ }
+
+ /**
+ * Returns the search participant which issued this search match.
+ *
+ * @return the participant which issued this search match
+ */
+ public final SearchParticipant getParticipant() {
+ return this.participant;
+ }
+
+ /**
+ * Returns the resource containing this search match.
+ *
+ * @return the resource of the match, or <code>null</code> if none
+ */
+ public final IResource getResource() {
+ return this.resource;
+ }
+
+ /**
+ * Returns the rule used while creating the match.
+ *
+ * @return one of {@link SearchPattern#R_FULL_MATCH}, {@link SearchPattern#R_EQUIVALENT_MATCH}
+ * or {@link SearchPattern#R_ERASURE_MATCH}
+ * @since 3.1
+ */
+ public final int getRule() {
+ return this.rule;
+ }
+
+ /**
+ * Returns whether match element is compatible with searched pattern or not.
+ * Note that equivalent matches are also erasure ones.
+ *
+ * @return <code>true</code> if match element is compatible
+ * <code>false</code> otherwise
+ * @since 3.1
+ */
+ public final boolean isEquivalent() {
+ return isErasure() && (this.rule & SearchPattern.R_EQUIVALENT_MATCH) != 0;
+ }
+
+ /**
+ * Returns whether match element only has same erasure than searched pattern or not.
+ * Note that this is always true for both generic and non-generic element as soon
+ * as the accuracy is accurate.
+ *
+ * @return <code>true</code> if match element has same erasure
+ * <code>false</code> otherwise
+ * @since 3.1
+ */
+ public final boolean isErasure() {
+ return (this.rule & SearchPattern.R_ERASURE_MATCH) != 0;
+ }
+
+ /**
+ * Returns whether element matches exactly searched pattern or not.
+ * Note that exact matches are also erasure and equivalent ones.
+ *
+ * @return <code>true</code> if match is exact
+ * <code>false</code> otherwise
+ * @since 3.1
+ */
+ public final boolean isExact() {
+ return isEquivalent() && (this.rule & SearchPattern.R_FULL_MATCH) != 0;
+ }
+
+ /**
+ * Returns whether the associated element is implicit or not.
+ *
+ * Note that this piece of information is currently only implemented
+ * for implicit member pair value in annotation.
+ *
+ * @return <code>true</code> if this match is associated to an implicit
+ * element and <code>false</code> otherwise
+ * @since 3.1
+ */
+ public final boolean isImplicit() {
+ return this.implicit;
+ }
+
+ /**
+ * Returns whether the associated element is a raw type/method or not.
+ *
+ * @return <code>true</code> if this match is associated to a raw
+ * type or method and <code>false</code> otherwise
+ * @since 3.1
+ */
+ public final boolean isRaw() {
+ return this.raw;
+ }
+
+ /**
+ * Returns whether this search match is inside a doc comment of a Java
+ * source file.
+ *
+ * @return <code>true</code> if this search match is inside a doc
+ * comment, and <code>false</code> otherwise
+ */
+ public final boolean isInsideDocComment() {
+ // default is outside a doc comment
+ return this.insideDocComment;
+ }
+
+ /**
+ * Sets the accuracy of this match.
+ *
+ * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
+ */
+ public final void setAccuracy (int accuracy) {
+ this.accuracy = accuracy;
+ }
+
+ /**
+ * Sets the element of this search match.
+ *
+ * @param element the element that encloses or corresponds to the match,
+ * or <code>null</code> if none
+ */
+ public final void setElement (Object element) {
+ this.element = element;
+ }
+
+ /**
+ * Sets whether this search match is inside a doc comment of a Java
+ * source file.
+ *
+ * @param insideDoc <code>true</code> if this search match is inside a doc
+ * comment, and <code>false</code> otherwise
+ */
+ public final void setInsideDocComment (boolean insideDoc) {
+ this.insideDocComment = insideDoc;
+ }
+
+ /**
+ * Sets whether the associated element is implicit or not.
+ * Typically, this is the case when match is on an implicit constructor
+ * or an implicit member pair value in annotation.
+ *
+ * @param implicit <code>true</code> if this match is associated to an implicit
+ * element and <code>false</code> otherwise
+ * @since 3.1
+ */
+ public final void setImplicit(boolean implicit) {
+ this.implicit = implicit;
+ }
+
+ /**
+ * Sets the length of this search match.
+ *
+ * @param length the length of the match, or -1 if unknown
+ */
+ public final void setLength(int length) {
+ this.length = length;
+ }
+
+ /**
+ * Sets the offset of this search match.
+ *
+ * @param offset the offset the match starts at, or -1 if unknown
+ */
+ public final void setOffset(int offset) {
+ this.offset = offset;
+ }
+
+ /**
+ * Sets the participant of this match.
+ *
+ * @param participant the search participant that created this match
+ */
+ public final void setParticipant (SearchParticipant participant) {
+ this.participant = participant;
+ }
+
+ /**
+ * Sets the resource of this match.
+ *
+ * @param resource the resource of the match, or <code>null</code> if none
+ */
+ public final void setResource (IResource resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Set the rule used while reporting the match.
+ *
+ * @param rule one of {@link SearchPattern#R_FULL_MATCH}, {@link SearchPattern#R_EQUIVALENT_MATCH}
+ * or {@link SearchPattern#R_ERASURE_MATCH}
+ * @since 3.1
+ */
+ public final void setRule(int rule) {
+ this.rule = rule;
+ }
+
+ /**
+ * Set whether the associated element is a raw type/method or not.
+ *
+ * @param raw <code>true</code> if this search match is associated to a raw
+ * type or method and <code>false</code> otherwise
+ * @since 3.1
+ */
+ public final void setRaw(boolean raw) {
+ this.raw = raw;
+ }
+
+ /* (non-javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Search match"); //$NON-NLS-1$
+ buffer.append("\n accuracy="); //$NON-NLS-1$
+ buffer.append(this.accuracy == A_ACCURATE ? "ACCURATE" : "INACCURATE"); //$NON-NLS-1$ //$NON-NLS-2$
+ buffer.append("\n rule="); //$NON-NLS-1$
+ if ((this.rule & SearchPattern.R_FULL_MATCH) != 0) {
+ buffer.append("EXACT"); //$NON-NLS-1$
+ } else if ((this.rule & SearchPattern.R_EQUIVALENT_MATCH) != 0) {
+ buffer.append("EQUIVALENT"); //$NON-NLS-1$
+ } else if ((this.rule & SearchPattern.R_ERASURE_MATCH) != 0) {
+ buffer.append("ERASURE"); //$NON-NLS-1$
+ }
+ buffer.append("\n raw="); //$NON-NLS-1$
+ buffer.append(this.raw);
+ buffer.append("\n offset="); //$NON-NLS-1$
+ buffer.append(this.offset);
+ buffer.append("\n length="); //$NON-NLS-1$
+ buffer.append(this.length);
+ if (this.element != null) {
+ buffer.append("\n element="); //$NON-NLS-1$
+ buffer.append(((RubyElement)getElement()).toStringWithAncestors());
+ }
+ buffer.append("\n"); //$NON-NLS-1$
+ return buffer.toString();
+ }
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchParticipant.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchParticipant.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchParticipant.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,232 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.core.search;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.rubypeople.rdt.internal.core.RubyModel;
+import org.rubypeople.rdt.internal.core.RubyModelManager;
+import org.rubypeople.rdt.internal.core.search.indexing.IndexManager;
+
+/**
+ * A search participant describes a particular extension to a generic search
+ * mechanism, permitting combined search actions which will involve all required
+ * participants.
+ * <p>
+ * A search participant is involved in the indexing phase and in the search phase.
+ * The indexing phase consists in taking one or more search documents, parse them, and
+ * add index entries in an index chosen by the participant. An index is identified by a
+ * path on disk.
+ * The search phase consists in selecting the indexes corresponding to a search pattern
+ * and a search scope, from these indexes the search infrastructure extracts the document paths
+ * that match the search pattern asking the search participant for the corresponding document,
+ * finally the search participant is asked to locate the matches precisely in these search documents.
+ * </p>
+ * <p>
+ * This class is intended to be subclassed by clients. During the indexing phase,
+ * a subclass will be called with the following requests in order:
+ * <ul>
+ * <li>{@link #scheduleDocumentIndexing(SearchDocument, IPath)}</li>
+ * <li>{@link #indexDocument(SearchDocument, IPath)}</li>
+ * </ul>
+ * During the search phase, a subclass will be called with the following requests in order:
+ * <ul>
+ * <li>{@link #selectIndexes(SearchPattern, IRubySearchScope)}</li>
+ * <li>one or more {@link #getDocument(String)}</li>
+ * <li>{@link #locateMatches(SearchDocument[], SearchPattern, IRubySearchScope, SearchRequestor, IProgressMonitor)}</li>
+ * </ul>
+ * </p>
+ *
+ * @since 3.0
+ */
+public abstract class SearchParticipant {
+
+ /**
+ * Creates a new search participant.
+ */
+ protected SearchParticipant() {
+ // do nothing
+ }
+
+ /**
+ * Notification that this participant's help is needed in a search.
+ * <p>
+ * This method should be re-implemented in subclasses that need to do something
+ * when the participant is needed in a search.
+ * </p>
+ */
+ public void beginSearching() {
+ // do nothing
+ }
+
+ /**
+ * Notification that this participant's help is no longer needed.
+ * <p>
+ * This method should be re-implemented in subclasses that need to do something
+ * when the participant is no longer needed in a search.
+ * </p>
+ */
+ public void doneSearching() {
+ // do nothing
+ }
+
+ /**
+ * Returns a displayable name of this search participant.
+ * <p>
+ * This method should be re-implemented in subclasses that need to
+ * display a meaningfull name.
+ * </p>
+ *
+ * @return the displayable name of this search participant
+ */
+ public String getDescription() {
+ return "Search participant"; //$NON-NLS-1$
+ }
+
+ /**
+ * Returns a search document for the given path.
+ * The given document path is a string that uniquely identifies the document.
+ * Most of the time it is a workspace-relative path, but it can also be a file system path, or a path inside a zip file.
+ * <p>
+ * Implementors of this method can either create an instance of their own subclass of
+ * {@link SearchDocument} or return an existing instance of such a subclass.
+ * </p>
+ *
+ * @param documentPath the path of the document.
+ * @return a search document
+ */
+ public abstract SearchDocument getDocument(String documentPath);
+
+ /**
+ * Indexes the given document in the given index. A search participant
+ * asked to index a document should parse it and call
+ * {@link SearchDocument#addIndexEntry(char[], char[])} as many times as
+ * needed to add index entries to the index. If delegating to another
+ * participant, it should use the original index location (and not the
+ * delegatee's one). In the particular case of delegating to the default
+ * search participant (see {@link SearchEngine#getDefaultSearchParticipant()}),
+ * the provided document's path must be a path ending with one of the
+ * {@link org.eclipse.jdt.core.RubyCore#getRubyLikeExtensions() Ruby-like extensions}
+ * or with '.class'.
+ * <p>
+ * The given index location must represent a path in the file system to a file that
+ * either already exists or is going to be created. If it exists, it must be an index file,
+ * otherwise its data might be overwritten.
+ * </p><p>
+ * Clients are not expected to call this method.
+ * </p>
+ *
+ * @param document the document to index
+ * @param indexLocation the location in the file system to the index
+ */
+ public abstract void indexDocument(SearchDocument document, IPath indexLocation);
+
+ /**
+ * Locates the matches in the given documents using the given search pattern
+ * and search scope, and reports them to the givenn search requestor. This
+ * method is called by the search engine once it has search documents
+ * matching the given pattern in the given search scope.
+ * <p>
+ * Note that a participant (e.g. a JSP participant) can pre-process the contents of the given documents,
+ * create its own documents whose contents are Ruby compilation units and delegate the match location
+ * to the default participant (see {@link SearchEngine#getDefaultSearchParticipant()}). Passing its own
+ * {@link SearchRequestor} this particpant can then map the match positions back to the original
+ * contents, create its own matches and report them to the original requestor.
+ * </p><p>
+ * Implementors of this method should check the progress monitor
+ * for cancelation when it is safe and appropriate to do so. The cancelation
+ * request should be propagated to the caller by throwing
+ * <code>OperationCanceledException</code>.
+ * </p>
+ *
+ * @param documents the documents to locate matches in
+ * @param pattern the search pattern to use when locating matches
+ * @param scope the scope to limit the search to
+ * @param requestor the requestor to report matches to
+ * @param monitor the progress monitor to report progress to,
+ * or <code>null</code> if no progress should be reported
+ * @throws CoreException if the requestor had problem accepting one of the matches
+ */
+ public abstract void locateMatches(SearchDocument[] documents, SearchPattern pattern, IRubySearchScope scope, SearchRequestor requestor, IProgressMonitor monitor) throws CoreException;
+
+ /**
+ * Removes the index for a given path.
+ * <p>
+ * The given index location must represent a path in the file system to a file that
+ * already exists and must be an index file, otherwise nothing will be done.
+ * </p><p>
+ * It is strongly recommended to use this method instead of deleting file directly
+ * otherwise cached index will not be removed.
+ * </p>
+ *
+ * @param indexLocation the location in the file system to the index
+ * @since 3.2
+ */
+ public void removeIndex(IPath indexLocation){
+ IndexManager manager = RubyModelManager.getRubyModelManager().getIndexManager();
+ manager.removeIndexPath(indexLocation);
+ }
+
+ /**
+ * Schedules the indexing of the given document.
+ * Once the document is ready to be indexed,
+ * {@link #indexDocument(SearchDocument, IPath) indexDocument(document, indexPath)}
+ * will be called in a different thread than the caller's thread.
+ * <p>
+ * The given index location must represent a path in the file system to a file that
+ * either already exists or is going to be created. If it exists, it must be an index file,
+ * otherwise its data might be overwritten.
+ * </p><p>
+ * When the index is no longer needed, clients should use {@link #removeIndex(IPath) }
+ * to discard it.
+ * </p>
+ *
+ * @param document the document to index
+ * @param indexLocation the location on the file system of the index
+ */
+ public final void scheduleDocumentIndexing(SearchDocument document, IPath indexLocation) {
+ IPath documentPath = new Path(document.getPath());
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ Object file = RubyModel.getTarget(root, documentPath, true);
+ IPath containerPath = documentPath;
+ if (file instanceof IResource) {
+ containerPath = ((IResource)file).getProject().getFullPath();
+ } else if (file == null) {
+ containerPath = documentPath.removeLastSegments(documentPath.segmentCount()-1);
+ }
+ IndexManager manager = RubyModelManager.getRubyModelManager().getIndexManager();
+ String osIndexLocation = indexLocation.toOSString();
+ // TODO (frederic) should not have to create index manually, should expose API that recreates index instead
+ manager.ensureIndexExists(osIndexLocation, containerPath);
+ manager.scheduleDocumentIndexing(document, containerPath, osIndexLocation, this);
+ }
+
+ /**
+ * Returns the collection of index locations to consider when performing the
+ * given search query in the given scope. The search engine calls this
+ * method before locating matches.
+ * <p>
+ * An index location represents a path in the file system to a file that holds index information.
+ * </p><p>
+ * Clients are not expected to call this method.
+ * </p>
+ *
+ * @param query the search pattern to consider
+ * @param scope the given search scope
+ * @return the collection of index paths to consider
+ */
+ public abstract IPath[] selectIndexes(SearchPattern query, IRubySearchScope scope);
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchPattern.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchPattern.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchPattern.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,133 @@
+package org.rubypeople.rdt.core.search;
+
+import org.rubypeople.rdt.internal.core.search.matching.InternalSearchPattern;
+import org.rubypeople.rdt.internal.core.util.CharOperation;
+
+public class SearchPattern extends InternalSearchPattern {
+// Rules for pattern matching: (exact, prefix, pattern) [ | case sensitive]
+ /**
+ * Match rule: The search pattern matches exactly the search result,
+ * that is, the source of the search result equals the search pattern.
+ */
+ public static final int R_EXACT_MATCH = 0;
+
+ /**
+ * Match rule: The search pattern is a prefix of the search result.
+ */
+ public static final int R_PREFIX_MATCH = 0x0001;
+
+ /**
+ * Match rule: The search pattern contains one or more wild cards ('*' or '?').
+ * A '*' wild-card can replace 0 or more characters in the search result.
+ * A '?' wild-card replaces exactly 1 character in the search result.
+ */
+ public static final int R_PATTERN_MATCH = 0x0002;
+
+ /**
+ * Match rule: The search pattern contains a regular expression.
+ */
+ public static final int R_REGEXP_MATCH = 0x0004;
+
+ /**
+ * Match rule: The search pattern matches the search result only if cases are the same.
+ * Can be combined to previous rules, e.g. {@link #R_EXACT_MATCH} | {@link #R_CASE_SENSITIVE}
+ */
+ public static final int R_CASE_SENSITIVE = 0x0008;
+
+ /**
+ * Match rule: The search pattern matches search results as raw/parameterized types/methods with same erasure.
+ * This mode has no effect on other java elements search.<br>
+ * Type search example:
+ * <ul>
+ * <li>pattern: <code>List<Exception></code></li>
+ * <li>match: <code>List<Object></code></li>
+ * </ul>
+ * Method search example:
+ * <ul>
+ * <li>declaration: <code><T>foo(T t)</code></li>
+ * <li>pattern: <code><Exception>foo(new Exception())</code></li>
+ * <li>match: <code><Object>foo(new Object())</code></li>
+ * </ul>
+ * Can be combined to all other match rules, e.g. {@link #R_CASE_SENSITIVE} | {@link #R_ERASURE_MATCH}
+ * This rule is not activated by default, so raw types or parameterized types with same erasure will not be found
+ * for pattern List<String>,
+ * Note that with this pattern, the match selection will be only on the erasure even for parameterized types.
+ * @since 3.1
+ */
+ public static final int R_ERASURE_MATCH = 0x0010;
+
+ /**
+ * Match rule: The search pattern matches search results as raw/parameterized types/methods with equivalent type parameters.
+ * This mode has no effect on other java elements search.<br>
+ * Type search example:
+ * <ul>
+ * <li>pattern: <code>List<Exception></code></li>
+ * <li>match:
+ * <ul>
+ * <li><code>List<? extends Throwable></code></li>
+ * <li><code>List<? super RuntimeException></code></li>
+ * <li><code>List<?></code></li>
+ * </ul>
+ * </li>
+ * </ul>
+ * Method search example:
+ * <ul>
+ * <li>declaration: <code><T>foo(T t)</code></li>
+ * <li>pattern: <code><Exception>foo(new Exception())</code></li>
+ * <li>match:
+ * <ul>
+ * <li><code><? extends Throwable>foo(new Exception())</code></li>
+ * <li><code><? super RuntimeException>foo(new Exception())</code></li>
+ * <li><code>foo(new Exception())</code></li>
+ * </ul>
+ * </ul>
+ * Can be combined to all other match rules, e.g. {@link #R_CASE_SENSITIVE} | {@link #R_EQUIVALENT_MATCH}
+ * This rule is not activated by default, so raw types or equivalent parameterized types will not be found
+ * for pattern List<String>,
+ * This mode is overridden by {@link #R_ERASURE_MATCH} as erasure matches obviously include equivalent ones.
+ * That means that pattern with rule set to {@link #R_EQUIVALENT_MATCH} | {@link #R_ERASURE_MATCH}
+ * will return same results than rule only set with {@link #R_ERASURE_MATCH}.
+ * @since 3.1
+ */
+ public static final int R_EQUIVALENT_MATCH = 0x0020;
+
+ /**
+ * Match rule: The search pattern matches exactly the search result,
+ * that is, the source of the search result equals the search pattern.
+ * @since 3.1
+ */
+ public static final int R_FULL_MATCH = 0x0040;
+
+ /**
+ * Match rule: The search pattern contains a Camel Case expression.
+ * <br>
+ * Examples:
+ * <ul>
+ * <li><code>NPE</code> type string pattern will match
+ * <code>NullPointerException</code> and <code>NpPermissionException</code> types,</li>
+ * <li><code>NuPoEx</code> type string pattern will only match
+ * <code>NullPointerException</code> type.</li>
+ * </ul>
+ * @see CharOperation#camelCaseMatch(char[], char[]) for a detailed explanation
+ * of Camel Case matching.
+ *<br>
+ * Can be combined to {@link #R_PREFIX_MATCH} match rule. For example,
+ * when prefix match rule is combined with Camel Case match rule,
+ * <code>"nPE"</code> pattern will match <code>nPException</code>.
+ *<br>
+ * Match rule {@link #R_PATTERN_MATCH} may also be combined but both rules
+ * will not be used simultaneously as they are mutually exclusive.
+ * Used match rule depends on whether string pattern contains specific pattern
+ * characters (e.g. '*' or '?') or not. If it does, then only Pattern match rule
+ * will be used, otherwise only Camel Case match will be used.
+ * For example, with <code>"NPE"</code> string pattern, search will only use
+ * Camel Case match rule, but with <code>N*P*E*</code> string pattern, it will
+ * use only Pattern match rule.
+ *
+ * @since 3.2
+ */
+ public static final int R_CAMELCASE_MATCH = 0x0080;
+
+ private static final int MODE_MASK = R_EXACT_MATCH | R_PREFIX_MATCH | R_PATTERN_MATCH | R_REGEXP_MATCH;
+
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchRequestor.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchRequestor.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/SearchRequestor.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.core.search;
+
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Collects the results from a search engine query.
+ * Clients implement a subclass to pass to <code>SearchEngine.search</code>
+ * and implement the {@link #acceptSearchMatch(SearchMatch)} method, and
+ * possibly override other life cycle methods.
+ * <p>
+ * The search engine calls <code>beginReporting()</code> when a search starts,
+ * then calls <code>acceptSearchMatch(...)</code> for each search result, and
+ * finally calls <code>endReporting()</code>. The order of the search results
+ * is unspecified and may vary from request to request; when displaying results,
+ * clients should not rely on the order but should instead arrange the results
+ * in an order that would be more meaningful to the user.
+ * </p>
+ *
+ * @see SearchEngine
+ * @since 3.0
+ */
+public abstract class SearchRequestor {
+
+ /**
+ * Accepts the given search match.
+ *
+ * @param match the found match
+ * @throws CoreException
+ */
+ public abstract void acceptSearchMatch(SearchMatch match) throws CoreException;
+
+ /**
+ * Notification sent before starting the search action.
+ * Typically, this would tell a search requestor to clear previously
+ * recorded search results.
+ * <p>
+ * The default implementation of this method does nothing. Subclasses
+ * may override.
+ * </p>
+ */
+ public void beginReporting() {
+ // do nothing
+ }
+
+ /**
+ * Notification sent after having completed the search action.
+ * Typically, this would tell a search requestor collector that no more
+ * results will be forthcomping in this search.
+ * <p>
+ * The default implementation of this method does nothing. Subclasses
+ * may override.
+ * </p>
+ */
+ public void endReporting() {
+ // do nothing
+ }
+
+ /**
+ * Intermediate notification sent when the given participant starts to
+ * contribute.
+ * <p>
+ * The default implementation of this method does nothing. Subclasses
+ * may override.
+ * </p>
+ *
+ * @param participant the participant that is starting to contribute
+ */
+ public void enterParticipant(SearchParticipant participant) {
+ // do nothing
+ }
+
+ /**
+ * Intermediate notification sent when the given participant is finished
+ * contributing.
+ * <p>
+ * The default implementation of this method does nothing. Subclasses
+ * may override.
+ * </p>
+ *
+ * @param participant the participant that finished contributing
+ */
+ public void exitParticipant(SearchParticipant participant) {
+ // do nothing
+ }
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/SourceElementParser.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/SourceElementParser.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/SourceElementParser.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,5 @@
+package org.rubypeople.rdt.internal.compiler;
+
+public class SourceElementParser {
+
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRestriction.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRestriction.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRestriction.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.compiler.env;
+
+public class AccessRestriction {
+
+ private AccessRule accessRule;
+ private String[] messageTemplates;
+ public AccessRestriction(AccessRule accessRule, String [] messageTemplates) {
+ this.accessRule = accessRule;
+ this.messageTemplates = messageTemplates;
+ }
+
+ /**
+ * Returns readable description for problem reporting,
+ * message is expected to contain room for restricted type name
+ * e.g. "{0} has restricted access"
+ */
+ public String getMessageTemplate() {
+ return this.messageTemplates[0];
+ }
+
+ public String getConstructorAccessMessageTemplate() {
+ return this.messageTemplates[1];
+ }
+
+ public String getMethodAccessMessageTemplate() {
+ return this.messageTemplates[2];
+ }
+
+ public String getFieldAccessMessageTemplate() {
+ return this.messageTemplates[3];
+ }
+
+ public int getProblemId() {
+ return this.accessRule.getProblemId();
+ }
+
+ public boolean ignoreIfBetter() {
+ return this.accessRule.ignoreIfBetter();
+ }
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRule.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRule.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRule.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.compiler.env;
+
+import org.rubypeople.rdt.core.parser.IProblem;
+import org.rubypeople.rdt.internal.core.util.CharOperation;
+
+public class AccessRule {
+
+ public static final int IgnoreIfBetter = 0x02000000; // value must be greater than IProblem#ForbiddenReference and DiscouragedReference
+
+ public char[] pattern;
+ public int problemId;
+
+ public AccessRule(char[] pattern, int problemId) {
+ this(pattern, problemId, false);
+ }
+
+ public AccessRule(char[] pattern, int problemId, boolean keepLooking) {
+ this.pattern = pattern;
+ this.problemId = keepLooking ? problemId | IgnoreIfBetter : problemId;
+ }
+
+ public int hashCode() {
+ return this.problemId * 17 + CharOperation.hashCode(this.pattern);
+ }
+
+ public boolean equals(Object obj) {
+ if (!(obj instanceof AccessRule)) return false;
+ AccessRule other = (AccessRule) obj;
+ if (this.problemId != other.problemId) return false;
+ return CharOperation.equals(this.pattern, other.pattern);
+ }
+
+ public int getProblemId() {
+ return this.problemId & ~IgnoreIfBetter;
+ }
+
+ public boolean ignoreIfBetter() {
+ return (this.problemId & IgnoreIfBetter) != 0;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("pattern="); //$NON-NLS-1$
+ buffer.append(this.pattern);
+ switch (getProblemId()) {
+ case IProblem.ForbiddenReference:
+ buffer.append(" (NON ACCESSIBLE"); //$NON-NLS-1$
+ break;
+ case IProblem.DiscouragedReference:
+ buffer.append(" (DISCOURAGED"); //$NON-NLS-1$
+ break;
+ default:
+ buffer.append(" (ACCESSIBLE"); //$NON-NLS-1$
+ break;
+ }
+ if (ignoreIfBetter())
+ buffer.append(" | IGNORE IF BETTER"); //$NON-NLS-1$
+ buffer.append(')');
+ return buffer.toString();
+ }
+}
Added: branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRuleSet.java
===================================================================
--- branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRuleSet.java (rev 0)
+++ branches/search_engine/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/compiler/env/AccessRuleSet.java 2007-03-13 17:39:10 UTC (rev 2144)
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.compiler.env;
+
+import org.rubypeople.rdt.core.parser.IProblem;
+import org.rubypeople.rdt.internal.core.util.CharOperation;
+
+/**
+ * Definition of a set of access rules used to flag forbidden references to non API code.
+ */
+public class AccessRuleSet {
+
+ private AccessRule[] accessRules;
+ public String[] messageTemplates;
+ public static final int MESSAGE_TEMPLATES_LENGTH = 4;
+
+ /**
+ * Make a new set of access rules.
+ * @param accessRules the access rules to be contained by the new set
+ * @param messageTemplates a Sting[4] array specifying the messages for type,
+ * constructor, method and field access violation; each should contain as many
+ * placeholders as expected by the respective access violation message (that is,
+ * one for type and constructor, two for method and field); replaced by a
+ * default value if null.
+ */
+ public AccessRuleSet(AccessRule[] accessRules, String[] messageTemplates) {
+ this.accessRules = accessRules;
+ if (messageTemplates != null && messageTemplates.length == MESSAGE_TEMPLATES_LENGTH)
+ this.messageTemplates = messageTemplates;
+ else
+ this.messageTemplates = new String[] {"{0}", "{0}", "{0} {1}", "{0} {1}"}; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ /**
+ * @see java.l...
[truncated message content] |