From: Marcelo V. <va...@us...> - 2013-05-29 04:34:16
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "LazyImporter plugin". The branch, master has been updated via 6c42e631cd2ba96b51f0db66bfe8ddf2583e0f5e (commit) via d0edc85255fb55417ad1008c700aae1ac3dd5691 (commit) from eaa766e878838efb442bf5d5deda0df08531d61b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit: http://jedit.git.sourceforge.net/git/gitweb.cgi?p=jedit/LazyImporter;a=commit;h=6c42e631cd2ba96b51f0db66bfe8ddf2583e0f5e commitdiff: http://jedit.git.sourceforge.net/git/gitweb.cgi?p=jedit/LazyImporter;a=commitdiff;h=6c42e631cd2ba96b51f0db66bfe8ddf2583e0f5e tree: http://jedit.git.sourceforge.net/git/gitweb.cgi?p=jedit/LazyImporter;a=tree;h=6c42e631cd2ba96b51f0db66bfe8ddf2583e0f5e;hb=6c42e631cd2ba96b51f0db66bfe8ddf2583e0f5e commit 6c42e631cd2ba96b51f0db66bfe8ddf2583e0f5e Author: Marcelo Vanzin <va...@us...> Date: Tue May 28 21:34:03 2013 -0700 Add missing character to whitelist. diff --git a/src/org/etheridge/lazyimporter/importer/JavaClass.java b/src/org/etheridge/lazyimporter/importer/JavaClass.java index 7bd3f12..e834aba 100644 --- a/src/org/etheridge/lazyimporter/importer/JavaClass.java +++ b/src/org/etheridge/lazyimporter/importer/JavaClass.java @@ -84,7 +84,7 @@ public class JavaClass // static strings private static String msValidPreClassCharacters = "\t() \n,!<@"; - private static String msValidPostClassCharacters = "\t)( .\n[,;<"; + private static String msValidPostClassCharacters = "\t)( .\n[,;<>"; public JavaClass(String classText) { commit: http://jedit.git.sourceforge.net/git/gitweb.cgi?p=jedit/LazyImporter;a=commit;h=d0edc85255fb55417ad1008c700aae1ac3dd5691 commitdiff: http://jedit.git.sourceforge.net/git/gitweb.cgi?p=jedit/LazyImporter;a=commitdiff;h=d0edc85255fb55417ad1008c700aae1ac3dd5691 tree: http://jedit.git.sourceforge.net/git/gitweb.cgi?p=jedit/LazyImporter;a=tree;h=d0edc85255fb55417ad1008c700aae1ac3dd5691;hb=d0edc85255fb55417ad1008c700aae1ac3dd5691 commit d0edc85255fb55417ad1008c700aae1ac3dd5691 Author: Marcelo Vanzin <va...@us...> Date: Tue Jul 10 23:08:17 2012 -0700 Smarter sorting of import statements. Puts classes before subpackages, and try to figure out when statements refer to nested classes without having to actually check the classpath for that. diff --git a/src/org/etheridge/lazyimporter/importer/ordering/AlphabeticalImportComparator.java b/src/org/etheridge/lazyimporter/importer/ordering/AlphabeticalImportComparator.java index 06a448a..08560c5 100644 --- a/src/org/etheridge/lazyimporter/importer/ordering/AlphabeticalImportComparator.java +++ b/src/org/etheridge/lazyimporter/importer/ordering/AlphabeticalImportComparator.java @@ -1,34 +1,36 @@ /* - * LazyImporter jEdit Plugin (AlphabeticalImportComparator.java) - * + * LazyImporter jEdit Plugin (AlphabeticalImportComparator.java) + * * Copyright (C) 2003 Matt Etheridge (ma...@et...) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + package org.etheridge.lazyimporter.importer.ordering; import java.text.Collator; import java.util.Comparator; +import java.util.StringTokenizer; import org.etheridge.lazyimporter.importer.ImportStatement; +import org.etheridge.lazyimporter.importer.ClassImportStatement; /** * Compares ImportStatement objects alphabetically. - */ + */ public class AlphabeticalImportComparator implements Comparator { public int compare(Object object1, Object object2) @@ -36,11 +38,81 @@ public class AlphabeticalImportComparator implements Comparator ImportStatement importStatement1 = (ImportStatement) object1; ImportStatement importStatement2 = (ImportStatement) object2; + // // compare the two import statements, based upon their package name - // and class name if it has one. + // and class name if it has one. The comparison puts classes before + // subpackages, like the following: + // + // foo.package.Class; + // foo.package.subpackage.OtherClass; + // + // It also considers that any sub-component of the fully qualified + // name starting with a capital letter is a class, following the + // Java convention. This allows nested class import statements to + // follow the above rule, so that you get something like this: + // + // foo.package.Class; + // foo.package.Class.Nested; + // foo.package.subpackage.OtherClass; + // + // This will sort of break if a class starts with a lower case + // letter. The code below works around that for regular class + // imports, but won't work for nested classes. + // Collator collator = Collator.getInstance(); - - return collator.compare(importStatement1.toString(), importStatement2.toString()); + + StringTokenizer pkg1 = + new StringTokenizer(importStatement1.getPackageName(), "."); + StringTokenizer pkg2 = + new StringTokenizer(importStatement2.getPackageName(), "."); + + while (pkg1.hasMoreTokens()) { + String t1 = pkg1.nextToken(); + if (!pkg2.hasMoreTokens()) { + return 1; + } + String t2 = pkg2.nextToken(); + + // Even though we're comparing "package names", they may + // actually be class names (e.g. when importing a nested + // class). Assume that if the name starts with a capital + // letter, it is a class. + if (Character.isLowerCase(t1.charAt(0))) { + // t1 is a package name + if (!Character.isLowerCase(t2.charAt(0))) { + // t2 is a class name, so it comes first + return 1; + } + } else if (Character.isLowerCase(t2.charAt(0))) { + // t2 is a package name, so t1 comes first + return -1; + } + + int comp = collator.compare(t1, t2); + if (comp != 0) { + return comp; + } + } + + // Statement 2 goes into subpackages of statement 1's package. + if (pkg2.hasMoreTokens()) { + return -1; + } + + // Check class names. + String klass1 = (importStatement1 instanceof ClassImportStatement) ? + ((ClassImportStatement)importStatement1).getClassName() : null; + String klass2 = (importStatement2 instanceof ClassImportStatement) ? + ((ClassImportStatement)importStatement2).getClassName() : null; + + if (klass1 == null) { + return klass2 != null ? 1 : 0; + } else if (klass2 != null) { + return collator.compare(klass1, klass2); + } + + // Must be a duplicate import statement. + return 0; } public boolean equals(Object obj) ----------------------------------------------------------------------- Summary of changes: .../etheridge/lazyimporter/importer/JavaClass.java | 2 +- .../ordering/AlphabeticalImportComparator.java | 90 ++++++++++++++++++-- 2 files changed, 82 insertions(+), 10 deletions(-) hooks/post-receive -- LazyImporter plugin |