After updating code from skeleton script constant cannot be resolved - Eclipse issue?

eclipse
Tags: #<Tag:0x00007f51df732e30>

(A-To-The-K) #1

Just getting started with the add-ons skeleton and already running into issues that I’m hoping someone can tell me if its an issue with the IDE or my grey matter. I’ve just changed a few constants from “THING_TYPE_SAMPLE” to more specific constants, but getting errors.

For example in UI_IP8_DPBindingConstants.java:

    public class UI_IP8_DPBindingConstants {

        private static final String BINDING_ID = "ui_ip8_dp";

        // List of all Thing Type UIDs
        public static final ThingTypeUID UI_IP8_DP = new ThingTypeUID(BINDING_ID, "UI-IP8-DP");

        // List of all Channel ids
        public static final String BUTTONS = "buttons";
        public static final String REDLEDS = "redLeds";
    }

Now in UI_IP8_DPHandlerFactory.java I have

    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(UI_IP8_DP);

    @Override
    public boolean supportsThingType(ThingTypeUID thingTypeUID) {
        return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
    }

    @Override
    protected @Nullable ThingHandler createHandler(Thing thing) {
        ThingTypeUID thingTypeUID = thing.getThingTypeUID();

        if (UI_IP8_DP.equals(thingTypeUID)) {
            return new UI_IP8_DPHandler(thing);
        }

        return null;
    }
}

On line private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(UI_IP8_DP);

Error: private static final Object UI_IP8_DP = null

and on line if (UI_IP8_DP.equals(thingTypeUID)) {

Error: UI_IP8_DP cannot be resolved

This all worked when it was “THING_TYPE_SAMPLE”. I’ve saved, re-opened, refreshed, cleaned. To the best of my knowledge Eclipse should recognize my new constant names, just as it did when the skeleton script first created the Sample items.

Thanks in advance!


(Hilbrand Bouwkamp) #2

The variable is imported static. See imports. Change in UI_IP8_DPHandlerFactory.

Btw. Use your real name in the @author tag not your alias.


(A-To-The-K) #3

Btw. Use your real name in the @author tag not your alias.

Thanks for the tip.

The variable name is correct and I can fix the error by including the class name, but I think something in Eclipse is broken, or my head is broken. For demonstrate, I created a skeleton binding called “skeletonTest”, import into the workspace and Eclipse throws no errors.

package org.openhab.binding.skeletontest.internal;

import static org.openhab.binding.skeletontest.internal.skeletonTestBindingConstants.*;

import java.util.Collections;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.skeletontest.internal.skeletonTestHandler;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.osgi.service.component.annotations.Component;

@NonNullByDefault
@Component(configurationPid = "binding.skeletontest", service = ThingHandlerFactory.class)
public class skeletonTestHandlerFactory extends BaseThingHandlerFactory {

    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_SAMPLE);

    @Override
    public boolean supportsThingType(ThingTypeUID thingTypeUID) {
        return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
    }

    @Override
    protected @Nullable ThingHandler createHandler(Thing thing) {
        ThingTypeUID thingTypeUID = thing.getThingTypeUID();

        if (THING_TYPE_SAMPLE.equals(thingTypeUID)) {
            return new skeletonTestHandler(thing);
        }

        return null;
    }
}

If I change THING_TYPE_SAMPLE to THING_TYPE_SAMPLE_TEST in skeltonTestBindingConstants.java and then in skeletonTestHandlerFactory.java, this is okay and no errors are thrown.

Now if I change THING_TYPE_SAMPLE_TEST back to THING_TYPE_SAMPLE in both files, Eclipse throws the errors I mentioned.

If I ADD import static org.openhab.binding.skeleton.internal.skeletonBindingConstants.*; then naturally its fixed, but this wasn’t in the skeleton to begin with. Hopefully this makes sense why this doesn’t make sense.

Running Version: Photon Release (4.8.0)


(A-To-The-K) #4

I created a 2 minute screenshare that helps describe what I’m seeing.

https://vimeo.com/user79434583/review/322346041/08fa35a86e


(A-To-The-K) #5

Just wondering if others are having this issue and it’s stumping others.