List of usage examples for org.eclipse.jdt.core.dom.rewrite ImportRewrite setStaticOnDemandImportThreshold
public void setStaticOnDemandImportThreshold(int threshold)
From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java
License:Open Source License
/********************************************************************************/ public void fixImports(String proj, String bid, String file, int demand, int staticdemand, String order, String add, IvyXmlWriter xw) throws BedrockException { FileData fd = findFile(proj, file, bid, null); if (fd == null) throw new BedrockException("Compilation unit for file " + file + " not available for import fixup"); CompilationUnit cu = fd.getDefaultRoot(bid); BedrockFixImports bfi = new BedrockFixImports(); Set<ITypeBinding> imports = bfi.findImports(cu); try {//from www . j av a 2 s . c o m IJavaProject ijp = null; if (proj != null) { IProject ip = our_plugin.getProjectManager().findProject(proj); ijp = JavaCore.create(ip); } if (order == null) { order = PreferenceConstants.getPreference("org.eclipse.jdt.ui.importorder", ijp); } if (demand <= 0) { String s = PreferenceConstants.getPreference("org.eclipse.jdt.ui.ondemandthreshold", ijp); if (s != null) { try { demand = Integer.parseInt(s); } catch (NumberFormatException e) { } } if (demand <= 0) demand = 99; } if (staticdemand <= 0) { String s = PreferenceConstants.getPreference("org.eclipse.jdt.ui.ondemandthreshold", ijp); if (s != null) { try { staticdemand = Integer.parseInt(s); } catch (NumberFormatException e) { } } if (staticdemand <= 0) staticdemand = demand; } } catch (Throwable t) { BedrockPlugin.logD("Problem with fix constant: " + t); } BedrockPlugin.logD("IMPORT prefs done: " + demand + " " + staticdemand + " " + order); boolean keepfg = (add == null ? false : true); try { ImportRewrite imp = ImportRewrite.create(cu, keepfg); if (demand >= 0) imp.setOnDemandImportThreshold(demand); if (staticdemand >= 0) imp.setStaticOnDemandImportThreshold(demand); if (order != null) { String[] ord = order.split("[;,]"); imp.setImportOrder(ord); } if (add != null) imp.addImport(add); else { for (ITypeBinding tb : imports) { BedrockPlugin.logD("Add type to importrewrite: " + tb.getQualifiedName()); imp.addImport(tb); } } TextEdit te = imp.rewriteImports(null); if (te != null) { BedrockUtil.outputTextEdit(te, xw); } } catch (Exception e) { throw new BedrockException("Problem doing imports", e); } }
From source file:org.eclipse.che.jdt.core.CoreTests.java
License:Open Source License
protected ImportRewrite newImportsRewrite(ICompilationUnit cu, String[] order, int normalThreshold, int staticThreshold, boolean restoreExistingImports) throws CoreException { ImportRewrite rewrite = StubUtility.createImportRewrite(cu, restoreExistingImports); rewrite.setImportOrder(order);/* w w w. jav a 2s.c om*/ rewrite.setOnDemandImportThreshold(normalThreshold); rewrite.setStaticOnDemandImportThreshold(staticThreshold); return rewrite; }
From source file:org.eclipse.che.jdt.core.CoreTests.java
License:Open Source License
protected ImportRewrite newImportsRewrite(CompilationUnit cu, String[] order, int normalThreshold, int staticThreshold, boolean restoreExistingImports) { ImportRewrite rewrite = ImportRewrite.create(cu, restoreExistingImports); rewrite.setImportOrder(order);/*from w w w .j a v a 2 s . c om*/ rewrite.setOnDemandImportThreshold(normalThreshold); rewrite.setStaticOnDemandImportThreshold(staticThreshold); return rewrite; }
From source file:org.eclipse.flux.jdt.services.TypeProposalUtils.java
License:Open Source License
static ImportRewrite createImportRewrite(ICompilationUnit compilationUnit) { try {/*from w w w . jav a 2s . c o m*/ ImportRewrite rewrite = ImportRewrite.create(compilationUnit, true); rewrite.setImportOrder(IMPORTS_ORDER); rewrite.setOnDemandImportThreshold(IMPORTS_THRESHOLD); rewrite.setStaticOnDemandImportThreshold(IMPORTS_THRESHOLD); return rewrite; } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:org.eclipse.gmf.internal.common.codegen.OrganizeImportsPostprocessor.java
License:Open Source License
private static ImportRewrite configureImportRewrite(ImportRewrite rewrite) { IJavaProject project = rewrite.getCompilationUnit().getJavaProject(); String order = PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_IMPORTORDER, project); rewrite.setImportOrder(order.split(";", 0)); //$NON-NLS-1$ String thres = PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, project); try {//w w w . ja v a 2 s .c o m int num = Integer.parseInt(thres); if (num == 0) { num = 1; } rewrite.setOnDemandImportThreshold(num); } catch (NumberFormatException e) { // ignore } String thresStatic = PreferenceConstants .getPreference(PreferenceConstants.ORGIMPORTS_STATIC_ONDEMANDTHRESHOLD, project); try { int num = Integer.parseInt(thresStatic); if (num == 0) { num = 1; } rewrite.setStaticOnDemandImportThreshold(num); } catch (NumberFormatException e) { // ignore } return rewrite; }
From source file:org.eclipse.scout.sdk.saml.importer.internal.jdt.imports.OrganizeImportsHelper.java
License:Open Source License
private static ImportRewrite configureImportRewrite(ImportRewrite rewrite) { // IJavaProject project = rewrite.getCompilationUnit().getJavaProject(); // String order = getPreference(ORGIMPORTS_IMPORTORDER, project); // if (order.endsWith(";")) { //$NON-NLS-1$ // order = order.substring(0, order.length() - 1); // }// ww w . jav a2 s. c om // String[] split = SEMICOLON_PATTERN.split(order, -1); // rewrite.setImportOrder(split); // // String thres = getPreference(ORGIMPORTS_ONDEMANDTHRESHOLD, project); // try { // int num = Integer.parseInt(thres); // if (num == 0) num = 1; // rewrite.setOnDemandImportThreshold(num); // } // catch (NumberFormatException e) { // // ignore // } // String thresStatic = getPreference(ORGIMPORTS_STATIC_ONDEMANDTHRESHOLD, project); // try { // int num = Integer.parseInt(thresStatic); // if (num == 0) num = 1; // rewrite.setStaticOnDemandImportThreshold(num); // } // catch (NumberFormatException e) { // // ignore // } rewrite.setImportOrder(new String[] { "java", "javax", "org", "com" }); rewrite.setOnDemandImportThreshold(99); rewrite.setStaticOnDemandImportThreshold(99); return rewrite; }