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

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

/*******************************************************************************
* 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 org.codehaus.backport175.com.thoughtworks.qdox.parser.structs.TagDef;
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.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 UnknownTMLTagMarkingHandler implements MarkingHandler {

  public static final String MARKER_ID = "de.innovationgate.eclipse.ids.markers.tml.UnknownTMLTag";
  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);
            if (!tmlInfo.isTagKnown(_versionCompliance)) {
              int charStart = partition.getOffset();
              int charEnd = charStart + partition.getLength();
              MarkerFactory.createErrorMarker(MARKER_ID, file, charStart, charEnd, "Unknown TML-Tag '" + tmlInfo.getTagName() + "'.");
            } else {
                TMLTagDefinitions tagDef = TMLTagDefinitions.getInstance(_versionCompliance);
                if (tagDef != null) {
                    TMLTag tag = tagDef.getTagByName(tmlInfo.getTagName());
                    if (tag.isDeprecated()) {
                        int charStart = partition.getOffset();
                                int charEnd = charStart + partition.getLength();
                                MarkerFactory.createWarningMarker(MARKER_ID, file, charStart, charEnd, "TML-Tag '" + tmlInfo.getTagName() + "' is deprecated. " + tag.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.UnknownTMLTagMarkingHandler

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.