Package de.innovationgate.eclipse.editors.tml.markers

Source Code of de.innovationgate.eclipse.editors.tml.markers.UnknownTMLAttributeMarkingHandler

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.tml.markers;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.ui.texteditor.IDocumentProvider;

import de.innovationgate.eclipse.editors.config.TMLTag;
import de.innovationgate.eclipse.editors.config.TMLTagAttribute;
import de.innovationgate.eclipse.editors.config.TMLTagDefinitions;
import de.innovationgate.eclipse.editors.helpers.MarkerFactory;
import de.innovationgate.eclipse.editors.helpers.MarkingHandler;
import de.innovationgate.eclipse.editors.tml.TMLPartitionScanner;
import de.innovationgate.eclipse.editors.tml.TMLRegion;
import de.innovationgate.wga.model.VersionCompliance;

/**
* checks the document for unknown tml tags
*
*
*/
public class UnknownTMLAttributeMarkingHandler implements MarkingHandler {

  public static final String MARKER_ID = "de.innovationgate.eclipse.ids.markers.tml.UnknownTMLAttribute";
  private VersionCompliance _versionCompliance;

  public void createMarkers(IFile file, IDocument document) throws CoreException{
    file.deleteMarkers(MARKER_ID, true, IResource.DEPTH_ZERO);
    try {
      ITypedRegion[] partitions = document.computePartitioning(0, document.getLength());
      for (ITypedRegion partition : partitions) {
        if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
          try {
            TMLRegion tmlInfo = TMLRegion.parse(partition, document);
            TMLTagDefinitions tagDef = TMLTagDefinitions.getInstance(_versionCompliance);
            if (tagDef != null) {
                TMLTag tag = tagDef.getTagByName(tmlInfo.getTagName());
                if (tag != null) {
                  List<String> tmpAttributes = new ArrayList<String>();
                  tmpAttributes.addAll(tmlInfo.getAttributeNames());
                  tmpAttributes.addAll(tmlInfo.getValuelessAttributes());
                 
                  Iterator<String> attributes = tmpAttributes.iterator();
                  while (attributes.hasNext()) {
                    String attribute = attributes.next();
                    if (tag.getName().equals("include") || tag.getName().equals("portlet")) {
                      if (attribute.startsWith("o_")) {
                        // attributes starting with "o_" mean implicit options - do not validate
                        continue;
                      }
                    }
                    int charStart = partition.getOffset();
                                    int charEnd = charStart + partition.getLength();
                                    int attributeStart = tmlInfo.getContent().indexOf(attribute);
                                    if (attributeStart != -1) {
                                        charStart = charStart + attributeStart;
                                        charEnd = charStart + attribute.length();
                                    }
                    if (tag.getAttribute(attribute) == null) {                                 
                      MarkerFactory.createErrorMarker(MARKER_ID, file, charStart, charEnd, "Unknown attribute '" + attribute + "'.");
                    } else {
                        TMLTagAttribute attrib  = tag.getAttribute(attribute);
                        if (attrib.isDeprecated()) {
                            MarkerFactory.createWarningMarker(MARKER_ID, file, charStart, charEnd, "Attribute '" + attribute + "' is deprecated. " + attrib.getDeprecated());
                        }
                    }
                  }
                 
                }
            }
          } catch (ParseException e) {
          }
         
        }
      }
    } catch (BadLocationException e) {     
    }
  }

  public void setWGAVersionCompliance(VersionCompliance versionCompliance) {
    _versionCompliance = versionCompliance;
  }

  public void setDocumentProvider(IDocumentProvider provider) {
    // TODO Auto-generated method stub
   
  }

  public void createMarkers(IResource resource) throws CoreException {
    // TODO Auto-generated method stub
   
  }
}
TOP

Related Classes of de.innovationgate.eclipse.editors.tml.markers.UnknownTMLAttributeMarkingHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.