├── .gitignore ├── nbproject ├── keystore ├── project.properties ├── genfiles.properties ├── platform.properties ├── build-impl.xml └── project.xml ├── release └── modules │ └── ext │ └── markdownj-core-0.4.1.jar ├── src └── com │ └── github │ └── mdolk │ └── ng │ └── netbeans │ ├── favicon.ico │ ├── favicon.png │ ├── Bundle.properties │ └── codecompletion │ ├── NgUtils.java │ ├── NgDoc.java │ ├── NgDocCache.java │ ├── NgHtmlCompletionContext.java │ ├── NgHtmlCompletionProvider.java │ ├── NgHtmlCompletionItem.java │ └── NgHtmlCompletionDocumentation.java ├── manifest.mf ├── test └── unit │ └── src │ └── com │ └── github │ └── mdolk │ └── ng │ └── codecompletion │ ├── NgUtilsTest.java │ └── NgDocTest.java ├── CHANGELOG.markdown ├── release.sh └── license └── gpl-2.0.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | /build 3 | /nbproject/private 4 | -------------------------------------------------------------------------------- /nbproject/keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdolk/angular-netbeans-plugin/HEAD/nbproject/keystore -------------------------------------------------------------------------------- /release/modules/ext/markdownj-core-0.4.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdolk/angular-netbeans-plugin/HEAD/release/modules/ext/markdownj-core-0.4.1.jar -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdolk/angular-netbeans-plugin/HEAD/src/com/github/mdolk/ng/netbeans/favicon.ico -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mdolk/angular-netbeans-plugin/HEAD/src/com/github/mdolk/ng/netbeans/favicon.png -------------------------------------------------------------------------------- /manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | OpenIDE-Module: com.github.mdolk.ng.netbeans 3 | OpenIDE-Module-Localizing-Bundle: com/github/mdolk/ng/netbeans/Bundle.properties 4 | OpenIDE-Module-Specification-Version: 0.4 5 | 6 | -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | javac.source=1.6 2 | javac.compilerargs=-Xlint -Xlint:-serial 3 | license.file=license/gpl-2.0.txt 4 | nbm.homepage=https://github.com/mdolk/angular-netbeans-plugin 5 | nbm.module.author=M\u00e5rten Dolk 6 | nbm.needs.restart=true 7 | keystore=nbproject/keystore 8 | nbm_alias=com.github.mdolk.ng.netbeans 9 | 10 | -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=4df9123e 2 | build.xml.script.CRC32=09922fb1 3 | build.xml.stylesheet.CRC32=a56c6a5b@1.46.2 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=4df9123e 7 | nbproject/build-impl.xml.script.CRC32=850bcdad 8 | nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.2 9 | -------------------------------------------------------------------------------- /nbproject/platform.properties: -------------------------------------------------------------------------------- 1 | cluster.path=\ 2 | ${nbplatform.active.dir}/profiler:\ 3 | ${nbplatform.active.dir}/apisupport:\ 4 | ${nbplatform.active.dir}/harness:\ 5 | ${nbplatform.active.dir}/ide:\ 6 | ${nbplatform.active.dir}/enterprise:\ 7 | ${nbplatform.active.dir}/java:\ 8 | ${nbplatform.active.dir}/nb:\ 9 | ${nbplatform.active.dir}/platform:\ 10 | ${nbplatform.active.dir}/dlight:\ 11 | ${nbplatform.active.dir}/websvccommon 12 | nbplatform.active=default 13 | -------------------------------------------------------------------------------- /test/unit/src/com/github/mdolk/ng/codecompletion/NgUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.github.mdolk.ng.codecompletion; 2 | 3 | import com.github.mdolk.ng.netbeans.codecompletion.NgUtils; 4 | import java.util.List; 5 | import org.junit.Test; 6 | import static org.junit.Assert.*; 7 | 8 | public class NgUtilsTest { 9 | @Test 10 | public void testGetDocs() { 11 | List docs = NgUtils.getDocComments("xxx /**\nfoo */ yyy /** bar\n */ zzz"); 12 | assertEquals(2, docs.size()); 13 | assertEquals("/**\nfoo */", docs.get(0)); 14 | assertEquals("/** bar\n */", docs.get(1)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/Bundle.properties: -------------------------------------------------------------------------------- 1 | OpenIDE-Module-Display-Category=HTML XML 2 | OpenIDE-Module-Long-Description=\ 3 |

\nNote! \ 4 | You need a non-minified version angular-x.y.z.js somewhere in your project for the plugin to work!\n\ 5 |

\n\n

\nProvides AngularJS aware code completion in HTML editor by scanning project's js-files looking for @ngdoc-tags in comments.\n\ 6 |

\n\n

\nCurrently support auto completion for:\n

\n

7 | OpenIDE-Module-Name=AngularJS Tools 8 | OpenIDE-Module-Short-Description=Code completion for AngularJS HTML files 9 | -------------------------------------------------------------------------------- /CHANGELOG.markdown: -------------------------------------------------------------------------------- 1 | 0.4 (in progress) 2 | ================= 3 | 4 | 5 | ----------------------------------------------------------------------------- 6 | 7 | 8 | 0.3 (2011-10-10) 9 | ================= 10 | 11 | Improvements 12 | ------------- 13 | * Distribute via NetBeans plugin portal 14 | * Signed .nbm file 15 | * Display name changed to "AngularJS Tools" 16 | 17 | ----------------------------------------------------------------------------- 18 | 19 | 0.2 (2011-10-05) 20 | ================= 21 | 22 | Improvements 23 | ------------ 24 | 25 | * Full support for advanced formatting in doc popups (thanks to [markdownj]) 26 | 27 | [markdownj]: http://markdownj.org/ 28 | 29 | ----------------------------------------------------------------------------- 30 | 31 | 0.1 (2011-10-04) 32 | ================ 33 | 34 | Features 35 | -------- 36 | 37 | * First release! -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e # exit script on any failed command 3 | 4 | MANIFEST=manifest.mf 5 | VERSION=`grep ^OpenIDE-Module-Specification-Version: < $MANIFEST | cut -d " " -f2-` 6 | 7 | # make sure we have no uncommited changes 8 | if [ -n "$(git status --porcelain)" ]; then 9 | echo "You have uncommited changes, you dirty little girl!" 10 | git status --porcelain 11 | exit 1; 12 | fi 13 | 14 | # build .nbm 15 | ant clean test nbm 16 | 17 | # prepare for next version 18 | echo "=========================================================================" 19 | echo "Current version will be tagged as \"$VERSION\"." 20 | read -p "What it the next version? " NEXT_VERSION 21 | git tag "$VERSION" 22 | sed "s/^\(OpenIDE-Module-Specification-Version:\) .*/\1 $NEXT_VERSION/" < $MANIFEST > $MANIFEST.next 23 | rm $MANIFEST 24 | mv $MANIFEST.next $MANIFEST 25 | git add $MANIFEST 26 | git commit -m "Released $VERSION. Started work on $NEXT_VERSION" 27 | 28 | echo "Another successful build!" 29 | echo "Now push the changes, remember the tags..." 30 | -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/codecompletion/NgUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.mdolk.ng.netbeans.codecompletion; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Enumeration; 5 | import java.util.List; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | import org.openide.filesystems.FileObject; 9 | 10 | public class NgUtils { 11 | 12 | public static List findByMimeType(FileObject root, String mime) { 13 | if (!root.isFolder()) { 14 | throw new IllegalArgumentException("Not a folder"); 15 | } 16 | List result = new ArrayList(); 17 | Enumeration children = root.getChildren(true); 18 | while (children.hasMoreElements()) { 19 | FileObject file = children.nextElement(); 20 | if (mime.equals(file.getMIMEType())) { 21 | result.add(file); 22 | } 23 | } 24 | return result; 25 | } 26 | 27 | /** 28 | * Find all groups staring with '/**' and ending with */ 29 | */ 30 | public static List getDocComments(String s) { 31 | Pattern pattern = Pattern.compile("/\\*\\*.*?\\*/", Pattern.DOTALL); 32 | Matcher matcher = pattern.matcher(s); 33 | List result = new ArrayList(); 34 | while (matcher.find()) { 35 | result.add(matcher.group()); 36 | } 37 | return result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /nbproject/build-impl.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /test/unit/src/com/github/mdolk/ng/codecompletion/NgDocTest.java: -------------------------------------------------------------------------------- 1 | package com.github.mdolk.ng.codecompletion; 2 | 3 | import com.github.mdolk.ng.netbeans.codecompletion.NgDoc; 4 | import java.util.List; 5 | import org.junit.Test; 6 | import static org.junit.Assert.*; 7 | 8 | public class NgDocTest { 9 | private static String DOC = 10 | "/**\n" + 11 | " * @workInProgress\n" + 12 | " * @ngdoc directive\n" + 13 | " * @name angular.directive.ng:hide\n" + 14 | " *\n" + 15 | " * @description\n" + 16 | " * The `ng:hide` and `ng:show` directives hide or show a portion\n" + 17 | " * of the HTML conditionally.\n" + 18 | " *\n" + 19 | " * @element ANY\n" + 20 | " * @param {expression} expression If the {@link guide/dev_guide.expressions expression} truthy then\n" + 21 | " * the element is shown or hidden respectively.\n" + 22 | " * @param {expression} foo some other cool expression.\n" + 23 | " *\n" + 24 | " * @batman is the {@link very/cool coolest} hero\n" + 25 | " * ever!\n" + 26 | " */"; 27 | 28 | @Test 29 | public void testIsPresent() { 30 | NgDoc ngDoc = new NgDoc(DOC); 31 | assertTrue(ngDoc.isPresent("@workInProgress")); 32 | assertFalse(ngDoc.isPresent("@notPresent")); 33 | } 34 | 35 | @Test 36 | public void testGetAttribute() { 37 | NgDoc ngDoc = new NgDoc(DOC); 38 | assertEquals("directive", ngDoc.getAttribute("@ngdoc")); 39 | } 40 | 41 | @Test 42 | public void testGetMultiLineAttribute() { 43 | NgDoc ngDoc = new NgDoc(DOC); 44 | String description = ngDoc.getMultilineAttribute("@description"); 45 | assertTrue(description.startsWith("The `ng:hide` and")); 46 | assertTrue(description.endsWith("HTML conditionally.\n\n")); 47 | String batman = ngDoc.getMultilineAttribute("@batman"); 48 | assertEquals("is the {@link very/cool coolest} hero\n ever!\n", batman); 49 | } 50 | 51 | @Test 52 | public void testGetMultiLineAttributes() { 53 | NgDoc ngDoc = new NgDoc(DOC); 54 | List params = ngDoc.getMultilineAttributes("@param"); 55 | assertEquals(2, params.size()); 56 | assertEquals("{expression} foo some other cool expression.\n\n", params.get(1)); 57 | } 58 | 59 | @Test 60 | public void testStripLeadingWhitespaceAndAsterisks() { 61 | NgDoc ngDoc = new NgDoc( 62 | "/**\n" + 63 | " * foo\n" + 64 | " *\n" + 65 | " * bar\n" + 66 | " * baz\n" + 67 | " boz\n" + 68 | " biz\n" + 69 | " */"); 70 | assertEquals("foo\n\nbar\nbaz\n boz\n biz\n", ngDoc.getText()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/codecompletion/NgDoc.java: -------------------------------------------------------------------------------- 1 | package com.github.mdolk.ng.netbeans.codecompletion; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | public class NgDoc { 9 | private final String text; 10 | 11 | public NgDoc(String text) { 12 | if (!text.startsWith("/**")) 13 | throw new IllegalArgumentException("Comment must start with '/**'"); 14 | if (!text.endsWith("*/")) 15 | throw new IllegalArgumentException("Comment must end with '*/'"); 16 | this.text = stripLeadingWhitespaceAndAsterisks(text.substring(3, text.length()-2)); 17 | } 18 | 19 | private static String stripLeadingWhitespaceAndAsterisks(String text) { 20 | Pattern pattern = Pattern.compile("(?:\\s*\\*)?[\\s&&[^\\r\\n]]?(.*\\n)"); 21 | Matcher matcher = pattern.matcher(text); 22 | StringBuilder sb = new StringBuilder(); 23 | while (matcher.find()) { 24 | sb.append(matcher.group(1)); 25 | } 26 | return sb.toString(); 27 | } 28 | 29 | public boolean isPresent(String attribute) { 30 | return text.contains(attribute); 31 | } 32 | 33 | public String getAttribute(String attribute) { 34 | attribute += " "; 35 | int start = text.lastIndexOf(attribute); 36 | if (start == -1) { 37 | return null; 38 | } 39 | start += attribute.length(); 40 | int end = text.indexOf("\n", start); 41 | return text.substring(start, end).trim(); 42 | } 43 | 44 | public String getMultilineAttribute(String attribute) { 45 | List all = getMultilineAttributes(attribute); 46 | if (all.isEmpty()) { 47 | return null; 48 | } 49 | return all.get(0); 50 | } 51 | 52 | public List getMultilineAttributes(String attribute) { 53 | // Match until next @ but ignore @ if in {}, e.g. can return "I have a {@link a/y link} embedded!" 54 | Pattern pattern = Pattern.compile(toRegExp(attribute)+"\\s((?:[^\\{@]*(?:\\{[^\\}]*\\})?)*)"); 55 | Matcher matcher = pattern.matcher(text); 56 | List result = new ArrayList(); 57 | while (matcher.find()) { 58 | result.add( matcher.group(1) ); 59 | } 60 | return result; 61 | } 62 | 63 | private static String toRegExp(String s) { 64 | final String[] ZEROS = new String[] {"0000","000","00","0", ""}; 65 | StringBuilder sb = new StringBuilder(); 66 | for (char c : s.toCharArray()) { 67 | String hexString = Integer.toHexString((int)c); 68 | sb.append("\\u").append(ZEROS[hexString.length()]).append(hexString); 69 | } 70 | return sb.toString(); 71 | } 72 | 73 | public String getText() { 74 | return text; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/codecompletion/NgDocCache.java: -------------------------------------------------------------------------------- 1 | package com.github.mdolk.ng.netbeans.codecompletion; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | import org.netbeans.api.project.FileOwnerQuery; 9 | import org.netbeans.api.project.Project; 10 | import org.netbeans.api.project.ProjectInformation; 11 | import org.netbeans.api.project.ProjectUtils; 12 | import org.openide.filesystems.FileChangeAdapter; 13 | import org.openide.filesystems.FileEvent; 14 | import org.openide.filesystems.FileObject; 15 | import org.openide.filesystems.FileUtil; 16 | import org.openide.util.Exceptions; 17 | 18 | public class NgDocCache { 19 | private final Map> cache = new HashMap>(); 20 | 21 | public NgDocCache() { 22 | FileUtil.addFileChangeListener(new UpdateCacheWhenJsFileChangedListener()); 23 | } 24 | 25 | private class UpdateCacheWhenJsFileChangedListener extends FileChangeAdapter { 26 | @Override 27 | public void fileDataCreated(FileEvent fe) { 28 | updateCache(fe); 29 | } 30 | 31 | @Override 32 | public void fileChanged(FileEvent fe) { 33 | updateCache(fe); 34 | } 35 | 36 | @Override 37 | public void fileDeleted(FileEvent fe) { 38 | updateCache(fe); 39 | } 40 | 41 | private void updateCache(FileEvent fe) { 42 | FileObject file = fe.getFile(); 43 | if (!"text/javascript".equals(file.getMIMEType())) { 44 | return; 45 | } 46 | Project project = FileOwnerQuery.getOwner(file); 47 | if (project == null) { 48 | return; 49 | } 50 | ProjectInformation info = ProjectUtils.getInformation(project); 51 | System.out.println("Update ngdoc cache for project '" + info.getDisplayName() + "'"); 52 | cache.put(info.getName(), readProjectNgDocsFromFiles(project)); 53 | } 54 | } 55 | 56 | public List getNgDocs(Project project) { 57 | ProjectInformation info = ProjectUtils.getInformation(project); 58 | String projectName = info.getName(); 59 | if (!cache.containsKey(projectName)) { 60 | System.out.println("Init ngdoc cache for project '" + info.getDisplayName() + "'"); 61 | cache.put(projectName, readProjectNgDocsFromFiles(project)); 62 | } 63 | return cache.get(projectName); 64 | } 65 | 66 | private static List readProjectNgDocsFromFiles(Project project) { 67 | List jsFiles = NgUtils.findByMimeType(project.getProjectDirectory(), "text/javascript"); 68 | List result = new ArrayList(); 69 | for (FileObject jsFile : jsFiles) { 70 | System.out.println(" -- " + jsFile.getPath()); 71 | try { 72 | for (String docComment : NgUtils.getDocComments(jsFile.asText()) ) { 73 | NgDoc ngDoc = new NgDoc(docComment); 74 | if (ngDoc.isPresent("@ngdoc")) { 75 | result.add(ngDoc); 76 | } 77 | } 78 | } catch (IOException ex) { 79 | Exceptions.printStackTrace(ex); 80 | } 81 | } 82 | return result; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/codecompletion/NgHtmlCompletionContext.java: -------------------------------------------------------------------------------- 1 | package com.github.mdolk.ng.netbeans.codecompletion; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashSet; 5 | import javax.swing.text.BadLocationException; 6 | import javax.swing.text.StyledDocument; 7 | import org.openide.util.Exceptions; 8 | 9 | public class NgHtmlCompletionContext { 10 | private final StyledDocument doc; 11 | private final int caretOffset; 12 | private final String filter; 13 | 14 | public NgHtmlCompletionContext(StyledDocument doc, int caretOffset) { 15 | this.doc = doc; 16 | this.caretOffset = caretOffset; 17 | this.filter = findFilter(); 18 | } 19 | 20 | public int getCaretOffset() { 21 | return caretOffset; 22 | } 23 | 24 | public int getFilterStartOffset() { 25 | return caretOffset - filter.length(); 26 | } 27 | 28 | public String getFilter() { 29 | return filter; 30 | } 31 | 32 | private String getInTagName() { 33 | int offset = lookLeftUntil('<','>'); 34 | try { 35 | if (offset == -1 || charAt(offset) == '>') { 36 | return null; // not between tag brackets 37 | } 38 | int tagNameStart = offset + 1; 39 | int tagNameEnd = tagNameStart; 40 | while (!Character.isWhitespace(charAt(++tagNameEnd))) {} 41 | return doc.getText(tagNameStart, tagNameEnd - tagNameStart); 42 | } catch (BadLocationException ex) { 43 | Exceptions.printStackTrace(ex); 44 | return null; 45 | } 46 | } 47 | 48 | private int lookLeftUntil(Character... lookFor) { 49 | Character[] l = lookFor; 50 | HashSet set = new HashSet(Arrays.asList(l)); 51 | int offset = caretOffset - 1; 52 | try { 53 | while (offset >= 0 && !set.contains(charAt(offset))) { 54 | offset--; 55 | } 56 | return offset; 57 | } catch (BadLocationException ex) { 58 | Exceptions.printStackTrace(ex); 59 | return -1; 60 | } 61 | } 62 | 63 | public boolean isOpeningTag() { 64 | int offset = lookLeftUntil('<', '>', ' ', '\t', '\n'); 65 | try { 66 | if (offset != -1 && charAt(offset) == '<') { 67 | return true; 68 | } 69 | return false; 70 | } catch (BadLocationException ex) { 71 | Exceptions.printStackTrace(ex); 72 | return false; 73 | } 74 | } 75 | 76 | public boolean isInMatchingTag(String allowedElement) { 77 | if (isOpeningTag()) { 78 | return false; 79 | } 80 | String inTagName = getInTagName(); 81 | if (inTagName == null) { 82 | return false; // not inside a tag brackets 83 | } 84 | if (allowedElement == null || "ANY".equalsIgnoreCase(allowedElement) || inTagName.equalsIgnoreCase(allowedElement)) { 85 | return true; 86 | } 87 | return false; 88 | } 89 | 90 | public boolean isInAttributeValue() { 91 | if (!isInMatchingTag("ANY")) { 92 | return false; 93 | } 94 | try { 95 | int offset = lookLeftUntil('"','<'); 96 | if (charAt(offset) == '<') { 97 | return false; 98 | } 99 | return charAt(offset - 1) == '='; 100 | } catch (BadLocationException ex) { 101 | Exceptions.printStackTrace(ex); 102 | return false; 103 | } 104 | } 105 | 106 | private String findFilter() { 107 | int offset = caretOffset - 1; 108 | if (offset < 0) { 109 | return ""; 110 | } 111 | try { 112 | char c = charAt(offset); 113 | while (offset > 0 && !Character.isWhitespace(c) && c != '<' && c != '>') { 114 | offset--; 115 | c = charAt(offset); 116 | } 117 | return doc.getText(offset + 1, caretOffset - offset - 1); 118 | } catch (BadLocationException ex) { 119 | Exceptions.printStackTrace(ex); 120 | return ""; 121 | } 122 | } 123 | 124 | private char charAt(int offset) throws BadLocationException { 125 | return doc.getText(offset, 1).charAt(0); 126 | } 127 | } -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/codecompletion/NgHtmlCompletionProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mdolk.ng.netbeans.codecompletion; 2 | 3 | import java.util.HashSet; 4 | import java.util.List; 5 | import java.util.Set; 6 | import javax.swing.text.Document; 7 | import javax.swing.text.JTextComponent; 8 | import javax.swing.text.StyledDocument; 9 | import org.netbeans.api.editor.mimelookup.MimeRegistration; 10 | import org.netbeans.api.project.FileOwnerQuery; 11 | import org.netbeans.api.project.Project; 12 | import org.netbeans.spi.editor.completion.CompletionProvider; 13 | import org.netbeans.spi.editor.completion.CompletionResultSet; 14 | import org.netbeans.spi.editor.completion.CompletionTask; 15 | import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery; 16 | import org.netbeans.spi.editor.completion.support.AsyncCompletionTask; 17 | import org.openide.filesystems.FileObject; 18 | import org.openide.util.Utilities; 19 | 20 | @MimeRegistration(mimeType="text/html", service=CompletionProvider.class) 21 | public class NgHtmlCompletionProvider implements CompletionProvider { 22 | 23 | private final NgDocCache ngDocCache = new NgDocCache(); 24 | 25 | @Override 26 | public CompletionTask createTask(int queryType, JTextComponent component) { 27 | if (queryType != CompletionProvider.COMPLETION_QUERY_TYPE) 28 | return null; 29 | return new AsyncCompletionTask(new AsyncCompletionQuery() { 30 | @Override 31 | protected void query(CompletionResultSet resultSet, Document document, int caretOffset) { 32 | NgHtmlCompletionContext ctx = new NgHtmlCompletionContext((StyledDocument)document, caretOffset); 33 | if (ctx.isInAttributeValue()) { 34 | resultSet.finish(); 35 | return; 36 | } 37 | String filter = ctx.getFilter(); 38 | Set added = new HashSet(); 39 | for (NgDoc ngDoc : getNgDocs()) { 40 | String type = ngDoc.getAttribute("@ngdoc"); 41 | String name = ngDoc.getAttribute("@name"); 42 | String allowedElement = ngDoc.getAttribute("@element"); 43 | if ("directive".equals(type) && ctx.isInMatchingTag(allowedElement)) { 44 | name = stripPrefix(name); // strip "angular.directive." from name 45 | if (!added.contains(name) && name.startsWith(filter)) { 46 | resultSet.addItem(new NgHtmlCompletionItem(name, ctx, ngDoc)); 47 | added.add(name); 48 | } 49 | } 50 | if ("widget".equals(type)) { 51 | name = stripPrefix(name); //strip "angular.widget." from name 52 | // attribute widgets 53 | if (!added.contains(name) && name.startsWith("@"+filter) && ctx.isInMatchingTag(allowedElement)) { 54 | resultSet.addItem(new NgHtmlCompletionItem(name.substring(1), ctx, ngDoc)); 55 | added.add(name); 56 | } 57 | // element widgets 58 | if (!added.contains(name) && !name.startsWith("@") && ctx.isOpeningTag() && name.startsWith(filter)) { 59 | resultSet.addItem(new NgHtmlCompletionItem(name, ctx, ngDoc)); 60 | added.add(name); 61 | } 62 | } 63 | } 64 | resultSet.finish(); 65 | } 66 | 67 | private String stripPrefix(String name) { 68 | int lastDotIndex = name.lastIndexOf("."); 69 | if (lastDotIndex == -1) { 70 | return name; 71 | } else { 72 | return name.substring(lastDotIndex+1); 73 | } 74 | } 75 | }, component); 76 | } 77 | 78 | private List getNgDocs() { 79 | // which file is currently beeing edited? 80 | FileObject editFile = Utilities.actionsGlobalContext().lookup(FileObject.class); 81 | // in which project? 82 | Project owner = FileOwnerQuery.getOwner(editFile); 83 | return ngDocCache.getNgDocs(owner); 84 | } 85 | 86 | @Override 87 | public int getAutoQueryTypes(JTextComponent component, String typedText) { 88 | return 0; // code completion box will not appear unless user explicitly asks 89 | } 90 | 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/codecompletion/NgHtmlCompletionItem.java: -------------------------------------------------------------------------------- 1 | package com.github.mdolk.ng.netbeans.codecompletion; 2 | 3 | import java.awt.Color; 4 | import java.awt.Font; 5 | import java.awt.Graphics; 6 | import java.awt.event.KeyEvent; 7 | import javax.swing.ImageIcon; 8 | import javax.swing.text.BadLocationException; 9 | import javax.swing.text.Document; 10 | import javax.swing.text.JTextComponent; 11 | import javax.swing.text.StyledDocument; 12 | import org.netbeans.api.editor.completion.Completion; 13 | import org.netbeans.spi.editor.completion.CompletionItem; 14 | import org.netbeans.spi.editor.completion.CompletionResultSet; 15 | import org.netbeans.spi.editor.completion.CompletionTask; 16 | import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery; 17 | import org.netbeans.spi.editor.completion.support.AsyncCompletionTask; 18 | import org.netbeans.spi.editor.completion.support.CompletionUtilities; 19 | import org.openide.util.Exceptions; 20 | import org.openide.util.ImageUtilities; 21 | 22 | public class NgHtmlCompletionItem implements CompletionItem { 23 | private static final ImageIcon fieldIcon = new ImageIcon( 24 | ImageUtilities.loadImage("com/github/mdolk/ng/netbeans/favicon.png") 25 | ); 26 | private static final Color fieldColor = Color.decode("0x0000B2"); 27 | 28 | private final String name; 29 | private final NgHtmlCompletionContext context; 30 | private final NgDoc ngDoc; 31 | 32 | public NgHtmlCompletionItem(String name, NgHtmlCompletionContext context, NgDoc ngDoc) { 33 | this.name = name; 34 | this.context = context; 35 | this.ngDoc = ngDoc; 36 | } 37 | 38 | @Override 39 | public int getPreferredWidth(Graphics g, Font font) { 40 | String type = ngDoc.getAttribute("@ngdoc"); 41 | String s = context.isOpeningTag() ? "<" + name + ">" : name; 42 | return CompletionUtilities.getPreferredWidth(s, type, g, font); 43 | } 44 | 45 | @Override 46 | public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) { 47 | String type = ngDoc.getAttribute("@ngdoc"); 48 | String s = context.isOpeningTag() ? "<" + name + ">" : name; 49 | CompletionUtilities.renderHtml(fieldIcon, s, ""+type+"", g, defaultFont, (selected ? Color.white : fieldColor), width, height, selected); 50 | } 51 | 52 | @Override 53 | public CharSequence getSortText() { 54 | return name; 55 | } 56 | 57 | @Override 58 | public CharSequence getInsertPrefix() { 59 | return name; 60 | } 61 | 62 | @Override 63 | public void defaultAction(JTextComponent component) { 64 | StyledDocument doc = (StyledDocument)component.getDocument(); 65 | try { 66 | boolean isOpeningTag = context.isOpeningTag(); // Need to check this before messing with the document! 67 | int startOffset = context.getFilterStartOffset(); 68 | int caretOffset = context.getCaretOffset(); 69 | doc.remove(startOffset, caretOffset-startOffset); 70 | if (isOpeningTag) { 71 | doc.insertString(startOffset, name, null); 72 | } else { 73 | String insert = name + "=\"\""; 74 | doc.insertString(startOffset, insert, null); 75 | component.setCaretPosition(startOffset + insert.length() - 1); 76 | } 77 | Completion.get().hideAll(); 78 | } catch (BadLocationException ex) { 79 | Exceptions.printStackTrace(ex); 80 | } 81 | } 82 | 83 | @Override 84 | public CompletionTask createDocumentationTask() { 85 | return new AsyncCompletionTask(new AsyncCompletionQuery() { 86 | @Override 87 | protected void query(CompletionResultSet crs, Document document, int i) { 88 | crs.setDocumentation(new NgHtmlCompletionDocumentation(NgHtmlCompletionItem.this)); 89 | crs.finish(); 90 | } 91 | }); 92 | } 93 | 94 | @Override 95 | public CompletionTask createToolTipTask() { 96 | return null; 97 | } 98 | 99 | 100 | @Override 101 | public int getSortPriority() { 102 | return 0; 103 | } 104 | 105 | @Override 106 | public boolean instantSubstitution(JTextComponent jtc) { 107 | return false; 108 | } 109 | 110 | @Override 111 | public void processKeyEvent(KeyEvent ke) { } 112 | 113 | public NgDoc getNgDoc() { 114 | return ngDoc; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.apisupport.project 4 | 5 | 6 | com.github.mdolk.ng.netbeans 7 | 8 | 9 | 10 | org.netbeans.modules.editor.completion 11 | 12 | 13 | 14 | 1 15 | 1.26.1.1 16 | 17 | 18 | 19 | org.netbeans.modules.editor.mimelookup 20 | 21 | 22 | 23 | 1 24 | 1.22.1 25 | 26 | 27 | 28 | org.netbeans.modules.projectapi 29 | 30 | 31 | 32 | 1 33 | 1.36.1 34 | 35 | 36 | 37 | org.openide.filesystems 38 | 39 | 40 | 41 | 7.47.1 42 | 43 | 44 | 45 | org.openide.modules 46 | 47 | 48 | 49 | 7.23.1 50 | 51 | 52 | 53 | org.openide.util 54 | 55 | 56 | 57 | 8.15.1 58 | 59 | 60 | 61 | org.openide.util.lookup 62 | 63 | 64 | 65 | 8.8.1 66 | 67 | 68 | 69 | 70 | 71 | unit 72 | 73 | org.netbeans.libs.junit4 74 | 75 | 76 | 77 | org.netbeans.modules.nbjunit 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | ext/markdownj-core-0.4.1.jar 86 | release/modules/ext/markdownj-core-0.4.1.jar 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/com/github/mdolk/ng/netbeans/codecompletion/NgHtmlCompletionDocumentation.java: -------------------------------------------------------------------------------- 1 | package com.github.mdolk.ng.netbeans.codecompletion; 2 | 3 | import com.petebevin.markdown.MarkdownProcessor; 4 | import java.net.MalformedURLException; 5 | import java.net.URL; 6 | import java.util.List; 7 | import java.util.Scanner; 8 | import java.util.regex.Matcher; 9 | import java.util.regex.Pattern; 10 | import javax.swing.Action; 11 | import org.netbeans.spi.editor.completion.CompletionDocumentation; 12 | import org.openide.util.Exceptions; 13 | 14 | public class NgHtmlCompletionDocumentation implements CompletionDocumentation { 15 | private final NgHtmlCompletionItem item; 16 | 17 | public NgHtmlCompletionDocumentation(NgHtmlCompletionItem item) { 18 | this.item = item; 19 | } 20 | 21 | @Override 22 | public String getText() { 23 | NgDoc ngDoc = item.getNgDoc(); 24 | StringBuilder sb = new StringBuilder(); 25 | appendWorkInProgress(sb, ngDoc); 26 | appendTitle(sb, ngDoc); 27 | appendDescription(sb, ngDoc); 28 | appendParameters(sb, ngDoc); 29 | appendExample(sb, ngDoc); 30 | return sb.toString(); 31 | } 32 | 33 | private static void appendWorkInProgress(StringBuilder sb, NgDoc ngDoc) { 34 | if (ngDoc.isPresent("@workInProgress")) { 35 | sb.append("Work in Progress!
"); 36 | sb.append("This documentation is currently being revised. "); 37 | sb.append("It might be incomplete or contain inaccuracies."); 38 | } 39 | } 40 | 41 | private static void appendTitle(StringBuilder sb, NgDoc ngDoc) { 42 | sb.append("

").append(ngDoc.getAttribute("@name")).append("

"); 43 | } 44 | 45 | private static void appendDescription(StringBuilder sb, NgDoc ngDoc) { 46 | sb.append("

Description

"); 47 | sb.append(format(ngDoc.getMultilineAttribute("@description"))); 48 | } 49 | 50 | private static void appendParameters(StringBuilder sb, NgDoc ngDoc) { 51 | List params = ngDoc.getMultilineAttributes("@param"); 52 | if (!params.isEmpty()) { 53 | sb.append("

Parameters

"); 54 | sb.append(""); 55 | for (String param : params) { 56 | String[] split = param.split(" ", 3); 57 | String type = split[0]; 58 | String name = split[1]; 59 | String desc = split[2]; 60 | sb.append(""); 61 | sb.append(""); 62 | sb.append(""); 63 | sb.append(""); 64 | sb.append(""); 65 | sb.append(""); 66 | sb.append(""); 67 | sb.append(""); 68 | } 69 | sb.append("
").append(name).append("").append(type).append("").append(format(desc)).append("
"); 70 | } 71 | } 72 | 73 | private static void appendExample(StringBuilder sb, NgDoc ngDoc) { 74 | List examples = ngDoc.getMultilineAttributes("@example"); 75 | for(String example : examples) { 76 | sb.append("

Example

"); 77 | int indexOfDocExample = example.indexOf(""); 78 | if (indexOfDocExample == -1) { 79 | // no 80 | sb.append(example); 81 | } else { 82 | // has 83 | sb.append(format(example.substring(0, indexOfDocExample))); // description 84 | Pattern pattern = Pattern.compile("(.*?)", Pattern.DOTALL); 85 | Matcher matcher = pattern.matcher(example); 86 | if (matcher.find()) { 87 | sb.append("
");
 88 | 					sb.append(matcher.group(1).replaceAll("<", "<").replaceAll(">", ">"));
 89 | 					sb.append("
"); 90 | } 91 | } 92 | } 93 | } 94 | 95 | private static String format(String text) { 96 | // Escape HTML tags in pre blocks 97 | Scanner scanner = new Scanner(text).useDelimiter(""); 98 | boolean isPre = false; 99 | StringBuilder sb = new StringBuilder(); 100 | while (scanner.hasNext()) { 101 | String group = scanner.next(); 102 | if (isPre) { 103 | sb 104 | .append("
")
105 | 				.append(group.replaceAll("<", "<").replaceAll(">", ">"))
106 | 				.append("
"); 107 | } else { 108 | sb.append(group); 109 | } 110 | isPre = !isPre; 111 | } 112 | text = sb.toString(); 113 | 114 | // Minor tweaks 115 | text = text.replaceAll("\\{@link\\s+([^\\s\\}]+)\\s*([^\\}]*?)\\s*}", "_$2_"); // display links in italic 116 | text = text.replaceAll("", "<angular/>"); 117 | 118 | // Markdown format the rest 119 | MarkdownProcessor mp = new MarkdownProcessor(); 120 | return mp.markdown(text); 121 | } 122 | 123 | @Override 124 | public URL getURL() { 125 | String name = item.getNgDoc().getAttribute("@name"); 126 | if (name.startsWith("angular.")) { 127 | try { 128 | // TODO: Netbeans does not like the hash bang URLs, rewrites and spams log :-/ 129 | return new URL("http://docs.angularjs.org/#!/api/" + name); 130 | } catch (MalformedURLException ex) { 131 | Exceptions.printStackTrace(ex); 132 | return null; 133 | } 134 | } 135 | return null; 136 | } 137 | 138 | @Override 139 | public CompletionDocumentation resolveLink(String string) { 140 | return null; 141 | } 142 | 143 | @Override 144 | public Action getGotoSourceAction() { 145 | return null; 146 | } 147 | } -------------------------------------------------------------------------------- /license/gpl-2.0.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------