use of org.eclipse.titan.designer.AST.ReferenceFinder.Hit in project titan.EclipsePlug-ins by eclipse.
the class OccurencesMarker method findOccurrencesReferenceBased.
/**
* Finds the occurrences of the element located on the given offset.
* This solution can be used, when the locations are not correct. (e.g.
* in case of an ASN.1 file)
*
* @param document
* @param reference
* @param module
* The module to search the occurrences in
* @param offset
* An offset in the module
* @return The found references. Includes the definition of the element.
*/
protected List<Hit> findOccurrencesReferenceBased(final IDocument document, final Reference reference, final Module module, final int offset) {
Scope scope = module.getSmallestEnclosingScope(offset);
if (scope == null) {
removeOccurences(false);
error(document, offset, "Can not determine the smallest enclosing scope.");
return new ArrayList<ReferenceFinder.Hit>();
}
reference.setMyScope(scope);
if (reference.getId() == null) {
removeOccurences(false);
error(document, offset, "The identifier of the reference is null.");
return new ArrayList<ReferenceFinder.Hit>();
}
if (reference.getSubreferences().size() > 1) {
// highlighting the subreferences is not yet supported
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
ReferenceFinder referenceFinder;
List<Hit> result = null;
boolean found = false;
if (scope.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), reference.getId()) || (scope.getModuleScope().hasImportedAssignmentWithID(CompilationTimeStamp.getBaseTimestamp(), reference.getId()))) {
Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment == null) {
error(document, offset, "The assignment could not be determined from the reference: " + reference.getDisplayName());
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
if (!assignment.shouldMarkOccurrences()) {
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
try {
referenceFinder = new ReferenceFinder(assignment);
} catch (final IllegalArgumentException e) {
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
result = referenceFinder.findReferencesInModule(module);
// Hack to eliminate false positive results
if (assignment.getLocation().containsOffset(offset)) {
found = true;
} else {
for (Hit hit : result) {
if (hit.identifier.getLocation().containsOffset(offset)) {
found = true;
break;
}
}
}
if (found && assignment.getMyScope().getModuleScope() == module && assignment.getIdentifier() != null) {
result.add(new Hit(assignment.getIdentifier()));
}
}
if (!found) {
// Check if the reference points to a field of a type
// definition
referenceFinder = new ReferenceFinder();
referenceFinder.detectAssignmentDataByOffset(module, offset, editor, false, false);
Assignment assignment = referenceFinder.assignment;
if (assignment == null) {
removeOccurences(false);
error(document, offset, "Could not detect the assignment.");
return new ArrayList<ReferenceFinder.Hit>();
}
if (assignment.getAssignmentType() != null && assignment.getAssignmentType() != Assignment_type.A_TYPE || referenceFinder.fieldId == null || !assignment.shouldMarkOccurrences()) {
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
result = referenceFinder.findReferencesInModule(module);
if (referenceFinder.fieldId != null) {
result.add(new Hit(referenceFinder.fieldId));
}
}
return result;
}
use of org.eclipse.titan.designer.AST.ReferenceFinder.Hit in project titan.EclipsePlug-ins by eclipse.
the class Qualifier method findReferences.
@Override
public /**
* {@inheritDoc}
*/
void findReferences(final ReferenceFinder referenceFinder, final List<Hit> foundIdentifiers) {
if (definition != null && subReferences != null) {
// qualifiers were not semantically analyzed
for (ISubReference sr : subReferences) {
sr.findReferences(referenceFinder, foundIdentifiers);
}
if (referenceFinder.fieldId != null) {
// we are searching for a field of a type
final IType t = definition.getType(CompilationTimeStamp.getBaseTimestamp());
if (t == null) {
return;
}
final List<IType> typeArray = new ArrayList<IType>();
final Reference reference = new Reference(null);
reference.addSubReference(new FieldSubReference(definition.getIdentifier()));
for (ISubReference sr : subReferences) {
reference.addSubReference(sr);
}
reference.setLocation(location);
reference.setMyScope(definition.getMyScope());
final boolean success = t.getFieldTypesAsArray(reference, 1, typeArray);
if (!success) {
// TODO: maybe a partially erroneous reference could be searched too
return;
}
if (subReferences.size() != typeArray.size()) {
ErrorReporter.INTERNAL_ERROR();
return;
}
for (int i = 0; i < subReferences.size(); i++) {
if (typeArray.get(i) == referenceFinder.type && !(subReferences.get(i) instanceof ArraySubReference) && subReferences.get(i).getId().equals(referenceFinder.fieldId)) {
foundIdentifiers.add(new Hit(subReferences.get(i).getId()));
}
}
}
}
}
use of org.eclipse.titan.designer.AST.ReferenceFinder.Hit in project titan.EclipsePlug-ins by eclipse.
the class Named_Template_List method findReferences.
@Override
public /**
* {@inheritDoc}
*/
void findReferences(final ReferenceFinder referenceFinder, final List<Hit> foundIdentifiers) {
super.findReferences(referenceFinder, foundIdentifiers);
if (asValue != null) {
asValue.findReferences(referenceFinder, foundIdentifiers);
return;
}
if (namedTemplates == null) {
return;
}
if (referenceFinder.assignment.getAssignmentType() == Assignment_type.A_TYPE && referenceFinder.fieldId != null && myGovernor != null) {
// check if this is the type and field we are searching
// for
final IType govLast = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (referenceFinder.type == govLast) {
final NamedTemplate nt = namedTemplates.getNamedTemplateByName(referenceFinder.fieldId);
if (nt != null) {
foundIdentifiers.add(new Hit(nt.getName()));
}
}
}
namedTemplates.findReferences(referenceFinder, foundIdentifiers);
}
use of org.eclipse.titan.designer.AST.ReferenceFinder.Hit in project titan.EclipsePlug-ins by eclipse.
the class Reference method findReferences.
@Override
public /**
* {@inheritDoc}
*/
void findReferences(final ReferenceFinder referenceFinder, final List<Hit> foundIdentifiers) {
for (int i = 0; i < subReferences.size(); i++) {
subReferences.get(i).findReferences(referenceFinder, foundIdentifiers);
}
if (referredAssignment == null) {
return;
}
if (referenceFinder.fieldId == null) {
// we are searching for the assignment itself
if (referenceFinder.assignment != referredAssignment) {
return;
}
foundIdentifiers.add(new Hit(getId(), this));
} else {
// we are searching for a field of a type
final IType t = referredAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
if (t == null) {
return;
}
final List<IType> typeArray = new ArrayList<IType>();
final boolean success = t.getFieldTypesAsArray(this, 1, typeArray);
if (!success) {
// TODO: maybe a partially erroneous reference could be searched too
return;
}
// TODO: subReferences.size()>0 is just temporary. Rethink if it is correct or or not
if (subReferences.size() > 0 && subReferences.size() != typeArray.size() + 1) {
ErrorReporter.INTERNAL_ERROR();
return;
}
for (int i = 1; i < subReferences.size(); i++) {
if (typeArray.get(i - 1) == referenceFinder.type && !(subReferences.get(i) instanceof ArraySubReference) && subReferences.get(i).getId().equals(referenceFinder.fieldId)) {
foundIdentifiers.add(new Hit(subReferences.get(i).getId()));
}
}
}
}
use of org.eclipse.titan.designer.AST.ReferenceFinder.Hit in project titan.EclipsePlug-ins by eclipse.
the class RenameRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
// search
idsMap = rf.findAllReferences(module, file.getProject(), pm, reportDebugInformation);
// add the referred identifier to the map of found identifiers
Identifier refdIdentifier = rf.getReferredIdentifier();
Module refdModule = rf.assignment.getMyScope().getModuleScope();
if (idsMap.containsKey(refdModule)) {
idsMap.get(refdModule).add(new Hit(refdIdentifier));
} else {
ArrayList<Hit> identifierList = new ArrayList<Hit>();
identifierList.add(new Hit(refdIdentifier));
idsMap.put(refdModule, identifierList);
}
// scopes
if (rf.fieldId == null) {
// check that in all affected scopes there is no
// definition with the new name
Identifier.Identifier_type idType = Identifier_type.ID_TTCN;
if (rf.scope.getModuleScope() instanceof ASN1Module) {
idType = Identifier_type.ID_ASN;
}
Identifier newId = new Identifier(idType, newIdentifierName);
// check for assignment with given id in all sub-scopes
// of the assignment's scope
// TODO: this does not detect runs on <-> component
// member conflicts because the RunsOnScope is not a
// sub-scope of the ComponentTypeBody scope,
// also it does not go into other modules
Scope rootScope = rf.assignment.getMyScope();
if (rootScope instanceof NamedBridgeScope && rootScope.getParentScope() != null) {
rootScope = rootScope.getParentScope();
}
SubScopeVisitor subScopeVisitor = new SubScopeVisitor(rootScope);
module.accept(subScopeVisitor);
List<Scope> subScopes = subScopeVisitor.getSubScopes();
subScopes.add(rootScope);
for (Scope ss : subScopes) {
if (ss.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), newId)) {
List<ISubReference> subReferences = new ArrayList<ISubReference>();
subReferences.add(new FieldSubReference(newId));
Reference reference = new Reference(null, subReferences);
Assignment assignment = ss.getAssBySRef(CompilationTimeStamp.getBaseTimestamp(), reference);
if (assignment != null && assignment.getLocation() != null) {
result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS2, newId.getDisplayName(), module.getName(), assignment.getLocation().getLine()));
} else {
result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS, newId.getDisplayName()));
}
// to avoid spam and multiple messages for the same conflict
return result;
}
}
} else {
boolean alreadyExists = false;
// name
if (rf.type instanceof TTCN3_Set_Seq_Choice_BaseType) {
alreadyExists = ((TTCN3_Set_Seq_Choice_BaseType) rf.type).hasComponentWithName(newIdentifierName);
} else if (rf.type instanceof TTCN3_Enumerated_Type) {
alreadyExists = ((TTCN3_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_TTCN, newIdentifierName));
} else if (rf.type instanceof ASN1_Choice_Type) {
alreadyExists = ((ASN1_Choice_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Enumerated_Type) {
alreadyExists = ((ASN1_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Sequence_Type) {
alreadyExists = ((ASN1_Sequence_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Set_Type) {
alreadyExists = ((ASN1_Set_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
}
if (alreadyExists) {
result.addError(MessageFormat.format(FIELDALREADYEXISTS, newIdentifierName, rf.type.getTypename()));
}
}
return result;
}
Aggregations