blob: 5ee87e412290f3f8f6343ee60e5f94a06ce60237 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2016, 2017 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.rj.eclient.core;
import org.eclipse.statet.ecommons.ts.core.Tool;
import org.eclipse.statet.rj.data.RLanguage;
import org.eclipse.statet.rj.data.RObject;
import org.eclipse.statet.rj.data.RReference;
import org.eclipse.statet.rj.services.FQRObjectRef;
public class ToolFQRObjectRef implements FQRObjectRef {
private static boolean isValidEnvObject(final RObject env) {
switch (env.getRObjectType()) {
case RObject.TYPE_REFERENCE:
return (((RReference) env).getReferencedRObjectType() == RObject.TYPE_ENVIRONMENT);
case RObject.TYPE_LANGUAGE:
return (((RLanguage) env).getLanguageType() == RLanguage.CALL);
default:
return false;
}
}
private static boolean isValidNameObject(final RObject env) {
switch (env.getRObjectType()) {
case RObject.TYPE_LANGUAGE:
switch (((RLanguage) env).getLanguageType()) {
case RLanguage.NAME:
case RLanguage.CALL:
return true;
default:
return false;
}
default:
return false;
}
}
private final Tool tool;
private final RObject env;
private final RObject name;
public ToolFQRObjectRef(final Tool tool, final RObject env, final RObject name) {
if (tool == null) {
throw new NullPointerException("tool"); //$NON-NLS-1$
}
if (env == null) {
throw new NullPointerException("env"); //$NON-NLS-1$
}
if (!isValidEnvObject(env)) {
throw new IllegalArgumentException("env"); //$NON-NLS-1$
}
if (name == null) {
throw new NullPointerException("name"); //$NON-NLS-1$
}
if (!isValidNameObject(name)) {
throw new IllegalArgumentException("name"); //$NON-NLS-1$
}
this.tool= tool;
this.env= env;
this.name= name;
}
@Override
public Tool getRHandle() {
return this.tool;
}
@Override
public RObject getEnv() {
return this.env;
}
@Override
public RObject getName() {
return this.name;
}
@Override
public String toString() {
return this.env + "\n" + this.name.toString();
}
}