use of org.kie.workbench.common.services.refactoring.ResourceReference in project kie-wb-common by kiegroup.
the class TestJavaSourceVisitor method visit.
public void visit(AnnotationSource<? extends JavaClassSource> annoSource) {
if (annoSource.getQualifiedName().equals(AssetsUsageServiceImplTest.REFERENCED)) {
ResourceReference reference = addResourceReference(annoSource.getStringValue("resourceFQN"), ResourceType.JAVA);
reference.addPartReference(annoSource.getStringValue("part"), PartType.FIELD);
}
}
use of org.kie.workbench.common.services.refactoring.ResourceReference in project drools-wb by kiegroup.
the class TestScenarioIndexVisitor method visit.
private void visit(final Fixture fixture) {
if (fixture instanceof FixtureList) {
for (Fixture child : ((FixtureList) fixture)) {
visit(child);
}
} else if (fixture instanceof FixturesMap) {
for (Fixture child : ((FixturesMap) fixture).values()) {
visit(child);
}
} else if (fixture instanceof FactData) {
final FactData factData = (FactData) fixture;
final String typeName = factData.getType();
final String fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
ResourceReference resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
factDataToFullyQualifiedClassNameMap.put(factData.getName(), fullyQualifiedClassName);
for (Field field : factData.getFieldData()) {
final String fieldName = field.getName();
final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
resRef.addPartReference(fieldName, PartType.FIELD);
addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
}
} else if (fixture instanceof VerifyFact) {
final VerifyFact verifyFact = (VerifyFact) fixture;
final String typeName = verifyFact.getName();
// If VerifyFact is not anonymous lookup FQCN from previous FactData elements
String fullyQualifiedClassName = null;
if (!verifyFact.anonymous) {
fullyQualifiedClassName = factDataToFullyQualifiedClassNameMap.get(verifyFact.getName());
} else {
fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
}
ResourceReference resRef = null;
if (fullyQualifiedClassName != null) {
resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
for (VerifyField field : verifyFact.getFieldValues()) {
final String fieldName = field.getFieldName();
final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
resRef.addPartReference(fieldName, PartType.FIELD);
addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
}
}
} else if (fixture instanceof VerifyRuleFired) {
final VerifyRuleFired verifyRuleFired = (VerifyRuleFired) fixture;
addResourceReference(verifyRuleFired.getRuleName(), ResourceType.RULE);
}
}
use of org.kie.workbench.common.services.refactoring.ResourceReference in project drools-wb by kiegroup.
the class EnumIndexVisitor method visit.
public void visit() {
if (enumLoader.hasErrors()) {
logger.error("Errors when indexing " + resourcePath.toAbsolutePath().toFile().getAbsolutePath());
return;
}
for (Map.Entry<String, String[]> e : enumLoader.getData().entrySet()) {
// Add type
final String typeName = getTypeName(e.getKey());
final String fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
// Add field
final String fieldName = getFieldName(e.getKey());
final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
// If either type or field could not be resolved log a warning
if (fullyQualifiedClassName == null) {
logger.warn("Index entry will not be created for '" + e.getKey() + "'. Unable to determine FQCN for '" + typeName + "'. ");
} else {
ResourceReference resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
if (fieldFullyQualifiedClassName == null) {
logger.warn("Index entry will not be created for '" + e.getKey() + "'. Unable to determine FQCN for '" + typeName + "." + fieldName + "'. ");
} else {
resRef.addPartReference(fieldName, PartType.FIELD);
addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
}
}
}
}
use of org.kie.workbench.common.services.refactoring.ResourceReference in project kie-wb-common by kiegroup.
the class DataModellerFormModelVisitor method index.
@Override
public void index(FormDefinition formDefinition, DataObjectFormModel formModel) {
ResourceReference reference = addResourceReference(formModel.getClassName(), ResourceType.JAVA);
formDefinition.getFields().forEach(fieldDefinition -> visitField(reference, fieldDefinition));
}
use of org.kie.workbench.common.services.refactoring.ResourceReference in project kie-wb-common by kiegroup.
the class ResourceReferenceCollector method addResourceReference.
/**
* Used by the Visitor implementation to add the FQN and type of a reference.
* @param fullyQualifiedName The FQN of the reference
* @param type The type of the reference part.
* @return The {@link ResourceReference} being added, so that more part references can be added.
*/
public ResourceReference addResourceReference(String fullyQualifiedName, ResourceType type) {
ResourceReference resRef = internalGetResourceReferences().get(fullyQualifiedName);
if (resRef == null) {
resRef = new ResourceReference(fullyQualifiedName, type);
referencedResourcesMap.put(fullyQualifiedName, resRef);
} else if (type != null && !type.equals(resRef.getResourceType())) {
String msg = "Existing resource reference found with type " + resRef.getResourceType().toString() + " (tried to add resrouce reference of type " + type.toString() + ")";
logger.error(msg);
}
return resRef;
}
Aggregations