use of org.eclipse.xtext.xbase.lib.Pair in project xtext-eclipse by eclipse.
the class XbaseUIValidator method checkRestrictedType.
protected void checkRestrictedType(final EObject context, final EStructuralFeature feature, final JvmDeclaredType typeToCheck) {
@SuppressWarnings("unchecked") Map<JvmDeclaredType, Pair<RestrictionKind, String>> validationContext = (Map<JvmDeclaredType, Pair<RestrictionKind, String>>) getContext().get(RestrictionKind.class);
if (validationContext == null) {
validationContext = Maps.newHashMap();
getContext().put(RestrictionKind.class, validationContext);
}
RestrictionKind restriction = null;
String javaProjectName = null;
Pair<RestrictionKind, String> cached = validationContext.get(typeToCheck);
if (cached != null) {
restriction = cached.getKey();
javaProjectName = cached.getValue();
}
if (restriction == null) {
final IJavaElement javaElement = javaElementFinder.findElementFor(typeToCheck);
if (javaElement == null || !(javaElement instanceof IType)) {
validationContext.put(typeToCheck, Pair.of(RestrictionKind.VALID, null));
return;
}
IJavaProject javaProject = javaElement.getJavaProject();
if (javaProject != null) {
javaProjectName = javaProject.getElementName();
}
restriction = computeRestriction(projectProvider.getJavaProject(context.eResource().getResourceSet()), (IType) javaElement);
validationContext.put(typeToCheck, Pair.of(restriction, javaProjectName));
}
if (restriction == RestrictionKind.FORBIDDEN) {
if (javaProjectName == null) {
IJavaProject javaProject = projectProvider.getJavaProject(context.eResource().getResourceSet());
if (javaProject != null) {
javaProjectName = javaProject.getElementName();
}
}
addIssue("Access restriction: The type " + typeToCheck.getSimpleName() + " is not accessible due to restriction on required project " + javaProjectName, context, feature, IssueCodes.FORBIDDEN_REFERENCE);
} else if (restriction == RestrictionKind.DISCOURAGED) {
if (javaProjectName == null) {
IJavaProject javaProject = projectProvider.getJavaProject(context.eResource().getResourceSet());
if (javaProject != null) {
javaProjectName = javaProject.getElementName();
}
}
addIssue("Discouraged access: The type " + typeToCheck.getSimpleName() + " is not accessible due to restriction on required project " + javaProjectName, context, feature, IssueCodes.DISCOURAGED_REFERENCE);
}
}
use of org.eclipse.xtext.xbase.lib.Pair in project metalib by softlang.
the class Tests method testNegativeKeyword.
/**
* Negative test for parser, s. figure D.37
*/
@Test
public void testNegativeKeyword() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("innnitial state locked {");
_builder.newLine();
_builder.append("\t");
_builder.append("ticket/collect -> unlocked;");
_builder.newLine();
_builder.append("\t");
_builder.append("pass/alarm -> exception;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("state unlocked {");
_builder.newLine();
_builder.append("\t");
_builder.append("ticket/eject;");
_builder.newLine();
_builder.append("\t");
_builder.append("pass -> locked;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("state exception {");
_builder.newLine();
_builder.append("\t");
_builder.append("ticket/eject;");
_builder.newLine();
_builder.append("\t");
_builder.append("pass;");
_builder.newLine();
_builder.append("\t");
_builder.append("mute;");
_builder.newLine();
_builder.append("\t");
_builder.append("release -> locked;");
_builder.newLine();
_builder.append("}");
final Pair<FSM, Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>>> annotatedFSM = this.annotatedParse(_builder);
FSM _key = annotatedFSM.getKey();
Assert.assertNull(_key);
Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>> _value = annotatedFSM.getValue();
EList<Resource.Diagnostic> _key_1 = _value.getKey();
int _size = _key_1.size();
Assert.assertEquals(_size, 0);
Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>> _value_1 = annotatedFSM.getValue();
EList<Resource.Diagnostic> _value_2 = _value_1.getValue();
int _size_1 = _value_2.size();
Assert.assertEquals(_size_1, 1);
Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>> _value_3 = annotatedFSM.getValue();
EList<Resource.Diagnostic> _value_4 = _value_3.getValue();
final Resource.Diagnostic error = IterableExtensions.<Resource.Diagnostic>head(_value_4);
int _line = error.getLine();
Assert.assertEquals(_line, 1);
String _message = error.getMessage();
Assert.assertEquals(_message, "missing EOF at \'innnitial\'");
}
use of org.eclipse.xtext.xbase.lib.Pair in project erlide_eclipse by erlang.
the class CompilerOptions method store.
public void store() throws BackingStoreException {
for (final CompilerOption option : ALL_OPTIONS) {
final Object value = options.get(option);
if (option instanceof BooleanOption) {
final Boolean val = (Boolean) value;
helper.putString(option.getName(), val.toString());
} else if (option instanceof PathsOption) {
if (value != null) {
@SuppressWarnings("unchecked") final Iterable<String> avalue = (Iterable<String>) value;
helper.putString(option.getName(), PathsOption.toString(avalue));
} else {
helper.remove(option.getName());
}
} else if (option instanceof ModuleOption || option instanceof RawOption) {
if (value != null) {
final String avalue = (String) value;
helper.putString(option.getName(), avalue);
} else {
helper.remove(option.getName());
}
} else if (value != null) {
@SuppressWarnings("unchecked") final Collection<Pair<String, String>> val = (Collection<Pair<String, String>>) value;
helper.putString(option.getName(), val.toString());
} else {
helper.remove(option.getName());
}
}
helper.flush();
}
use of org.eclipse.xtext.xbase.lib.Pair in project erlide_eclipse by erlang.
the class BackendManager method addCodeBundle.
private void addCodeBundle(final IExtension extension) {
final String pluginId = extension.getContributor().getName();
final Bundle plugin = Platform.getBundle(pluginId);
final Multimap<CodeContext, String> paths = HashMultimap.create();
final List<Pair<String, String>> inits = Lists.newArrayList();
RuntimeVersion ver = RuntimeVersion.NO_VERSION;
for (final IConfigurationElement el : extension.getConfigurationElements()) {
if ("beam_dir".equals(el.getName())) {
final String dir = el.getAttribute("path");
final String t = el.getAttribute("context").toUpperCase();
final CodeContext type = Enum.valueOf(CodeContext.class, t);
paths.put(type, dir);
} else if ("init".equals(el.getName())) {
final String module = el.getAttribute("module");
final String function = el.getAttribute("function");
inits.add(new Pair<>(module, function));
} else if ("otp_version".equals(el.getName())) {
final String attribute = el.getAttribute("value");
if (attribute != null) {
ver = RuntimeVersion.Serializer.parse(attribute);
}
} else {
ErlLogger.error("Unknown code bundle element: %s", el.getName());
}
}
addBundle(plugin, ver, paths, inits);
}
use of org.eclipse.xtext.xbase.lib.Pair in project erlide_eclipse by erlang.
the class CompilerOptionTest method testToTerm_5.
@Test
public void testToTerm_5() throws OtpParserException {
final DefineOption option = CompilerOptions.DEFINE;
@SuppressWarnings("unchecked") final List<Pair<String, String>> values = Lists.newArrayList(new Pair<>("Macro", "[hej,1]"));
final OtpErlangObject actual = option.toTerm(values);
final String expected = "[{d,'Macro',[hej,1]}]";
Assert.assertEquals(expected, actual.toString());
}
Aggregations