diff --git a/org.eclipse.angularjs.core.neon/.classpath b/org.eclipse.angularjs.core.neon/.classpath new file mode 100644 index 0000000..0b1bcf9 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.angularjs.core.neon/.gitignore b/org.eclipse.angularjs.core.neon/.gitignore new file mode 100644 index 0000000..934e0e0 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/.gitignore @@ -0,0 +1,2 @@ +/bin +/target diff --git a/org.eclipse.angularjs.core.neon/.project b/org.eclipse.angularjs.core.neon/.project new file mode 100644 index 0000000..ba681f8 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/.project @@ -0,0 +1,34 @@ + + + org.eclipse.angularjs.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.angularjs.core.neon/.settings/.gitignore b/org.eclipse.angularjs.core.neon/.settings/.gitignore new file mode 100644 index 0000000..9976760 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/.settings/.gitignore @@ -0,0 +1,2 @@ +/org.eclipse.core.resources.prefs +/org.eclipse.m2e.core.prefs diff --git a/org.eclipse.angularjs.core.neon/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.angularjs.core.neon/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..f287d53 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.eclipse.angularjs.core.neon/META-INF/MANIFEST.MF b/org.eclipse.angularjs.core.neon/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4230cef --- /dev/null +++ b/org.eclipse.angularjs.core.neon/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-Vendor: %pluginProvider +Bundle-Localization: plugin +Bundle-SymbolicName: org.eclipse.angularjs.core.neon;singleton:=true +Bundle-Version: 1.2.0.qualifier +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.wst.html.core;bundle-version="1.1.802", + org.eclipse.wst.sse.core, + org.eclipse.wst.xml.core, + org.eclipse.angularjs.core;bundle-version="1.2.0", + org.eclipse.core.resources, + tern.core +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Bundle-Activator: org.eclipse.angularjs.internal.core.AngularCoreNeonPlugin +Import-Package: com.eclipsesource.json;version="[0.9.4,0.9.5)" diff --git a/org.eclipse.angularjs.core.neon/build.properties b/org.eclipse.angularjs.core.neon/build.properties new file mode 100644 index 0000000..0dc34f7 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties diff --git a/org.eclipse.angularjs.core.neon/plugin.properties b/org.eclipse.angularjs.core.neon/plugin.properties new file mode 100644 index 0000000..33d10e8 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/plugin.properties @@ -0,0 +1,20 @@ +############################################################################### +# Copyright (c) 2013 Angelo Zerr and others. +# 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 - Initial API and implementation +############################################################################### +pluginProvider=Angelo ZERR +pluginName=Eclipse AngularJS Core + +angularNature=AngularJS Nature +angularContentType=AngularJS Source File + +HTMLAngularValidator.name=HTML Angular Syntax Validator + +# Protractor +ProtractorLaunchConfigurationDelegate.name=Protractor \ No newline at end of file diff --git a/org.eclipse.angularjs.core.neon/plugin.xml b/org.eclipse.angularjs.core.neon/plugin.xml new file mode 100644 index 0000000..f970438 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/plugin.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/org.eclipse.angularjs.core.neon/pom.xml b/org.eclipse.angularjs.core.neon/pom.xml new file mode 100644 index 0000000..320b772 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/pom.xml @@ -0,0 +1,10 @@ + + 4.0.0 + org.eclipse.angularjs.core.neon + eclipse-plugin + + fr.opensagres.angularjs + angularjs-eclipse + 1.2.0-SNAPSHOT + + diff --git a/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/AngularCoreNeonPlugin.java b/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/AngularCoreNeonPlugin.java new file mode 100644 index 0000000..641666d --- /dev/null +++ b/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/AngularCoreNeonPlugin.java @@ -0,0 +1,54 @@ +/** + * 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 - initial API and implementation + */ +package org.eclipse.angularjs.internal.core; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +/** + * Angular Core Plugin. + * + */ +public class AngularCoreNeonPlugin extends Plugin { + + public static final String PLUGIN_ID = "org.eclipse.angularjs.core.neon"; //$NON-NLS-1$ + + // The shared instance. + private static AngularCoreNeonPlugin plugin; + + /** + * The constructor. + */ + public AngularCoreNeonPlugin() { + super(); + plugin = this; + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static AngularCoreNeonPlugin getDefault() { + return plugin; + } +} diff --git a/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/Trace.java b/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/Trace.java new file mode 100644 index 0000000..4ed9457 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/Trace.java @@ -0,0 +1,101 @@ +/** + * 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 - initial API and implementation + */ +package org.eclipse.angularjs.internal.core; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +/** + * Helper class to route trace output. + */ +public class Trace { + public static final byte CONFIG = 0; + public static final byte INFO = 1; + public static final byte WARNING = 2; + public static final byte SEVERE = 3; + public static final byte FINEST = 4; + public static final byte FINER = 5; + public static final byte PERFORMANCE = 6; + public static final byte EXTENSION_POINT = 7; + + private static final String[] levelNames = new String[] { "CONFIG ", + "INFO ", "WARNING", "SEVERE ", "FINER ", "FINEST ", "PERF ", + "EXTENSION" }; + + private static final SimpleDateFormat sdf = new SimpleDateFormat( + "dd/MM/yy HH:mm.ss.SSS"); + + private static Set logged = new HashSet(); + + /** + * Trace constructor comment. + */ + private Trace() { + super(); + } + + /** + * Trace the given text. + * + * @param level + * a trace level + * @param s + * a message + */ + public static void trace(byte level, String s) { + trace(level, s, null); + } + + /** + * Trace the given message and exception. + * + * @param level + * a trace level + * @param s + * a message + * @param t + * a throwable + */ + public static void trace(byte level, String s, Throwable t) { + if (s == null) + return; + + if (level == SEVERE) { + if (!logged.contains(s)) { + AngularCoreNeonPlugin + .getDefault() + .getLog() + .log(new Status(IStatus.ERROR, + AngularCoreNeonPlugin.PLUGIN_ID, s, t)); + logged.add(s); + } + } + + if (!AngularCoreNeonPlugin.getDefault().isDebugging()) + return; + + StringBuilder sb = new StringBuilder(AngularCoreNeonPlugin.PLUGIN_ID); + sb.append(" "); + sb.append(levelNames[level]); + sb.append(" "); + sb.append(sdf.format(new Date())); + sb.append(" "); + sb.append(s); + System.out.println(sb.toString()); + if (t != null) + t.printStackTrace(); + } +} diff --git a/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/validation/AbstractHTMLAngularValidator.java b/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/validation/AbstractHTMLAngularValidator.java new file mode 100644 index 0000000..85d5176 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/validation/AbstractHTMLAngularValidator.java @@ -0,0 +1,52 @@ +package org.eclipse.angularjs.internal.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.jface.text.IDocument; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; +import org.eclipse.wst.sse.core.internal.validate.ValidationMessage; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; + +import tern.angular.modules.AngularModulesManager; +import tern.angular.modules.Directive; +import tern.angular.modules.Restriction; + +public abstract class AbstractHTMLAngularValidator { + + protected static final ValidationMessage IGNORE_VALIDATION_MESSAGE = new ValidationMessage("", 0, + ValidationMessage.IGNORE); + + private AngularProject angularProject; + + public void init(IStructuredDocument doc) { + this.angularProject = null; + if (doc instanceof IDocument) { + IFile file = DOMUtils.getFile((IDocument) doc); + IProject project = file.getProject(); + if (AngularProject.hasAngularNature(project)) { + try { + this.angularProject = AngularProject.getAngularProject(project); + } catch (CoreException e) { + Trace.trace(Trace.SEVERE, "Error while getting angular project", e); + } + } + } + } + + public final boolean canValidate(IDOMElement target) { + if (this.angularProject != null) { + return doCanValidate(target); + } + return false; + } + + protected Directive getDirective(String tagName, String attrName, Restriction restriction) { + return AngularModulesManager.getInstance().getDirective(angularProject, tagName, attrName, restriction); + } + + protected abstract boolean doCanValidate(IDOMElement target); +} diff --git a/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/validation/HTMLAngularAttributeValidator.java b/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/validation/HTMLAngularAttributeValidator.java new file mode 100644 index 0000000..f444ba7 --- /dev/null +++ b/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/validation/HTMLAngularAttributeValidator.java @@ -0,0 +1,53 @@ +package org.eclipse.angularjs.internal.core.validation; + +import org.eclipse.wst.html.core.internal.validate.Segment; +import org.eclipse.wst.html.core.validate.extension.CustomValidatorUtil; +import org.eclipse.wst.html.core.validate.extension.IHTMLCustomAttributeValidator; +import org.eclipse.wst.sse.core.internal.validate.ValidationMessage; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; + +import tern.angular.modules.Directive; +import tern.angular.modules.Restriction; + +public class HTMLAngularAttributeValidator extends AbstractHTMLAngularValidator + implements IHTMLCustomAttributeValidator { + + @Override + protected boolean doCanValidate(IDOMElement target) { + // any HTML element could have angular attribute: + //