org.eclipse.pde.core_3.7.1.v20120103_r372

ckage org.eclipse.pde.internal.core.text.plugin;

import java.util.ArrayList;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.core.plugin.IPluginLibrary;
import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
import org.eclipse.pde.internal.core.text.IDocumentElementNode;

public class PluginLibraryNode
  extends PluginObjectNode
  implements IPluginLibrary
{
  private static final long serialVersionUID = 1L;
  
  public String[] getContentFilters()
  {
    IDocumentElementNode[] children = getChildNodes();
    ArrayList result = new ArrayList();
    for (int i = 0; i < children.length; i++)
    {
      PluginObjectNode node = (PluginObjectNode)children[i];
      if (node.getName().equals("export"))
      {
        String name = children[i].getXMLAttributeValue("name");
        if ((name != null) && (!name.equals("*")))
        {
          int index = name.indexOf(".*");
          if (index != -1) {
            name = name.substring(0, index);
          }
          result.add(name);
        }
      }
    }
    return (String[])result.toArray(new String[result.size()]);
  }
  
  public String[] getPackages()
  {
    return new String[0];
  }
  
  public boolean isExported()
  {
    IDocumentElementNode[] children = getChildNodes();
    for (int i = 0; i < children.length; i++)
    {
      PluginObjectNode node = (PluginObjectNode)children[i];
      if (node.getName().equals("export")) {
        return true;
      }
    }
    return false;
  }
  
  public boolean isFullyExported()
  {
    IDocumentElementNode[] children = getChildNodes();
    for (int i = 0; i < children.length; i++)
    {
      PluginObjectNode node = (PluginObjectNode)children[i];
      if (node.getName().equals("export"))
      {
        String name = children[i].getXMLAttributeValue("name");
        if ((name != null) && (name.equals("*"))) {
          return true;
        }
      }
    }
    return false;
  }
  
  public String getType()
  {
    String type = getXMLAttributeValue("type");
    return (type != null) && (type.equals("resource")) ? "resource" : "code";
  }
  
  public void setContentFilters(String[] filters)
    throws CoreException
  {}
  
  public void addContentFilter(String filter)
    throws CoreException
  {
    PluginElementNode node = new PluginElementNode();
    node.setXMLTagName("export");
    node.setParentNode(this);
    node.setModel(getModel());
    node.setXMLAttribute("name", filter + ".*");
    addContentFilter(node);
  }
  
  public void addContentFilter(PluginElementNode node)
  {
    addChildNode(node);
    if (isInTheModel())
    {
      node.setInTheModel(true);
      fireStructureChanged(node, 1);
    }
  }
  
  public void removeContentFilter(String filter)
    throws CoreException
  {
    if (!filter.endsWith(".*")) {
      filter = filter + ".*";
    }
    IDocumentElementNode[] children = getChildNodes();
    for (int i = 0; i < children.length; i++) {
      if ((children[i].getXMLTagName().equals("export")) && (filter.equals(children[i].getXMLAttributeValue("name")))) {
        removeContentFilter((PluginElementNode)children[i]);
      }
    }
  }
  
  public void removeContentFilter(PluginElementNode node)
  {
    removeChildNode(node);
    if (isInTheModel())
    {
      node.setInTheModel(false);
      fireStructureChanged(node, 2);
    }
  }
  
  public void setPackages(String[] packages)
    throws CoreException
  {}
  
  public void setExported(boolean exported)
    throws CoreException
  {
    IDocumentElementNode[] children = getChildNodes();
    boolean alreadyExported = false;
    for (int i = 0; i < children.length; i++) {
      if (children[i].getXMLTagName().equals("export")) {
        if (!"*".equals(children[i].getXMLAttributeValue("name")))
        {
          removeContentFilter((PluginElementNode)children[i]);
        }
        else
        {
          alreadyExported = true;
          if (!exported) {
            removeContentFilter((PluginElementNode)children[i]);
          }
        }
      }
    }
    if ((exported) && (!alreadyExported)) {
      addContentFilter("*");
    }
  }
  
  public void setType(String type)
    throws CoreException
  {}
  
  public String getName()
  {
    return getXMLAttributeValue("name");
  }
  
  public void setName(String name)
    throws CoreException
  {
    setXMLAttribute("name", name);
  }
  
  public String write(boolean indent)
  {
    String sep = getLineDelimiter();
    StringBuffer buffer = new StringBuffer();
    if (indent) {
      buffer.append(getIndent());
    }
    IDocumentElementNode[] children = getChildNodes();
    if (children.length > 0)
    {
      buffer.append(writeShallow(false) + sep);
      for (int i = 0; i < children.length; i++)
      {
        children[i].setLineIndent(getLineIndent() + 3);
        buffer.append(children[i].write(true) + sep);
      }
      buffer.append(getIndent() + "</" + getXMLTagName() + ">");
    }
    else
    {
      buffer.append(writeShallow(true));
    }
    return buffer.toString();
  }
  
  public String writeShallow(boolean terminate)
  {
    StringBuffer buffer = new StringBuffer("<" + getXMLTagName());
    
    IDocumentAttributeNode[] attrs = getNodeAttributes();
    for (int i = 0; i < attrs.length; i++) {
      appendAttribute(buffer, attrs[i].getAttributeName());
    }
    if (terminate) {
      buffer.append("/");
    }
    buffer.append(">");
    return buffer.toString();
  }
  
  public String toString()
  {
    return getName();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.plugin.PluginLibraryNode
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text.plugin;

import org.eclipse.jface.text.IDocument;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.pde.core.plugin.IPlugin;
import org.eclipse.pde.core.plugin.IPluginModel;

public class PluginModel
  extends PluginModelBase
  implements IPluginModel
{
  public PluginModel(IDocument document, boolean isReconciling)
  {
    super(document, isReconciling);
  }
  
  public IPlugin getPlugin()
  {
    return (IPlugin)getPluginBase();
  }
  
  public boolean isFragmentModel()
  {
    return false;
  }
  
  public BundleDescription getBundleDescription()
  {
    return null;
  }
  
  public void setBundleDescription(BundleDescription description) {}
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.plugin.PluginModel
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text.plugin;

import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.pde.core.IModel;
import org.eclipse.pde.core.IWritable;
import org.eclipse.pde.core.build.IBuildModel;
import org.eclipse.pde.core.plugin.IExtensions;
import org.eclipse.pde.core.plugin.IExtensionsModelFactory;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.IPluginModelFactory;
import org.eclipse.pde.internal.core.NLResourceHelper;
import org.eclipse.pde.internal.core.PDEManager;
import org.eclipse.pde.internal.core.text.IDocumentElementNode;
import org.eclipse.pde.internal.core.text.XMLEditingModel;
import org.xml.sax.helpers.DefaultHandler;

public abstract class PluginModelBase
  extends XMLEditingModel
  implements IPluginModelBase, IDocumentListener
{
  private PluginBaseNode fPluginBase;
  private boolean fIsEnabled;
  private PluginDocumentHandler fHandler;
  private IPluginModelFactory fFactory;
  private String fLocalization;
  private boolean fHasTriedToCreateModel;
  
  public PluginModelBase(IDocument document, boolean isReconciling)
  {
    super(document, isReconciling);
    fFactory = new PluginDocumentNodeFactory(this);
    document.addDocumentListener(this);
  }
  
  public IPluginBase createPluginBase(boolean isFragment)
  {
    if (isFragment)
    {
      fPluginBase = new FragmentNode();
      fPluginBase.setXMLTagName("fragment");
    }
    else
    {
      fPluginBase = new PluginNode();
      fPluginBase.setXMLTagName("plugin");
    }
    fPluginBase.setInTheModel(true);
    fPluginBase.setModel(this);
    return fPluginBase;
  }
  
  protected IWritable getRoot()
  {
    return getPluginBase();
  }
  
  public IPluginBase createPluginBase()
  {
    return createPluginBase(isFragmentModel());
  }
  
  public IBuildModel getBuildModel()
  {
    return null;
  }
  
  public IPluginBase getPluginBase()
  {
    return getPluginBase(true);
  }
  
  public IExtensions getExtensions()
  {
    return getPluginBase();
  }
  
  /* Error */
  public IPluginBase getPluginBase(boolean createIfMissing)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 158	org/eclipse/pde/internal/core/text/plugin/PluginModelBase:fLoaded	Z
    //   4: ifne +48 -> 52
    //   7: aload_0
    //   8: getfield 156	org/eclipse/pde/internal/core/text/plugin/PluginModelBase:fHasTriedToCreateModel	Z
    //   11: ifne +41 -> 52
    //   14: iload_1
    //   15: ifeq +37 -> 52
    //   18: aload_0
    //   19: invokevirtual 182	org/eclipse/pde/internal/core/text/plugin/PluginModelBase:createPluginBase	()Lorg/eclipse/pde/core/plugin/IPluginBase;
    //   22: pop
    //   23: aload_0
    //   24: invokevirtual 178	org/eclipse/pde/internal/core/text/plugin/PluginModelBase:load	()V
    //   27: goto +20 -> 47
    //   30: pop
    //   31: aload_0
    //   32: iconst_1
    //   33: putfield 156	org/eclipse/pde/internal/core/text/plugin/PluginModelBase:fHasTriedToCreateModel	Z
    //   36: goto +16 -> 52
    //   39: astore_2
    //   40: aload_0
    //   41: iconst_1
    //   42: putfield 156	org/eclipse/pde/internal/core/text/plugin/PluginModelBase:fHasTriedToCreateModel	Z
    //   45: aload_2
    //   46: athrow
    //   47: aload_0
    //   48: iconst_1
    //   49: putfield 156	org/eclipse/pde/internal/core/text/plugin/PluginModelBase:fHasTriedToCreateModel	Z
    //   52: aload_0
    //   53: getfield 161	org/eclipse/pde/internal/core/text/plugin/PluginModelBase:fPluginBase	Lorg/eclipse/pde/internal/core/text/plugin/PluginBaseNode;
    //   56: areturn
    // Line number table:
    //   Java source line #88	-> byte code offset #0
    //   Java source line #90	-> byte code offset #18
    //   Java source line #91	-> byte code offset #23
    //   Java source line #92	-> byte code offset #30
    //   Java source line #94	-> byte code offset #31
    //   Java source line #93	-> byte code offset #39
    //   Java source line #94	-> byte code offset #40
    //   Java source line #95	-> byte code offset #45
    //   Java source line #94	-> byte code offset #47
    //   Java source line #97	-> byte code offset #52
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	57	0	this	PluginModelBase
    //   0	57	1	createIfMissing	boolean
    //   39	7	2	localObject	Object
    //   30	1	3	localCoreException	org.eclipse.core.runtime.CoreException
    // Exception table:
    //   from	to	target	type
    //   18	27	30	org/eclipse/core/runtime/CoreException
    //   18	31	39	finally
  }
  
  public IExtensions getExtensions(boolean createIfMissing)
  {
    return getPluginBase(createIfMissing);
  }
  
  public boolean isEnabled()
  {
    return fIsEnabled;
  }
  
  public void setEnabled(boolean enabled)
  {
    fIsEnabled = enabled;
  }
  
  public IPluginModelFactory getPluginFactory()
  {
    return fFactory;
  }
  
  public URL getNLLookupLocation()
  {
    try
    {
      String installLocation = getInstallLocation();
      return installLocation == null ? null : new URL("file:" + installLocation);
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
  
  public IExtensionsModelFactory getFactory()
  {
    return fFactory;
  }
  
  protected NLResourceHelper createNLResourceHelper()
  {
    URL[] locations = PDEManager.getNLLookupLocations(this);
    return locations.length == 0 ? null : new NLResourceHelper(fLocalization == null ? "plugin" : fLocalization, 
      locations);
  }
  
  protected DefaultHandler createDocumentHandler(IModel model, boolean reconciling)
  {
    if (fHandler == null) {
      fHandler = new PluginDocumentHandler(this, reconciling);
    }
    return fHandler;
  }
  
  public IDocumentElementNode getLastErrorNode()
  {
    if (fHandler != null) {
      return fHandler.getLastErrorNode();
    }
    return null;
  }
  
  public void setLocalization(String localization)
  {
    fLocalization = localization;
  }
  
  public void dispose()
  {
    getDocument().removeDocumentListener(this);
    super.dispose();
  }
  
  public void documentChanged(DocumentEvent event)
  {
    fHasTriedToCreateModel = false;
  }
  
  public void documentAboutToBeChanged(DocumentEvent event) {}
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.plugin.PluginModelBase
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text.plugin;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.core.plugin.IPlugin;

public class PluginNode
  extends PluginBaseNode
  implements IPlugin
{
  private static final long serialVersionUID = 1L;
  
  public String getClassName()
  {
    return getXMLAttributeValue("class");
  }
  
  public void setClassName(String className)
    throws CoreException
  {
    setXMLAttribute("class", className);
  }
  
  protected String[] getSpecificAttributes()
  {
    String classname = getClassName();
    if ((classname != null) && (classname.trim().length() > 0)) {
      return new String[] { "   class=\"" + classname + "\"" };
    }
    return new String[0];
  }
  
  public boolean hasExtensibleAPI()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.plugin.PluginNode
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text.plugin;

import java.io.PrintWriter;
import java.util.TreeMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.pde.core.IModel;
import org.eclipse.pde.core.IModelChangeProvider;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.core.ModelChangedEvent;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.IPluginObject;
import org.eclipse.pde.core.plugin.ISharedPluginModel;
import org.eclipse.pde.internal.core.plugin.IWritableDelimiter;
import org.eclipse.pde.internal.core.text.DocumentElementNode;
import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
import org.eclipse.pde.internal.core.text.IDocumentElementNode;
import org.eclipse.pde.internal.core.text.IDocumentRange;
import org.eclipse.pde.internal.core.text.IEditingModel;
import org.eclipse.pde.internal.core.util.PDEXMLHelper;

public class PluginObjectNode
  extends DocumentElementNode
  implements IPluginObject, IWritableDelimiter
{
  private transient boolean fInTheModel;
  private transient ISharedPluginModel fModel;
  private static final long serialVersionUID = 1L;
  private String fName;
  
  public ISharedPluginModel getModel()
  {
    return fModel;
  }
  
  public IPluginModelBase getPluginModel()
  {
    return (IPluginModelBase)fModel;
  }
  
  public String getName()
  {
    return fName;
  }
  
  public boolean isInTheModel()
  {
    return fInTheModel;
  }
  
  public String getTranslatedName()
  {
    return getResourceString(getName());
  }
  
  public IPluginObject getParent()
  {
    return (IPluginObject)getParentNode();
  }
  
  public IPluginBase getPluginBase()
  {
    return fModel != null ? ((IPluginModelBase)fModel).getPluginBase() : null;
  }
  
  public String getResourceString(String key)
  {
    return fModel != null ? fModel.getResourceString(key) : key;
  }
  
  public void setName(String name)
    throws CoreException
  {
    fName = name;
  }
  
  public boolean isValid()
  {
    return false;
  }
  
  public void write(String indent, PrintWriter writer) {}
  
  public Object getAdapter(Class adapter)
  {
    return null;
  }
  
  public void setInTheModel(boolean inModel)
  {
    fInTheModel = inModel;
  }
  
  public void setModel(ISharedPluginModel model)
  {
    fModel = model;
  }
  
  public boolean setXMLAttribute(String name, String value)
  {
    String oldValue = getXMLAttributeValue(name);
    if ((oldValue != null) && (oldValue.equals(value))) {
      return false;
    }
    PluginAttribute attr = (PluginAttribute)getNodeAttributesMap().get(name);
    try
    {
      if (value == null) {
        value = "";
      }
      if (attr == null)
      {
        attr = new PluginAttribute();
        attr.setName(name);
        attr.setEnclosingElement(this);
        attr.setModel(getModel());
        getNodeAttributesMap().put(name, attr);
      }
      attr.setValue(value == null ? "" : value);
    }
    catch (CoreException localCoreException) {}
    if (fInTheModel) {
      firePropertyChanged(attr.getEnclosingElement(), attr.getAttributeName(), oldValue, value);
    }
    return true;
  }
  
  protected void firePropertyChanged(IDocumentRange node, String property, Object oldValue, Object newValue)
  {
    if (fModel.isEditable()) {
      fModel.fireModelObjectChanged(node, property, oldValue, newValue);
    }
  }
  
  protected void fireStructureChanged(IPluginObject child, int changeType)
  {
    IModel model = getModel();
    if ((model.isEditable()) && ((model instanceof IModelChangeProvider)))
    {
      IModelChangedEvent e = new ModelChangedEvent(fModel, changeType, new Object[] { child }, null);
      fireModelChanged(e);
    }
  }
  
  protected void fireStructureChanged(IPluginObject[] children, int changeType)
  {
    IModel model = getModel();
    if ((model.isEditable()) && ((model instanceof IModelChangeProvider)))
    {
      IModelChangedEvent e = new ModelChangedEvent(fModel, changeType, children, null);
      fireModelChanged(e);
    }
  }
  
  private void fireModelChanged(IModelChangedEvent e)
  {
    IModel model = getModel();
    if ((model.isEditable()) && ((model instanceof IModelChangeProvider)))
    {
      IModelChangeProvider provider = (IModelChangeProvider)model;
      provider.fireModelChanged(e);
    }
  }
  
  public String getWritableString(String source)
  {
    return PDEXMLHelper.getWritableString(source);
  }
  
  protected void appendAttribute(StringBuffer buffer, String attrName)
  {
    appendAttribute(buffer, attrName, "");
  }
  
  protected void appendAttribute(StringBuffer buffer, String attrName, String defaultValue)
  {
    IDocumentAttributeNode attr = getDocumentAttribute(attrName);
    if (attr != null)
    {
      String value = attr.getAttributeValue();
      if ((value != null) && (value.trim().length() > 0) && (!value.equals(defaultValue))) {
        buffer.append(" " + attr.write());
      }
    }
  }
  
  public String getLineDelimiter()
  {
    ISharedPluginModel model = getModel();
    IDocument document = ((IEditingModel)model).getDocument();
    return TextUtilities.getDefaultLineDelimiter(document);
  }
  
  public void addChildNode(IDocumentElementNode child, int position)
  {
    super.addChildNode(child, position);
    ((IPluginObject)child).setInTheModel(true);
  }
  
  public String toString()
  {
    return write(false);
  }
  
  public void reconnect(IDocumentElementNode parent, IModel model)
  {
    super.reconnect(parent, model);
    
    fInTheModel = true;
    if ((model instanceof ISharedPluginModel)) {
      fModel = ((ISharedPluginModel)model);
    }
  }
  
  public void writeDelimeter(PrintWriter writer) {}
  
  public String getXMLAttributeValue(String name)
  {
    PluginAttribute attr = (PluginAttribute)getNodeAttributesMap().get(name);
    return attr == null ? null : attr.getValue();
  }
  
  public String write(boolean indent)
  {
    return "";
  }
  
  public String writeShallow(boolean terminate)
  {
    return "";
  }
  
  protected String getFileEncoding()
  {
    if ((fModel != null) && ((fModel instanceof IEditingModel))) {
      return ((IEditingModel)fModel).getCharset();
    }
    return super.getFileEncoding();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.plugin.PluginObjectNode
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text.plugin;

import java.util.ArrayList;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.core.plugin.IPluginObject;
import org.eclipse.pde.core.plugin.IPluginParent;
import org.eclipse.pde.internal.core.text.IDocumentElementNode;

public class PluginParentNode
  extends PluginObjectNode
  implements IPluginParent
{
  private static final long serialVersionUID = 1L;
  
  public void add(int index, IPluginObject child)
    throws CoreException
  {
    addChildNode((IDocumentElementNode)child, index);
    fireStructureChanged(child, 1);
  }
  
  public void add(IPluginObject child)
    throws CoreException
  {
    add(getChildCount(), child);
    child.setInTheModel(true);
    ((PluginObjectNode)child).setModel(getModel());
  }
  
  public int getChildCount()
  {
    return getChildNodes().length;
  }
  
  public int getIndexOf(IPluginObject child)
  {
    return indexOf((IDocumentElementNode)child);
  }
  
  public void swap(IPluginObject child1, IPluginObject child2)
    throws CoreException
  {
    swap((IDocumentElementNode)child1, (IDocumentElementNode)child2);
    firePropertyChanged(this, "sibling_order", child1, child2);
  }
  
  public IPluginObject[] getChildren()
  {
    ArrayList result = new ArrayList();
    IDocumentElementNode[] nodes = getChildNodes();
    for (int i = 0; i < nodes.length; i++) {
      result.add(nodes[i]);
    }
    return (IPluginObject[])result.toArray(new IPluginObject[result.size()]);
  }
  
  public void remove(IPluginObject child)
    throws CoreException
  {
    removeChildNode((IDocumentElementNode)child);
    child.setInTheModel(false);
    fireStructureChanged(child, 2);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.plugin.PluginParentNode
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text.plugin;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.internal.core.PDECoreMessages;
import org.eclipse.pde.internal.core.text.AbstractTextChangeListener;
import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
import org.eclipse.pde.internal.core.text.IDocumentElementNode;
import org.eclipse.pde.internal.core.text.IDocumentTextNode;
import org.eclipse.pde.internal.core.util.PDEXMLHelper;
import org.eclipse.text.edits.DeleteEdit;
import org.eclipse.text.edits.InsertEdit;
import org.eclipse.text.edits.MoveSourceEdit;
import org.eclipse.text.edits.MoveTargetEdit;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;

public class XMLTextChangeListener
  extends AbstractTextChangeListener
{
  private ArrayList fOperationList = new ArrayList();
  private HashMap fReadableNames = null;
  
  public XMLTextChangeListener(IDocument document)
  {
    this(document, false);
  }
  
  public XMLTextChangeListener(IDocument document, boolean generateReadableNames)
  {
    super(document);
    if (generateReadableNames) {
      fReadableNames = new HashMap();
    }
  }
  
  public TextEdit[] getTextOperations()
  {
    if (fOperationList.size() == 0) {
      return new TextEdit[0];
    }
    return (TextEdit[])fOperationList.toArray(new TextEdit[fOperationList.size()]);
  }
  
  protected static void insert(TextEdit parent, TextEdit edit)
  {
    if (!parent.hasChildren())
    {
      parent.addChild(edit);
      if ((edit instanceof MoveSourceEdit)) {
        parent.addChild(((MoveSourceEdit)edit).getTargetEdit());
      }
      return;
    }
    TextEdit[] children = parent.getChildren();
    for (int i = 0; i < children.length; i++)
    {
      TextEdit child = children[i];
      if (covers(child, edit))
      {
        insert(child, edit);
        return;
      }
    }
    for (int i = children.length - 1; i >= 0; i--)
    {
      TextEdit child = children[i];
      if (covers(edit, child))
      {
        parent.removeChild(i);
        edit.addChild(child);
      }
    }
    parent.addChild(edit);
    if ((edit instanceof MoveSourceEdit)) {
      parent.addChild(((MoveSourceEdit)edit).getTargetEdit());
    }
  }
  
  protected static boolean covers(TextEdit thisEdit, TextEdit otherEdit)
  {
    if (thisEdit.getLength() == 0) {
      return false;
    }
    int thisOffset = thisEdit.getOffset();
    int thisEnd = thisEdit.getExclusiveEnd();
    if (otherEdit.getLength() == 0)
    {
      int otherOffset = otherEdit.getOffset();
      return (thisOffset < otherOffset) && (otherOffset < thisEnd);
    }
    int otherOffset = otherEdit.getOffset();
    int otherEnd = otherEdit.getExclusiveEnd();
    return (thisOffset <= otherOffset) && (otherEnd <= thisEnd);
  }
  
  protected void deleteNode(IDocumentElementNode node)
  {
    TextEdit old = (TextEdit)fOperationTable.get(node);
    if (old != null)
    {
      Object op = fOperationTable.remove(node);
      fOperationList.remove(op);
      if (fReadableNames != null) {
        fReadableNames.remove(op);
      }
    }
    if (node.getOffset() > -1)
    {
      TextEdit op = getDeleteNodeOperation(node);
      fOperationTable.put(node, op);
      fOperationList.add(op);
      if (fReadableNames != null) {
        fReadableNames.put(op, NLS.bind(PDECoreMessages.XMLTextChangeListener_editNames_removeNode, node.getXMLTagName()));
      }
    }
    else if (old == null)
    {
      insertNode(node);
    }
  }
  
  protected void insertNode(IDocumentElementNode node)
  {
    TextEdit op = null;
    node = getHighestNodeToBeWritten(node);
    if (node.getParentNode() == null)
    {
      if (node.isRoot()) {
        op = new InsertEdit(0, node.write(true));
      }
    }
    else if (node.getOffset() > -1)
    {
      op = new ReplaceEdit(node.getOffset(), node.getLength(), node.write(false));
    }
    else
    {
      op = insertAfterSibling(node);
      if (op == null) {
        op = insertAsFirstChild(node);
      }
    }
    fOperationTable.put(node, op);
    fOperationList.add(op);
    if (fReadableNames != null) {
      fReadableNames.put(op, NLS.bind(PDECoreMessages.XMLTextChangeListener_editNames_insertNode, node.getXMLTagName()));
    }
  }
  
  private InsertEdit insertAfterSibling(IDocumentElementNode node)
  {
    IDocumentElementNode sibling = node.getPreviousSibling();
    while (sibling != null)
    {
      if (sibling.getOffset() > -1)
      {
        node.setLineIndent(sibling.getLineIndent());
        return new InsertEdit(sibling.getOffset() + sibling.getLength(), fSep + node.write(true));
      }
      sibling = sibling.getPreviousSibling();
    }
    return null;
  }
  
  private InsertEdit insertAsFirstChild(IDocumentElementNode node)
  {
    int offset = node.getParentNode().getOffset();
    int length = getNextPosition(fDocument, offset, '>');
    node.setLineIndent(node.getParentNode().getLineIndent() + 3);
    return new InsertEdit(offset + length + 1, fSep + node.write(true));
  }
  
  protected void modifyNode(IDocumentElementNode node, IModelChangedEvent event)
  {
    IDocumentElementNode oldNode = (IDocumentElementNode)event.getOldValue();
    IDocumentElementNode newNode = (IDocumentElementNode)event.getNewValue();
    
    IDocumentElementNode node1 = (oldNode.getPreviousSibling() == null) || (oldNode.equals(newNode.getPreviousSibling())) ? oldNode : newNode;
    IDocumentElementNode node2 = node1.equals(oldNode) ? newNode : oldNode;
    if ((node1.getOffset() < 0) && (node2.getOffset() < 0))
    {
      TextEdit op = (TextEdit)fOperationTable.get(node1);
      if (op == null) {
        insertNode(node);
      }
    }
    else if ((node1.getOffset() > -1) && (node2.getOffset() > -1))
    {
      IRegion region = getMoveRegion(node1);
      MoveSourceEdit source = new MoveSourceEdit(region.getOffset(), region.getLength());
      region = getMoveRegion(node2);
      source.setTargetEdit(new MoveTargetEdit(region.getOffset()));
      fOperationTable.put(node, source);
      fOperationList.add(source);
      if (fReadableNames != null) {
        fReadableNames.put(source, NLS.bind(PDECoreMessages.XMLTextChangeListener_editNames_modifyNode, node.getXMLTagName()));
      }
    }
    else
    {
      insertNode(node1.getOffset() < 0 ? node1 : node2);
    }
  }
  
  private IRegion getMoveRegion(IDocumentElementNode node)
  {
    int offset = node.getOffset();
    int length = node.getLength();
    int i = 1;
    try
    {
      for (;; i++)
      {
        char ch = fDocument.get(offset - i, 1).toCharArray()[0];
        if (!Character.isWhitespace(ch))
        {
          i--;
          break;
        }
      }
    }
    catch (BadLocationException localBadLocationException) {}
    return new Region(offset - i, length + i);
  }
  
  protected void addAttributeOperation(IDocumentAttributeNode attr, IModelChangedEvent event)
  {
    int offset = attr.getValueOffset();
    Object newValue = event.getNewValue();
    Object changedObject = attr;
    String name = null;
    TextEdit op = null;
    if (offset > -1) {
      if ((newValue == null) || (newValue.toString().length() == 0))
      {
        int length = attr.getValueOffset() + attr.getValueLength() + 1 - attr.getNameOffset();
        op = getAttributeDeleteEditOperation(attr.getNameOffset(), length);
        if (fReadableNames != null) {
          name = NLS.bind(PDECoreMessages.XMLTextChangeListener_editNames_removeAttribute, new String[] { attr.getAttributeName(), attr.getEnclosingElement().getXMLTagName() });
        }
      }
      else
      {
        op = new ReplaceEdit(offset, attr.getValueLength(), getWritableString(event.getNewValue().toString()));
        if (fReadableNames != null) {
          name = NLS.bind(PDECoreMessages.XMLTextChangeListener_editNames_modifyAttribute, new String[] { attr.getAttributeName(), attr.getEnclosingElement().getXMLTagName() });
        }
      }
    }
    if (op == null)
    {
      IDocumentElementNode node = attr.getEnclosingElement();
      if (node.getOffset() > -1)
      {
        changedObject = node;
        int len = getNextPosition(fDocument, node.getOffset(), '>');
        op = new ReplaceEdit(node.getOffset(), len + 1, node.writeShallow(shouldTerminateElement(fDocument, node.getOffset() + len)));
        if (fReadableNames != null) {
          name = NLS.bind(PDECoreMessages.XMLTextChangeListener_editNames_addAttribute, new String[] { attr.getAttributeName(), attr.getEnclosingElement().getXMLTagName() });
        }
      }
      else
      {
        insertNode(node);
        return;
      }
    }
    fOperationTable.put(changedObject, op);
    fOperationList.add(op);
    if ((fReadableNames != null) && (name != null)) {
      fReadableNames.put(op, name);
    }
  }
  
  protected void addElementContentOperation(IDocumentTextNode textNode)
  {
    TextEdit op = null;
    Object changedObject = textNode;
    if (textNode.getOffset() > -1)
    {
      String newText = getWritableString(textNode.getText());
      op = new ReplaceEdit(textNode.getOffset(), textNode.getLength(), newText);
    }
    else
    {
      IDocumentElementNode parent = textNode.getEnclosingElement();
      if (parent.getOffset() > -1) {
        try
        {
          String endChars = fDocument.get(parent.getOffset() + parent.getLength() - 2, 2);
          if ("/>".equals(endChars))
          {
            insertNode(parent);
            return;
          }
        }
        catch (BadLocationException localBadLocationException)
        {
          changedObject = parent;
          StringBuffer buffer = new StringBuffer(fSep);
          for (int i = 0; i < parent.getLineIndent(); i++) {
            buffer.append(" ");
          }
          buffer.append("   " + getWritableString(textNode.getText()));
          int offset = parent.getOffset();
          int length = getNextPosition(fDocument, offset, '>');
          op = new InsertEdit(offset + length + 1, buffer.toString());
        }
      }
      insertNode(parent);
      return;
    }
    fOperationTable.put(changedObject, op);
    fOperationList.add(op);
    if (fReadableNames != null) {
      fReadableNames.put(op, NLS.bind(PDECoreMessages.XMLTextChangeListener_editNames_addContent, textNode.getEnclosingElement().getXMLTagName()));
    }
  }
  
  private boolean shouldTerminateElement(IDocument doc, int offset)
  {
    try
    {
      return doc.get(offset - 1, 1).toCharArray()[0] == '/';
    }
    catch (BadLocationException localBadLocationException) {}
    return false;
  }
  
  private int getNextPosition(IDocument doc, int offset, char ch)
  {
    int i = 0;
    try
    {
      for (i = 0; i + offset < doc.getLength(); i++) {
        if (ch == doc.get(offset + i, 1).toCharArray()[0]) {
          break;
        }
      }
    }
    catch (BadLocationException localBadLocationException) {}
    return i;
  }
  
  private DeleteEdit getAttributeDeleteEditOperation(int offset, int length)
  {
    try
    {
      for (;;)
      {
        char ch = fDocument.get(offset + length, 1).toCharArray()[0];
        if (!Character.isWhitespace(ch)) {
          break;
        }
        length++;
      }
    }
    catch (BadLocationException localBadLocationException) {}
    return new DeleteEdit(offset, length);
  }
  
  private DeleteEdit getDeleteNodeOperation(IDocumentElementNode node)
  {
    int offset = node.getOffset();
    int length = node.getLength();
    try
    {
      int startLine = fDocument.getLineOfOffset(offset);
      
      int startLineOffset = fDocument.getLineOffset(startLine);
      for (int startOffset = offset - 1; startOffset >= startLineOffset; startOffset--) {
        if (!Character.isWhitespace(fDocument.getChar(startOffset))) {
          break;
        }
      }
      startOffset++;
      
      int endLine = fDocument.getLineOfOffset(offset + length);
      
      int endLineDelimLength = fDocument.getLineDelimiter(endLine).length();
      
      int extraLength = length;
      do
      {
        extraLength++;
        if (!Character.isWhitespace(fDocument.getChar(offset + extraLength)))
        {
          extraLength--;
          break;
        }
      } while (fDocument.getLineOfOffset(offset + extraLength) <= endLine);
      extraLength -= endLineDelimLength;
      if (startOffset == startLineOffset) {
        startOffset -= fDocument.getLineDelimiter(startLine).length();
      }
      length = extraLength + (offset - startOffset);
      offset = startOffset;
    }
    catch (BadLocationException localBadLocationException) {}
    return new DeleteEdit(offset, length);
  }
  
  protected void printDeletionRange(int offset, int length)
  {
    try
    {
      String string = fDocument.get(offset, length);
      StringBuffer buffer = new StringBuffer();
      for (int i = 0; i < string.length(); i++)
      {
        char c = string.charAt(i);
        if (c == '\n') {
          buffer.append("\\n");
        } else if (c == '\r') {
          buffer.append("\\r");
        } else if (c == '\t') {
          buffer.append("\\t");
        } else if (c == ' ') {
          buffer.append('*');
        } else {
          buffer.append(c);
        }
      }
      System.out.println(buffer.toString());
    }
    catch (BadLocationException localBadLocationException) {}
  }
  
  private IDocumentElementNode getHighestNodeToBeWritten(IDocumentElementNode node)
  {
    IDocumentElementNode parent = node.getParentNode();
    if (parent == null) {
      return node;
    }
    if (parent.getOffset() > -1) {
      try
      {
        String endChars = fDocument.get(parent.getOffset() + parent.getLength() - 2, 2);
        return "/>".equals(endChars) ? parent : node;
      }
      catch (BadLocationException localBadLocationException)
      {
        return node;
      }
    }
    return getHighestNodeToBeWritten(parent);
  }
  
  private String getWritableString(String source)
  {
    return PDEXMLHelper.getWritableString(source);
  }
  
  public void modelChanged(IModelChangedEvent event)
  {
    Object[] objects = event.getChangedObjects();
    if (objects == null) {
      return;
    }
    for (int i = 0; i < objects.length; i++) {
      if ((objects[i] instanceof IDocumentElementNode))
      {
        IDocumentElementNode node = (IDocumentElementNode)objects[i];
        Object op = fOperationTable.remove(node);
        fOperationList.remove(op);
        if (fReadableNames != null) {
          fReadableNames.remove(op);
        }
        switch (event.getChangeType())
        {
        case 2: 
          deleteNode(node);
          break;
        case 1: 
          insertNode(node);
          break;
        case 3: 
          IDocumentAttributeNode attr = node.getDocumentAttribute(event.getChangedProperty());
          if (attr != null) {
            addAttributeOperation(attr, event);
          } else if ((event.getOldValue() instanceof IDocumentTextNode)) {
            addElementContentOperation((IDocumentTextNode)event.getOldValue());
          } else if (((event.getOldValue() instanceof IDocumentElementNode)) && ((event.getNewValue() instanceof IDocumentElementNode))) {
            modifyNode(node, event);
          }
          break;
        }
      }
    }
  }
  
  public String getReadableName(TextEdit edit)
  {
    if ((fReadableNames != null) && (fReadableNames.containsKey(edit))) {
      return (String)fReadableNames.get(edit);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.plugin.XMLTextChangeListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.util;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.parsers.FactoryConfigurationError;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
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.eclipse.core.runtime.Platform;
import org.eclipse.jface.text.Document;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.HostSpecification;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginLibrary;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.FeatureModelManager;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.ibundle.IBundle;
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
import org.eclipse.pde.internal.core.ifeature.IFeature;
import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
import org.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd