Lines 30-39
Link Here
|
30 |
import org.eclipse.jdt.core.dom.ImportDeclaration; |
30 |
import org.eclipse.jdt.core.dom.ImportDeclaration; |
31 |
import org.eclipse.jdt.core.dom.PackageDeclaration; |
31 |
import org.eclipse.jdt.core.dom.PackageDeclaration; |
32 |
import org.eclipse.jdt.core.formatter.CodeFormatter; |
32 |
import org.eclipse.jdt.core.formatter.CodeFormatter; |
|
|
33 |
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
33 |
import org.eclipse.jdt.core.search.IJavaSearchConstants; |
34 |
import org.eclipse.jdt.core.search.IJavaSearchConstants; |
34 |
import org.eclipse.jdt.core.search.IJavaSearchScope; |
35 |
import org.eclipse.jdt.core.search.IJavaSearchScope; |
35 |
import org.eclipse.jdt.core.search.SearchEngine; |
36 |
import org.eclipse.jdt.core.search.SearchEngine; |
36 |
import org.eclipse.jdt.core.search.TypeNameRequestor; |
37 |
import org.eclipse.jdt.core.search.TypeNameRequestor; |
|
|
38 |
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; |
39 |
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions; |
37 |
import org.eclipse.jface.text.BadLocationException; |
40 |
import org.eclipse.jface.text.BadLocationException; |
38 |
import org.eclipse.jface.text.Document; |
41 |
import org.eclipse.jface.text.Document; |
39 |
import org.eclipse.jface.text.IRegion; |
42 |
import org.eclipse.jface.text.IRegion; |
Lines 637-656
Link Here
|
637 |
* @return Probes if the formatter allows spaces between imports |
640 |
* @return Probes if the formatter allows spaces between imports |
638 |
*/ |
641 |
*/ |
639 |
private boolean useSpaceBetweenGroups() { |
642 |
private boolean useSpaceBetweenGroups() { |
640 |
try { |
643 |
String option= this.compilationUnit.getJavaProject().getOption(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, true); |
641 |
String sample= "import a.A;\n\n import b.B;\nclass C {}"; //$NON-NLS-1$ |
644 |
return Integer.valueOf(option).intValue() > 0; |
642 |
TextEdit res= ToolFactory.createCodeFormatter(this.compilationUnit.getJavaProject().getOptions(true)).format(CodeFormatter.K_COMPILATION_UNIT, sample, 0, sample.length(), 0, String.valueOf('\n')); |
|
|
643 |
Document doc= new Document(sample); |
644 |
res.apply(doc); |
645 |
int idx1= doc.search(0, "import", true, true, false); //$NON-NLS-1$ |
646 |
int line1= doc.getLineOfOffset(idx1); |
647 |
int idx2= doc.search(idx1 + 1, "import", true, true, false); //$NON-NLS-1$ |
648 |
int line2= doc.getLineOfOffset(idx2); |
649 |
return line2 - line1 > 1; |
650 |
} catch (BadLocationException e) { |
651 |
// should not happen |
652 |
} |
653 |
return true; |
654 |
} |
645 |
} |
655 |
|
646 |
|
656 |
private Set evaluateStarImportConflicts(IProgressMonitor monitor) throws JavaModelException { |
647 |
private Set evaluateStarImportConflicts(IProgressMonitor monitor) throws JavaModelException { |