Skip to content

Commit

Permalink
implement Adapter instead of extending AdapterImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Feb 4, 2024
1 parent b6b9016 commit 90c17f2
Showing 1 changed file with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,37 @@
*******************************************************************************/
package org.eclipse.xtext.common.types.util;

import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.xtext.common.types.JvmTypeReference;

/**
* @author Lorenzo Bettini - Initial contribution and API
*/
public class JvmTypeReferenceUtil {
private static class Marker implements Adapter {
@Override
public Notifier getTarget() {
return null;
}

private static class ExpectedClassMarker extends AdapterImpl {
@Override
public boolean isAdapterForType(Object type) {
return type == ExpectedClassMarker.class;
return false;
}
}

private static class ExpectedInterfaceMarker extends AdapterImpl {
@Override
public boolean isAdapterForType(Object type) {
return type == ExpectedInterfaceMarker.class;
public void notifyChanged(Notification notification) {
}
}

private static final ExpectedClassMarker EXPECTED_CLASS_MARKER = new ExpectedClassMarker();
private static final ExpectedInterfaceMarker EXPECTED_INTERFACE_MARKER = new ExpectedInterfaceMarker();
@Override
public void setTarget(Notifier newTarget) {
}
};

private static final Marker EXPECTED_CLASS_MARKER = new Marker();
private static final Marker EXPECTED_INTERFACE_MARKER = new Marker();

private JvmTypeReferenceUtil() {
// only static methods
Expand All @@ -43,14 +49,14 @@ public static void setExpectedAsClass(JvmTypeReference typeReference) {
}

public static boolean isExpectedAsClass(JvmTypeReference typeReference) {
return EcoreUtil.getAdapter(typeReference.eAdapters(), ExpectedClassMarker.class) != null;
return typeReference.eAdapters().contains(EXPECTED_CLASS_MARKER);
}

public static void setExpectedAsInterface(JvmTypeReference typeReference) {
typeReference.eAdapters().add(EXPECTED_INTERFACE_MARKER);
}

public static boolean isExpectedAsInterface(JvmTypeReference typeReference) {
return EcoreUtil.getAdapter(typeReference.eAdapters(), ExpectedInterfaceMarker.class) != null;
return typeReference.eAdapters().contains(EXPECTED_INTERFACE_MARKER);
}
}

0 comments on commit 90c17f2

Please sign in to comment.