Java Code Examples for org.eclipse.jdt.ui.PreferenceConstants#getPreference()

The following examples show how to use org.eclipse.jdt.ui.PreferenceConstants#getPreference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.17
 */
protected Iterable<JvmFeature> getFavoriteStaticFeatures(EObject context, Predicate<JvmFeature> filter) {
	String pref = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
	List<JvmFeature> result = newArrayList();
	if (Strings.isEmpty(pref)) {
		return result;
	}
	String[] favorites = pref.split(";"); //$NON-NLS-1$
	for (String fav : favorites) {
		boolean isWildcard = fav.lastIndexOf("*") > 0; //$NON-NLS-1$
		int indexOfLastDot = fav.lastIndexOf("."); //$NON-NLS-1$
		if (indexOfLastDot > 0) {
			String typeName = fav.substring(0, indexOfLastDot);
			JvmType type = typeReferences.findDeclaredType(typeName, context);
			final String membername = fav.substring(indexOfLastDot + 1, fav.length());
			if (type != null) {
				if (type instanceof JvmDeclaredType) {
					JvmDeclaredType genericType = (JvmDeclaredType) type;
					// All features but no Constructor
					FluentIterable<JvmFeature> allFeaturesToImport = FluentIterable.from(genericType.getMembers()).filter(JvmFeature.class).filter(input -> {
						boolean isValid = !(input instanceof JvmConstructor) && input.isStatic();
						if (isWildcard) {
							return isValid;
						} else {
							return isValid && input.getSimpleName().equals(membername);
						}
					});
					FluentIterable<JvmFeature> featuresToImport = allFeaturesToImport.filter(filter);
					if (context != null) {
						// Make sure that already imported static features are not proposed
						RewritableImportSection importSection = importSectionFactory.parse((XtextResource) context.eResource());
						featuresToImport = featuresToImport.filter(input -> !importSection.hasStaticImport(input.getSimpleName(), false));
					}
					featuresToImport.copyInto(result);
				}
			}
		}
	}
	return result;
}
 
Example 2
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testStaticFavoriteImports_operation() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      ContentAssistProcessorTestBuilder _applyProposal = _newBuilder.append(_builder.toString()).applyProposal("staticMethod()");
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("package mypack");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("import static org.eclipse.xtend.ide.tests.data.contentassist.StaticClassExample.staticMethod");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("class Bar{");
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("def void foo(){");
      _builder_1.newLine();
      _builder_1.append("staticMethod()");
      _applyProposal.expectContent(_builder_1.toString());
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testStaticFavoriteImports_operation_direct() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".staticMethod");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      ContentAssistProcessorTestBuilder _applyProposal = _newBuilder.append(_builder.toString()).applyProposal("staticMethod()");
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("package mypack");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("import static org.eclipse.xtend.ide.tests.data.contentassist.StaticClassExample.staticMethod");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("class Bar{");
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("def void foo(){");
      _builder_1.newLine();
      _builder_1.append("staticMethod()");
      _applyProposal.expectContent(_builder_1.toString());
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testStaticFavoriteImports_field() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      ContentAssistProcessorTestBuilder _applyProposal = _newBuilder.append(_builder.toString()).applyProposal("STATICFIELD");
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("package mypack");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("import static org.eclipse.xtend.ide.tests.data.contentassist.StaticClassExample.STATICFIELD");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("class Bar{");
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("def void foo(){");
      _builder_1.newLine();
      _builder_1.append("STATICFIELD");
      _applyProposal.expectContent(_builder_1.toString());
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testStaticFavoriteImports_no_constructor() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("<|>");
      _newBuilder.append(_builder.toString()).assertNoProposalAtCursor("StaticClassExample");
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testStaticFavoriteImports_no_proposal_non_static_operation() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("<|>");
      _newBuilder.append(_builder.toString()).assertNoProposalAtCursor("nonStaticMethod");
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testStaticFavoriteImports_no_proposal_non_static_operation_extension() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("\"FOO\".<|>");
      _newBuilder.append(_builder.toString()).assertNoProposalAtCursor("nonStaticMethod");
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 8
Source File: SelfEncapsulateFieldInputPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String[] getRelevantOptions(IJavaProject project) {
	return new String[] {
		project.getOption(JavaCore.CODEASSIST_FIELD_PREFIXES, true),
		project.getOption(JavaCore.CODEASSIST_FIELD_SUFFIXES, true),
		PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_IS_FOR_GETTERS, project)
	};
}
 
Example 9
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testStaticFavoriteImports_operation_direct_extension() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".staticMethod");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("\"foo\".");
      ContentAssistProcessorTestBuilder _applyProposal = _newBuilder.append(_builder.toString()).applyProposal("staticMethod");
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("package mypack");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("import static extension org.eclipse.xtend.ide.tests.data.contentassist.StaticClassExample.staticMethod");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("class Bar{");
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("def void foo(){");
      _builder_1.newLine();
      _builder_1.append("\t\t");
      _builder_1.append("\"foo\".staticMethod");
      _applyProposal.expectContent(_builder_1.toString());
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 10
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testStaticFavoriteImports_operation_extension() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("\"foo\".");
      ContentAssistProcessorTestBuilder _applyProposal = _newBuilder.append(_builder.toString()).applyProposal("staticMethod");
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("package mypack");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("import static extension org.eclipse.xtend.ide.tests.data.contentassist.StaticClassExample.staticMethod");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("class Bar{");
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("def void foo(){");
      _builder_1.newLine();
      _builder_1.append("\t\t");
      _builder_1.append("\"foo\".staticMethod");
      _applyProposal.expectContent(_builder_1.toString());
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testStaticFavoriteImports_field_No_additional_import() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("STATICFIELD");
      _builder.newLine();
      ContentAssistProcessorTestBuilder _applyProposal = _newBuilder.append(_builder.toString()).applyProposal("STATICFIELD");
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("package mypack");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("import static org.eclipse.xtend.ide.tests.data.contentassist.StaticClassExample.STATICFIELD");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("class Bar{");
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("def void foo(){");
      _builder_1.newLine();
      _builder_1.append("\t\t");
      _builder_1.append("STATICFIELD");
      _builder_1.newLine();
      _builder_1.append("STATICFIELD");
      _applyProposal.expectContent(_builder_1.toString());
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 12
Source File: XImportSectionContentAssistTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testStaticFavoriteImports_No_additional_import() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      String _name = StaticClassExample.class.getName();
      String _plus = (_name + ".*");
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, _plus);
      ContentAssistProcessorTestBuilder _newBuilder = this.newBuilder();
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("package mypack");
      _builder.newLine();
      _builder.append("class Bar{");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void foo(){");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("staticMethod()");
      _builder.newLine();
      ContentAssistProcessorTestBuilder _applyProposal = _newBuilder.append(_builder.toString()).applyProposal("staticMethod()");
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("package mypack");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("import static org.eclipse.xtend.ide.tests.data.contentassist.StaticClassExample.staticMethod");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("class Bar{");
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("def void foo(){");
      _builder_1.newLine();
      _builder_1.append("\t\t");
      _builder_1.append("staticMethod()");
      _builder_1.newLine();
      _builder_1.append("staticMethod()");
      _applyProposal.expectContent(_builder_1.toString());
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 13
Source File: ContentAssistPrioritiesTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testPriorities() {
  try {
    final String defaultprefs = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null);
    final IEclipsePreferences jdtPreference = InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
    try {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, "");
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("public class Example {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("String aField;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("String zField;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("static String aStaticField;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("static String zStaticField;");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void aMethod(String aParam,String zParam) {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("val aVar = \'fdfg\';");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("val zVar = \'fdfg\';");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("//CURSOR");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def void zMethod() {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("\t");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def static void aStaticMethod() {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def static void zStaticMethod() {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final String text = _builder.toString();
      int _indexOf = text.indexOf("//CURSOR");
      final int idx = (_indexOf - 1);
      final Iterator<ICompletionProposal> proposals = ((List<ICompletionProposal>)Conversions.doWrapArray(this.newBuilder().append(text).insert("", idx).computeCompletionProposals())).iterator();
      this.assertContains(proposals.next(), "aParam");
      this.assertContains(proposals.next(), "aVar");
      this.assertContains(proposals.next(), "zParam");
      this.assertContains(proposals.next(), "zVar");
      this.assertContains(proposals.next(), "aField");
      this.assertContains(proposals.next(), "aStaticField");
      this.assertContains(proposals.next(), "zField");
      this.assertContains(proposals.next(), "zStaticField");
      this.assertContains(proposals.next(), "aMethod");
      this.assertContains(proposals.next(), "aStaticMethod");
    } finally {
      jdtPreference.put(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, defaultprefs);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 14
Source File: StubUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static String getExceptionVariableName(IJavaProject project) {
	return PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_EXCEPTION_VAR_NAME, project);
}
 
Example 15
Source File: UnresolvedElementsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static void addStaticImportFavoriteProposals(IInvocationContext context, SimpleName node, boolean isMethod, Collection<ICommandAccess> proposals) throws JavaModelException {
	IJavaProject project= context.getCompilationUnit().getJavaProject();
	if (JavaModelUtil.is50OrHigher(project)) {
		String pref= PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
		String[] favourites= pref.split(";"); //$NON-NLS-1$
		if (favourites.length == 0) {
			return;
		}

		CompilationUnit root= context.getASTRoot();
		AST ast= root.getAST();
		
		String name= node.getIdentifier();
		String[] staticImports= SimilarElementsRequestor.getStaticImportFavorites(context.getCompilationUnit(), name, isMethod, favourites);
		for (int i= 0; i < staticImports.length; i++) {
			String curr= staticImports[i];
			
			ImportRewrite importRewrite= StubUtility.createImportRewrite(root, true);
			ASTRewrite astRewrite= ASTRewrite.create(ast);
			
			String label;
			String qualifiedTypeName= Signature.getQualifier(curr);
			String elementLabel= BasicElementLabels.getJavaElementName(JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));
			
			String res= importRewrite.addStaticImport(qualifiedTypeName, name, isMethod, new ContextSensitiveImportRewriteContext(root, node.getStartPosition(), importRewrite));
			int dot= res.lastIndexOf('.');
			if (dot != -1) {
				String usedTypeName= importRewrite.addImport(qualifiedTypeName);
				Name newName= ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
				astRewrite.replace(node, newName, null);
				label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_change_to_static_import_description, elementLabel);
			} else {
				label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description, elementLabel);
			}

			Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
			ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_STATIC_IMPORT, image);
			proposal.setImportRewrite(importRewrite);
			proposals.add(proposal);
		}
	}
}