/**
 *  Copyright (c) 2013-2014 Angelo ZERR.
 *  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:
 *  Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
 */
package org.eclipse.angularjs.core.validation;

import org.eclipse.angularjs.core.AngularProject;
import org.eclipse.angularjs.core.utils.DOMUtils;
import org.eclipse.angularjs.internal.core.Trace;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.wst.html.core.internal.validation.HTMLValidationReporter;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.validate.ErrorInfo;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
import org.w3c.dom.Node;

import tern.angular.modules.AngularModulesManager;
import tern.angular.modules.DOMDirectiveProvider;
import tern.angular.modules.Directive;
import tern.angular.modules.Restriction;

public class HTMLAngularValidationReporter extends HTMLValidationReporter {

	private final IProject project;

	public HTMLAngularValidationReporter(IValidator owner, IReporter reporter,
			IFile file, IStructuredModel model) {
		super(owner, reporter, file, model);
		this.project = file.getProject();
	}

	@Override
	public void report(ErrorInfo info) {
		int targetType = info.getTargetType();
		// org.eclipse.wst.html.core.internal.validate.ErrorState.UNDEFINED_NAME_ERROR
		// = 11 is private -(
		if ((targetType == Node.ATTRIBUTE_NODE || targetType == Node.ELEMENT_NODE)
				&& info.getState() == 11) {
			// It's an error about attribute name, check if it's an Angular
			// Attribute (ex : ng-app)
			String name = info.getHint();
			if (!isDirective(project, name, targetType)) {
				// it's not an angular directive, report the error
				super.report(info);
			}
		} else {
			// report the error
			super.report(info);
		}
	}

	/**
	 * Returns true if the given name is a directive for the current node
	 * (attribute, element) and false otherwise.
	 * 
	 * @param project
	 * @param name
	 * @param targetType
	 * @return
	 */
	private boolean isDirective(IProject project, String name, int targetType) {
		try {
			AngularProject angularProject = AngularProject
					.getAngularProject(project);
			return AngularModulesManager.getInstance().getDirective(
					angularProject, null, name, getRestriction(targetType)) != null;
		} catch (CoreException e) {
			Trace.trace(Trace.WARNING, "Error while getting angular project", e);
		}
		return false;
	}

	private Restriction getRestriction(int targetType) {
		switch (targetType) {
		case Node.ATTRIBUTE_NODE:
			return Restriction.A;
		case Node.ELEMENT_NODE:
			return Restriction.E;
		}
		return null;
	}

}

@@ -2503,16 +2503,68 @@
 %09%09try %7B%0A
+%09%09%09if (AngularProject.hasAngularNature(project)) %7B%0A%09
 %09%09%09Angul
@@ -2605,16 +2605,17 @@
 Project%0A
+%09
 %09%09%09%09%09.ge
@@ -2639,24 +2639,25 @@
 roject);%0A%09%09%09
+%09
 return Angul
@@ -2701,16 +2701,17 @@
 ective(%0A
+%09
 %09%09%09%09%09ang
@@ -2772,16 +2772,21 @@
 = null;%0A
+%09%09%09%7D%0A
 %09%09%7D catc

Check if project has angular nature. See https://github.com/angelozerr/angularjs-eclipse/issues/78