Skip to content
Snippets Groups Projects
Commit 4012edad authored by Dominique Marcadet's avatar Dominique Marcadet
Browse files

rewrite buildExplicitLinks

parent 440fd1e5
No related branches found
No related tags found
1 merge request!11Resolve "avoid doing setRefersToXXX( null )"
Showing
with 145 additions and 96 deletions
......@@ -28,6 +28,7 @@ import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Optional;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
......@@ -513,23 +514,29 @@ public abstract class AnyLNClassImpl extends TitledClassImpl implements AnyLNCla
@Override
public boolean buildExplicitLinks( IRiseClipseConsole console ) {
if( super.buildExplicitLinks( console ) ) return true;
if( !isSetBase() ) return false;
// This code assumes that the referred AbstractLNClass is in the same NS
// TODO: check that it is right
LNClasses lNClasses = ( LNClasses ) eContainer();
EList< AbstractLNClass > l = lNClasses.getAbstractLNClass();
setRefersToAbstractLNClass( l.stream()
.filter( abstractLNClass -> abstractLNClass.getName().equals( getBase() ) ).findAny().orElse( null ) );
if( getRefersToAbstractLNClass() == null ) {
console.error( "AbstractLNClass (name: " + getBase() + ") refers by AnyLNClass (name: " + getName()
+ ") in NS (id:" + lNClasses.getNS().getId() + ") is unknown" );
}
else {
console.verbose( "AbstractLNClass (name: " + getBase() + ") refers by AnyLNClass (name: " + getName()
+ ") in NS (id:" + lNClasses.getNS().getId() + ") found in NS (id:"
+ getRefersToAbstractLNClass().getLNClasses().getNS().getId() + ")" );
if( isSetBase() ) {
// This code assumes that the referred AbstractLNClass is in the same NS
// TODO: check that it is right
getLNClasses()
.getAbstractLNClass()
.stream()
.filter( abstractLNClass -> abstractLNClass.getName().equals( getBase() ) )
.findAny()
.ifPresent( abstractLNClass -> setRefersToAbstractLNClass( abstractLNClass ) );
if( isSetRefersToAbstractLNClass() ) {
console.verbose( "AbstractLNClass (name: " + getBase() + ") refers by AnyLNClass (name: " + getName()
+ ") in NS (id:" + getLNClasses().getNS().getId() + ") found in NS (id:"
+ getRefersToAbstractLNClass().getLNClasses().getNS().getId() + ")" );
}
else {
console.error( "AbstractLNClass (name: " + getBase() + ") refers by AnyLNClass (name: " + getName()
+ ") in NS (id:" + getLNClasses().getNS().getId() + ") is unknown" );
}
}
return false;
}
......
......@@ -29,6 +29,7 @@ import fr.centralesupelec.edf.riseclipse.iec61850.nsd.CDC;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DataAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DefinedAttributeTypeKind;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.FunctionalConstraint;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NS;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NsdFactory;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NsdPackage;
......@@ -3046,71 +3047,89 @@ public class DataAttributeImpl extends DocumentedClassImpl implements DataAttrib
public boolean buildExplicitLinks( IRiseClipseConsole console ) {
if( super.buildExplicitLinks( console ) ) return true;
NS ns = getCDC().getCDCs().getNS();
if( isSetFc() ) {
setRefersToFunctionalConstraint( getCDC().getCDCs().getNS().findFunctionalConstraint( getFc(), console ) );
if( getRefersToFunctionalConstraint() == null ) {
FunctionalConstraint foundFC = ns.findFunctionalConstraint( getFc(), console );
if( foundFC == null ) {
console.error( "FunctionalConstraint (abbreviation: " + getFc() + ") refers by DataAttribute (name: "
+ getName() + ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") is unknown" );
+ getName() + ") in NS (id:" + ns.getId() + ") is unknown" );
}
else {
setRefersToFunctionalConstraint( foundFC );
console.verbose( "FunctionalConstraint (abbreviation: " + getFc() + ") refers by DataAttribute (name: "
+ getName() + ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") found in NS (id:"
+ getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
+ getRefersToFunctionalConstraint().getFunctionalConstraints().getNS().getId() + ")" );
}
}
if( isSetPresCond() ) {
setRefersToPresenceCondition( getCDC().getCDCs().getNS().findPresenceCondition( getPresCond(), console ) );
if( getRefersToPresenceCondition() == null ) {
PresenceCondition foundPC = ns.findPresenceCondition( getPresCond(), console );
if( foundPC == null ) {
console.error( "PresenceCondition (name: " + getPresCond() + ") refers by DataAttribute (name: "
+ getName() + ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") is unknown" );
+ getName() + ") in NS (id:" + ns.getId() + ") is unknown" );
}
else {
setRefersToPresenceCondition( foundPC );
console.verbose( "PresenceCondition (name: " + getPresCond() + ") refers by DataAttribute (name: "
+ getName() + ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") found in NS (id:"
+ getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
+ getRefersToPresenceCondition().getPresenceConditions().getNS().getId() + ")" );
}
}
if( isSetSizeAttribute() ) {
setRefersToSizeAttribute( getCDC().getDataAttribute().stream()
.filter( att -> att.getName().equals( getSizeAttribute() ) ).findAny().orElse( null ) );
if( getRefersToSizeAttribute() == null ) {
console.error( "DataAttribute (name: " + getSizeAttribute()
getCDC()
.getDataAttribute()
.stream()
.filter( att -> att.getName().equals( getSizeAttribute() ) )
.findAny()
.ifPresent( att -> setRefersToSizeAttribute( att ) );
if( isSetRefersToSizeAttribute() ) {
console.verbose( "DataAttribute (name: " + getSizeAttribute()
+ ") refers as sizeAttribute by DataAttribute (name: " + getName() + ") in NS (id:"
+ getCDC().getCDCs().getNS().getId() + ") is unknown" );
+ ns.getId() + ") found" );
}
else {
console.verbose( "DataAttribute (name: " + getSizeAttribute()
console.error( "DataAttribute (name: " + getSizeAttribute()
+ ") refers as sizeAttribute by DataAttribute (name: " + getName() + ") in NS (id:"
+ getCDC().getCDCs().getNS().getId() + ") found" );
+ ns.getId() + ") is unknown" );
}
}
if( isSetMaxIndexAttribute() ) {
setRefersToMaxIndexAttribute( getCDC().getDataAttribute().stream()
.filter( att -> att.getName().equals( getMaxIndexAttribute() ) ).findAny().orElse( null ) );
if( getRefersToMaxIndexAttribute() == null ) {
console.error( "DataAttribute (name: " + getMaxIndexAttribute()
getCDC()
.getDataAttribute()
.stream()
.filter( att -> att.getName().equals( getMaxIndexAttribute() ) )
.findAny()
.ifPresent( att -> setRefersToMaxIndexAttribute( att ) );
if( isSetRefersToMaxIndexAttribute() ) {
console.verbose( "DataAttribute (name: " + getMaxIndexAttribute()
+ ") refers as maxIndexAttribute by DataAttribute (name: " + getName() + ") in NS (id:"
+ getCDC().getCDCs().getNS().getId() + ") is unknown" );
+ ns.getId() + ") found" );
}
else {
console.verbose( "DataAttribute (name: " + getMaxIndexAttribute()
console.error( "DataAttribute (name: " + getMaxIndexAttribute()
+ ") refers as maxIndexAttribute by DataAttribute (name: " + getName() + ") in NS (id:"
+ getCDC().getCDCs().getNS().getId() + ") found" );
+ ns.getId() + ") is unknown" );
}
}
if( getTypeKind().equals( DefinedAttributeTypeKind.BASIC ) ) {
setRefersToBasicType( getCDC().getCDCs().getNS().findBasicType( getType(), console ) );
if( getRefersToBasicType() == null ) {
BasicType foundBT = ns.findBasicType( getType(), console );
if( foundBT == null ) {
console.error( "BasicType (name: " + getType() + ") refers as type by DataAttribute (name: " + getName()
+ ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") is unknown" );
+ ") in NS (id:" + ns.getId() + ") is unknown" );
}
else {
setRefersToBasicType( foundBT );
console.verbose( "BasicType (name: " + getType() + ") refers as type by DataAttribute (name: "
+ getName() + ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") found in NS (id:"
+ getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
+ getRefersToBasicType().getBasicTypes().getNS().getId() + ")" );
}
}
......
......@@ -26,6 +26,7 @@ import fr.centralesupelec.edf.riseclipse.iec61850.nsd.AnyLNClass;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.CDC;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DataObject;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DefinedAttributeTypeKind;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NS;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NsdPackage;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.PresenceCondition;
......@@ -1841,44 +1842,46 @@ public class DataObjectImpl extends DocumentedClassImpl implements DataObject {
public boolean buildExplicitLinks( IRiseClipseConsole console ) {
if( super.buildExplicitLinks( console ) ) return true;
NS ns = getAnyLNClass().getLNClasses().getNS();
if( isSetType() ) {
setRefersToCDC( getAnyLNClass().getLNClasses().getNS().findCDC( getType(), console ) );
if( getRefersToCDC() == null ) {
CDC foundCDC = ns.findCDC( getType(), console );
if( foundCDC == null ) {
console.error( "CDC (name: " + getType() + ") refers by DataObject (name: " + getName() + ") in NS (id:"
+ getAnyLNClass().getLNClasses().getNS().getId() + ") is unknown" );
+ ns.getId() + ") is unknown" );
}
else {
setRefersToCDC( foundCDC );
console.verbose( "CDC (name: " + getType() + ") refers by DataObject (name: " + getName()
+ ") in NS (id:" + getAnyLNClass().getLNClasses().getNS().getId() + ") found in NS (id:"
+ ") in NS (id:" + ns.getId() + ") found in NS (id:"
+ getRefersToCDC().getCDCs().getNS().getId() + ")" );
}
}
if( isSetPresCond() ) {
setRefersToPresenceCondition(
getAnyLNClass().getLNClasses().getNS().findPresenceCondition( getPresCond(), console ) );
if( getRefersToPresenceCondition() == null ) {
console.error(
"PresenceCondition (name: " + getPresCond() + ") refers by DataObject (name: " + getName()
+ ") in NS (id:" + getAnyLNClass().getLNClasses().getNS().getId() + ") is unknown" );
PresenceCondition foundPC = ns.findPresenceCondition( getPresCond(), console );
if( foundPC == null ) {
console.error( "PresenceCondition (name: " + getPresCond() + ") refers by DataObject (name: "
+ getName() + ") in NS (id:" + ns.getId() + ") is unknown" );
}
else {
console.verbose(
"PresenceCondition (name: " + getPresCond() + ") refers by DataObject (name: " + getName()
+ ") in NS (id:" + getAnyLNClass().getLNClasses().getNS().getId() + ") found in NS (id:"
+ getRefersToPresenceCondition().getPresenceConditions().getNS().getId() + ")" );
setRefersToPresenceCondition( foundPC );
console.verbose( "PresenceCondition (name: " + getPresCond() + ") refers by DataObject (name: "
+ getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
+ getRefersToPresenceCondition().getPresenceConditions().getNS().getId() + ")" );
}
}
if( isSetDsPresCond() ) {
setRefersToPresenceConditionDerivedStatistics(
getAnyLNClass().getLNClasses().getNS().findPresenceCondition( getDsPresCond(), console ) );
if( getRefersToPresenceConditionDerivedStatistics() == null ) {
PresenceCondition foundPC = ns.findPresenceCondition( getDsPresCond(), console );
if( foundPC == null ) {
console.error(
"PresenceCondition (name: " + getDsPresCond() + ") refers by DataObject (name: " + getName()
+ ") in NS (id:" + getAnyLNClass().getLNClasses().getNS().getId() + ") is unknown" );
}
else {
setRefersToPresenceConditionDerivedStatistics( foundPC );
console.verbose( "PresenceCondition (name: " + getDsPresCond() + ") refers by DataObject (name: "
+ getName() + ") in NS (id:" + getAnyLNClass().getLNClasses().getNS().getId()
+ ") found in NS (id:"
......
......@@ -891,13 +891,13 @@ public class DependsOnImpl extends NsdObjectImpl implements DependsOn {
public boolean buildExplicitLinks( IRiseClipseConsole console ) {
if( super.buildExplicitLinks( console ) ) return true;
NsdResourceSetImpl resourceSet = ( NsdResourceSetImpl ) eResource().getResourceSet();
setRefersToNS( resourceSet.getNS( getId() ) );
if( getRefersToNS() == null ) {
NS ns = ( ( NsdResourceSetImpl ) eResource().getResourceSet() ).getNS( getId() );
if( ns == null ) {
console.error(
"NS (id: " + getId() + ") and refers by DependsOn in NS (id:" + getNS().getId() + ") is unknown" );
}
else {
setRefersToNS( ns );
console.verbose(
"NS (id: " + getId() + ") and refers by DependsOn in NS (id:" + getNS().getId() + ") found" );
}
......
......@@ -22,6 +22,7 @@ package fr.centralesupelec.edf.riseclipse.iec61850.nsd.impl;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.Enumeration;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.Enumerations;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.Literal;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NS;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NsdPackage;
import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole;
......@@ -709,15 +710,17 @@ public class EnumerationImpl extends TitledClassImpl implements Enumeration {
public boolean buildExplicitLinks( IRiseClipseConsole console ) {
if( super.buildExplicitLinks( console ) ) return true;
NS ns = getEnumerations().getNS();
if( isSetInheritedFrom() ) {
setRefersToBaseEnumeration( getEnumerations().getNS().findEnumeration( getInheritedFrom(), console ) );
if( getRefersToBaseEnumeration() == null ) {
Enumeration foundBase = ns.findEnumeration( getInheritedFrom(), console );
if( foundBase == null ) {
console.error( "Enumeration (name: " + getInheritedFrom() + ") refers by Enumeration (name: "
+ getName() + ") in NS (id:" + getEnumerations().getNS().getId() + ") is unknown" );
+ getName() + ") in NS (id:" + ns.getId() + ") is unknown" );
}
else {
setRefersToBaseEnumeration( foundBase );
console.verbose( "Enumeration (name: " + getInheritedFrom() + ") refers by Enumeration (name: "
+ getName() + ") in NS (id:" + getEnumerations().getNS().getId() + ") found in NS (id:"
+ getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
+ getRefersToBaseEnumeration().getEnumerations().getNS().getId() + ")" );
}
}
......
......@@ -24,6 +24,7 @@ import fr.centralesupelec.edf.riseclipse.iec61850.nsd.AgAttributeType;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.AgAttributeTypeAndValues;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.AgPresenceCondition;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.ConstructedAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NS;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NsdFactory;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NsdPackage;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.PresenceCondition;
......@@ -1761,18 +1762,17 @@ public class SubDataAttributeImpl extends DocumentedClassImpl implements SubData
public boolean buildExplicitLinks( IRiseClipseConsole console ) {
if( super.buildExplicitLinks( console ) ) return true;
NS ns = getConstructedAttribute().getConstructedAttributes().getNS();
if( isSetPresCond() ) {
setRefersToPresenceCondition( getConstructedAttribute().getConstructedAttributes().getNS()
.findPresenceCondition( getPresCond(), console ) );
if( getRefersToPresenceCondition() == null ) {
PresenceCondition foundPC = ns.findPresenceCondition( getPresCond(), console );
if( foundPC == null ) {
console.error( "PresenceCondition (name: " + getPresCond() + ") refers by SubDataAttribute (name: "
+ getName() + ") in NS (id:"
+ getConstructedAttribute().getConstructedAttributes().getNS().getId() + ") is unknown" );
+ getName() + ") in NS (id:" + ns.getId() + ") is unknown" );
}
else {
setRefersToPresenceCondition( foundPC );
console.verbose( "PresenceCondition (name: " + getPresCond() + ") refers by SubDataAttribute (name: "
+ getName() + ") in NS (id:"
+ getConstructedAttribute().getConstructedAttributes().getNS().getId() + ") found in NS (id:"
+ getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
+ getRefersToPresenceCondition().getPresenceConditions().getNS().getId() + ")" );
}
}
......
......@@ -25,6 +25,7 @@ import fr.centralesupelec.edf.riseclipse.iec61850.nsd.AgUnderlyingType;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.CDC;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DataAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DefinedAttributeTypeKind;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NS;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NsdPackage;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.PresenceCondition;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.SubDataObject;
......@@ -1994,59 +1995,75 @@ public class SubDataObjectImpl extends DocumentedClassImpl implements SubDataObj
public boolean buildExplicitLinks( IRiseClipseConsole console ) {
if( super.buildExplicitLinks( console ) ) return true;
NS ns = getCDC().getCDCs().getNS();
if( isSetType() ) {
setRefersToCDC( getCDC().getCDCs().getNS().findCDC( getType(), console ) );
if( getRefersToCDC() == null ) {
console.error( "CDC (name: " + getType() + ") refers by SubDataObject (name: " + getName()
+ ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") is unknown" );
CDC foundCDC = ns.findCDC( getType(), console );
if( foundCDC == null ) {
console.error(
"CDC (name: " + getType() + ") refers by SubDataObject (name: " + getName() + ") in NS (id:"
+ ns.getId() + ") is unknown" );
}
else {
setRefersToCDC( foundCDC );
console.verbose( "CDC (name: " + getType() + ") refers by SubDataObject (name: " + getName()
+ ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") found in NS (id:"
+ ") in NS (id:" + ns.getId() + ") found in NS (id:"
+ getRefersToCDC().getCDCs().getNS().getId() + ")" );
}
}
if( isSetPresCond() ) {
setRefersToPresenceCondition( getCDC().getCDCs().getNS().findPresenceCondition( getPresCond(), console ) );
if( getRefersToPresenceCondition() == null ) {
PresenceCondition foundPC = ns.findPresenceCondition( getPresCond(), console );
if( foundPC == null ) {
console.error( "PresenceCondition (name: " + getPresCond() + ") refers by SubDataObject (name: "
+ getName() + ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") is unknown" );
+ getName() + ") in NS (id:" + ns.getId() + ") is unknown" );
}
else {
setRefersToPresenceCondition( foundPC );
console.verbose( "PresenceCondition (name: " + getPresCond() + ") refers by SubDataObject (name: "
+ getName() + ") in NS (id:" + getCDC().getCDCs().getNS().getId() + ") found in NS (id:"
+ getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
+ getRefersToPresenceCondition().getPresenceConditions().getNS().getId() + ")" );
}
}
if( isSetSizeAttribute() ) {
setRefersToSizeAttribute( getCDC().getDataAttribute().stream()
.filter( att -> att.getName().equals( getSizeAttribute() ) ).findAny().orElse( null ) );
if( getRefersToSizeAttribute() == null ) {
console.error( "DataAttribute (name: " + getSizeAttribute()
getCDC()
.getDataAttribute()
.stream()
.filter( att -> att.getName().equals( getSizeAttribute() ) )
.findAny()
.ifPresent( att -> setRefersToSizeAttribute( att ) );
if( isSetRefersToSizeAttribute() ) {
console.verbose( "DataAttribute (name: " + getSizeAttribute()
+ ") refers as sizeAttribute by SubDataObject (name: " + getName() + ") in NS (id:"
+ getCDC().getCDCs().getNS().getId() + ") is unknown" );
+ ns.getId() + ") found" );
}
else {
console.verbose( "DataAttribute (name: " + getSizeAttribute()
console.error( "DataAttribute (name: " + getSizeAttribute()
+ ") refers as sizeAttribute by SubDataObject (name: " + getName() + ") in NS (id:"
+ getCDC().getCDCs().getNS().getId() + ") found" );
+ ns.getId() + ") is unknown" );
}
}
if( isSetMaxIndexAttribute() ) {
setRefersToMaxIndexAttribute( getCDC().getDataAttribute().stream()
.filter( att -> att.getName().equals( getMaxIndexAttribute() ) ).findAny().orElse( null ) );
if( getRefersToMaxIndexAttribute() == null ) {
console.error( "DataAttribute (name: " + getMaxIndexAttribute()
getCDC()
.getDataAttribute()
.stream()
.filter( att -> att.getName().equals( getSizeAttribute() ) )
.findAny()
.ifPresent( att -> setRefersToMaxIndexAttribute( att ) );
if( isSetRefersToMaxIndexAttribute() ) {
console.verbose( "DataAttribute (name: " + getMaxIndexAttribute()
+ ") refers as maxIndexAttribute by SubDataObject (name: " + getName() + ") in NS (id:"
+ getCDC().getCDCs().getNS().getId() + ") is unknown" );
+ ns.getId() + ") found" );
}
else {
console.verbose( "DataAttribute (name: " + getMaxIndexAttribute()
console.error( "DataAttribute (name: " + getMaxIndexAttribute()
+ ") refers as maxIndexAttribute by SubDataObject (name: " + getName() + ") in NS (id:"
+ getCDC().getCDCs().getNS().getId() + ") found" );
+ ns.getId() + ") is unknown" );
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment