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

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

/*******************************************************************************
* 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.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.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;

public class UnclosedTMLTagMarkingHandler implements MarkingHandler {
 
  public static final String MARKER_ID = "de.innovationgate.eclipse.ids.markers.tml.UnclosedTMLTag";
  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) || partition.getType().equals(TMLPartitionScanner.TML_TAG_STOP)) {
          if (!TMLRegion.isTMLPartitionClosed(partition, document)) {
            int charStart = partition.getOffset();
            int charEnd = charStart + partition.getLength();
            TMLRegion tmlInfo = null;
            try {
              tmlInfo = TMLRegion.parse(partition, document);             
            } catch (ParseException e) {
            }
            // create markers only for known tags
            if (tmlInfo != null && tmlInfo.isTagKnown(_versionCompliance)) {
              String message = null;
              if (tmlInfo != null) {
                if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
                  message = "Missing close tag '" + tmlInfo.getTagName() + "'.";
                } else {
                  message = "Missing start tag '" + tmlInfo.getTagName() + "'.";
                }
              } else {
                message = "Unclosed tag.";
              }
              MarkerFactory.createErrorMarker(MARKER_ID, file, charStart, charEnd, message);
            }
          }
        }
      }
    } 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.UnclosedTMLTagMarkingHandler

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.