package hu.elte.txtuml.validation.common;

import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.TypeDeclaration;

/**
 * Base class for all txtUML validation problems.
 * <p>
 * By default, {@link #isError}, {@link #isWarning} and {@link isInfo} all
 * return false.
 */
public abstract class AbstractValidationProblem extends CategorizedProblem implements IValidationProblem {

	private final SourceInfo sourceInfo;
	private int sourceStart;
	private int sourceEnd;
	private int lineNumber;

	public AbstractValidationProblem(SourceInfo sourceInfo, ASTNode node) {
		this.sourceInfo = sourceInfo;
		Class<?> c = ASTNode.nodeClassForType(node.getNodeType());
		if (c == TypeDeclaration.class) {
			SimpleName name = ((TypeDeclaration) node).getName();
			this.sourceStart = name.getStartPosition();
			this.sourceEnd = name.getStartPosition() + name.getLength();
		} else {
			this.sourceStart = node.getStartPosition();
			this.sourceEnd = node.getStartPosition() + node.getLength();
		}
		this.lineNumber = sourceInfo.getSourceLineNumber(getSourceEnd());
	}

	@Override
	public String[] getArguments() {
		return new String[0];
	}

	@Override
	public char[] getOriginatingFileName() {
		return sourceInfo.getOriginatingFileName().toCharArray();
	}

	@Override
	public int getCategoryID() {
		return 0;
	}

	@Override
	public boolean isError() {
		return false;
	}

	@Override
	public boolean isWarning() {
		return false;
	}

	@Override
	public boolean isInfo() {
		return super.isInfo();
	}

	@Override
	public int getSourceStart() {
		return sourceStart;
	}

	@Override
	public int getSourceEnd() {
		return sourceEnd;
	}

	@Override
	public int getSourceLineNumber() {
		return lineNumber;
	}

	@Override
	public void setSourceStart(int sourceStart) {
		this.sourceStart = sourceStart;
	}

	@Override
	public void setSourceEnd(int sourceEnd) {
		this.sourceEnd = sourceEnd;
	}

	@Override
	public void setSourceLineNumber(int lineNumber) {
		this.lineNumber = lineNumber;
	}

}

@@ -134,16 +134,67 @@
 STNode;%0A
+import org.eclipse.jdt.core.dom.MethodDeclaration;%0A
 import o
@@ -860,68 +860,213 @@
 lass
-) %7B%0A%09%09%09SimpleName name = ((TypeDeclaration) node).getName();
+ %7C%7C c == MethodDeclaration.class) %7B%0A%09%09%09SimpleName name;%0A%09%09%09if (c == TypeDeclaration.class) %7B%0A%09%09%09%09name = ((TypeDeclaration) node).getName();%0A%09%09%09%7D else %7B%0A%09%09%09%09name = ((MethodDeclaration) node).getName();%0A%09%09%09%7D
 %0A%09%09%09

Fix MethodDeclaration error markers