Modified: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/IvyContentAssistProcessor.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/IvyContentAssistProcessor.java?rev=679833&r1=679832&r2=679833&view=diff
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/IvyContentAssistProcessor.java
 (original)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/IvyContentAssistProcessor.java
 Fri Jul 25 08:26:55 2008
@@ -24,12 +24,15 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ivyde.common.completion.CodeCompletionProposal;
+import org.apache.ivyde.common.completion.IvyCodeCompletionProcessor;
+import org.apache.ivyde.common.ivyfile.IvyModuleDescriptorModel;
+import org.apache.ivyde.common.model.IvyFile;
+import org.apache.ivyde.common.model.IvyModel;
+import org.apache.ivyde.common.model.IvyTag;
+import org.apache.ivyde.common.model.IvyTagAttribute;
+import org.apache.ivyde.common.model.Proposal;
 import org.apache.ivyde.eclipse.IvyPlugin;
-import org.apache.ivyde.eclipse.ui.core.model.IvyFile;
-import org.apache.ivyde.eclipse.ui.core.model.IvyModel;
-import org.apache.ivyde.eclipse.ui.core.model.IvyTag;
-import org.apache.ivyde.eclipse.ui.core.model.IvyTagAttribute;
-import org.apache.ivyde.eclipse.ui.core.model.Proposal;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IStatus;
@@ -46,14 +49,14 @@
 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
 import org.eclipse.swt.graphics.Point;
 
-public class IvyContentAssistProcessor implements IContentAssistProcessor {
+public abstract class IvyContentAssistProcessor implements 
IContentAssistProcessor {
     private IContextInformationValidator fValidator = new 
ContextInformationValidator(this);
 
     private String errorMessage = null;
 
     private IFile file;
 
-    private IvyModel _model;
+    private IvyCodeCompletionProcessor completionProcessor;
 
     /**
      * Call by viewer to retrieve a list of ICompletionProposal
@@ -63,7 +66,6 @@
         IDocument doc = viewer.getDocument();
         // Retrieve current selection range
         Point selectedRange = viewer.getSelectedRange();
-        List propList = new ArrayList();
         String ivyFileString;
         try {
             ivyFileString = doc.get(0, doc.getLength());
@@ -74,172 +76,22 @@
             return null;
         }
         IProject project = getProject();
-        IvyFile ivyfile = new IvyFile(project != null ? project.getName() : 
"", ivyFileString,
+        IvyFile ivyfile = completionProcessor.getModel().newIvyFile(project != 
null ? project.getName() : "", ivyFileString,
                 documentOffset);
-        if (ivyfile.inTag()) {
-            String tagName = ivyfile.getTagName();
-            if (ivyfile.readyForValue()) {
-                computeValueProposals(tagName, ivyfile, propList, 
selectedRange);
-            } else {
-                // found a value to put in tag
-                computeTagAttributeProposals(tagName, ivyfile, propList, 
selectedRange);
-            }
-        } else { // not in an xml tag
-            computeStructureProposals(ivyfile, propList, selectedRange);
+        CodeCompletionProposal[] proposals = 
+            completionProcessor.computeCompletionProposals(ivyfile, 
selectedRange.y);
+        
+        // convert code completion proposal into eclipse ICompletionProposal
+        ICompletionProposal[] ret = new ICompletionProposal[proposals.length];
+        for (int i = 0; i < proposals.length; i++) {
+            CodeCompletionProposal prop = proposals[i];
+            ret[i] = new CompletionProposal(
+                prop.getReplacementString(), prop.getReplacementOffset(), 
+                prop.getReplacementLength(), prop.getCursorPosition(), 
+                null, prop.getDisplayString(), null, prop.getDoc());
         }
-        // Create completion proposal array
-        ICompletionProposal[] proposals = new 
ICompletionProposal[propList.size()];
 
-        // and fill with list elements
-        propList.toArray(proposals);
-
-        // Return the proposals
-        return proposals;
-    }
-
-    /**
-     * Compute a list of possible attribute for the tag given in 
arguement.<br/> If attribute are
-     * already used in tag they are discard of the list
-     * 
-     * @param tagName
-     * @param doc
-     * @param documentOffset
-     * @param propList
-     * @param selectedRange
-     */
-    private void computeTagAttributeProposals(String tagName, IvyFile ivyfile, 
List propList,
-            Point selectedRange) {
-        String qualifier = ivyfile.getQualifier();
-        int qlen = qualifier.length();
-        if (qualifier.indexOf('/') > -1) {
-            String text = "/>";
-            CompletionProposal proposal = new CompletionProposal(text, 
ivyfile.getOffset() - qlen,
-                    qlen + selectedRange.y, text.length());
-            propList.add(proposal);
-        } else {
-            String parent = ivyfile.getParentTagName();
-            IvyTag tag = _model.getIvyTag(tagName, parent);
-            if (tag == null) {
-                errorMessage = "tag :" + tagName + " not found in model:";
-                return;
-            }
-            errorMessage = null;
-            List atts = tag.getAttributes();
-            Map existingAtts = ivyfile.getAllAttsValues();
-            // Loop through all proposals
-            for (Iterator iter = atts.iterator(); iter.hasNext();) {
-                IvyTagAttribute att = (IvyTagAttribute) iter.next();
-                if (att.getName().startsWith(qualifier) && 
!existingAtts.containsKey(att.getName())) {
-                    // Yes -- compute whole proposal text
-                    String text = att.getName() + "=\"\"";
-                    // Construct proposal
-                    CompletionProposal proposal = new CompletionProposal(text, 
ivyfile.getOffset()
-                            - qlen, qlen + selectedRange.y, text.length() - 1, 
null, att.getName(),
-                            null, att.getDoc());
-                    // and add to result list
-                    propList.add(proposal);
-                }
-            }
-        }
-    }
-
-    /**
-     * Compute a list of possible values for the current attribute of the 
given tag.<br>
-     * The list is retrieve by calling <code> 
IvyTag.getPossibleValuesForAttribute</code>
-     * 
-     * @see IvyTag#getPossibleValuesForAttribute(String, Map, String)
-     * @param tagName
-     * @param doc
-     * @param documentOffset
-     * @param propList
-     * @param selection
-     */
-    private void computeValueProposals(String tagName, IvyFile ivyfile, List 
propList,
-            Point selection) {
-        String parent = null;
-        String tag = ivyfile.getTagName();
-        if (tag != null) {
-            parent = 
ivyfile.getParentTagName(ivyfile.getStringIndexBackward("<" + tag));
-        }
-        IvyTag ivyTag = _model.getIvyTag(tag, parent);
-        if (ivyTag != null) {
-            String[] values = 
ivyTag.getPossibleValuesForAttribute(ivyfile.getAttributeName(),
-                ivyfile);
-            if (values != null) {
-                String qualifier = ivyfile.getAttributeValueQualifier();
-                int qlen = qualifier == null ? 0 : qualifier.length();
-                Arrays.sort(values);
-                for (int i = 0; i < values.length; i++) {
-                    String val = values[i];
-                    CompletionProposal proposal = new CompletionProposal(val, 
ivyfile.getOffset()
-                            - qlen, qlen + selection.y, val.length());
-                    propList.add(proposal);
-                }
-            }
-        }
-    }
-
-    /**
-     * Compute xml structural proposition
-     */
-    private void computeStructureProposals(IvyFile ivyfile, List propList, 
Point selectedRange) {
-        String parent = ivyfile.getParentTagName();
-        String qualifier = ivyfile.getQualifier();
-        int qlen = qualifier.length();
-        if (parent != null
-                && ivyfile.getOffset() >= 2 + qualifier.length()
-                && ivyfile.getString(ivyfile.getOffset() - 2 - 
qualifier.length(),
-                    ivyfile.getOffset()).startsWith("</")) {
-            // closing tag (already started)
-            String text = "</" + parent + ">";
-            CompletionProposal proposal = new CompletionProposal(text, 
ivyfile.getOffset() - qlen
-                    - 2, qlen + 2 + selectedRange.y, text.length());
-            propList.add(proposal);
-        } else {
-            if (parent != null && qualifier.length() == 0) {
-                String text = "</" + parent + ">";
-                int closingIndex = ivyfile.getStringIndexForward(text);
-                int openingIndex = ivyfile.getStringIndexForward("<" + parent);
-                if (closingIndex == -1 || (openingIndex != -1 && closingIndex 
> openingIndex)) {
-                    // suggest closing tag if tag not yet closed
-                    CompletionProposal proposal = new CompletionProposal(text, 
ivyfile.getOffset(),
-                            selectedRange.y, text.length());
-                    propList.add(proposal);
-                }
-            }
-
-            List childs = null;
-
-            if (parent != null) {
-                String parentParent = 
ivyfile.getParentTagName(ivyfile.getStringIndexBackward("<"
-                        + parent));
-                IvyTag root = _model.getIvyTag(parent, parentParent);
-                if (root == null) {
-                    errorMessage = "parent tag :" + parent + " not found in 
model:";
-                    return;
-                } else {
-                    childs = root.getChilds();
-                }
-            } else {
-                childs = Collections.singletonList(_model.getRootIvyTag());
-            }
-            errorMessage = null;
-            for (Iterator iter = childs.iterator(); iter.hasNext();) {
-                IvyTag child = (IvyTag) iter.next();
-
-                // Check if proposal matches qualifier
-                if (child.getStartTag().startsWith(qualifier)) {
-                    Proposal[] props = child.getProposals();
-                    for (int i = 0; i < props.length; i++) {
-                        // Construct proposal and add to result list
-                        propList.add(new 
CompletionProposal(props[i].getProposal(), ivyfile
-                                .getOffset()
-                                - qlen, qlen + selectedRange.y, 
props[i].getCursor(), null, null,
-                                null, props[i].getDoc()));
-                    }
-                }
-            }
-        }
+        return ret;
     }
 
     public IContextInformation[] computeContextInformation(ITextViewer viewer, 
int offset) {
@@ -273,7 +125,9 @@
 
     public void setFile(IFile file) {
         this.file = file;
-        _model = new IvyModel(getJavaProject());
+        completionProcessor = new 
IvyCodeCompletionProcessor(newCompletionModel(file));
     }
 
+    protected abstract IvyModel newCompletionModel(IFile file);
+
 }

Modified: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/XMLConfiguration.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/XMLConfiguration.java?rev=679833&r1=679832&r2=679833&view=diff
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/XMLConfiguration.java
 (original)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/XMLConfiguration.java
 Fri Jul 25 08:26:55 2008
@@ -50,8 +50,9 @@
 
     private IFile _file;
 
-    public XMLConfiguration(ColorManager colorManager) {
+    public XMLConfiguration(ColorManager colorManager, 
IvyContentAssistProcessor processor) {
         this.colorManager = colorManager;
+        this._processor = processor;
     }
 
     public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
@@ -114,7 +115,6 @@
             }
         });
 
-        _processor = new IvyContentAssistProcessor();
         _processor.setFile(_file);
         // Set this processor for each supported content type
         assistant.setContentAssistProcessor(_processor, 
XMLPartitionScanner.XML_TAG);

Modified: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/XMLEditor.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/XMLEditor.java?rev=679833&r1=679832&r2=679833&view=diff
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/XMLEditor.java
 (original)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/xml/XMLEditor.java
 Fri Jul 25 08:26:55 2008
@@ -29,10 +29,10 @@
 
     private ColorManager colorManager;
 
-    public XMLEditor() {
+    public XMLEditor(IvyContentAssistProcessor processor) {
         super();
         colorManager = new ColorManager();
-        _configuration = new XMLConfiguration(colorManager);
+        _configuration = new XMLConfiguration(colorManager, processor);
         setSourceViewerConfiguration(_configuration);
         setDocumentProvider(new XMLDocumentProvider());
 

Modified: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/wizards/IvyNewWizard.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/wizards/IvyNewWizard.java?rev=679833&r1=679832&r2=679833&view=diff
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/wizards/IvyNewWizard.java
 (original)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/wizards/IvyNewWizard.java
 Fri Jul 25 08:26:55 2008
@@ -26,7 +26,7 @@
 
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.apache.ivyde.eclipse.ui.core.IvyFileEditorInput;
-import org.apache.ivyde.eclipse.ui.editors.IvyEditor;
+import org.apache.ivyde.eclipse.ui.editors.IvyModuleDescriptorEditor;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
@@ -156,7 +156,7 @@
                 IWorkbenchPage page = 
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                         .getActivePage();
                 try {
-                    page.openEditor(new IvyFileEditorInput(file), 
IvyEditor.ID, true);
+                    page.openEditor(new IvyFileEditorInput(file), 
IvyModuleDescriptorEditor.ID, true);
                     // IDE.openEditor(page, file, IvyEditor.ID, true);
                 } catch (PartInitException e) {
                     // this should not happen

Copied: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/test/java/org/apache/ivyde/common/model/IvyFileUtilTest.java
 (from r679832, 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/test/java/org/apache/ivyde/eclipse/core/model/IvyFileUtilTest.java)
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/test/java/org/apache/ivyde/common/model/IvyFileUtilTest.java?p2=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/test/java/org/apache/ivyde/common/model/IvyFileUtilTest.java&p1=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/test/java/org/apache/ivyde/eclipse/core/model/IvyFileUtilTest.java&r1=679832&r2=679833&rev=679833&view=diff
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/test/java/org/apache/ivyde/eclipse/core/model/IvyFileUtilTest.java
 (original)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/test/java/org/apache/ivyde/common/model/IvyFileUtilTest.java
 Fri Jul 25 08:26:55 2008
@@ -15,7 +15,7 @@
  *  limitations under the License.
  *
  */
-package org.apache.ivyde.eclipse.core.model;
+package org.apache.ivyde.common.model;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -24,7 +24,8 @@
 
 import junit.framework.TestCase;
 
-import org.apache.ivyde.eclipse.ui.core.model.IvyFile;
+import org.apache.ivyde.common.ivyfile.IvyModuleDescriptorFile;
+import org.apache.ivyde.common.model.IvyFile;
 
 public class IvyFileUtilTest extends TestCase {
     String hibContentStr;
@@ -48,13 +49,13 @@
     }
 
     public void testInTag() {
-        IvyFile ivyFile = new IvyFile("", hibContentStr);
+        IvyFile ivyFile = new IvyModuleDescriptorFile(null, "", hibContentStr);
         boolean b = ivyFile.inTag(200);
         assertEquals(b, true);
     }
 
     public void testGetTagName() {
-        IvyFile ivyFile = new IvyFile("", hibContentStr);
+        IvyFile ivyFile = new IvyModuleDescriptorFile(null, "", hibContentStr);
         String tag = ivyFile.getTagName(200);
         assertEquals("info", tag);
         tag = ivyFile.getTagName(864);
@@ -64,7 +65,7 @@
 
     public void testGetAllAttsValues() {
         String test = "<test att1=\"value1\" att2 =\"value 2 \"  att3 =\" 
value3 \" att4   =   \"  4  \"";
-        IvyFile ivyFile = new IvyFile("", test);
+        IvyFile ivyFile = new IvyModuleDescriptorFile(null, "", test);
         Map all = ivyFile.getAllAttsValues(1);
         assertNotNull(all);
         assertEquals(4, all.size());
@@ -76,7 +77,7 @@
 
     public void testGetAttributeName() {
         String test = "<test nospace=\"\" 1Space =\"\"  2Space = \"\" 
lotofSpace   =   \"    \"";
-        IvyFile ivyFile = new IvyFile("", test);
+        IvyFile ivyFile = new IvyModuleDescriptorFile(null, "", test);
         String name = ivyFile.getAttributeName(15);
         assertEquals("nospace", name);
         name = ivyFile.getAttributeName(28);
@@ -88,7 +89,7 @@
     }
 
     public void testGetParentTagName() {
-        IvyFile ivyFile = new IvyFile("", hibContentStr);
+        IvyFile ivyFile = new IvyModuleDescriptorFile(null, "", hibContentStr);
         String tag = ivyFile.getParentTagName(200);
         assertEquals("ivy-module", tag);
         tag = ivyFile.getParentTagName(2000);


Reply via email to