├── .gitignore
├── .travis.yml
├── README.md
├── build.sh
├── bundles
├── com.eclipsesource.jshint.ui
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.jdt.core.prefs
│ │ ├── org.eclipse.jdt.ui.prefs
│ │ └── org.moreunit.prefs
│ ├── META-INF
│ │ └── MANIFEST.MF
│ ├── build.properties
│ ├── plugin.xml
│ ├── pom.xml
│ └── src
│ │ └── com
│ │ └── eclipsesource
│ │ └── jshint
│ │ └── ui
│ │ └── internal
│ │ ├── Activator.java
│ │ ├── builder
│ │ ├── BuilderUtil.java
│ │ ├── CommentsFilter.java
│ │ ├── ConfigLoader.java
│ │ ├── JSHintBuilder.java
│ │ ├── JSHintBuilderVisitor.java
│ │ ├── MarkerAdapter.java
│ │ └── MarkerHandler.java
│ │ ├── preferences
│ │ ├── EnablementPreferences.java
│ │ ├── JSHintPreferences.java
│ │ ├── OptionParserUtil.java
│ │ ├── OptionsPreferences.java
│ │ ├── PathEncoder.java
│ │ ├── PathPattern.java
│ │ ├── PathSegmentPattern.java
│ │ ├── PreferencesFactory.java
│ │ ├── ResourceSelector.java
│ │ └── ui
│ │ │ ├── AbstractPropertyPage.java
│ │ │ ├── BrowserSupport.java
│ │ │ ├── ButtonBar.java
│ │ │ ├── ConfigEditor.java
│ │ │ ├── ConfigPreferencePage.java
│ │ │ ├── ConfigPropertyPage.java
│ │ │ ├── IncludesView.java
│ │ │ ├── JSHintPreferencePage.java
│ │ │ ├── PathPatternDialog.java
│ │ │ └── ProjectPropertyPage.java
│ │ └── util
│ │ ├── FillLayoutConfig.java
│ │ ├── FormDataConfig.java
│ │ ├── FormLayoutConfig.java
│ │ ├── GridDataConfig.java
│ │ ├── GridLayoutConfig.java
│ │ ├── IOUtil.java
│ │ ├── JsonUtil.java
│ │ ├── LayoutUtil.java
│ │ ├── RowDataConfig.java
│ │ └── RowLayoutConfig.java
└── com.eclipsesource.jshint
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.core.runtime.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.jdt.ui.prefs
│ └── org.moreunit.prefs
│ ├── META-INF
│ └── MANIFEST.MF
│ ├── build.properties
│ ├── pom.xml
│ └── src
│ └── com
│ ├── eclipsesource
│ ├── jshint
│ │ ├── JSHint.java
│ │ ├── Problem.java
│ │ ├── ProblemHandler.java
│ │ ├── Text.java
│ │ └── internal
│ │ │ ├── JSHintRunner.java
│ │ │ └── ProblemImpl.java
│ └── json
│ │ ├── JsonArray.java
│ │ ├── JsonLiteral.java
│ │ ├── JsonNumber.java
│ │ ├── JsonObject.java
│ │ ├── JsonParser.java
│ │ ├── JsonString.java
│ │ ├── JsonValue.java
│ │ ├── JsonWriter.java
│ │ ├── ParseException.java
│ │ ├── PrettyPrintJsonWriter.java
│ │ └── README.txt
│ └── jshint
│ ├── jshint-2.5.6.js
│ ├── jshint-2.9.0.js
│ └── jshint-2.9.1.js
├── jshint-blue.png
├── jshint.target
├── pom.xml
├── releng
├── com.eclipsesource.jshint.feature
│ ├── .project
│ ├── build.properties
│ ├── epl-v10.html
│ ├── feature.properties
│ ├── feature.xml
│ └── pom.xml
└── com.eclipsesource.jshint.repository
│ ├── .project
│ ├── category.xml
│ └── pom.xml
└── tests
├── com.eclipsesource.jshint.test
├── .classpath
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.core.runtime.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.jdt.ui.prefs
│ └── org.eclipse.pde.core.prefs
├── JSHint Tests.launch
├── META-INF
│ └── MANIFEST.MF
├── build.properties
├── pom.xml
└── src
│ └── com
│ ├── eclipsesource
│ └── jshint
│ │ ├── JSHint_Compatibility_Test.java
│ │ ├── JSHint_Test.java
│ │ ├── Text_Test.java
│ │ └── internal
│ │ ├── JSHintRunner_Test.java
│ │ └── ProblemImpl_Test.java
│ └── jshint
│ ├── jshint-1.1.0.js
│ ├── jshint-2.1.10.js
│ ├── jshint-2.1.2.js
│ ├── jshint-2.4.3.js
│ ├── jshint-2.5.6.js
│ ├── jshint-2.6.3.js
│ ├── jshint-2.7.0.js
│ ├── jshint-2.8.0.js
│ ├── jshint-2.9.0.js
│ ├── jshint-2.9.1.js
│ ├── jshint-r03.js
│ ├── jshint-r04.js
│ ├── jshint-r05.js
│ ├── jshint-r06.js
│ ├── jshint-r07.js
│ ├── jshint-r08.js
│ ├── jshint-r09.js
│ ├── jshint-r10.js
│ ├── jshint-r11.js
│ └── jshint-r12.js
└── com.eclipsesource.jshint.ui.test
├── .classpath
├── .project
├── .settings
├── org.eclipse.jdt.core.prefs
├── org.eclipse.jdt.ui.prefs
└── org.eclipse.pde.core.prefs
├── META-INF
└── MANIFEST.MF
├── build.properties
├── pom.xml
└── src
├── com
└── eclipsesource
│ └── jshint
│ └── ui
│ ├── internal
│ ├── builder
│ │ ├── BuilderUtil_Test.java
│ │ ├── CommentsFilter_Test.java
│ │ ├── ConfigLoader_Test.java
│ │ ├── JSHintBuilderVisitor_Test.java
│ │ ├── MarkerAdapter_Test.java
│ │ └── MarkerHandler_Test.java
│ ├── preferences
│ │ ├── EnablementPreferences_Test.java
│ │ ├── IncludesView_Test.java
│ │ ├── JSHintPreferences_Test.java
│ │ ├── OptionParserUtil_Test.java
│ │ ├── OptionsPreferences_Test.java
│ │ ├── PathEncoder_Test.java
│ │ ├── PathPattern_Test.java
│ │ ├── PathSegmentPattern_Test.java
│ │ ├── PreferencesFactory_Test.java
│ │ ├── PreferencesMock.java
│ │ ├── ProjectPreferences_Test.java
│ │ ├── ResourceSelector_Test.java
│ │ └── ui
│ │ │ ├── BrowserSupport_Test.java
│ │ │ ├── ConfigEditor_Test.java
│ │ │ ├── ConfigPreferencePage_Test.java
│ │ │ ├── ConfigPropertyPage_Test.java
│ │ │ └── PathPatternDialog_Test.java
│ └── util
│ │ ├── JsonUtil_Test.java
│ │ └── LayoutUtil_Test.java
│ └── test
│ ├── TestUtil.java
│ └── jshint-0.9.prefs
└── log4j.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | target/
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | before_install:
3 | - "export DISPLAY=:99.0"
4 | - "sh -e /etc/init.d/xvfb start"
5 | env: DISPLAY=:99
6 | script: mvn integration-test -B
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | JSHint integration for the Eclipse IDE
2 | ======================================
3 |
4 | 
5 |
7 |
8 |
9 |
10 | [](http://travis-ci.org/eclipsesource/jshint-eclipse)
11 |
12 | [JSHint](http://www.jshint.com/about/) is a popular, community-driven tool to detect
13 | errors and potential problems in JavaScript code. This project integrates JSHint into
14 | the Eclipse IDE. It automatically validates \*.js files and adds warning markers for
15 | every problem found by JSHint.
16 |
17 | Please see the [project page](http://github.eclipsesource.com/jshint-eclipse/)
18 | for details on features and usage. ([Published on Eclipse Marketplace]())
19 |
20 | Requirements
21 | ------------
22 |
23 | Eclipse 3.6 (Helios) or newer.
24 |
25 | JSHint included
26 | ---------------
27 |
28 | A [recent version](https://github.com/eclipsesource/jshint-eclipse/tree/master/bundles/com.eclipsesource.jshint/src/com/jshint) of JSHint is included.
29 |
30 | Installation
31 | ------------
32 |
33 | Install from this Eclipse update site: http://github.eclipsesource.com/jshint-eclipse/updates/
34 |
35 | License
36 | -------
37 |
38 | The code is published under the terms of the [Eclipse Public License, version 1.0](http://www.eclipse.org/legal/epl-v10.html).
39 |
40 | Includes code from [jshint](https://github.com/jshint/jshint/), which is published under the terms of the MIT license with the addition "The Software shall be used for Good, not Evil."
41 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | MVN=$HOME/bin/mvn
4 | BUILD_TARGET_DIR=/tmp/jshint-eclipse
5 |
6 | # path that are relevant for effective commit
7 | includePaths="bundles/com.eclipsesource.jshint bundles/com.eclipsesource.jshint.ui releng/com.eclipsesource.jshint.feature"
8 |
9 | # make sure we're in the git repository root
10 | GIT_ROOT="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
11 | cd $GIT_ROOT
12 | if [ ! -d ".git" ]; then
13 | echo "git root directory not found"
14 | exit 1
15 | fi
16 |
17 | # determine last commit
18 | stat="$(git status -s)"
19 | if [ -z "$stat" ]; then
20 | echo "Find latest commit date in paths:"
21 | for path in $includePaths; do
22 | echo "* $path"
23 | done
24 | commit_hash=$(git log -1 --format='%h' -- $includePaths)
25 | commit_subject=$(git log -1 --format='%s' -- $includePaths)
26 | commit_date=$(date -u -d "$(git log -1 --format='%ci' -- $includePaths)" +"%Y%m%d-%H%M")
27 | echo "-> $commit_date $commit_subject [$commit_hash]"
28 | else
29 | echo "Uncommitted changes, run 'git status'"
30 | fi
31 |
32 | $MVN clean install || exit 1
33 |
34 | if [ -n "$commit_hash" ]; then
35 | # copy resulting repository
36 | feature_version=`ls -1 releng/com.eclipsesource.jshint.repository/target/repository/features/*.jar | sed -e 's/.*_\([0-9\.-]*\)\.jar/\1/'`
37 | if [ -z "$feature_version" ]; then
38 | echo "Could not determine feature version"
39 | exit 1
40 | fi
41 | version="$feature_version-$commit_hash"
42 | echo "Version: $version"
43 |
44 | mkdir -p $BUILD_TARGET_DIR
45 | rsync -av releng/com.eclipsesource.jshint.repository/target/repository/ $BUILD_TARGET_DIR/jshint-eclipse-$version
46 | cp releng/com.eclipsesource.jshint.repository/target/com.eclipsesource.jshint.repository-*.zip $BUILD_TARGET_DIR/jshint-eclipse-$version.zip
47 | fi
48 |
49 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.eclipsesource.jshint.ui
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.pde.ManifestBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.pde.SchemaBuilder
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.pde.PluginNature
26 | org.eclipse.jdt.core.javanature
27 |
28 |
29 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.5
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.5
12 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.ui.javadoc=true
3 | org.eclipse.jdt.ui.text.custom_code_templates=/*******************************************************************************\n * Copyright (c) ${year} EclipseSource.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * ${user} - initial implementation and API\n ******************************************************************************/${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}\n\n\n\n// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();// ${todo} Auto-generated method stub\n${body_statement}${body_statement}\n// ${todo} Auto-generated constructor stubreturn ${field};${field} \= ${param};
4 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/.settings/org.moreunit.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.moreunit.preferences.version=2
3 | org.moreunit.testClassNameTemplate=${srcFile}_Test
4 | org.moreunit.unitsourcefolder=com.eclipsesource.jshint.ui\:src\:com.eclipsesource.jshint.ui.test\:src
5 | org.moreunit.useprojectsettings=true
6 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Bundle-ManifestVersion: 2
3 | Bundle-Name: JSHint Eclipse Integration
4 | Bundle-SymbolicName: com.eclipsesource.jshint.ui;singleton:=true
5 | Bundle-Version: 0.10.1.qualifier
6 | Bundle-Activator: com.eclipsesource.jshint.ui.internal.Activator
7 | Bundle-Vendor: EclipseSource
8 | Require-Bundle: org.eclipse.ui;bundle-version="3.6.0",
9 | org.eclipse.core.runtime;bundle-version="3.6.0",
10 | org.eclipse.core.resources;bundle-version="3.6.0"
11 | Bundle-RequiredExecutionEnvironment: J2SE-1.5
12 | Bundle-ActivationPolicy: lazy
13 | Import-Package: com.eclipsesource.jshint;version="[0.10.1,1.0.0)",
14 | com.eclipsesource.json;version="[0.9.0.jshint,0.9.0.jshint]"
15 | Export-Package: com.eclipsesource.jshint.ui.internal;version="0.10.1";x-internal:=true,
16 | com.eclipsesource.jshint.ui.internal.builder;version="0.10.1";x-internal:=true,
17 | com.eclipsesource.jshint.ui.internal.preferences;version="0.10.1";x-internal:=true,
18 | com.eclipsesource.jshint.ui.internal.preferences.ui;version="0.10.1";x-internal:=true
19 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/build.properties:
--------------------------------------------------------------------------------
1 | source.. = src/
2 | output.. = bin/
3 | bin.includes = .,\
4 | META-INF/,\
5 | plugin.xml
6 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
11 |
12 |
14 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
28 |
30 |
31 |
32 |
33 |
34 |
35 |
37 |
41 |
42 |
47 |
48 |
49 |
53 |
58 |
60 |
61 |
62 |
63 |
67 |
69 |
70 |
72 |
73 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.eclipsesource.jshint
8 | com.eclipsesource.jshint.ui
9 | 0.10.1-SNAPSHOT
10 | eclipse-plugin
11 |
12 |
13 | com.eclipsesource.jshint
14 | com.eclipsesource.jshint.build
15 | 0.10.1-SNAPSHOT
16 | ../../pom.xml
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/Activator.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal;
12 |
13 | import org.eclipse.core.runtime.IStatus;
14 | import org.eclipse.core.runtime.Status;
15 | import org.eclipse.jface.resource.ImageDescriptor;
16 | import org.eclipse.ui.plugin.AbstractUIPlugin;
17 | import org.eclipse.ui.statushandlers.StatusManager;
18 | import org.osgi.framework.BundleContext;
19 |
20 |
21 | public class Activator extends AbstractUIPlugin {
22 |
23 | public static final String PLUGIN_ID = "com.eclipsesource.jshint.ui"; //$NON-NLS-1$
24 | private static Activator instance;
25 |
26 | @Override
27 | public void start( BundleContext context ) throws Exception {
28 | super.start( context );
29 | instance = this;
30 | }
31 |
32 | @Override
33 | public void stop( BundleContext context ) throws Exception {
34 | instance = null;
35 | super.stop( context );
36 | }
37 |
38 | /**
39 | * Returns the shared instance
40 | *
41 | * @return the shared instance
42 | */
43 | public static Activator getDefault() {
44 | return instance;
45 | }
46 |
47 | /**
48 | * Returns an image descriptor for the image file at the given plug-in
49 | * relative path
50 | *
51 | * @param path the path
52 | * @return the image descriptor
53 | */
54 | public static ImageDescriptor getImageDescriptor( String path ) {
55 | return imageDescriptorFromPlugin( PLUGIN_ID, path );
56 | }
57 |
58 | public static void logError( String message, Exception exception ) {
59 | Status status = new Status( IStatus.ERROR, PLUGIN_ID, message, exception );
60 | StatusManager.getManager().handle( status );
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/builder/BuilderUtil.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import org.eclipse.core.resources.ICommand;
17 | import org.eclipse.core.resources.IProject;
18 | import org.eclipse.core.resources.IProjectDescription;
19 | import org.eclipse.core.resources.IncrementalProjectBuilder;
20 | import org.eclipse.core.runtime.CoreException;
21 |
22 |
23 | public class BuilderUtil {
24 |
25 | private BuilderUtil() {
26 | // prevent instantiation
27 | }
28 |
29 | public static void triggerClean( IProject project, String builderName ) throws CoreException {
30 | project.build( IncrementalProjectBuilder.CLEAN_BUILD, builderName, null, null );
31 | }
32 |
33 | public static void triggerBuild( IProject project, String builderName ) throws CoreException {
34 | project.build( IncrementalProjectBuilder.FULL_BUILD, builderName, null, null );
35 | }
36 |
37 | public static boolean addBuilderToProject( IProject project, String builderId )
38 | throws CoreException
39 | {
40 | IProjectDescription description = project.getDescription();
41 | if( !containsBuildCommand( description, builderId ) ) {
42 | addBuildCommand( description, builderId );
43 | project.setDescription( description, null );
44 | return true;
45 | }
46 | return false;
47 | }
48 |
49 | public static boolean removeBuilderFromProject( IProject project, String builderId )
50 | throws CoreException
51 | {
52 | IProjectDescription description = project.getDescription();
53 | if( containsBuildCommand( description, builderId ) ) {
54 | removeBuildCommands( description, builderId );
55 | project.setDescription( description, null );
56 | return true;
57 | }
58 | return false;
59 | }
60 |
61 | private static boolean containsBuildCommand( IProjectDescription description, String builderId ) {
62 | for( ICommand command : description.getBuildSpec() ) {
63 | if( command.getBuilderName().equals( builderId ) ) {
64 | return true;
65 | }
66 | }
67 | return false;
68 | }
69 |
70 | private static void addBuildCommand( IProjectDescription description, String builderId ) {
71 | ICommand[] oldCommands = description.getBuildSpec();
72 | ICommand[] newCommands = new ICommand[oldCommands.length + 1];
73 | System.arraycopy( oldCommands, 0, newCommands, 0, oldCommands.length );
74 | newCommands[newCommands.length - 1] = createBuildCommand( description, builderId );
75 | description.setBuildSpec( newCommands );
76 | }
77 |
78 | private static void removeBuildCommands( IProjectDescription description, String builderId ) {
79 | ICommand[] oldCommands = description.getBuildSpec();
80 | List list = new ArrayList();
81 | for( ICommand command : oldCommands ) {
82 | if( !command.getBuilderName().equals( builderId ) ) {
83 | list.add( command );
84 | }
85 | }
86 | ICommand[] newCommands = new ICommand[list.size()];
87 | list.toArray( newCommands );
88 | description.setBuildSpec( newCommands );
89 | }
90 |
91 | private static ICommand createBuildCommand( IProjectDescription description, String builderId ) {
92 | ICommand command = description.newCommand();
93 | command.setBuilderName( builderId );
94 | return command;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/builder/CommentsFilter.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013, 2014 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 |
14 | public class CommentsFilter {
15 |
16 | private final char[] chars;
17 | private char lastCh;
18 | private boolean inLineComment;
19 | private boolean inBlockComment;
20 |
21 | public CommentsFilter( String input ) {
22 | this.chars = input.toCharArray();
23 | process();
24 | }
25 |
26 | private void process() {
27 | for( int i = 0; i < chars.length; i++ ) {
28 | char ch = chars[i];
29 | if( inLineComment ) {
30 | if( ch == '\n' || ch == '\r' ) {
31 | inLineComment = false;
32 | } else {
33 | chars[i] = ' ';
34 | }
35 | } else if( inBlockComment ) {
36 | if( lastCh == '*' && ch == '/' ) {
37 | inBlockComment = false;
38 | }
39 | chars[i] = chars[i] == '\n' ? '\n' : ' ';
40 | } else if( lastCh == '/' && ch == '/' ) {
41 | inLineComment = true;
42 | chars[i-1] = ' ';
43 | chars[i] = ' ';
44 | } else if( lastCh == '/' && ch == '*' ) {
45 | inBlockComment = true;
46 | chars[i-1] = ' ';
47 | chars[i] = ' ';
48 | }
49 | lastCh = ch;
50 | }
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return new String( chars );
56 | }
57 |
58 | public static String filterComments( String input ) {
59 | return new CommentsFilter( input ).toString();
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/builder/ConfigLoader.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013, 2014 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 | import java.io.IOException;
14 |
15 | import org.eclipse.core.resources.IFile;
16 | import org.eclipse.core.resources.IProject;
17 | import org.eclipse.core.runtime.CoreException;
18 | import org.osgi.service.prefs.Preferences;
19 |
20 | import com.eclipsesource.jshint.ui.internal.Activator;
21 | import com.eclipsesource.jshint.ui.internal.preferences.OptionsPreferences;
22 | import com.eclipsesource.jshint.ui.internal.preferences.PreferencesFactory;
23 | import com.eclipsesource.json.JsonObject;
24 |
25 | import static com.eclipsesource.jshint.ui.internal.builder.CommentsFilter.filterComments;
26 | import static com.eclipsesource.jshint.ui.internal.util.IOUtil.readFileUtf8;
27 |
28 |
29 | public class ConfigLoader {
30 |
31 | private final IProject project;
32 |
33 | public ConfigLoader( IProject project ) {
34 | this.project = project;
35 | }
36 |
37 | public JsonObject getConfiguration() {
38 | Preferences projectNode = PreferencesFactory.getProjectPreferences( project );
39 | OptionsPreferences projectPreferences = new OptionsPreferences( projectNode );
40 | if( projectPreferences.getProjectSpecific() ) {
41 | return getProjectConfig( projectPreferences );
42 | }
43 | return getWorkspaceConfig();
44 | }
45 |
46 | private JsonObject getProjectConfig( OptionsPreferences projectPrefs ) {
47 | try {
48 | String json = getProjectConfigJson( projectPrefs );
49 | return JsonObject.readFrom( filterComments( json ) );
50 | } catch( Exception exception ) {
51 | String message = "Failed to read jshint configuration for project " + project.getName();
52 | Activator.logError( message, exception );
53 | return new JsonObject();
54 | }
55 | }
56 |
57 | private String getProjectConfigJson( OptionsPreferences projectPrefs ) throws CoreException,
58 | IOException
59 | {
60 | IFile configFile = getProjectConfigFile();
61 | if( !configFile.exists() ) {
62 | // compatibility
63 | return projectPrefs.getConfig();
64 | }
65 | return readFileUtf8( configFile );
66 | }
67 |
68 | private IFile getProjectConfigFile() {
69 | return project.getFile( ".jshintrc" );
70 | }
71 |
72 | private static JsonObject getWorkspaceConfig() {
73 | try {
74 | String json = getWorkspaceConfigJson();
75 | return JsonObject.readFrom( filterComments( json ) );
76 | } catch( Exception exception ) {
77 | String message = "Failed to read jshint configuration from workspace preferences";
78 | Activator.logError( message, exception );
79 | return new JsonObject();
80 | }
81 | }
82 |
83 | private static String getWorkspaceConfigJson() {
84 | Preferences workspaceNode = PreferencesFactory.getWorkspacePreferences();
85 | return new OptionsPreferences( workspaceNode ).getConfig();
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/builder/JSHintBuilder.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 | import java.util.Map;
14 |
15 | import org.eclipse.core.resources.IProject;
16 | import org.eclipse.core.resources.IResourceDelta;
17 | import org.eclipse.core.resources.IncrementalProjectBuilder;
18 | import org.eclipse.core.runtime.CoreException;
19 | import org.eclipse.core.runtime.IProgressMonitor;
20 |
21 | import com.eclipsesource.jshint.ui.internal.Activator;
22 |
23 |
24 | public class JSHintBuilder extends IncrementalProjectBuilder {
25 |
26 | public static final String ID = Activator.PLUGIN_ID + ".builder";
27 | public static final String ID_OLD = "com.eclipsesource.jshint.builder";
28 |
29 | @Override
30 | protected IProject[] build( int kind, Map args, IProgressMonitor monitor )
31 | throws CoreException
32 | {
33 | if( kind == IncrementalProjectBuilder.FULL_BUILD ) {
34 | fullBuild( monitor );
35 | } else {
36 | IResourceDelta delta = getDelta( getProject() );
37 | if( delta == null ) {
38 | fullBuild( monitor );
39 | } else {
40 | incrementalBuild( delta, monitor );
41 | }
42 | }
43 | return null;
44 | }
45 |
46 | @Override
47 | protected void clean( IProgressMonitor monitor ) throws CoreException {
48 | new MarkerAdapter( getProject() ).removeMarkers();
49 | }
50 |
51 | private void fullBuild( IProgressMonitor monitor ) throws CoreException {
52 | IProject project = getProject();
53 | getProject().accept( new JSHintBuilderVisitor( project, monitor ) );
54 | }
55 |
56 | private void incrementalBuild( IResourceDelta delta, IProgressMonitor monitor )
57 | throws CoreException
58 | {
59 | IProject project = getProject();
60 | delta.accept( new JSHintBuilderVisitor( project, monitor ) );
61 | }
62 |
63 | static class CoreExceptionWrapper extends RuntimeException {
64 |
65 | private static final long serialVersionUID = 2267576736168605043L;
66 |
67 | public CoreExceptionWrapper( CoreException wrapped ) {
68 | super( wrapped );
69 | }
70 |
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/builder/MarkerAdapter.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 | import org.eclipse.core.resources.IMarker;
14 | import org.eclipse.core.resources.IResource;
15 | import org.eclipse.core.runtime.CoreException;
16 |
17 |
18 | public class MarkerAdapter {
19 |
20 | private static final String TYPE_PROBLEM = "com.eclipsesource.jshint.ui.problemmarker";
21 | private static final String TYPE_PROBLEM_OLD = "com.eclipsesource.jshint.problemmarker";
22 | private final IResource resource;
23 |
24 | public MarkerAdapter( IResource resource ) {
25 | this.resource = resource;
26 | }
27 |
28 | public void removeMarkers() throws CoreException {
29 | resource.deleteMarkers( TYPE_PROBLEM, true, IResource.DEPTH_INFINITE );
30 | resource.deleteMarkers( TYPE_PROBLEM_OLD, true, IResource.DEPTH_INFINITE );
31 | }
32 |
33 | public void createWarning( int line, int start, int end, String message ) throws CoreException {
34 | createMarker( line, start, end, message, IMarker.SEVERITY_WARNING );
35 | }
36 |
37 | public void createError( int line, int start, int end, String message ) throws CoreException {
38 | createMarker( line, start, end, message, IMarker.SEVERITY_ERROR );
39 | }
40 |
41 | private void createMarker( int line, int start, int end, String message, int severity )
42 | throws CoreException
43 | {
44 | if( message == null ) {
45 | throw new NullPointerException( "message is null" );
46 | }
47 | IMarker marker = resource.createMarker( TYPE_PROBLEM );
48 | marker.setAttribute( IMarker.SEVERITY, severity );
49 | marker.setAttribute( IMarker.MESSAGE, message );
50 | if( line >= 1 ) {
51 | // needed to display line number in problems view location column
52 | marker.setAttribute( IMarker.LINE_NUMBER, line );
53 | }
54 | if( start >= 0 ) {
55 | marker.setAttribute( IMarker.CHAR_START, new Integer( start ) );
56 | marker.setAttribute( IMarker.CHAR_END, new Integer( end >= start ? end : start ) );
57 | }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/builder/MarkerHandler.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 | import org.eclipse.core.runtime.CoreException;
14 |
15 | import com.eclipsesource.jshint.Problem;
16 | import com.eclipsesource.jshint.ProblemHandler;
17 | import com.eclipsesource.jshint.Text;
18 | import com.eclipsesource.jshint.ui.internal.builder.JSHintBuilder.CoreExceptionWrapper;
19 | import com.eclipsesource.jshint.ui.internal.preferences.JSHintPreferences;
20 |
21 |
22 | final class MarkerHandler implements ProblemHandler {
23 |
24 | private final MarkerAdapter markerAdapter;
25 | private final Text code;
26 | private final boolean enableErrorMarkers;
27 |
28 | MarkerHandler( MarkerAdapter markerAdapter, Text code ) {
29 | this.markerAdapter = markerAdapter;
30 | this.code = code;
31 | enableErrorMarkers = new JSHintPreferences().getEnableErrorMarkers();
32 | }
33 |
34 | public void handleProblem( Problem problem ) {
35 | int line = problem.getLine();
36 | int character = problem.getCharacter();
37 | if( isValidLine( line ) ) {
38 | int offset = -1;
39 | if( isValidCharacter( line, character ) ) {
40 | offset = code.getLineOffset( line - 1 ) + character;
41 | }
42 | createMarker( line, offset, problem.getMessage(), problem.isError() );
43 | } else {
44 | createMarker( -1, -1, problem.getMessage(), problem.isError() );
45 | }
46 | }
47 |
48 | private void createMarker( int line, int character, String message, boolean isError )
49 | throws CoreExceptionWrapper
50 | {
51 | try {
52 | if( enableErrorMarkers && isError ) {
53 | markerAdapter.createError( line, character, character, message );
54 | } else {
55 | markerAdapter.createWarning( line, character, character, message );
56 | }
57 | } catch( CoreException ce ) {
58 | throw new CoreExceptionWrapper( ce );
59 | }
60 | }
61 |
62 | private boolean isValidLine( int line ) {
63 | return line >= 1 && line <= code.getLineCount();
64 | }
65 |
66 | private boolean isValidCharacter( int line, int character ) {
67 | return character >= 0 && character < code.getLineLength( line - 1 );
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/EnablementPreferences.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import java.util.List;
14 |
15 | import org.eclipse.core.resources.IResource;
16 | import org.osgi.service.prefs.Preferences;
17 |
18 |
19 | public class EnablementPreferences {
20 |
21 | private static final String KEY_EXCLUDED = "excluded";
22 | private static final String KEY_INCLUDED = "included";
23 | private static final String DEF_EXCLUDED = "";
24 | private static final String DEF_INCLUDED = "";
25 |
26 | private final Preferences node;
27 | private boolean changed;
28 |
29 | public EnablementPreferences( Preferences node ) {
30 | this.node = node;
31 | changed = false;
32 | }
33 |
34 | public void setIncludePatterns( List patterns ) {
35 | String value = PathEncoder.encodePaths( patterns );
36 | if( !value.equals( node.get( KEY_INCLUDED, DEF_INCLUDED ) ) ) {
37 | if( DEF_INCLUDED.equals( value ) ) {
38 | node.remove( KEY_INCLUDED );
39 | } else {
40 | node.put( KEY_INCLUDED, value );
41 | }
42 | changed = true;
43 | }
44 | }
45 |
46 | public List getIncludePatterns() {
47 | String value = node.get( KEY_INCLUDED, DEF_INCLUDED );
48 | return PathEncoder.decodePaths( value );
49 | }
50 |
51 | public void setExcludePatterns( List patterns ) {
52 | String value = PathEncoder.encodePaths( patterns );
53 | if( !value.equals( node.get( KEY_EXCLUDED, DEF_EXCLUDED ) ) ) {
54 | if( DEF_EXCLUDED.equals( value ) ) {
55 | node.remove( KEY_EXCLUDED );
56 | } else {
57 | node.put( KEY_EXCLUDED, value );
58 | }
59 | changed = true;
60 | }
61 | }
62 |
63 | public List getExcludePatterns() {
64 | String value = node.get( KEY_EXCLUDED, DEF_EXCLUDED );
65 | return PathEncoder.decodePaths( value );
66 | }
67 |
68 | public boolean hasChanged() {
69 | return changed;
70 | }
71 |
72 | public void clearChanged() {
73 | changed = false;
74 | }
75 |
76 | public static String getResourcePath( IResource resource ) {
77 | return resource.getProjectRelativePath().toPortableString();
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/OptionParserUtil.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import com.eclipsesource.json.JsonObject;
17 | import com.eclipsesource.json.JsonValue;
18 | import com.eclipsesource.json.ParseException;
19 |
20 |
21 | public class OptionParserUtil {
22 |
23 | private OptionParserUtil() {
24 | // prevent instantiation
25 | }
26 |
27 | public static JsonObject createConfiguration( String options, String globals ) {
28 | JsonObject configuration = new JsonObject();
29 | for( Entry entry : parseOptionString( options ) ) {
30 | configuration.add( entry.name, entry.value );
31 | }
32 | JsonObject globalsObject = new JsonObject();
33 | for( Entry entry : parseOptionString( globals ) ) {
34 | globalsObject.add( entry.name, entry.value == JsonValue.TRUE );
35 | }
36 | if( !globalsObject.isEmpty() ) {
37 | configuration.add( "globals", globalsObject );
38 | }
39 | return configuration;
40 | }
41 |
42 | static List parseOptionString( String input ) {
43 | List result = new ArrayList();
44 | String[] elements = input.split( "," );
45 | for( String element : elements ) {
46 | element = parseOptionElement( result, element.trim() );
47 | }
48 | return result;
49 | }
50 |
51 | private static String parseOptionElement( List result, String element ) {
52 | if( element.length() > 0 ) {
53 | String[] parts = element.split( ":", 2 );
54 | String key = parts[ 0 ].trim();
55 | if( key.length() > 0 ) {
56 | if( parts.length != 2 ) {
57 | // TODO handle error
58 | } else {
59 | try {
60 | JsonValue value = JsonValue.readFrom( parts[ 1 ].trim() );
61 | result.add( new Entry( key, value ) );
62 | } catch( ParseException exception ) {
63 | // TODO handle error
64 | }
65 | }
66 | }
67 | }
68 | return element;
69 | }
70 |
71 | static class Entry {
72 | public final String name;
73 | public final JsonValue value;
74 | public Entry( String name, JsonValue value ) {
75 | this.name = name;
76 | this.value = value;
77 | }
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/OptionsPreferences.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import org.osgi.service.prefs.Preferences;
14 |
15 | import static com.eclipsesource.jshint.ui.internal.util.JsonUtil.prettyPrint;
16 |
17 |
18 | public class OptionsPreferences {
19 |
20 | private static final String KEY_PROJ_SPECIFIC = "projectSpecificOptions";
21 | private static final String KEY_GLOBALS = "globals";
22 | private static final String KEY_OPTIONS = "options";
23 | private static final String KEY_CONFIG = "config";
24 |
25 | public static final boolean DEFAULT_PROJ_SPECIFIC = false;
26 | // TODO set sensible default config
27 | public static final String DEFAULT_CONFIG = "{\n \n}";
28 |
29 | private final Preferences node;
30 | private boolean changed;
31 |
32 | public OptionsPreferences( Preferences node ) {
33 | this.node = node;
34 | }
35 |
36 | public Preferences getNode() {
37 | return node;
38 | }
39 |
40 | public boolean getProjectSpecific() {
41 | return node.getBoolean( KEY_PROJ_SPECIFIC, DEFAULT_PROJ_SPECIFIC );
42 | }
43 |
44 | public void setProjectSpecific( boolean value ) {
45 | if( value != node.getBoolean( KEY_PROJ_SPECIFIC, DEFAULT_PROJ_SPECIFIC ) ) {
46 | if( value == DEFAULT_PROJ_SPECIFIC ) {
47 | node.remove( KEY_PROJ_SPECIFIC );
48 | } else {
49 | node.putBoolean( KEY_PROJ_SPECIFIC, value );
50 | }
51 | changed = true;
52 | }
53 | }
54 |
55 | public String getConfig() {
56 | String config = node.get( KEY_CONFIG, null );
57 | return config != null ? config : getOldConfig();
58 | }
59 |
60 | private String getOldConfig() {
61 | String options = node.get( KEY_OPTIONS, "" );
62 | String globals = node.get( KEY_GLOBALS, "" );
63 | return prettyPrint( OptionParserUtil.createConfiguration( options, globals ) );
64 | }
65 |
66 | public void setConfig( String value ) {
67 | if( !value.equals( node.get( KEY_CONFIG, null ) ) ) {
68 | node.put( KEY_CONFIG, value );
69 | changed = true;
70 | }
71 | }
72 |
73 | public boolean hasChanged() {
74 | return changed;
75 | }
76 |
77 | public void clearChanged() {
78 | changed = false;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/PathEncoder.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 |
17 | public class PathEncoder {
18 |
19 | public static String encodePaths( List paths ) {
20 | StringBuilder builder = new StringBuilder();
21 | for( String path : paths ) {
22 | if( path.length() > 0 ) {
23 | if( builder.length() > 0 ) {
24 | builder.append( ':' );
25 | }
26 | builder.append( path );
27 | }
28 | }
29 | return builder.toString();
30 | }
31 |
32 | public static ArrayList decodePaths( String encodedPaths ) {
33 | ArrayList list = new ArrayList();
34 | for( String path : encodedPaths.split( ":" ) ) {
35 | if( path.length() > 0 ) {
36 | list.add( path );
37 | }
38 | }
39 | return list;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/PathSegmentPattern.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 |
14 | public class PathSegmentPattern {
15 |
16 | public static final PathSegmentPattern ALL = new PathSegmentPattern( "*" );
17 | public static final PathSegmentPattern NONE = new PathSegmentPattern( "" );
18 | public static final PathSegmentPattern ANY_NUMBER = new PathSegmentPattern( "" );
19 |
20 | private final String expression;
21 |
22 | private final Matcher matcher;
23 |
24 | private PathSegmentPattern( String expression ) {
25 | this.expression = checkExpression( expression );
26 | matcher = new Matcher( expression );
27 | }
28 |
29 | public static PathSegmentPattern create( String expression ) {
30 | if( expression == null ) {
31 | throw new NullPointerException( "parameter is null" );
32 | }
33 | if( "".equals( expression ) ) {
34 | return NONE;
35 | }
36 | if( "*".equals( expression ) ) {
37 | return ALL;
38 | }
39 | return new PathSegmentPattern( expression );
40 | }
41 |
42 | public boolean matches( String string ) {
43 | if( this == ALL || this == ANY_NUMBER ) {
44 | return true;
45 | }
46 | if( this == NONE ) {
47 | return false;
48 | }
49 | return matcher.match( string );
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | if( this == ANY_NUMBER ) {
55 | return "//";
56 | }
57 | if( this == NONE ) {
58 | return "NONE";
59 | }
60 | return expression;
61 | }
62 |
63 | private static String checkExpression( String expression ) {
64 | int length = expression.length();
65 | for( int i = 0; i < length; i++ ) {
66 | char ch = expression.charAt( i );
67 | if( isIllegalCharacter( ch ) ) {
68 | throw new IllegalArgumentException( "Illegal character in expression: '" + ch + "'" );
69 | }
70 | }
71 | return expression;
72 | }
73 |
74 | private static boolean isIllegalCharacter( char ch ) {
75 | return ch == '!'
76 | || ch == '+'
77 | || ch == ':'
78 | || ch == '|'
79 | || ch == '('
80 | || ch == ')'
81 | || ch == '['
82 | || ch == ']'
83 | || ch == '}'
84 | || ch == '{'
85 | || ch == '/'
86 | || ch == '\\';
87 | }
88 |
89 | private static class Matcher {
90 |
91 | private final char[] pattern;
92 |
93 | public Matcher( String pattern ) {
94 | this.pattern = pattern.toCharArray();
95 | }
96 |
97 | public boolean match( String input ) {
98 | return match( 0, 0, input.toCharArray() );
99 | }
100 |
101 | private boolean match( int patternPos, int inputPos, char[] input ) {
102 | if( patternPos == pattern.length ) {
103 | return inputPos == input.length;
104 | }
105 | if( inputPos == input.length ) {
106 | if( pattern[ patternPos ] == '*' ) {
107 | return match( patternPos + 1, inputPos, input );
108 | }
109 | return false;
110 | }
111 | if( pattern[ patternPos ] == '*' ) {
112 | int nextInputPos = inputPos;
113 | while( nextInputPos <= input.length ) {
114 | if( match( patternPos + 1, nextInputPos, input ) ) {
115 | return true;
116 | }
117 | nextInputPos++;
118 | }
119 | return false;
120 | } else if( pattern[ patternPos ] == '?' ) {
121 | return match( patternPos + 1, inputPos + 1, input );
122 | } else if( pattern[ patternPos ] == input[ inputPos ] ) {
123 | return match( patternPos + 1, inputPos + 1, input );
124 | }
125 | return false;
126 | }
127 |
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/PreferencesFactory.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import org.eclipse.core.resources.IProject;
14 | import org.eclipse.core.resources.ProjectScope;
15 | import org.eclipse.core.runtime.preferences.InstanceScope;
16 | import org.osgi.service.prefs.Preferences;
17 |
18 | import com.eclipsesource.jshint.ui.internal.Activator;
19 |
20 |
21 | public class PreferencesFactory {
22 |
23 | public static Preferences getProjectPreferences( IProject project ) {
24 | return new ProjectScope( project ).getNode( Activator.PLUGIN_ID );
25 | }
26 |
27 | @SuppressWarnings( "deprecation" )
28 | public static Preferences getWorkspacePreferences() {
29 | // InstanceScope.INSTANCE does not yet exist in Eclipse 3.6
30 | return new InstanceScope().getNode( Activator.PLUGIN_ID );
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/ResourceSelector.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import org.eclipse.core.resources.IProject;
17 | import org.eclipse.core.resources.IResource;
18 | import org.osgi.service.prefs.Preferences;
19 |
20 |
21 | public class ResourceSelector {
22 |
23 | private final List includePatterns;
24 | private final List excludePatterns;
25 |
26 | public ResourceSelector( IProject project ) {
27 | Preferences preferenceNode = PreferencesFactory.getProjectPreferences( project );
28 | EnablementPreferences preferences = new EnablementPreferences( preferenceNode );
29 | includePatterns = createPatterns( preferences.getIncludePatterns() );
30 | excludePatterns = createPatterns( preferences.getExcludePatterns() );
31 | }
32 |
33 | public boolean allowVisitProject() {
34 | return !includePatterns.isEmpty();
35 | }
36 |
37 | public boolean allowVisitFolder( IResource resource ) {
38 | return !includePatterns.isEmpty();
39 | }
40 |
41 | public boolean allowVisitFile( IResource resource ) {
42 | String[] pathSegments = resource.getParent().getProjectRelativePath().segments();
43 | String fileName = resource.getName();
44 | return isFileIncluded( pathSegments, fileName ) && !isFileExcluded( pathSegments, fileName );
45 | }
46 |
47 | private boolean isFileIncluded( String[] parentSegments, String fileName ) {
48 | for( PathPattern pattern : includePatterns ) {
49 | if( pattern.matchesFolder( parentSegments ) ) {
50 | if( pattern.matchesFile( fileName ) ) {
51 | return true;
52 | }
53 | }
54 | }
55 | return false;
56 | }
57 |
58 | private boolean isFileExcluded( String[] parentSegments, String fileName ) {
59 | for( PathPattern pattern : excludePatterns ) {
60 | if( pattern.matchesFolder( parentSegments ) ) {
61 | if( pattern.matchesFile( fileName ) ) {
62 | return true;
63 | }
64 | }
65 | }
66 | return false;
67 | }
68 |
69 | private static List createPatterns( List expressions ) {
70 | List patterns = new ArrayList( expressions.size() );
71 | for( String expression : expressions ) {
72 | patterns.add( PathPattern.create( expression ) );
73 | }
74 | return patterns;
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/ui/AbstractPropertyPage.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences.ui;
12 |
13 | import org.eclipse.core.resources.IProject;
14 | import org.eclipse.core.resources.IResource;
15 | import org.eclipse.core.runtime.CoreException;
16 | import org.eclipse.core.runtime.IAdaptable;
17 | import org.eclipse.core.runtime.IStatus;
18 | import org.eclipse.core.runtime.Status;
19 | import org.eclipse.ui.dialogs.PropertyPage;
20 | import org.osgi.service.prefs.BackingStoreException;
21 | import org.osgi.service.prefs.Preferences;
22 |
23 | import com.eclipsesource.jshint.ui.internal.Activator;
24 | import com.eclipsesource.jshint.ui.internal.preferences.PreferencesFactory;
25 |
26 |
27 | public abstract class AbstractPropertyPage extends PropertyPage {
28 |
29 | protected IResource getResource() {
30 | IAdaptable element = getElement();
31 | if( element instanceof IResource ) {
32 | return ( IResource )element;
33 | }
34 | return ( IResource )element.getAdapter( IResource.class );
35 | }
36 |
37 | protected Preferences getPreferences() {
38 | IProject project = getResource().getProject();
39 | return PreferencesFactory.getProjectPreferences( project );
40 | }
41 |
42 | protected void savePreferences() throws CoreException {
43 | Preferences node = getPreferences();
44 | try {
45 | node.flush();
46 | } catch( BackingStoreException exception ) {
47 | String message = "Failed to store preferences";
48 | Status status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, message, exception );
49 | throw new CoreException( status );
50 | }
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/ui/BrowserSupport.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences.ui;
12 |
13 | import java.net.MalformedURLException;
14 | import java.net.URL;
15 |
16 | import org.eclipse.swt.SWT;
17 | import org.eclipse.swt.widgets.Event;
18 | import org.eclipse.swt.widgets.Link;
19 | import org.eclipse.swt.widgets.Listener;
20 | import org.eclipse.ui.PartInitException;
21 | import org.eclipse.ui.PlatformUI;
22 | import org.eclipse.ui.browser.IWebBrowser;
23 | import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
24 | import org.eclipse.ui.statushandlers.StatusManager;
25 |
26 |
27 | public class BrowserSupport {
28 |
29 | private static final int BROWSER_STYLE = IWorkbenchBrowserSupport.AS_EDITOR
30 | | IWorkbenchBrowserSupport.LOCATION_BAR
31 | | IWorkbenchBrowserSupport.NAVIGATION_BAR
32 | | IWorkbenchBrowserSupport.STATUS;
33 |
34 | public static final BrowserSupport INSTANCE = new BrowserSupport();
35 |
36 | private final Listener selectionListener;
37 |
38 | private BrowserSupport() {
39 | selectionListener = createSelectionListener();
40 | }
41 |
42 | public void openUrl( String url ) {
43 | if( url == null ) {
44 | throw new NullPointerException( "url is null" );
45 | }
46 | IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
47 | try {
48 | IWebBrowser browser = support.createBrowser( BROWSER_STYLE, url, null, null );
49 | browser.openURL( new URL( url ) );
50 | } catch( MalformedURLException exception ) {
51 | throw new IllegalArgumentException( "Invalid URL: " + url );
52 | } catch( PartInitException exception ) {
53 | StatusManager.getManager().handle( exception.getStatus(), StatusManager.LOG );
54 | }
55 | }
56 |
57 | public void enableHyperlinks( Link link ) {
58 | link.addListener( SWT.Selection, selectionListener );
59 | }
60 |
61 | private Listener createSelectionListener() {
62 | return new Listener() {
63 | public void handleEvent( Event event ) {
64 | if( isSupportedUrl( event.text ) ) {
65 | openUrl( event.text );
66 | }
67 | }
68 | };
69 | }
70 |
71 | private static boolean isSupportedUrl( String text ) {
72 | return text.startsWith( "http://" ) || text.startsWith( "https://" );
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/ui/ButtonBar.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences.ui;
12 |
13 | import org.eclipse.swt.SWT;
14 | import org.eclipse.swt.widgets.Button;
15 | import org.eclipse.swt.widgets.Composite;
16 | import org.eclipse.swt.widgets.Listener;
17 |
18 | import static com.eclipsesource.jshint.ui.internal.util.LayoutUtil.rowLayout;
19 |
20 |
21 | public class ButtonBar extends Composite {
22 |
23 | public ButtonBar( Composite parent, int style ) {
24 | super( parent, style );
25 | rowLayout( this ).vertical().fill( true ).spacing( 3 );
26 | }
27 |
28 | public Button addButton( String text, Listener listener ) {
29 | Button button = new Button( this, SWT.PUSH );
30 | button.setText( text );
31 | button.addListener( SWT.Selection, listener );
32 | return button;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/preferences/ui/ProjectPropertyPage.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences.ui;
12 |
13 | import org.eclipse.core.resources.IProject;
14 | import org.eclipse.core.runtime.CoreException;
15 | import org.eclipse.swt.SWT;
16 | import org.eclipse.swt.widgets.Composite;
17 | import org.eclipse.swt.widgets.Control;
18 | import org.osgi.service.prefs.Preferences;
19 |
20 | import com.eclipsesource.jshint.ui.internal.Activator;
21 | import com.eclipsesource.jshint.ui.internal.builder.BuilderUtil;
22 | import com.eclipsesource.jshint.ui.internal.builder.JSHintBuilder;
23 | import com.eclipsesource.jshint.ui.internal.preferences.EnablementPreferences;
24 | import com.eclipsesource.jshint.ui.internal.preferences.ResourceSelector;
25 |
26 | import static com.eclipsesource.jshint.ui.internal.util.LayoutUtil.gridData;
27 | import static com.eclipsesource.jshint.ui.internal.util.LayoutUtil.gridLayout;
28 |
29 |
30 | public class ProjectPropertyPage extends AbstractPropertyPage {
31 |
32 | private IncludesView includesView;
33 |
34 | @Override
35 | public boolean performOk() {
36 | try {
37 | if( storePreferences() ) {
38 | boolean enabled = new ResourceSelector( getResource().getProject() ).allowVisitProject();
39 | setBuilderEnabled( enabled );
40 | triggerRebuild();
41 | }
42 | } catch( CoreException exception ) {
43 | String message = "Failed to store settings";
44 | Activator.logError( message, exception );
45 | return false;
46 | }
47 | return true;
48 | }
49 |
50 | @Override
51 | protected void performDefaults() {
52 | super.performDefaults();
53 | includesView.loadDefaults();
54 | }
55 |
56 | @Override
57 | protected Control createContents( Composite parent ) {
58 | Composite composite = new Composite( parent, SWT.NONE );
59 | gridLayout( composite ).margin( 0, 0 ).columns( 1 );
60 | gridData( composite ).fillBoth();
61 | includesView = new IncludesView( composite, SWT.NONE, getResource().getProject() );
62 | gridData( includesView ).fillBoth();
63 | loadPreferences();
64 | return composite;
65 | }
66 |
67 | private void loadPreferences() {
68 | Preferences node = getPreferences();
69 | EnablementPreferences enablePreferences = new EnablementPreferences( node );
70 | includesView.loadPreferences( enablePreferences );
71 | }
72 |
73 | private boolean storePreferences() throws CoreException {
74 | Preferences node = getPreferences();
75 | EnablementPreferences enablePreferences = new EnablementPreferences( node );
76 | includesView.storePreferences( enablePreferences );
77 | if( enablePreferences.hasChanged() ) {
78 | savePreferences();
79 | return true;
80 | }
81 | return false;
82 | }
83 |
84 | private boolean setBuilderEnabled( boolean enabled ) throws CoreException {
85 | IProject project = getResource().getProject();
86 | if( enabled ) {
87 | return BuilderUtil.addBuilderToProject( project, JSHintBuilder.ID );
88 | }
89 | return BuilderUtil.removeBuilderFromProject( project, JSHintBuilder.ID );
90 | }
91 |
92 | private void triggerRebuild() throws CoreException {
93 | IProject project = getResource().getProject();
94 | BuilderUtil.triggerClean( project, JSHintBuilder.ID );
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/FillLayoutConfig.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial API and implementation
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import org.eclipse.swt.SWT;
14 | import org.eclipse.swt.layout.FillLayout;
15 | import org.eclipse.swt.widgets.Layout;
16 |
17 |
18 | public class FillLayoutConfig {
19 |
20 | private final FillLayout layout;
21 |
22 | FillLayoutConfig() {
23 | layout = new FillLayout();
24 | }
25 |
26 | Layout getLayout() {
27 | return layout;
28 | }
29 |
30 | public FillLayoutConfig type( int type ) {
31 | layout.type = type;
32 | return this;
33 | }
34 |
35 | public FillLayoutConfig vertical() {
36 | layout.type = SWT.VERTICAL;
37 | return this;
38 | }
39 |
40 | public FillLayoutConfig horizontal() {
41 | layout.type = SWT.HORIZONTAL;
42 | return this;
43 | }
44 |
45 | public FillLayoutConfig margin( int allEdges ) {
46 | layout.marginWidth = allEdges;
47 | layout.marginHeight = allEdges;
48 | return this;
49 | }
50 |
51 | public FillLayoutConfig margin( int leftAndRight, int topAndBottom ) {
52 | layout.marginWidth = leftAndRight;
53 | layout.marginHeight = topAndBottom;
54 | return this;
55 | }
56 |
57 | public FillLayoutConfig spacing( int spacing ) {
58 | layout.spacing = spacing;
59 | return this;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/FormDataConfig.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial API and implementation
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import org.eclipse.swt.layout.FormAttachment;
14 | import org.eclipse.swt.layout.FormData;
15 | import org.eclipse.swt.widgets.Control;
16 |
17 |
18 | public class FormDataConfig {
19 |
20 | private final FormData data;
21 |
22 | FormDataConfig() {
23 | data = new FormData();
24 | }
25 |
26 | Object getLayoutData() {
27 | return data;
28 | }
29 |
30 | public FormDataConfig top( int percentage ) {
31 | data.top = new FormAttachment( percentage );
32 | return this;
33 | }
34 |
35 | public FormDataConfig top( int percentage, int offset ) {
36 | data.top = new FormAttachment( percentage, offset );
37 | return this;
38 | }
39 |
40 | public FormDataConfig top( Control control ) {
41 | data.top = new FormAttachment( control );
42 | return this;
43 | }
44 |
45 | public FormDataConfig top( Control control, int offset ) {
46 | data.top = new FormAttachment( control, offset );
47 | return this;
48 | }
49 |
50 | public FormDataConfig top( Control control, int offset, int alignment ) {
51 | data.top = new FormAttachment( control, offset, alignment );
52 | return this;
53 | }
54 |
55 | public FormDataConfig right( int percentage ) {
56 | data.right = new FormAttachment( percentage );
57 | return this;
58 | }
59 |
60 | public FormDataConfig right( int percentage, int offset ) {
61 | data.right = new FormAttachment( percentage, offset );
62 | return this;
63 | }
64 |
65 | public FormDataConfig right( Control control ) {
66 | data.right = new FormAttachment( control );
67 | return this;
68 | }
69 |
70 | public FormDataConfig right( Control control, int offset ) {
71 | data.right = new FormAttachment( control, offset );
72 | return this;
73 | }
74 |
75 | public FormDataConfig right( Control control, int offset, int alignment ) {
76 | data.right = new FormAttachment( control, offset, alignment );
77 | return this;
78 | }
79 |
80 | public FormDataConfig bottom( int percentage ) {
81 | data.bottom = new FormAttachment( percentage );
82 | return this;
83 | }
84 |
85 | public FormDataConfig bottom( int percentage, int offset ) {
86 | data.bottom = new FormAttachment( percentage, offset );
87 | return this;
88 | }
89 |
90 | public FormDataConfig bottom( Control control ) {
91 | data.bottom = new FormAttachment( control );
92 | return this;
93 | }
94 |
95 | public FormDataConfig bottom( Control control, int offset ) {
96 | data.bottom = new FormAttachment( control, offset );
97 | return this;
98 | }
99 |
100 | public FormDataConfig bottom( Control control, int offset, int alignment ) {
101 | data.bottom = new FormAttachment( control, offset, alignment );
102 | return this;
103 | }
104 |
105 | public FormDataConfig left( int percentage ) {
106 | data.left = new FormAttachment( percentage );
107 | return this;
108 | }
109 |
110 | public FormDataConfig left( int percentage, int offset ) {
111 | data.left = new FormAttachment( percentage, offset );
112 | return this;
113 | }
114 |
115 | public FormDataConfig left( Control control ) {
116 | data.left = new FormAttachment( control );
117 | return this;
118 | }
119 |
120 | public FormDataConfig left( Control control, int offset ) {
121 | data.left = new FormAttachment( control, offset );
122 | return this;
123 | }
124 |
125 | public FormDataConfig left( Control control, int offset, int alignment ) {
126 | data.left = new FormAttachment( control, offset, alignment );
127 | return this;
128 | }
129 |
130 | public FormDataConfig width( int width ) {
131 | data.width = width;
132 | return this;
133 | }
134 |
135 | public FormDataConfig height( int height ) {
136 | data.height = height;
137 | return this;
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/FormLayoutConfig.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial API and implementation
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import org.eclipse.swt.layout.FormLayout;
14 | import org.eclipse.swt.widgets.Layout;
15 |
16 |
17 | public class FormLayoutConfig {
18 |
19 | private final FormLayout layout;
20 |
21 | FormLayoutConfig() {
22 | this.layout = new FormLayout();
23 | }
24 |
25 | Layout getLayout() {
26 | return layout;
27 | }
28 |
29 | public FormLayoutConfig margin( int allEdges ) {
30 | margin( allEdges, allEdges, allEdges, allEdges );
31 | return this;
32 | }
33 |
34 | public FormLayoutConfig margin( int leftAndRight, int topAndBottom ) {
35 | margin( topAndBottom, leftAndRight, topAndBottom, leftAndRight );
36 | return this;
37 | }
38 |
39 | public FormLayoutConfig margin( int top, int right, int bottom, int left ) {
40 | layout.marginTop = top;
41 | layout.marginRight = right;
42 | layout.marginBottom = bottom;
43 | layout.marginLeft = left;
44 | return this;
45 | }
46 |
47 | public FormLayoutConfig spacing( int spacing ) {
48 | layout.spacing = spacing;
49 | return this;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/GridDataConfig.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial API and implementation
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import org.eclipse.swt.SWT;
14 | import org.eclipse.swt.layout.GridData;
15 |
16 |
17 | public class GridDataConfig {
18 |
19 | private final GridData data;
20 |
21 | GridDataConfig() {
22 | data = new GridData();
23 | data.verticalAlignment = SWT.CENTER;
24 | }
25 |
26 | Object getLayoutData() {
27 | return data;
28 | }
29 |
30 | public GridDataConfig align( int horizontal, int vertical ) {
31 | data.horizontalAlignment = horizontal;
32 | data.verticalAlignment = vertical;
33 | return this;
34 | }
35 |
36 | public GridDataConfig align( int horizontalAlignment,
37 | int verticalAlignment,
38 | boolean grabExcessHorizontal,
39 | boolean grabExcessVertical )
40 | {
41 | data.horizontalAlignment = horizontalAlignment;
42 | data.verticalAlignment = verticalAlignment;
43 | data.grabExcessHorizontalSpace = grabExcessHorizontal;
44 | data.grabExcessVerticalSpace = grabExcessVertical;
45 | return this;
46 | }
47 |
48 | public GridDataConfig fillBoth() {
49 | data.horizontalAlignment = SWT.FILL;
50 | data.verticalAlignment = SWT.FILL;
51 | data.grabExcessHorizontalSpace = true;
52 | data.grabExcessVerticalSpace = true;
53 | return this;
54 | }
55 |
56 | public GridDataConfig fillHorizontal() {
57 | data.horizontalAlignment = SWT.FILL;
58 | data.grabExcessHorizontalSpace = true;
59 | return this;
60 | }
61 |
62 | public GridDataConfig fillVertical() {
63 | data.verticalAlignment = SWT.FILL;
64 | data.grabExcessVerticalSpace = true;
65 | return this;
66 | }
67 |
68 | public GridDataConfig span( int horizontal, int vertical ) {
69 | data.horizontalSpan = horizontal;
70 | data.verticalSpan = vertical;
71 | return this;
72 | }
73 |
74 | public GridDataConfig indent( int horizontal, int vertical ) {
75 | data.horizontalIndent = horizontal;
76 | data.verticalIndent = vertical;
77 | return this;
78 | }
79 |
80 | public GridDataConfig sizeHint( int width, int height ) {
81 | data.widthHint = width;
82 | data.heightHint = height;
83 | return this;
84 | }
85 |
86 | public GridDataConfig widthHint( int width ) {
87 | data.widthHint = width;
88 | return this;
89 | }
90 |
91 | public GridDataConfig heightHint( int height ) {
92 | data.widthHint = height;
93 | return this;
94 | }
95 |
96 | public GridDataConfig minimalSize( int width, int height ) {
97 | data.minimumWidth = width;
98 | data.minimumHeight = height;
99 | return this;
100 | }
101 |
102 | public GridDataConfig minimalWidth( int width ) {
103 | data.minimumWidth = width;
104 | return this;
105 | }
106 |
107 | public GridDataConfig minimalHeight( int height ) {
108 | data.minimumHeight = height;
109 | return this;
110 | }
111 |
112 | public GridDataConfig exclude( boolean exclude ) {
113 | data.exclude = exclude;
114 | return this;
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/GridLayoutConfig.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial API and implementation
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import org.eclipse.swt.layout.GridLayout;
14 | import org.eclipse.swt.widgets.Layout;
15 |
16 |
17 | public class GridLayoutConfig {
18 |
19 | private final GridLayout layout;
20 |
21 | GridLayoutConfig() {
22 | layout = new GridLayout();
23 | layout.marginHeight = 0;
24 | layout.marginWidth = 0;
25 | layout.verticalSpacing = 0;
26 | layout.horizontalSpacing = 0;
27 | }
28 |
29 | Layout getLayout() {
30 | return layout;
31 | }
32 |
33 | public GridLayoutConfig columns( int columns ) {
34 | layout.numColumns = columns;
35 | return this;
36 | }
37 |
38 | public GridLayoutConfig columns( int columns, boolean equalWidth ) {
39 | layout.numColumns = columns;
40 | layout.makeColumnsEqualWidth = equalWidth;
41 | return this;
42 | }
43 |
44 | public GridLayoutConfig margin( int allEdges ) {
45 | margin( allEdges, allEdges, allEdges, allEdges );
46 | return this;
47 | }
48 |
49 | public GridLayoutConfig margin( int leftAndRight, int topAndBottom ) {
50 | margin( topAndBottom, leftAndRight, topAndBottom, leftAndRight );
51 | return this;
52 | }
53 |
54 | public GridLayoutConfig margin( int top, int right, int bottom, int left ) {
55 | layout.marginTop = top;
56 | layout.marginRight = right;
57 | layout.marginBottom = bottom;
58 | layout.marginLeft = left;
59 | return this;
60 | }
61 |
62 | public GridLayoutConfig marginTop( int margin ) {
63 | layout.marginTop = margin;
64 | return this;
65 | }
66 |
67 | public GridLayoutConfig marginBottom( int margin ) {
68 | layout.marginBottom = margin;
69 | return this;
70 | }
71 |
72 | public GridLayoutConfig marginLeft( int margin ) {
73 | layout.marginLeft = margin;
74 | return this;
75 | }
76 |
77 | public GridLayoutConfig marginRight( int margin ) {
78 | layout.marginRight = margin;
79 | return this;
80 | }
81 |
82 | public GridLayoutConfig spacing( int spacing ) {
83 | layout.verticalSpacing = spacing;
84 | layout.horizontalSpacing = spacing;
85 | return this;
86 | }
87 |
88 | public GridLayoutConfig spacing( int horizontal, int vertical ) {
89 | layout.verticalSpacing = vertical;
90 | layout.horizontalSpacing = horizontal;
91 | return this;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/IOUtil.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import java.io.BufferedInputStream;
14 | import java.io.BufferedOutputStream;
15 | import java.io.BufferedReader;
16 | import java.io.ByteArrayInputStream;
17 | import java.io.FileInputStream;
18 | import java.io.FileOutputStream;
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 | import java.io.InputStreamReader;
22 | import java.io.OutputStream;
23 | import java.io.UnsupportedEncodingException;
24 |
25 | import org.eclipse.core.resources.IFile;
26 | import org.eclipse.core.runtime.CoreException;
27 |
28 |
29 | public class IOUtil {
30 |
31 | public static final String UTF_8 = "UTF-8";
32 |
33 | public static String readFileUtf8( IFile file ) throws CoreException, IOException {
34 | if( file.isAccessible() ) {
35 | InputStream inputStream = file.getContents( true );
36 | try {
37 | return readStringUtf8( inputStream );
38 | } finally {
39 | inputStream.close();
40 | }
41 | }
42 | return null;
43 | }
44 |
45 | public static void writeFileUtf8( IFile file, String content ) throws CoreException {
46 | ByteArrayInputStream inputStream = createInputStreamUtf8( content );
47 | if( file.isAccessible() ) {
48 | file.setContents( inputStream, true, true, null );
49 | } else {
50 | file.create( inputStream, true, null );
51 | file.setCharset( UTF_8, null );
52 | }
53 | }
54 |
55 | public static String readFromFileUtf8( String fileName ) throws IOException {
56 | InputStream inputStream = null;
57 | try {
58 | inputStream = new BufferedInputStream( new FileInputStream( fileName ) );
59 | return readStringUtf8( inputStream );
60 | } finally {
61 | if( inputStream != null ) {
62 | inputStream.close();
63 | }
64 | }
65 | }
66 |
67 | public static void writeToFileUtf8( String fileName, String content ) throws IOException {
68 | OutputStream outputStream = null;
69 | try {
70 | outputStream = new BufferedOutputStream( new FileOutputStream( fileName ) );
71 | outputStream.write( content.getBytes( UTF_8 ) );
72 | } finally {
73 | if( outputStream != null ) {
74 | outputStream.close();
75 | }
76 | }
77 | }
78 |
79 | public static String readStringUtf8( InputStream inputStream ) throws IOException {
80 | BufferedReader reader = createReaderUtf8( inputStream );
81 | char[] buffer = new char[ 1024 ];
82 | StringBuilder builder = new StringBuilder();
83 | try {
84 | int read = reader.read( buffer );
85 | while( read != -1 ) {
86 | builder.append( buffer, 0, read );
87 | read = reader.read( buffer );
88 | }
89 | } finally {
90 | reader.close();
91 | }
92 | return builder.toString();
93 | }
94 |
95 | public static BufferedReader createReaderUtf8( InputStream inputStream ) {
96 | try {
97 | return new BufferedReader( new InputStreamReader( inputStream, UTF_8 ) );
98 | } catch( UnsupportedEncodingException exception ) {
99 | throw new RuntimeException( exception );
100 | }
101 | }
102 |
103 | public static ByteArrayInputStream createInputStreamUtf8( String string ) {
104 | try {
105 | return new ByteArrayInputStream( string.getBytes( UTF_8 ) );
106 | } catch( UnsupportedEncodingException exception ) {
107 | throw new RuntimeException( exception );
108 | }
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/JsonUtil.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import java.io.IOException;
14 | import java.io.StringWriter;
15 |
16 | import com.eclipsesource.jshint.ui.internal.builder.CommentsFilter;
17 | import com.eclipsesource.json.JsonObject;
18 | import com.eclipsesource.json.PrettyPrintJsonWriter;
19 |
20 |
21 | public class JsonUtil {
22 |
23 | public static boolean jsonEquals( String string1, String string2 ) {
24 | if( string1 != null && string2 != null ) {
25 | try {
26 | JsonObject json1 = JsonObject.readFrom( new CommentsFilter( string1 ).toString() );
27 | JsonObject json2 = JsonObject.readFrom( new CommentsFilter( string2 ).toString() );
28 | return json1.equals( json2 );
29 | } catch( Exception exception ) {
30 | // ignore exceptions and return false
31 | }
32 | }
33 | return false;
34 | }
35 |
36 | public static String prettyPrint( JsonObject oldConfig ) throws RuntimeException {
37 | StringWriter writer = new StringWriter();
38 | try {
39 | oldConfig.writeTo( new PrettyPrintJsonWriter( writer ) );
40 | } catch( IOException exception ) {
41 | // StringWriter does not throw IOExceptions
42 | throw new RuntimeException( exception );
43 | }
44 | return writer.toString();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/LayoutUtil.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import org.eclipse.swt.widgets.Composite;
14 | import org.eclipse.swt.widgets.Control;
15 |
16 |
17 | public class LayoutUtil {
18 |
19 | public static FillLayoutConfig fillLayout( Composite composite ) {
20 | FillLayoutConfig config = new FillLayoutConfig();
21 | composite.setLayout( config.getLayout() );
22 | return config;
23 | }
24 |
25 | public static FormLayoutConfig formLayout( Composite composite ) {
26 | FormLayoutConfig config = new FormLayoutConfig();
27 | composite.setLayout( config.getLayout() );
28 | return config;
29 | }
30 |
31 | public static RowLayoutConfig rowLayout( Composite composite ) {
32 | RowLayoutConfig config = new RowLayoutConfig();
33 | composite.setLayout( config.getLayout() );
34 | return config;
35 | }
36 |
37 | public static GridLayoutConfig gridLayout( Composite composite ) {
38 | GridLayoutConfig config = new GridLayoutConfig();
39 | composite.setLayout( config.getLayout() );
40 | return config;
41 | }
42 |
43 | public static FormDataConfig formData( Control control ) {
44 | FormDataConfig config = new FormDataConfig();
45 | control.setLayoutData( config.getLayoutData() );
46 | return config;
47 | }
48 |
49 | public static GridDataConfig gridData( Control control ) {
50 | GridDataConfig config = new GridDataConfig();
51 | control.setLayoutData( config.getLayoutData() );
52 | return config;
53 | }
54 |
55 | public static RowDataConfig rowData( Control control ) {
56 | RowDataConfig config = new RowDataConfig();
57 | control.setLayoutData( config.getLayoutData() );
58 | return config;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/RowDataConfig.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial API and implementation
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import org.eclipse.swt.layout.RowData;
14 |
15 |
16 | public class RowDataConfig {
17 |
18 | private final RowData data;
19 |
20 | RowDataConfig() {
21 | data = new RowData();
22 | }
23 |
24 | RowData getLayoutData() {
25 | return data;
26 | }
27 |
28 | public RowDataConfig size( int width, int height ) {
29 | data.width = width;
30 | data.height = height;
31 | return this;
32 | }
33 |
34 | public RowDataConfig width( int width ) {
35 | data.width = width;
36 | return this;
37 | }
38 |
39 | public RowDataConfig height( int height ) {
40 | data.height = height;
41 | return this;
42 | }
43 |
44 | public RowDataConfig exclude( boolean exclude ) {
45 | data.exclude = exclude;
46 | return this;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint.ui/src/com/eclipsesource/jshint/ui/internal/util/RowLayoutConfig.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial API and implementation
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import org.eclipse.swt.SWT;
14 | import org.eclipse.swt.layout.RowLayout;
15 | import org.eclipse.swt.widgets.Layout;
16 |
17 |
18 | public class RowLayoutConfig {
19 |
20 | private final RowLayout layout;
21 |
22 | RowLayoutConfig() {
23 | layout = new RowLayout();
24 | layout.marginTop = 0;
25 | layout.marginRight = 0;
26 | layout.marginBottom = 0;
27 | layout.marginLeft = 0;
28 | layout.spacing = 0;
29 | layout.wrap = false;
30 | layout.pack = false;
31 | }
32 |
33 | Layout getLayout() {
34 | return layout;
35 | }
36 |
37 | public RowLayoutConfig type( int type ) {
38 | layout.type = type;
39 | return this;
40 | }
41 |
42 | public RowLayoutConfig vertical() {
43 | layout.type = SWT.VERTICAL;
44 | return this;
45 | }
46 |
47 | public RowLayoutConfig horizontal() {
48 | layout.type = SWT.HORIZONTAL;
49 | return this;
50 | }
51 |
52 | public RowLayoutConfig center( boolean center ) {
53 | layout.center = center;
54 | return this;
55 | }
56 |
57 | public RowLayoutConfig fill( boolean fill ) {
58 | layout.fill = fill;
59 | return this;
60 | }
61 |
62 | public RowLayoutConfig justify( boolean justify ) {
63 | layout.justify = justify;
64 | return this;
65 | }
66 |
67 | public RowLayoutConfig pack( boolean pack ) {
68 | layout.pack = pack;
69 | return this;
70 | }
71 |
72 | public RowLayoutConfig wrap( boolean wrap ) {
73 | layout.wrap = wrap;
74 | return this;
75 | }
76 |
77 | public RowLayoutConfig margin( int allEdges ) {
78 | layout.marginTop = allEdges;
79 | layout.marginRight = allEdges;
80 | layout.marginBottom = allEdges;
81 | layout.marginLeft = allEdges;
82 | return this;
83 | }
84 |
85 | public RowLayoutConfig margin( int leftAndRight, int topAndBottom ) {
86 | layout.marginTop = topAndBottom;
87 | layout.marginRight = leftAndRight;
88 | layout.marginBottom = topAndBottom;
89 | layout.marginLeft = leftAndRight;
90 | return this;
91 | }
92 |
93 | public RowLayoutConfig margin( int top, int right, int bottom, int left ) {
94 | layout.marginTop = top;
95 | layout.marginRight = right;
96 | layout.marginBottom = bottom;
97 | layout.marginLeft = left;
98 | return this;
99 | }
100 |
101 | public RowLayoutConfig marginTop( int margin ) {
102 | layout.marginTop = margin;
103 | return this;
104 | }
105 |
106 | public RowLayoutConfig marginBottom( int margin ) {
107 | layout.marginBottom = margin;
108 | return this;
109 | }
110 |
111 | public RowLayoutConfig marginLeft( int margin ) {
112 | layout.marginLeft = margin;
113 | return this;
114 | }
115 |
116 | public RowLayoutConfig marginRight( int margin ) {
117 | layout.marginRight = margin;
118 | return this;
119 | }
120 |
121 | public RowLayoutConfig spacing( int spacing ) {
122 | layout.spacing = spacing;
123 | return this;
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.eclipsesource.jshint
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.pde.ManifestBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.pde.SchemaBuilder
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.pde.PluginNature
26 | org.eclipse.jdt.core.javanature
27 |
28 |
29 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | #Mon Jan 02 18:36:13 CET 2012
2 | eclipse.preferences.version=1
3 | encoding/=UTF-8
4 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | #Mon Jan 02 18:36:13 CET 2012
2 | eclipse.preferences.version=1
3 | line.separator=\n
4 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.5
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.5
12 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.ui.javadoc=true
3 | org.eclipse.jdt.ui.text.custom_code_templates=/*******************************************************************************\n * Copyright (c) ${year} EclipseSource.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * ${user} - initial implementation and API\n ******************************************************************************/${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}\n\n\n\n// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();// ${todo} Auto-generated method stub\n${body_statement}${body_statement}\n// ${todo} Auto-generated constructor stubreturn ${field};${field} \= ${param};
4 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/.settings/org.moreunit.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.moreunit.preferences.version=2
3 | org.moreunit.testClassNameTemplate=${srcFile}_Test
4 | org.moreunit.unitsourcefolder=com.eclipsesource.jshint\:src\:com.eclipsesource.jshint.test\:src
5 | org.moreunit.useprojectsettings=true
6 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Bundle-ManifestVersion: 2
3 | Bundle-Name: JSHint
4 | Bundle-SymbolicName: com.eclipsesource.jshint
5 | Bundle-Version: 0.10.1.qualifier
6 | Bundle-RequiredExecutionEnvironment: J2SE-1.5
7 | Bundle-Vendor: EclipseSource
8 | Bundle-ActivationPolicy: lazy
9 | Export-Package: com.eclipsesource.jshint;version="0.10.1",
10 | com.eclipsesource.jshint.internal;version="0.10.1";x-friends:="com.eclipsesource.jshint.test",
11 | com.eclipsesource.json;version="0.9.0.jshint"
12 | Require-Bundle: org.mozilla.javascript;bundle-version="1.7.4"
13 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/build.properties:
--------------------------------------------------------------------------------
1 | source.. = src/
2 | output.. = bin/
3 | bin.includes = META-INF/,\
4 | .
5 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.eclipsesource.jshint
8 | com.eclipsesource.jshint
9 | 0.10.1-SNAPSHOT
10 | eclipse-plugin
11 |
12 |
13 | com.eclipsesource.jshint
14 | com.eclipsesource.jshint.build
15 | 0.10.1-SNAPSHOT
16 | ../../pom.xml
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/jshint/Problem.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint;
12 |
13 |
14 | /**
15 | * Holds information about a problem found by JSHint.
16 | */
17 | public interface Problem {
18 |
19 | /**
20 | * Returns the line number in which the problem occurred.
21 | *
22 | * @return the line number, beginning with 1
23 | */
24 | int getLine();
25 |
26 | /**
27 | * Returns the character offset within the line in which the character occurred.
28 | *
29 | * @return the character offset, beginning with 0
30 | */
31 | int getCharacter();
32 |
33 | /**
34 | * The problem message returned by JSHint.
35 | *
36 | * @return the message
37 | */
38 | String getMessage();
39 |
40 | /**
41 | * The error code returned by JSHint.
42 | *
43 | * @return the error code
44 | */
45 | String getCode();
46 |
47 | /**
48 | * Returns whether this problem represents an error.
49 | *
50 | * @return true
if this is an error
51 | */
52 | boolean isError();
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/jshint/ProblemHandler.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint;
12 |
13 |
14 | /**
15 | * Implementations of this class are used to handle problems returned from JSHint.
16 | */
17 | public interface ProblemHandler {
18 |
19 | /**
20 | * Handles a problem occurred during the code check.
21 | *
22 | * @param problem
23 | * the problem
24 | */
25 | void handleProblem( Problem problem );
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/jshint/Text.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint;
12 |
13 | import java.io.IOException;
14 | import java.io.Reader;
15 | import java.io.StringReader;
16 |
17 |
18 | /**
19 | * Wrapper class for the text, used to read the content of a text file and to track line offsets.
20 | */
21 | public class Text {
22 |
23 | private String code;
24 | private int lineCount = 1;
25 | private int[] lineOffsets = new int[ 200 ];
26 |
27 | public Text( String text ) {
28 | if( text == null ) {
29 | throw new NullPointerException( "text is null" );
30 | }
31 | StringReader reader = new StringReader( text );
32 | try {
33 | read( reader );
34 | } catch( IOException exception ) {
35 | throw new RuntimeException( exception );
36 | } finally {
37 | reader.close();
38 | }
39 | }
40 |
41 | public Text( Reader reader ) throws IOException {
42 | if( reader == null ) {
43 | throw new NullPointerException( "reader is null" );
44 | }
45 | read( reader );
46 | }
47 |
48 | public String getContent() {
49 | return code;
50 | }
51 |
52 | public int getLineCount() {
53 | return lineCount;
54 | }
55 |
56 | /**
57 | * Returns the offset of the given line's first character.
58 | *
59 | * @param line
60 | * zero-relative line index
61 | * @return the line offset
62 | */
63 | public int getLineOffset( int line ) {
64 | if( line < 0 || line >= lineCount ) {
65 | throw new IndexOutOfBoundsException( "line does not exist: " + line );
66 | }
67 | return lineOffsets[ line ];
68 | }
69 |
70 | /**
71 | * Returns the length of the given line, including linebreak characters.
72 | *
73 | * @param line
74 | * zero-relative line index
75 | * @return the line length in characters
76 | */
77 | public int getLineLength( int line ) {
78 | if( line < 0 || line >= lineCount ) {
79 | throw new IndexOutOfBoundsException( "line does not exist: " + line );
80 | }
81 | int nextOffset = line + 1 == lineCount ? code.length() : lineOffsets[ line + 1 ];
82 | return nextOffset - lineOffsets[ line ];
83 | }
84 |
85 | private void read( Reader reader ) throws IOException {
86 | StringBuilder builder = new StringBuilder();
87 | char[] cbuf = new char[ 8096 ];
88 | int read = reader.read( cbuf );
89 | while( read != -1 ) {
90 | for( int i = 0; i < read; i++ ) {
91 | if( cbuf[i] == '\n' ) {
92 | if( lineCount >= lineOffsets.length ) {
93 | growLineOffsets();
94 | }
95 | lineOffsets[ lineCount++ ] = builder.length() + i + 1;
96 | }
97 | }
98 | builder.append( cbuf, 0, read );
99 | read = reader.read( cbuf );
100 | }
101 | code = builder.toString();
102 | }
103 |
104 | private void growLineOffsets() {
105 | int[] newLineOffsets = new int[ lineOffsets.length * 2 ];
106 | System.arraycopy( lineOffsets, 0, newLineOffsets, 0, lineOffsets.length );
107 | lineOffsets = newLineOffsets;
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/jshint/internal/ProblemImpl.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.internal;
12 |
13 | import com.eclipsesource.jshint.Problem;
14 |
15 |
16 | public class ProblemImpl implements Problem {
17 | private final int line;
18 | private final int character;
19 | private final String message;
20 | private final String code;
21 |
22 | public ProblemImpl( int line, int character, String message, String code ) {
23 | this.line = line;
24 | this.character = character;
25 | this.message = message;
26 | this.code = code;
27 | }
28 |
29 | public int getLine() {
30 | return line;
31 | }
32 |
33 | public int getCharacter() {
34 | return character;
35 | }
36 |
37 | public String getMessage() {
38 | return message;
39 | }
40 |
41 | public String getCode() {
42 | return code;
43 | }
44 |
45 | public boolean isError() {
46 | return code != null && code.length() > 0 && code.charAt( 0 ) == 'E';
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/json/JsonLiteral.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.json;
12 |
13 | import java.io.IOException;
14 |
15 |
16 | @SuppressWarnings( "serial" ) // use default serial UID
17 | class JsonLiteral extends JsonValue {
18 |
19 | private final String value;
20 |
21 | JsonLiteral( String value ) {
22 | this.value = value;
23 | }
24 |
25 | @Override
26 | protected void write( JsonWriter writer ) throws IOException {
27 | writer.write( value );
28 | }
29 |
30 | @Override
31 | public String toString() {
32 | return value;
33 | }
34 |
35 | @Override
36 | public boolean asBoolean() {
37 | return isBoolean() ? isTrue() : super.asBoolean();
38 | }
39 |
40 | @Override
41 | public boolean isNull() {
42 | return this == NULL;
43 | }
44 |
45 | @Override
46 | public boolean isBoolean() {
47 | return this == TRUE || this == FALSE;
48 | }
49 |
50 | @Override
51 | public boolean isTrue() {
52 | return this == TRUE;
53 | }
54 |
55 | @Override
56 | public boolean isFalse() {
57 | return this == FALSE;
58 | }
59 |
60 | @Override
61 | public int hashCode() {
62 | return value.hashCode();
63 | }
64 |
65 | @Override
66 | public boolean equals( Object object ) {
67 | if( this == object ) {
68 | return true;
69 | }
70 | if( object == null ) {
71 | return false;
72 | }
73 | if( getClass() != object.getClass() ) {
74 | return false;
75 | }
76 | JsonLiteral other = (JsonLiteral)object;
77 | return value.equals( other.value );
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/json/JsonNumber.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.json;
12 |
13 | import java.io.IOException;
14 |
15 |
16 | @SuppressWarnings( "serial" ) // use default serial UID
17 | class JsonNumber extends JsonValue {
18 |
19 | private final String string;
20 |
21 | JsonNumber( String string ) {
22 | if( string == null ) {
23 | throw new NullPointerException( "string is null" );
24 | }
25 | this.string = string;
26 | }
27 |
28 | @Override
29 | public String toString() {
30 | return string;
31 | }
32 |
33 | @Override
34 | protected void write( JsonWriter writer ) throws IOException {
35 | writer.write( string );
36 | }
37 |
38 | @Override
39 | public boolean isNumber() {
40 | return true;
41 | }
42 |
43 | @Override
44 | public int asInt() {
45 | return Integer.parseInt( string, 10 );
46 | }
47 |
48 | @Override
49 | public long asLong() {
50 | return Long.parseLong( string, 10 );
51 | }
52 |
53 | @Override
54 | public float asFloat() {
55 | return Float.parseFloat( string );
56 | }
57 |
58 | @Override
59 | public double asDouble() {
60 | return Double.parseDouble( string );
61 | }
62 |
63 | @Override
64 | public int hashCode() {
65 | return string.hashCode();
66 | }
67 |
68 | @Override
69 | public boolean equals( Object object ) {
70 | if( this == object ) {
71 | return true;
72 | }
73 | if( object == null ) {
74 | return false;
75 | }
76 | if( getClass() != object.getClass() ) {
77 | return false;
78 | }
79 | JsonNumber other = (JsonNumber)object;
80 | return string.equals( other.string );
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/json/JsonString.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.json;
12 |
13 | import java.io.IOException;
14 |
15 |
16 | @SuppressWarnings( "serial" ) // use default serial UID
17 | class JsonString extends JsonValue {
18 |
19 | private final String string;
20 |
21 | JsonString( String string ) {
22 | if( string == null ) {
23 | throw new NullPointerException( "string is null" );
24 | }
25 | this.string = string;
26 | }
27 |
28 | @Override
29 | protected void write( JsonWriter writer ) throws IOException {
30 | writer.writeString( string );
31 | }
32 |
33 | @Override
34 | public boolean isString() {
35 | return true;
36 | }
37 |
38 | @Override
39 | public String asString() {
40 | return string;
41 | }
42 |
43 | @Override
44 | public int hashCode() {
45 | return string.hashCode();
46 | }
47 |
48 | @Override
49 | public boolean equals( Object object ) {
50 | if( this == object ) {
51 | return true;
52 | }
53 | if( object == null ) {
54 | return false;
55 | }
56 | if( getClass() != object.getClass() ) {
57 | return false;
58 | }
59 | JsonString other = (JsonString)object;
60 | return string.equals( other.string );
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/json/JsonWriter.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.json;
12 |
13 | import java.io.IOException;
14 | import java.io.Writer;
15 |
16 |
17 | class JsonWriter {
18 |
19 | private static final int CONTROL_CHARACTERS_START = 0x0000;
20 | private static final int CONTROL_CHARACTERS_END = 0x001f;
21 |
22 | private static final char[] QUOT_CHARS = { '\\', '"' };
23 | private static final char[] BS_CHARS = { '\\', '\\' };
24 | private static final char[] LF_CHARS = { '\\', 'n' };
25 | private static final char[] CR_CHARS = { '\\', 'r' };
26 | private static final char[] TAB_CHARS = { '\\', 't' };
27 | // In JavaScript, U+2028 and U+2029 characters count as line endings and must be encoded.
28 | // http://stackoverflow.com/questions/2965293/javascript-parse-error-on-u2028-unicode-character
29 | private static final char[] UNICODE_2028_CHARS = { '\\', 'u', '2', '0', '2', '8' };
30 | private static final char[] UNICODE_2029_CHARS = { '\\', 'u', '2', '0', '2', '9' };
31 | private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
32 | 'a', 'b', 'c', 'd', 'e', 'f' };
33 |
34 | protected final Writer writer;
35 |
36 | JsonWriter( Writer writer ) {
37 | this.writer = writer;
38 | }
39 |
40 | void write( String string ) throws IOException {
41 | writer.write( string );
42 | }
43 |
44 | void writeString( String string ) throws IOException {
45 | writer.write( '"' );
46 | int length = string.length();
47 | int start = 0;
48 | char[] chars = new char[ length ];
49 | string.getChars( 0, length, chars, 0 );
50 | for( int index = 0; index < length; index++ ) {
51 | char[] replacement = getReplacementChars( chars[index] );
52 | if( replacement != null ) {
53 | writer.write( chars, start, index - start );
54 | writer.write( replacement );
55 | start = index+1;
56 | }
57 | }
58 | writer.write( chars, start, length - start );
59 | writer.write( '"' );
60 | }
61 |
62 | private static char[] getReplacementChars( char ch ) {
63 | char[] replacement = null;
64 | if( ch == '"' ) {
65 | replacement = QUOT_CHARS;
66 | } else if( ch == '\\' ) {
67 | replacement = BS_CHARS;
68 | } else if( ch == '\n' ) {
69 | replacement = LF_CHARS;
70 | } else if( ch == '\r' ) {
71 | replacement = CR_CHARS;
72 | } else if( ch == '\t' ) {
73 | replacement = TAB_CHARS;
74 | } else if( ch == '\u2028' ) {
75 | replacement = UNICODE_2028_CHARS;
76 | } else if( ch == '\u2029' ) {
77 | replacement = UNICODE_2029_CHARS;
78 | } else if( ch >= CONTROL_CHARACTERS_START && ch <= CONTROL_CHARACTERS_END ) {
79 | replacement = new char[] { '\\', 'u', '0', '0', '0', '0' };
80 | replacement[4] = HEX_DIGITS[ ch >> 4 & 0x000f ];
81 | replacement[5] = HEX_DIGITS[ ch & 0x000f ];
82 | }
83 | return replacement;
84 | }
85 |
86 | protected void writeObject( JsonObject object ) throws IOException {
87 | writeBeginObject();
88 | boolean first = true;
89 | for( JsonObject.Member member : object ) {
90 | if( !first ) {
91 | writeObjectValueSeparator();
92 | }
93 | writeString( member.getName() );
94 | writeNameValueSeparator();
95 | member.getValue().write( this );
96 | first = false;
97 | }
98 | writeEndObject();
99 | }
100 |
101 | protected void writeBeginObject() throws IOException {
102 | writer.write( '{' );
103 | }
104 |
105 | protected void writeEndObject() throws IOException {
106 | writer.write( '}' );
107 | }
108 |
109 | protected void writeNameValueSeparator() throws IOException {
110 | writer.write( ':' );
111 | }
112 |
113 | protected void writeObjectValueSeparator() throws IOException {
114 | writer.write( ',' );
115 | }
116 |
117 | protected void writeArray( JsonArray array ) throws IOException {
118 | writeBeginArray();
119 | boolean first = true;
120 | for( JsonValue value : array ) {
121 | if( !first ) {
122 | writeArrayValueSeparator();
123 | }
124 | value.write( this );
125 | first = false;
126 | }
127 | writeEndArray();
128 | }
129 |
130 | protected void writeBeginArray() throws IOException {
131 | writer.write( '[' );
132 | }
133 |
134 | protected void writeEndArray() throws IOException {
135 | writer.write( ']' );
136 | }
137 |
138 | protected void writeArrayValueSeparator() throws IOException {
139 | writer.write( ',' );
140 | }
141 |
142 | }
143 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/json/ParseException.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.json;
12 |
13 |
14 | /**
15 | * An unchecked exception to indicate that an input does not qualify as valid JSON.
16 | */
17 | @SuppressWarnings( "serial" ) // use default serial UID
18 | public class ParseException extends RuntimeException {
19 |
20 | private final int offset;
21 | private final int line;
22 | private final int column;
23 |
24 | ParseException( String message, int offset, int line, int column ) {
25 | super( message + " at " + line + ":" + column );
26 | this.offset = offset;
27 | this.line = line;
28 | this.column = column;
29 | }
30 |
31 | /**
32 | * Returns the absolute index of the character at which the error occurred. The
33 | * index of the first character of a document is 0.
34 | *
35 | * @return the character offset at which the error occurred, will be >= 0
36 | */
37 | public int getOffset() {
38 | return offset;
39 | }
40 |
41 | /**
42 | * Returns the number of the line in which the error occurred. The first line counts as 1.
43 | *
44 | * @return the line in which the error occurred, will be >= 1
45 | */
46 | public int getLine() {
47 | return line;
48 | }
49 |
50 | /**
51 | * Returns the index of the character at which the error occurred, relative to the line. The
52 | * index of the first character of a line is 0.
53 | *
54 | * @return the column in which the error occurred, will be >= 0
55 | */
56 | public int getColumn() {
57 | return column;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/json/PrettyPrintJsonWriter.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.json;
12 |
13 | import java.io.IOException;
14 | import java.io.Writer;
15 |
16 |
17 | public class PrettyPrintJsonWriter extends JsonWriter {
18 |
19 | public PrettyPrintJsonWriter( Writer writer ) {
20 | super( writer );
21 | }
22 |
23 | private int indent = 0;
24 |
25 | @Override
26 | protected void writeBeginObject() throws IOException {
27 | super.writeBeginObject();
28 | indent++;
29 | writeNewline();
30 | }
31 |
32 | @Override
33 | protected void writeEndObject() throws IOException {
34 | indent--;
35 | writeNewline();
36 | super.writeEndObject();
37 | }
38 |
39 | @Override
40 | protected void writeNameValueSeparator() throws IOException {
41 | super.writeNameValueSeparator();
42 | writer.write( ' ' );
43 | }
44 |
45 | @Override
46 | protected void writeObjectValueSeparator() throws IOException {
47 | super.writeObjectValueSeparator();
48 | writeNewline();
49 | }
50 |
51 | @Override
52 | protected void writeArrayValueSeparator() throws IOException {
53 | super.writeArrayValueSeparator();
54 | writer.write( ' ' );
55 | }
56 |
57 | protected void writeNewline() throws IOException {
58 | writer.write( '\n' );
59 | for( int i = 0; i < indent; i++ ) {
60 | writer.write( " " );
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/bundles/com.eclipsesource.jshint/src/com/eclipsesource/json/README.txt:
--------------------------------------------------------------------------------
1 | This package contains a copy of the minimal JSON parser [1], version 0.9.0, with small adjustments
2 | to support formatted JSON output.
3 |
4 | [1] https://github.com/ralfstx/minimal-json
5 |
--------------------------------------------------------------------------------
/jshint-blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eclipsesource/jshint-eclipse/76dd9f9cedea11bf40b379d9b3275bbc4d7e3d71/jshint-blue.png
--------------------------------------------------------------------------------
/jshint.target:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | linux
30 | gtk
31 | x86_64
32 | en_US
33 |
34 |
35 | -Dosgi.requiredJavaVersion=1.5 -XX:-UseLoopPredicate -XX:CompileCommand=exclude,org/eclipse/core/internal/dtree/DataTreeNode,forwardDeltaWith -XX:CompileCommand=exclude,java/text/SimpleDateFormat,subParseZoneString -XX:CompileCommand=exclude,org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.<init> -XX:MaxPermSize=256m -Xms128m -Xmx512m
36 |
37 |
38 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | 0.18.1
9 | UTF-8
10 |
11 |
12 |
13 | 3.0
14 |
15 |
16 | jshint-eclipse
17 |
18 | com.eclipsesource.jshint
19 | com.eclipsesource.jshint.build
20 | 0.10.1-SNAPSHOT
21 | pom
22 |
23 |
24 | bundles/com.eclipsesource.jshint
25 | bundles/com.eclipsesource.jshint.ui
26 | tests/com.eclipsesource.jshint.test
27 | tests/com.eclipsesource.jshint.ui.test
28 | releng/com.eclipsesource.jshint.feature
29 | releng/com.eclipsesource.jshint.repository
30 |
31 |
32 |
33 |
34 |
35 | target-repo
36 | p2
37 | http://download.eclipse.org/releases/mars/
38 |
39 |
40 | orbit-repo
41 | p2
42 | http://download.eclipse.org/tools/orbit/downloads/drops/R20150821153341/repository/
43 |
44 |
45 | swtbot-repo
46 | p2
47 | http://download.eclipse.org/technology/swtbot/releases/2.3.0/
48 |
49 |
50 | mockito-all-repo
51 | p2
52 | http://download.eclipsesource.com/~rsternberg/mockito-all/
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | org.eclipse.tycho
62 | tycho-maven-plugin
63 | ${tycho-version}
64 | true
65 |
66 |
67 |
68 | org.eclipse.tycho
69 | tycho-packaging-plugin
70 | ${tycho-version}
71 |
72 | yyyyMMdd-HHmm
73 |
74 |
75 |
76 |
77 | org.eclipse.tycho
78 | tycho-source-plugin
79 | ${tycho-version}
80 |
81 |
82 | plugin-source
83 |
84 | plugin-source
85 |
86 |
87 |
88 |
89 |
90 |
91 | org.eclipse.tycho
92 | tycho-surefire-plugin
93 | ${tycho-version}
94 |
95 | true
96 | -nl en -consoleLog
97 |
98 | **/*Test.*
99 |
100 | random
101 |
102 | eclipse-feature
103 | org.eclipse.rcp
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/releng/com.eclipsesource.jshint.feature/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.eclipsesource.jshint.feature
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.pde.FeatureBuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.pde.FeatureNature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/releng/com.eclipsesource.jshint.feature/build.properties:
--------------------------------------------------------------------------------
1 | bin.includes = feature.xml,\
2 | epl-v10.html,\
3 | feature.properties
4 |
--------------------------------------------------------------------------------
/releng/com.eclipsesource.jshint.feature/feature.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 | %description
10 |
11 |
12 |
13 | %copyright
14 |
15 |
16 |
17 | %license
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
36 |
37 |
43 |
44 |
50 |
51 |
57 |
58 |
64 |
65 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/releng/com.eclipsesource.jshint.feature/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.eclipsesource.jshint
8 | com.eclipsesource.jshint.feature
9 | 0.10.1-SNAPSHOT
10 | eclipse-feature
11 |
12 |
13 | com.eclipsesource.jshint
14 | com.eclipsesource.jshint.build
15 | 0.10.1-SNAPSHOT
16 | ../../pom.xml
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/releng/com.eclipsesource.jshint.repository/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.eclipsesource.jshint.repository
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/releng/com.eclipsesource.jshint.repository/category.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | JSHint Integration for Eclipse
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/releng/com.eclipsesource.jshint.repository/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.eclipsesource.jshint
8 | com.eclipsesource.jshint.repository
9 | 0.10.1-SNAPSHOT
10 | eclipse-repository
11 |
12 |
13 | com.eclipsesource.jshint
14 | com.eclipsesource.jshint.build
15 | 0.10.1-SNAPSHOT
16 | ../../pom.xml
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.tycho
23 | tycho-p2-repository-plugin
24 | ${tycho-version}
25 |
26 | JSHint Eclipse Integration
27 | false
28 | true
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.eclipsesource.jshint.test
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.pde.ManifestBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.pde.SchemaBuilder
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.pde.PluginNature
26 | org.eclipse.jdt.core.javanature
27 |
28 |
29 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\n
3 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.5
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.5
12 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.ui.javadoc=true
3 | org.eclipse.jdt.ui.text.custom_code_templates=/*******************************************************************************\n * Copyright (c) ${year} EclipseSource.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * ${user} - initial implementation and API\n ******************************************************************************/${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}\n\n\n\n// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();// ${todo} Auto-generated method stub\n${body_statement}${body_statement}\n// ${todo} Auto-generated constructor stubreturn ${field};${field} \= ${param};
4 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/.settings/org.eclipse.pde.core.prefs:
--------------------------------------------------------------------------------
1 | #Fri Jan 06 16:07:26 CET 2012
2 | eclipse.preferences.version=1
3 | pluginProject.extensions=false
4 | resolve.requirebundle=false
5 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/JSHint Tests.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Bundle-ManifestVersion: 2
3 | Bundle-Name: Tests for JSHint Eclipse Integration
4 | Bundle-SymbolicName: com.eclipsesource.jshint.test
5 | Bundle-Version: 0.10.1.qualifier
6 | Fragment-Host: com.eclipsesource.jshint;bundle-version="0.10.1"
7 | Bundle-RequiredExecutionEnvironment: J2SE-1.5
8 | Import-Package: org.junit;version="4.8.2",
9 | org.junit.runner;version="4.8.2",
10 | org.junit.runners;version="4.8.2"
11 | Bundle-Vendor: EclipseSource
12 | Require-Bundle: org.hamcrest.core;bundle-version="1.1.0",
13 | org.mockito.mockito-all;bundle-version="[1.9.5,2.0.0)",
14 | org.eclipse.equinox.ds,
15 | org.eclipse.equinox.event
16 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/build.properties:
--------------------------------------------------------------------------------
1 | source.. = src/
2 | output.. = bin/
3 | bin.includes = META-INF/,\
4 | .
5 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.eclipsesource.jshint
8 | com.eclipsesource.jshint.test
9 | 0.10.1-SNAPSHOT
10 | eclipse-test-plugin
11 |
12 |
13 | com.eclipsesource.jshint
14 | com.eclipsesource.jshint.build
15 | 0.10.1-SNAPSHOT
16 | ../../pom.xml
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.test/src/com/eclipsesource/jshint/internal/ProblemImpl_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.internal;
12 |
13 | import org.junit.Test;
14 |
15 | import com.eclipsesource.jshint.Problem;
16 |
17 | import static org.junit.Assert.assertFalse;
18 | import static org.junit.Assert.assertTrue;
19 |
20 |
21 | public class ProblemImpl_Test {
22 |
23 | @Test
24 | public void isError_falseForNull() {
25 | Problem problem = new ProblemImpl( 0, 0, null, null );
26 |
27 | assertFalse( problem.isError() );
28 | }
29 |
30 | @Test
31 | public void isError_falseForEmptyString() {
32 | Problem problem = new ProblemImpl( 0, 0, null, "" );
33 |
34 | assertFalse( problem.isError() );
35 | }
36 |
37 | @Test
38 | public void isError_falseForAnythingElse() {
39 | Problem problem = new ProblemImpl( 0, 0, null, "foo" );
40 |
41 | assertFalse( problem.isError() );
42 | }
43 |
44 | @Test
45 | public void isError_trueForErrors() {
46 | Problem problem = new ProblemImpl( 0, 0, null, "E000" );
47 |
48 | assertTrue( problem.isError() );
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.eclipsesource.jshint.ui.test
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.pde.ManifestBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.pde.SchemaBuilder
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.pde.PluginNature
26 | org.eclipse.jdt.core.javanature
27 |
28 |
29 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.5
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.5
12 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.ui.javadoc=true
3 | org.eclipse.jdt.ui.text.custom_code_templates=/*******************************************************************************\n * Copyright (c) ${year} EclipseSource.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * ${user} - initial implementation and API\n ******************************************************************************/${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}\n\n\n\n// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();// ${todo} Auto-generated method stub\n${body_statement}${body_statement}\n// ${todo} Auto-generated constructor stubreturn ${field};${field} \= ${param};
4 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/.settings/org.eclipse.pde.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | pluginProject.extensions=false
3 | resolve.requirebundle=false
4 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Bundle-ManifestVersion: 2
3 | Bundle-Name: Tests for JSHint UI
4 | Bundle-SymbolicName: com.eclipsesource.jshint.ui.test
5 | Bundle-Version: 0.10.1.qualifier
6 | Bundle-Vendor: EclipseSource
7 | Fragment-Host: com.eclipsesource.jshint.ui;bundle-version="0.10.1"
8 | Bundle-RequiredExecutionEnvironment: J2SE-1.5
9 | Import-Package: org.apache.log4j;version="[1.2.13,1.3.0)",
10 | org.eclipse.swt.custom,
11 | org.eclipse.swtbot.swt.finder,
12 | org.eclipse.swtbot.swt.finder.widgets,
13 | org.junit;version="4.8.2",
14 | org.junit.runner;version="4.8.2"
15 | Require-Bundle: org.hamcrest.core;bundle-version="1.1.0",
16 | org.mockito.mockito-all;bundle-version="[1.9.5,2.0.0)",
17 | org.eclipse.equinox.ds,
18 | org.eclipse.equinox.event
19 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/build.properties:
--------------------------------------------------------------------------------
1 | source.. = src/
2 | output.. = bin/
3 | bin.includes = META-INF/,\
4 | .
5 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.eclipsesource.jshint
8 | com.eclipsesource.jshint.ui.test
9 | 0.10.1-SNAPSHOT
10 | eclipse-test-plugin
11 |
12 |
13 | com.eclipsesource.jshint
14 | com.eclipsesource.jshint.build
15 | 0.10.1-SNAPSHOT
16 | ../../pom.xml
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/builder/BuilderUtil_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 | import java.io.IOException;
14 |
15 | import org.eclipse.core.resources.IFile;
16 | import org.eclipse.core.resources.IProject;
17 | import org.eclipse.core.runtime.CoreException;
18 | import org.junit.After;
19 | import org.junit.Before;
20 | import org.junit.Test;
21 |
22 | import com.eclipsesource.jshint.ui.test.TestUtil;
23 |
24 | import static com.eclipsesource.jshint.ui.test.TestUtil.*;
25 | import static org.junit.Assert.assertFalse;
26 | import static org.junit.Assert.assertTrue;
27 |
28 |
29 | public class BuilderUtil_Test {
30 |
31 | private IProject project;
32 |
33 | @Before
34 | public void setUp() {
35 | project = createProject( "test" );
36 | createFile( project, "/test.js", "test" );
37 | }
38 |
39 | @After
40 | public void tearDown() {
41 | deleteProject( project );
42 | }
43 |
44 | @Test
45 | public void addBuilder() throws CoreException, IOException {
46 | boolean result = BuilderUtil.addBuilderToProject( project, TestUtil.BUILDER_ID );
47 |
48 | assertTrue( result );
49 | IFile metadata = project.getFile( ".project" );
50 | assertTrue( readContent( metadata ).contains( TestUtil.BUILDER_ID ) );
51 | }
52 |
53 | @Test
54 | public void addBuilderTwice() throws CoreException {
55 | BuilderUtil.addBuilderToProject( project, TestUtil.BUILDER_ID );
56 |
57 | boolean result = BuilderUtil.addBuilderToProject( project, TestUtil.BUILDER_ID );
58 |
59 | assertFalse( result );
60 | }
61 |
62 | @Test
63 | public void removeBuilder() throws CoreException, IOException {
64 | BuilderUtil.addBuilderToProject( project, TestUtil.BUILDER_ID );
65 |
66 | boolean result = BuilderUtil.removeBuilderFromProject( project, TestUtil.BUILDER_ID );
67 |
68 | assertTrue( result );
69 | IFile metadata = project.getFile( ".project" );
70 | assertFalse( readContent( metadata ).contains( TestUtil.BUILDER_ID ) );
71 | }
72 |
73 | @Test
74 | public void removeNonExistingBuilder() throws CoreException {
75 | boolean result = BuilderUtil.removeBuilderFromProject( project, TestUtil.BUILDER_ID );
76 |
77 | assertFalse( result );
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/builder/CommentsFilter_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 | import org.junit.Test;
14 |
15 | import static org.junit.Assert.assertEquals;
16 |
17 |
18 | public class CommentsFilter_Test {
19 |
20 | @Test
21 | public void filter_emptyImput() {
22 | assertEquals( "",
23 | filter( "" ) );
24 | }
25 |
26 | @Test
27 | public void filter_lineComment_atStart() {
28 | assertEquals( " ",
29 | filter( "//foo" ) );
30 | }
31 |
32 | @Test
33 | public void filter_lineComment_embedded() {
34 | assertEquals( "one\ntwo \nthreee\n",
35 | filter( "one\ntwo//foo\nthreee\n" ) );
36 | }
37 |
38 | @Test
39 | public void filter_blockComment_inSingleLine() {
40 | assertEquals( "one\ntwo bar\nthreee\n",
41 | filter( "one\ntwo/*foo*/bar\nthreee\n" ) );
42 | }
43 |
44 | @Test
45 | public void filter_blockComment_overMultipleLines() {
46 | assertEquals( "one\ntwo \n threee\n",
47 | filter( "one\ntwo/*foo\nbar*/threee\n" ) );
48 | }
49 |
50 | private static String filter( String input ) {
51 | return new CommentsFilter( input ).toString();
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/builder/JSHintBuilderVisitor_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 | import org.eclipse.core.resources.IFile;
14 | import org.eclipse.core.resources.IProject;
15 | import org.eclipse.core.runtime.CoreException;
16 | import org.eclipse.core.runtime.IProgressMonitor;
17 | import org.eclipse.core.runtime.NullProgressMonitor;
18 | import org.junit.After;
19 | import org.junit.Before;
20 | import org.junit.Test;
21 | import org.osgi.service.prefs.BackingStoreException;
22 | import org.osgi.service.prefs.Preferences;
23 |
24 | import com.eclipsesource.jshint.ui.internal.preferences.EnablementPreferences;
25 | import com.eclipsesource.jshint.ui.internal.preferences.PreferencesFactory;
26 |
27 | import static com.eclipsesource.jshint.ui.test.TestUtil.*;
28 | import static org.junit.Assert.assertFalse;
29 | import static org.junit.Assert.assertTrue;
30 |
31 |
32 | public class JSHintBuilderVisitor_Test {
33 |
34 | private IProject project;
35 | private IFile file;
36 | private IProgressMonitor monitor;
37 |
38 | @Before
39 | public void setUp() throws BackingStoreException {
40 | PreferencesFactory.getWorkspacePreferences().clear();
41 | project = createProject( "test" );
42 | file = createFile( project, "/test.js", "test content" );
43 | monitor = new NullProgressMonitor();
44 | }
45 |
46 | @After
47 | public void tearDown() {
48 | deleteProject( project );
49 | }
50 |
51 | @Test
52 | public void skipsProjectWithoutIncludePattern() throws CoreException {
53 | JSHintBuilderVisitor visitor = new JSHintBuilderVisitor( project, monitor );
54 |
55 | assertFalse( visitor.visit( project ) );
56 | }
57 |
58 | @Test
59 | public void visitsProjectWhenIncludePatternIsPresent() throws CoreException {
60 | addIncludePattern( project, "/test.js" );
61 | JSHintBuilderVisitor visitor = new JSHintBuilderVisitor( project, monitor );
62 |
63 | assertTrue( visitor.visit( project ) );
64 | }
65 |
66 | @Test
67 | public void skipsProjectWhenCancelled() throws CoreException {
68 | addIncludePattern( project, "/test.js" );
69 | JSHintBuilderVisitor visitor = new JSHintBuilderVisitor( project, monitor );
70 |
71 | monitor.setCanceled( true );
72 |
73 | assertFalse( visitor.visit( project ) );
74 | }
75 |
76 | @Test
77 | public void visitsResourceWhenIncluded() throws CoreException {
78 | addIncludePattern( project, "/test.js" );
79 | JSHintBuilderVisitor visitor = new JSHintBuilderVisitor( project, monitor );
80 |
81 | assertTrue( visitor.visit( file ) );
82 | }
83 |
84 | @Test
85 | public void skipsResourceWhenCancelled() throws CoreException {
86 | addIncludePattern( project, "/test.js" );
87 | JSHintBuilderVisitor visitor = new JSHintBuilderVisitor( project, monitor );
88 |
89 | monitor.setCanceled( true );
90 |
91 | assertFalse( visitor.visit( file ) );
92 | }
93 |
94 | private void addIncludePattern( IProject project, String... pattern ) {
95 | Preferences projectPrefsNode = PreferencesFactory.getProjectPreferences( project );
96 | new EnablementPreferences( projectPrefsNode ).setIncludePatterns( list( pattern ) );
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/builder/MarkerHandler_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.builder;
12 |
13 | import org.eclipse.core.runtime.CoreException;
14 | import org.junit.After;
15 | import org.junit.Before;
16 | import org.junit.Test;
17 |
18 | import com.eclipsesource.jshint.Problem;
19 | import com.eclipsesource.jshint.Text;
20 | import com.eclipsesource.jshint.ui.internal.preferences.JSHintPreferences;
21 |
22 | import static org.mockito.Mockito.*;
23 |
24 |
25 | public class MarkerHandler_Test {
26 |
27 | private MarkerAdapter adapter;
28 |
29 | @Before
30 | public void setUp() {
31 | adapter = mock( MarkerAdapter.class );
32 | }
33 |
34 | @After
35 | public void tearDown() throws CoreException {
36 | JSHintPreferences prefs = new JSHintPreferences();
37 | prefs.resetToDefaults();
38 | prefs.save();
39 | }
40 |
41 | @Test
42 | public void handleProblem_createsWarning() throws CoreException {
43 | MarkerHandler handler = new MarkerHandler( adapter, new Text( "test" ) );
44 |
45 | handler.handleProblem( mockWarning( 1, 2, "foo" ) );
46 |
47 | verify( adapter ).createWarning( 1, 2, 2, "foo" );
48 | }
49 |
50 | @Test
51 | public void handleProblem_createsWarningForError() throws CoreException {
52 | MarkerHandler handler = new MarkerHandler( adapter, new Text( "test" ) );
53 |
54 | handler.handleProblem( mockError( 1, 2, "foo" ) );
55 |
56 | verify( adapter ).createWarning( 1, 2, 2, "foo" );
57 | }
58 |
59 | @Test
60 | public void handleProblem_createsError_ifEnabled() throws CoreException {
61 | JSHintPreferences prefs = new JSHintPreferences();
62 | prefs.setEnableErrorMarkers( true );
63 | prefs.save();
64 | MarkerHandler handler = new MarkerHandler( adapter, new Text( "test" ) );
65 |
66 | handler.handleProblem( mockError( 1, 2, "foo" ) );
67 |
68 | verify( adapter ).createError( 1, 2, 2, "foo" );
69 | }
70 |
71 | @Test
72 | public void handleProblem_createsProblemAtDocumentWhenLineIsZero() throws CoreException {
73 | MarkerHandler handler = new MarkerHandler( adapter, new Text( "test" ) );
74 |
75 | handler.handleProblem( mockWarning( 0, 1, "test" ) );
76 |
77 | verify( adapter ).createWarning( -1, -1, -1, "test" );
78 | }
79 |
80 | @Test
81 | public void handleProblem_createsProblemAtDocumentWhenLineIsNegative() throws CoreException {
82 | MarkerHandler handler = new MarkerHandler( adapter, new Text( "test" ) );
83 |
84 | handler.handleProblem( mockWarning( -1, 1, "test" ) );
85 |
86 | verify( adapter ).createWarning( -1, -1, -1, "test" );
87 | }
88 |
89 | @Test
90 | public void handleProblem_createsProblemAtDocumentWhenLineExceedsDocument() throws CoreException {
91 | MarkerHandler handler = new MarkerHandler( adapter, new Text( "test" ) );
92 |
93 | handler.handleProblem( mockWarning( 2, 1, "test" ) );
94 |
95 | verify( adapter ).createWarning( -1, -1, -1, "test" );
96 | }
97 |
98 | @Test
99 | public void handleProblem_createsProblemAtLineWhenCharacterIsNegative() throws CoreException {
100 | MarkerHandler handler = new MarkerHandler( adapter, new Text( "test" ) );
101 |
102 | handler.handleProblem( mockWarning( 1, -1, "test" ) );
103 |
104 | verify( adapter ).createWarning( 1, -1, -1, "test" );
105 | }
106 |
107 | @Test
108 | public void handleProblem_createsProblemAtLineWhenCharacterExceedsLine() throws CoreException {
109 | MarkerHandler handler = new MarkerHandler( adapter, new Text( "line1\nline2\n" ) );
110 |
111 | handler.handleProblem( mockWarning( 1, 6, "test" ) );
112 |
113 | verify( adapter ).createWarning( 1, -1, -1, "test" );
114 | }
115 |
116 | @Test
117 | public void handleProblem_createsProblemAtLineWhenCharacterExceedsDocument() throws CoreException
118 | {
119 | MarkerHandler handler = new MarkerHandler( adapter, new Text( "line1\nline2\n" ) );
120 |
121 | handler.handleProblem( mockWarning( 1, 13, "test" ) );
122 |
123 | verify( adapter ).createWarning( 1, -1, -1, "test" );
124 | }
125 |
126 | private Problem mockError( int line, int character, String message ) {
127 | Problem problem = mockWarning( line, character, message );
128 | when( Boolean.valueOf( problem.isError() ) ).thenReturn( Boolean.TRUE );
129 | return problem;
130 | }
131 |
132 | private Problem mockWarning( int line, int character, String message ) {
133 | Problem problem = mock( Problem.class );
134 | when( Integer.valueOf( problem.getLine() ) ).thenReturn( Integer.valueOf( line ) );
135 | when( Integer.valueOf( problem.getCharacter() ) ).thenReturn( Integer.valueOf( character ) );
136 | when( problem.getMessage() ).thenReturn( message );
137 | return problem;
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/EnablementPreferences_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import java.util.Collections;
14 |
15 | import org.junit.Before;
16 | import org.junit.Test;
17 | import org.osgi.service.prefs.BackingStoreException;
18 | import org.osgi.service.prefs.Preferences;
19 |
20 | import static com.eclipsesource.jshint.ui.test.TestUtil.list;
21 | import static org.junit.Assert.assertFalse;
22 | import static org.junit.Assert.assertTrue;
23 |
24 |
25 | public class EnablementPreferences_Test {
26 |
27 | private Preferences node;
28 | private EnablementPreferences prefs;
29 |
30 | @Before
31 | public void setUp() {
32 | node = new PreferencesMock( "test" );
33 | prefs = new EnablementPreferences( node );
34 | }
35 |
36 | @Test
37 | public void defaults() {
38 | assertTrue( prefs.getIncludePatterns().isEmpty() );
39 | assertTrue( prefs.getExcludePatterns().isEmpty() );
40 | assertFalse( prefs.hasChanged() );
41 | }
42 |
43 | @Test
44 | public void getExcludePatterns_default() {
45 | assertTrue( prefs.getExcludePatterns().isEmpty() );
46 | }
47 |
48 | @Test
49 | public void setExcludePatterns_unchanged() {
50 | prefs.setExcludePatterns( Collections.emptyList() );
51 |
52 | assertTrue( prefs.getExcludePatterns().isEmpty() );
53 | assertFalse( prefs.hasChanged() );
54 | }
55 |
56 | @Test
57 | public void setExcludePatterns_emptyList() {
58 | prefs.setExcludePatterns( list( "/foo" ) );
59 | prefs.clearChanged();
60 |
61 | prefs.setExcludePatterns( Collections.emptyList() );
62 |
63 | assertTrue( prefs.getExcludePatterns().isEmpty() );
64 | assertTrue( prefs.hasChanged() );
65 | }
66 |
67 | @Test
68 | public void setExcludePatterns_reset() {
69 | prefs.setExcludePatterns( list( "/foo" ) );
70 | prefs.clearChanged();
71 |
72 | prefs.setExcludePatterns( Collections.emptyList() );
73 |
74 | assertTrue( prefs.hasChanged() );
75 | assertTrue( isEmpty( node ) );
76 | }
77 |
78 | @Test
79 | public void setExcludePatterns_emptyPatternIgnored() {
80 | prefs.setExcludePatterns( list( "" ) );
81 |
82 | assertFalse( prefs.hasChanged() );
83 | }
84 |
85 | @Test
86 | public void setExcludePatterns_multiplePaths() {
87 | prefs.setExcludePatterns( list( "/foo", "/bar", "" ) );
88 |
89 | assertTrue( prefs.getExcludePatterns().contains( "/foo" ) );
90 | assertTrue( prefs.getExcludePatterns().contains( "/bar" ) );
91 | assertFalse( prefs.getExcludePatterns().contains( "" ) );
92 | }
93 |
94 | @Test
95 | public void getIncludePatterns_default() {
96 | assertTrue( prefs.getIncludePatterns().isEmpty() );
97 | }
98 |
99 | @Test
100 | public void setIncludePatterns_unchanged() {
101 | prefs.setIncludePatterns( Collections.emptyList() );
102 |
103 | assertTrue( prefs.getIncludePatterns().isEmpty() );
104 | assertFalse( prefs.hasChanged() );
105 | }
106 |
107 | @Test
108 | public void setIncludePatterns_writeThrough() {
109 | prefs.setIncludePatterns( list( "/foo" ) );
110 |
111 | assertTrue( new EnablementPreferences( node ).getIncludePatterns().contains( "/foo" ) );
112 | }
113 |
114 | @Test
115 | public void setIncludePatterns_emptyList() {
116 | prefs.setIncludePatterns( list( "/foo" ) );
117 | prefs.clearChanged();
118 |
119 | prefs.setIncludePatterns( Collections.emptyList() );
120 |
121 | assertTrue( prefs.getIncludePatterns().isEmpty() );
122 | assertTrue( prefs.hasChanged() );
123 | }
124 |
125 | @Test
126 | public void setIncludePatterns_emptyPatternIgnored() {
127 | prefs.setIncludePatterns( list( "" ) );
128 |
129 | assertFalse( prefs.hasChanged() );
130 | }
131 |
132 | @Test
133 | public void setIncludePatterns_multiplePaths() {
134 | prefs.setIncludePatterns( list( "/foo", "/bar", "" ) );
135 |
136 | assertTrue( prefs.getIncludePatterns().contains( "/foo" ) );
137 | assertTrue( prefs.getIncludePatterns().contains( "/bar" ) );
138 | assertFalse( prefs.getIncludePatterns().contains( "" ) );
139 | }
140 |
141 | @Test
142 | public void clearChanged() {
143 | prefs.setExcludePatterns( list( "/foo" ) );
144 |
145 | prefs.clearChanged();
146 |
147 | assertFalse( prefs.hasChanged() );
148 | }
149 |
150 | private static boolean isEmpty( Preferences node ) {
151 | try {
152 | return node.keys().length == 0;
153 | } catch( BackingStoreException exception ) {
154 | throw new RuntimeException( exception );
155 | }
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/IncludesView_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import org.eclipse.core.resources.IProject;
14 | import org.eclipse.swt.SWT;
15 | import org.eclipse.swt.widgets.Composite;
16 | import org.eclipse.swt.widgets.Display;
17 | import org.eclipse.swt.widgets.Shell;
18 | import org.eclipse.swt.widgets.TableItem;
19 | import org.eclipse.swtbot.swt.finder.SWTBot;
20 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
21 | import org.junit.After;
22 | import org.junit.Before;
23 | import org.junit.Test;
24 |
25 | import com.eclipsesource.jshint.ui.internal.preferences.ui.IncludesView;
26 |
27 | import static com.eclipsesource.jshint.ui.test.TestUtil.*;
28 | import static org.junit.Assert.assertEquals;
29 | import static org.junit.Assert.assertTrue;
30 |
31 |
32 | public class IncludesView_Test {
33 |
34 | private Composite parent;
35 | private IProject project;
36 | private EnablementPreferences preferences;
37 |
38 | @Before
39 | public void setUp() {
40 | Display display = Display.getDefault();
41 | parent = new Shell( display );
42 | project = createProject( "test" );
43 | preferences = new EnablementPreferences( new PreferencesMock( "test" ) );
44 | }
45 |
46 | @After
47 | public void tearDown() {
48 | deleteProject( project );
49 | parent.dispose();
50 | }
51 |
52 | @Test
53 | public void tablesEmptyByDefault() {
54 | IncludesView view = new IncludesView( parent, SWT.NONE, project );
55 |
56 | SWTBotTable includeTable = findIncludeTable( view );
57 | SWTBotTable excludeTable = findExcludeTable( view );
58 | assertEquals( 0, includeTable.rowCount() );
59 | assertEquals( 0, excludeTable.rowCount() );
60 | }
61 |
62 | @Test
63 | public void loadDefaults() {
64 | IncludesView view = new IncludesView( parent, SWT.NONE, project );
65 | SWTBotTable includeTable = findIncludeTable( view );
66 | SWTBotTable excludeTable = findExcludeTable( view );
67 | new TableItem( includeTable.widget, SWT.NONE ).setText( "/foo/" );
68 | new TableItem( excludeTable.widget, SWT.NONE ).setText( "/bar/" );
69 |
70 | view.loadDefaults();
71 |
72 | assertEquals( 0, includeTable.rowCount() );
73 | assertEquals( 0, excludeTable.rowCount() );
74 | }
75 |
76 | @Test
77 | public void loadPreferences() {
78 | IncludesView view = new IncludesView( parent, SWT.NONE, project );
79 | preferences.setIncludePatterns( list( "/foo/" ) );
80 | preferences.setExcludePatterns( list( "/bar/" ) );
81 |
82 | view.loadPreferences( preferences );
83 |
84 | SWTBotTable includeTable = findIncludeTable( view );
85 | SWTBotTable excludeTable = findExcludeTable( view );
86 | assertEquals( 1, includeTable.rowCount() );
87 | assertEquals( 1, excludeTable.rowCount() );
88 | assertEquals( "/foo/", includeTable.getTableItem( 0 ).getText() );
89 | assertEquals( "/bar/", excludeTable.getTableItem( 0 ).getText() );
90 | }
91 |
92 | @Test
93 | public void loadPreferences_changed() {
94 | IncludesView view = new IncludesView( parent, SWT.NONE, project );
95 | preferences.setIncludePatterns( list( "/foo/" ) );
96 | view.loadPreferences( preferences );
97 |
98 | preferences.setIncludePatterns( list( "/bar/" ) );
99 | view.loadPreferences( preferences );
100 |
101 | SWTBotTable table = findIncludeTable( view );
102 | assertEquals( 1, table.rowCount() );
103 | assertEquals( "/bar/", table.getTableItem( 0 ).getText() );
104 | }
105 |
106 | @Test
107 | public void storePreferences() {
108 | IncludesView view = new IncludesView( parent, SWT.NONE, project );
109 | SWTBotTable includeTable = findIncludeTable( view );
110 | SWTBotTable excludeTable = findExcludeTable( view );
111 | new TableItem( includeTable.widget, SWT.NONE ).setText( "/foo/" );
112 | new TableItem( excludeTable.widget, SWT.NONE ).setText( "/bar/" );
113 |
114 | view.storePreferences( preferences );
115 |
116 | assertTrue( preferences.getIncludePatterns().contains( "/foo/" ) );
117 | assertTrue( preferences.getExcludePatterns().contains( "/bar/" ) );
118 | }
119 |
120 | private static SWTBotTable findIncludeTable( Composite parent ) {
121 | return new SWTBot( parent ).table( 0 );
122 | }
123 |
124 | private static SWTBotTable findExcludeTable( Composite parent ) {
125 | return new SWTBot( parent ).table( 1 );
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/JSHintPreferences_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import org.junit.Before;
14 | import org.junit.Test;
15 | import org.osgi.service.prefs.BackingStoreException;
16 | import org.osgi.service.prefs.Preferences;
17 |
18 | import static org.junit.Assert.*;
19 |
20 |
21 | public class JSHintPreferences_Test {
22 |
23 | @Before
24 | public void setUp() throws BackingStoreException {
25 | Preferences node = PreferencesFactory.getWorkspacePreferences();
26 | node.clear();
27 | }
28 |
29 | @Test
30 | public void defaultPrefsForEmptyProject() {
31 | JSHintPreferences prefs = new JSHintPreferences();
32 |
33 | assertFalse( prefs.getUseCustomLib() );
34 | assertEquals( "", prefs.getCustomLibPath() );
35 | assertFalse( prefs.getEnableErrorMarkers() );
36 | }
37 |
38 | @Test
39 | public void resetToDefaults() throws Exception {
40 | JSHintPreferences prefs = new JSHintPreferences();
41 | prefs.setUseCustomLib( true );
42 | prefs.setCustomLibPath( "foo" );
43 | prefs.setEnableErrorMarkers( true );
44 | prefs.save();
45 |
46 | prefs.resetToDefaults();
47 |
48 | assertTrue( prefs.hasChanged() );
49 | assertFalse( prefs.getUseCustomLib() );
50 | assertEquals( "", prefs.getCustomLibPath() );
51 | assertFalse( prefs.getEnableErrorMarkers() );
52 | }
53 |
54 | @Test
55 | public void setUseCustomLib() {
56 | JSHintPreferences prefs = new JSHintPreferences();
57 |
58 | prefs.setUseCustomLib( true );
59 |
60 | assertTrue( prefs.hasChanged() );
61 | assertTrue( prefs.getUseCustomLib() );
62 | assertFalse( new JSHintPreferences().getUseCustomLib() );
63 | }
64 |
65 | @Test
66 | public void setUseCustomLib_unchanged() {
67 | JSHintPreferences prefs = new JSHintPreferences();
68 |
69 | prefs.setUseCustomLib( prefs.getUseCustomLib() );
70 |
71 | assertFalse( prefs.hasChanged() );
72 | }
73 |
74 | @Test
75 | public void setEnableErrorMarkers() {
76 | JSHintPreferences prefs = new JSHintPreferences();
77 |
78 | prefs.setEnableErrorMarkers( true );
79 |
80 | assertTrue( prefs.hasChanged() );
81 | assertTrue( prefs.getEnableErrorMarkers() );
82 | assertFalse( new JSHintPreferences().getEnableErrorMarkers() );
83 | }
84 |
85 | @Test
86 | public void setEnableErrorMarkers_unchanged() {
87 | JSHintPreferences prefs = new JSHintPreferences();
88 |
89 | prefs.setEnableErrorMarkers( prefs.getEnableErrorMarkers() );
90 |
91 | assertFalse( prefs.hasChanged() );
92 | }
93 |
94 | @Test
95 | public void setCustomLibPath() {
96 | JSHintPreferences prefs = new JSHintPreferences();
97 |
98 | prefs.setCustomLibPath( "foo" );
99 |
100 | assertTrue( prefs.hasChanged() );
101 | assertEquals( "foo", prefs.getCustomLibPath() );
102 | assertEquals( "", new JSHintPreferences().getCustomLibPath() );
103 | }
104 |
105 | @Test
106 | public void setCustomLibPath_unchanged() {
107 | JSHintPreferences prefs = new JSHintPreferences();
108 |
109 | prefs.setCustomLibPath( prefs.getCustomLibPath() );
110 |
111 | assertFalse( prefs.hasChanged() );
112 | }
113 |
114 | @Test
115 | public void save() throws Exception {
116 | JSHintPreferences prefs = new JSHintPreferences();
117 | prefs.setCustomLibPath( "foo" );
118 |
119 | prefs.save();
120 |
121 | assertFalse( prefs.hasChanged() );
122 | assertEquals( "foo", new JSHintPreferences().getCustomLibPath() );
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/OptionParserUtil_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import java.util.List;
14 |
15 | import org.junit.Test;
16 |
17 | import com.eclipsesource.jshint.ui.internal.preferences.OptionParserUtil.Entry;
18 | import com.eclipsesource.json.JsonObject;
19 | import com.eclipsesource.json.JsonValue;
20 |
21 | import static org.junit.Assert.assertEquals;
22 | import static org.junit.Assert.assertTrue;
23 |
24 |
25 | public class OptionParserUtil_Test {
26 |
27 | @Test
28 | public void createConfiguration() {
29 | JsonObject result = OptionParserUtil.createConfiguration( "foo: true", "org: false" );
30 |
31 | assertEquals( "{\"foo\":true,\"globals\":{\"org\":false}}", result.toString() );
32 | }
33 |
34 | @Test
35 | public void createConfiguration_withEmptyParameters() {
36 | JsonObject result = OptionParserUtil.createConfiguration( "", "" );
37 |
38 | assertEquals( "{}", result.toString() );
39 | }
40 |
41 | @Test( expected = NullPointerException.class )
42 | public void createConfiguration_withOptionsNull() {
43 | OptionParserUtil.createConfiguration( null, "" );
44 | }
45 |
46 | @Test( expected = NullPointerException.class )
47 | public void createConfiguration_withGlobalsNull() {
48 | OptionParserUtil.createConfiguration( "", null );
49 | }
50 |
51 | @Test( expected = NullPointerException.class )
52 | public void parseNull() {
53 | OptionParserUtil.parseOptionString( null );
54 | }
55 |
56 | @Test
57 | public void parseEmpty() {
58 | List result = OptionParserUtil.parseOptionString( "" );
59 |
60 | assertTrue( result.isEmpty() );
61 | }
62 |
63 | @Test
64 | public void parseSingle() {
65 | List result = OptionParserUtil.parseOptionString( "foo: true" );
66 |
67 | assertEquals( 1, result.size() );
68 | assertEquals( "foo", result.get( 0 ).name );
69 | assertEquals( JsonValue.TRUE, result.get( 0 ).value );
70 | }
71 |
72 | @Test
73 | public void parseTwoOptions() {
74 | List result = OptionParserUtil.parseOptionString( "foo: true, bar: false" );
75 |
76 | assertEquals( 2, result.size() );
77 | assertEquals( "foo", result.get( 0 ).name );
78 | assertEquals( JsonValue.TRUE, result.get( 0 ).value );
79 | assertEquals( "bar", result.get( 1 ).name );
80 | assertEquals( JsonValue.FALSE, result.get( 1 ).value );
81 | }
82 |
83 | @Test
84 | public void parseAdditionalWhitespace() {
85 | List result = OptionParserUtil.parseOptionString( "\tfoo : true ,\n\t bar : false " );
86 |
87 | assertEquals( 2, result.size() );
88 | assertEquals( "foo", result.get( 0 ).name );
89 | assertEquals( JsonValue.TRUE, result.get( 0 ).value );
90 | assertEquals( "bar", result.get( 1 ).name );
91 | assertEquals( JsonValue.FALSE, result.get( 1 ).value );
92 | }
93 |
94 | // TODO check for illegal names
95 | @Test
96 | public void parseWhitespaceInName() {
97 | List result = OptionParserUtil.parseOptionString( "foo bar: true" );
98 |
99 | assertEquals( 1, result.size() );
100 | assertEquals( "foo bar", result.get( 0 ).name );
101 | assertEquals( JsonValue.TRUE, result.get( 0 ).value );
102 | }
103 |
104 | @Test
105 | public void parseNumericValue() {
106 | List result = OptionParserUtil.parseOptionString( "foo: 23" );
107 |
108 | assertEquals( 1, result.size() );
109 | assertEquals( "foo", result.get( 0 ).name );
110 | assertEquals( JsonValue.valueOf( 23 ), result.get( 0 ).value );
111 | }
112 |
113 | @Test
114 | public void parseIllegalValue() {
115 | List result = OptionParserUtil.parseOptionString( "foo: (invalidJSON)" );
116 |
117 | assertEquals( 0, result.size() );
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/OptionsPreferences_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import org.junit.Before;
14 | import org.junit.Test;
15 | import org.osgi.service.prefs.BackingStoreException;
16 | import org.osgi.service.prefs.Preferences;
17 |
18 | import static org.junit.Assert.*;
19 |
20 |
21 | public class OptionsPreferences_Test {
22 |
23 | private Preferences node;
24 | private OptionsPreferences prefs;
25 |
26 | @Before
27 | public void setUp() {
28 | node = new PreferencesMock( "test" );
29 | prefs = new OptionsPreferences( node );
30 | }
31 |
32 | @Test
33 | public void getNode() {
34 | assertSame( node, prefs.getNode() );
35 | }
36 |
37 | @Test
38 | public void defaultPrefsForEmptyProject() {
39 | assertFalse( prefs.getProjectSpecific() );
40 | assertEquals( "{\n \n}", prefs.getConfig() );
41 | }
42 |
43 | @Test
44 | public void setProjectSpecific() {
45 | prefs.setProjectSpecific( true );
46 |
47 | assertTrue( prefs.getProjectSpecific() );
48 | assertTrue( prefs.hasChanged() );
49 | assertTrue( new OptionsPreferences( node ).getProjectSpecific() );
50 | }
51 |
52 | @Test
53 | public void setProjectSpecific_unchanged() {
54 | prefs.setProjectSpecific( false );
55 |
56 | assertFalse( prefs.hasChanged() );
57 | }
58 |
59 | @Test
60 | public void setProjectSpecific_reset() throws BackingStoreException {
61 | prefs.setProjectSpecific( true );
62 | prefs.clearChanged();
63 |
64 | prefs.setProjectSpecific( false );
65 |
66 | assertTrue( prefs.hasChanged() );
67 | assertEquals( 0, node.keys().length );
68 | }
69 |
70 | @Test
71 | public void setConfig() {
72 | prefs.setConfig( "foo" );
73 |
74 | assertEquals( "foo", prefs.getConfig() );
75 | assertTrue( prefs.hasChanged() );
76 | assertEquals( prefs.getConfig(), new OptionsPreferences( node ).getConfig() );
77 | }
78 |
79 | @Test
80 | public void setConfig_unchanged() {
81 | prefs.setConfig( "{ \"foo\": true }" );
82 | prefs.clearChanged();
83 |
84 | prefs.setConfig( prefs.getConfig() );
85 |
86 | assertFalse( prefs.hasChanged() );
87 | }
88 |
89 | @Test
90 | public void getConfig_fallsBackToOldPreferences() {
91 | prefs.getNode().put( "options", "foo: true, bar: false" );
92 | prefs.getNode().put( "globals", "org: true, com: false" );
93 |
94 | String expected = "{\n"
95 | + " \"foo\": true,\n"
96 | + " \"bar\": false,\n"
97 | + " \"globals\": {\n"
98 | + " \"org\": true,\n"
99 | + " \"com\": false\n"
100 | + " }\n"
101 | + "}";
102 | assertEquals( expected, prefs.getConfig() );
103 | }
104 |
105 | @Test
106 | public void clearChanges() {
107 | prefs.setConfig( "foo" );
108 |
109 | prefs.clearChanged();
110 |
111 | assertFalse( prefs.hasChanged() );
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/PathEncoder_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import org.junit.Test;
17 |
18 | import static org.junit.Assert.assertEquals;
19 |
20 |
21 | public class PathEncoder_Test {
22 |
23 | @Test
24 | public void encodeEmptyList() {
25 | assertEquals( "", PathEncoder.encodePaths( createList() ) );
26 | }
27 |
28 | @Test
29 | public void encodeEmptyString() {
30 | assertEquals( "", PathEncoder.encodePaths( createList( "" ) ) );
31 | }
32 |
33 | @Test
34 | public void encodeSingleString() {
35 | assertEquals( "foo", PathEncoder.encodePaths( createList( "foo" ) ) );
36 | }
37 |
38 | @Test
39 | public void encodeMixedStrings() {
40 | assertEquals( "foo:bar", PathEncoder.encodePaths( createList( "foo", "", "bar" ) ) );
41 | }
42 |
43 | @Test
44 | public void decodeEmptyList() {
45 | assertListEquals( createList(), PathEncoder.decodePaths( "" ) );
46 | }
47 |
48 | @Test
49 | public void decodeSimpleString() {
50 | assertListEquals( createList( "foo" ), PathEncoder.decodePaths( "foo" ) );
51 | }
52 |
53 | @Test
54 | public void decodeMultipleStrings() {
55 | assertListEquals( createList( "foo", "bar" ), PathEncoder.decodePaths( "foo:bar" ) );
56 | }
57 |
58 | private static List createList( String ... strings ) {
59 | ArrayList result = new ArrayList();
60 | for( String string : strings ) {
61 | result.add( string );
62 | }
63 | return result;
64 | }
65 |
66 | private static void assertListEquals( List list1, List list2 ) {
67 | assertEquals( "lists size differs", list1.size(), list2.size() );
68 | for( int i = 0; i < list1.size(); i++ ) {
69 | assertEquals( list1.get( i ), list2.get( i ) );
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/PreferencesFactory_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import org.eclipse.core.resources.IProject;
14 | import org.junit.After;
15 | import org.junit.Before;
16 | import org.junit.Test;
17 | import org.osgi.service.prefs.Preferences;
18 |
19 | import static com.eclipsesource.jshint.ui.test.TestUtil.createProject;
20 | import static com.eclipsesource.jshint.ui.test.TestUtil.deleteProject;
21 | import static org.junit.Assert.assertNotNull;
22 | import static org.junit.Assert.assertSame;
23 |
24 |
25 | public class PreferencesFactory_Test {
26 | private IProject project;
27 |
28 | @Before
29 | public void setUp() {
30 | project = createProject( "test" );
31 | }
32 |
33 | @After
34 | public void tearDown() {
35 | deleteProject( project );
36 | }
37 |
38 | @Test
39 | public void getProjectPreferences() {
40 | Preferences preferences = PreferencesFactory.getProjectPreferences( project );
41 |
42 | assertNotNull( preferences );
43 | assertSame( preferences, PreferencesFactory.getProjectPreferences( project ) );
44 | }
45 |
46 | @Test
47 | public void getWorkspacePreferences() {
48 | Preferences preferences = PreferencesFactory.getWorkspacePreferences();
49 |
50 | assertNotNull( preferences );
51 | assertSame( preferences, PreferencesFactory.getWorkspacePreferences() );
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/PreferencesMock.java:
--------------------------------------------------------------------------------
1 | package com.eclipsesource.jshint.ui.internal.preferences;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.Set;
6 |
7 | import org.osgi.service.prefs.BackingStoreException;
8 | import org.osgi.service.prefs.Preferences;
9 |
10 |
11 | public class PreferencesMock implements Preferences {
12 |
13 | private final String name;
14 | private final Map values;
15 |
16 | public PreferencesMock( String name ) {
17 | this.name = name;
18 | values = new HashMap();
19 | }
20 |
21 | public void put( String key, String value ) {
22 | values.put( key, value );
23 | }
24 |
25 | public String get( String key, String def ) {
26 | String result = (String)values.get( key );
27 | return result != null ? result : def;
28 | }
29 |
30 | public void remove( String key ) {
31 | values.remove( key );
32 | }
33 |
34 | public void clear() throws BackingStoreException {
35 | values.clear();
36 | }
37 |
38 | public void putInt( String key, int value ) {
39 | values.put( key, Integer.valueOf( value ) );
40 | }
41 |
42 | public int getInt( String key, int def ) {
43 | Integer result = (Integer)values.get( key );
44 | return result != null ? result.intValue() : def;
45 | }
46 |
47 | public void putLong( String key, long value ) {
48 | values.put( key, Long.valueOf( value ) );
49 | }
50 |
51 | public long getLong( String key, long def ) {
52 | Long result = (Long)values.get( key );
53 | return result != null ? result.longValue() : def;
54 | }
55 |
56 | public void putBoolean( String key, boolean value ) {
57 | values.put( key, Boolean.valueOf( value ) );
58 |
59 | }
60 |
61 | public boolean getBoolean( String key, boolean def ) {
62 | Boolean result = (Boolean)values.get( key );
63 | return result != null ? result.booleanValue() : def;
64 | }
65 |
66 | public void putFloat( String key, float value ) {
67 | values.put( key, Float.valueOf( value ) );
68 | }
69 |
70 | public float getFloat( String key, float def ) {
71 | Float result = (Float)values.get( key );
72 | return result != null ? result.floatValue() : def;
73 | }
74 |
75 | public void putDouble( String key, double value ) {
76 | values.put( key, Double.valueOf( value ) );
77 | }
78 |
79 | public double getDouble( String key, double def ) {
80 | Double result = (Double)values.get( key );
81 | return result != null ? result.doubleValue() : def;
82 | }
83 |
84 | public void putByteArray( String key, byte[] value ) {
85 | values.put( key, value );
86 | }
87 |
88 | public byte[] getByteArray( String key, byte[] def ) {
89 | byte[] result = (byte[])values.get( key );
90 | return result != null ? result : def;
91 | }
92 |
93 | public String[] keys() throws BackingStoreException {
94 | Set keys = values.keySet();
95 | return keys.toArray( new String[ values.size() ] );
96 | }
97 |
98 | public String[] childrenNames() throws BackingStoreException {
99 | return new String[ 0 ];
100 | }
101 |
102 | public Preferences parent() {
103 | return null;
104 | }
105 |
106 | public Preferences node( String pathName ) {
107 | throw new UnsupportedOperationException();
108 | }
109 |
110 | public boolean nodeExists( String pathName ) throws BackingStoreException {
111 | return false;
112 | }
113 |
114 | public void removeNode() throws BackingStoreException {
115 | throw new UnsupportedOperationException();
116 | }
117 |
118 | public String name() {
119 | return name;
120 | }
121 |
122 | public String absolutePath() {
123 | throw new UnsupportedOperationException();
124 | }
125 |
126 | public void flush() throws BackingStoreException {
127 | // do nothing
128 | }
129 |
130 | public void sync() throws BackingStoreException {
131 | // do nothing
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/ProjectPreferences_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 EclipseSource.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences;
12 |
13 | import org.eclipse.core.resources.IFile;
14 | import org.eclipse.core.resources.IProject;
15 | import org.junit.After;
16 | import org.junit.Before;
17 | import org.junit.Test;
18 | import org.osgi.service.prefs.Preferences;
19 |
20 | import static com.eclipsesource.jshint.ui.test.TestUtil.*;
21 | import static org.junit.Assert.*;
22 |
23 |
24 | public class ProjectPreferences_Test {
25 | private IProject project;
26 | private IFile file;
27 | private Preferences node;
28 |
29 | @Before
30 | public void setUp() {
31 | project = createProject( "test" );
32 | file = createFile( project, "/test.js", "test content" );
33 | node = PreferencesFactory.getProjectPreferences( project );
34 | }
35 |
36 | @After
37 | public void tearDown() {
38 | deleteProject( project );
39 | }
40 |
41 | @Test
42 | public void defaultPrefsForEmptyProject() {
43 | EnablementPreferences prefs = new EnablementPreferences( node );
44 |
45 | assertTrue( prefs.getIncludePatterns().isEmpty() );
46 | }
47 |
48 | @Test
49 | public void enablementPrefsFromExampleSettingsFile() throws Exception {
50 | createExampleSettingsFile( project, SETTINGS_FILE_NAME, SETTINGS_TEMPLATE_0_9 );
51 |
52 | EnablementPreferences prefs = new EnablementPreferences( node );
53 |
54 | assertTrue( prefs.getExcludePatterns().contains( "js/test.js" ) );
55 | assertTrue( prefs.getExcludePatterns().contains( "target" ) );
56 | assertFalse( prefs.hasChanged() );
57 | }
58 |
59 | @Test
60 | public void optionPrefsFromExampleSettingsFile() throws Exception {
61 | createExampleSettingsFile( project, SETTINGS_FILE_NAME, SETTINGS_TEMPLATE_0_9 );
62 |
63 | OptionsPreferences optionPrefs = new OptionsPreferences( node );
64 |
65 | String expected = "{\n"
66 | + " \"bitwise\": true,\n"
67 | + " \"curly\": true,\n"
68 | + " \"eqnull\": true,\n"
69 | + " \"globals\": {\n"
70 | + " \"org\": true,\n"
71 | + " \"com\": false\n"
72 | + " }\n"
73 | + "}";
74 | assertEquals( expected, optionPrefs.getConfig() );
75 | assertFalse( optionPrefs.hasChanged() );
76 | }
77 |
78 | @Test
79 | public void resourcePaths() {
80 | assertEquals( "", EnablementPreferences.getResourcePath( project ) );
81 | assertEquals( "test.js", EnablementPreferences.getResourcePath( file ) );
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/ui/BrowserSupport_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences.ui;
12 |
13 | import org.junit.Test;
14 |
15 | import static org.junit.Assert.assertNotNull;
16 |
17 |
18 | public class BrowserSupport_Test {
19 |
20 | @Test
21 | public void instance_isNotNull() {
22 | assertNotNull( BrowserSupport.INSTANCE );
23 | }
24 |
25 | @Test( expected = NullPointerException.class )
26 | public void openUrl_rejectsNullUrl() {
27 | BrowserSupport.INSTANCE.openUrl( null );
28 | }
29 |
30 | @Test( expected = IllegalArgumentException.class )
31 | public void openUrl_rejectsInvalidUrl() {
32 | BrowserSupport.INSTANCE.openUrl( "eclipse.org" );
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/preferences/ui/ConfigEditor_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.preferences.ui;
12 |
13 | import java.util.concurrent.atomic.AtomicReference;
14 |
15 | import org.eclipse.swt.SWT;
16 | import org.eclipse.swt.graphics.Color;
17 | import org.eclipse.swt.graphics.GC;
18 | import org.eclipse.swt.widgets.Shell;
19 | import org.junit.After;
20 | import org.junit.Before;
21 | import org.junit.Test;
22 |
23 | import static org.junit.Assert.*;
24 |
25 |
26 | public class ConfigEditor_Test {
27 |
28 | private Shell shell;
29 |
30 | @Before
31 | public void setUp() {
32 | shell = new Shell();
33 | shell.open();
34 | }
35 |
36 | @After
37 | public void tearDown() {
38 | shell.close();
39 | }
40 |
41 | @Test
42 | public void createsStyledText() {
43 | ConfigEditor editor = new ConfigEditor( shell );
44 |
45 | assertSame( shell, editor.getControl().getParent() );
46 | }
47 |
48 | @Test
49 | public void styledText_isEditable() {
50 | ConfigEditor editor = new ConfigEditor( shell );
51 |
52 | assertTrue( editor.getControl().getEditable() );
53 | }
54 |
55 | @Test
56 | public void styledText_hasMonospaceFont() {
57 | ConfigEditor editor = new ConfigEditor( shell );
58 |
59 | GC gc = new GC( editor.getControl() );
60 | assertEquals( gc.stringExtent( "i" ), gc.stringExtent( "m" ) );
61 | }
62 |
63 | @Test
64 | public void setEnabled_setsEditableAndForeground() {
65 | ConfigEditor editor = new ConfigEditor( shell );
66 | Color gray = shell.getDisplay().getSystemColor( SWT.COLOR_GRAY );
67 |
68 | editor.setEnabled( false );
69 |
70 | assertFalse( editor.getControl().getEditable() );
71 | assertEquals( gray, editor.getControl().getForeground() );
72 | }
73 |
74 | @Test
75 | public void setEnabled_restoresEditableAndForeground() {
76 | ConfigEditor editor = new ConfigEditor( shell );
77 | Color defaultForeground = editor.getControl().getForeground();
78 | editor.setEnabled( false );
79 |
80 | editor.setEnabled( true );
81 |
82 | assertTrue( editor.getControl().getEditable() );
83 | assertEquals( defaultForeground, editor.getControl().getForeground() );
84 | }
85 |
86 | @Test
87 | public void getText_returnsTrimmedTextWithTrailingLinebreak() {
88 | ConfigEditor editor = new ConfigEditor( shell );
89 | editor.setText( " foo bar " );
90 |
91 | String text = editor.getText();
92 |
93 | assertEquals( "foo bar", text );
94 | }
95 |
96 | @Test
97 | public void validatesOnType() {
98 | final AtomicReference errorMessage = new AtomicReference();
99 | ConfigEditor editor = new ConfigEditor( shell ) {
100 | @Override
101 | protected void handleError( String string ) {
102 | errorMessage.set( string );
103 | }
104 | };
105 |
106 | editor.getControl().setText( "-invalid-" );
107 |
108 | assertTrue( errorMessage.get().startsWith( "Syntax error" ) );
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/internal/util/JsonUtil_Test.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 EclipseSource and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ralf Sternberg - initial implementation and API
10 | ******************************************************************************/
11 | package com.eclipsesource.jshint.ui.internal.util;
12 |
13 | import org.junit.Test;
14 |
15 | import com.eclipsesource.json.JsonArray;
16 | import com.eclipsesource.json.JsonObject;
17 |
18 | import static org.junit.Assert.*;
19 |
20 |
21 | public class JsonUtil_Test {
22 |
23 | @Test
24 | public void jsonEquals() {
25 | assertFalse( JsonUtil.jsonEquals( null, null ) );
26 | assertFalse( JsonUtil.jsonEquals( null, "{}" ) );
27 | assertFalse( JsonUtil.jsonEquals( "{}", null ) );
28 | assertFalse( JsonUtil.jsonEquals( "{}", "" ) );
29 | assertFalse( JsonUtil.jsonEquals( "", "" ) );
30 | assertFalse( JsonUtil.jsonEquals( "{\"a\":true}", "{\"a\":false}" ) );
31 | assertTrue( JsonUtil.jsonEquals( "{}", "{}" ) );
32 | assertTrue( JsonUtil.jsonEquals( "{\"a\":true}", "{\"a\":true}" ) );
33 | }
34 |
35 | @Test
36 | public void prettyPrint_emptyObject() {
37 | assertEquals( "{\n \n}", JsonUtil.prettyPrint( new JsonObject() ) );
38 | }
39 |
40 | @Test
41 | public void prettyPrint_withNestedArray() {
42 | JsonObject object = new JsonObject()
43 | .add( "foo", true )
44 | .add( "bar", new JsonArray().add( 23 ).add( 42 ) );
45 |
46 | assertEquals( "{\n \"foo\": true,\n \"bar\": [23, 42]\n}", JsonUtil.prettyPrint( object ) );
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/com/eclipsesource/jshint/ui/test/jshint-0.9.prefs:
--------------------------------------------------------------------------------
1 | #Tue Jan 10 12:59:32 CET 2012
2 | eclipse.preferences.version=1
3 | enabled=true
4 | excluded=js/test.js\:target
5 | globals=org\: true, com\: false
6 | options=bitwise\: true, curly\: true, eqnull\: true
7 |
--------------------------------------------------------------------------------
/tests/com.eclipsesource.jshint.ui.test/src/log4j.properties:
--------------------------------------------------------------------------------
1 | # Needed for SWTBot, which requires log4j.
2 | # Set root logger level to WARN and its only appender to A1.
3 | log4j.rootLogger = WARN, A1
4 |
5 | # A1 is set to be a ConsoleAppender.
6 | log4j.appender.A1 = org.apache.log4j.ConsoleAppender
7 |
8 | # A1 uses PatternLayout.
9 | log4j.appender.A1.layout = org.apache.log4j.PatternLayout
10 | log4j.appender.A1.layout.ConversionPattern = %-4r [%t] %-5p %c %x - %m%n
11 |
--------------------------------------------------------------------------------