Package: VdmNewCompletionExtractor

VdmNewCompletionExtractor

nameinstructionbranchcomplexitylinemethod
VdmNewCompletionExtractor()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
generateNewCompletionProposals(VdmCompletionContext, VdmDocument, List, int, List, TemplateContext, ITextViewer)
M: 40 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.overture.ide.ui.templates;
2:
3: import java.util.ArrayList;
4: import java.util.HashSet;
5: import java.util.List;
6: import java.util.Set;
7:
8: import org.eclipse.jface.text.ITextViewer;
9: import org.eclipse.jface.text.contentassist.ICompletionProposal;
10: import org.eclipse.jface.text.templates.TemplateContext;
11: import org.overture.ast.analysis.AnalysisException;
12: import org.overture.ast.analysis.DepthFirstAnalysisAdaptor;
13: import org.overture.ast.definitions.AClassClassDefinition;
14: import org.overture.ast.definitions.AExplicitOperationDefinition;
15: import org.overture.ast.definitions.PDefinition;
16: import org.overture.ast.node.INode;
17: import org.overture.ast.types.PType;
18: import org.overture.ide.ui.VdmUIPlugin;
19: import org.overture.ide.ui.editor.core.VdmDocument;
20:
21: public final class VdmNewCompletionExtractor {
22:         
23:         private static VdmCompletionHelper VdmHelper = new VdmCompletionHelper();
24:         private static VdmOperationCompletionExtractor VdmOperationHelper = new VdmOperationCompletionExtractor();
25:
26:         private ArrayList<String> dynamicTemplateProposals = new ArrayList<String>();
27:
28:         public void generateNewCompletionProposals(final VdmCompletionContext info,
29:                         VdmDocument document, final List<ICompletionProposal> proposals,
30:                         final int offset, List<INode> Ast, final TemplateContext context,final ITextViewer viewer)
31:         {
32:•                for (final INode element : Ast)
33:                 {
34:                         try
35:                         {
36:                                 element.apply(new DepthFirstAnalysisAdaptor()
37:                                 {                
38:                                         @Override
39:                                         public void caseAExplicitOperationDefinition(AExplicitOperationDefinition node)
40: throws AnalysisException{
41:                                                 String extractedName[] = VdmOperationHelper.explicitOperationNameExtractor(node);
42:                                                 PType classType = node.getClassDefinition().getClasstype();
43:                                                 if(classType != null){
44:                                                         String className = classType.toString();
45:                                                         String operationName = node.getName().toString();
46:                                                         operationName = operationName.split("\\(")[0];
47:                                                 
48:                                                         if(className.equals(operationName) && VdmHelper.nullOrEmptyCheck(extractedName[1])){
49:                                                                 extractedName[0] = "new " + extractedName[0];
50:                                                                 extractedName[1] = "new " + extractedName[1];
51:                                                                 if(!VdmHelper.checkForDuplicates(extractedName[1],dynamicTemplateProposals)){
52:                                                                         VdmHelper.dynamicTemplateCreator(extractedName,"New",offset,context,proposals,info,viewer,node.getLocation().getEndOffset());
53:                                                                         dynamicTemplateProposals.add(extractedName[1]);
54:                                                                 }
55:                                                         }
56:                                                 }        
57:                                         }
58:                                         
59:                                         Set<INode> visitedNodes = new HashSet<>();
60:                                         
61:                                         @Override
62:                                         public void caseAClassClassDefinition(AClassClassDefinition node) throws AnalysisException {
63:                                                 if(visitedNodes.contains(node)){ return;        }                                                
64:                                                 visitedNodes.add(node);
65:                                                 
66:                                                 if (!noOperationsExist(node)) {
67:                                                         for (PDefinition def : node.getDefinitions()) {
68:                                                                 def.apply(THIS);
69:                                                         }
70:                                                 }
71:                                                 
72:                                                 // Corner case for the default constructor proposals
73:                                                 PType classType = node.getClasstype();
74:                                                 String className = classType.toString();
75:                                                 String extractedNamesDefaultCtor = (String) ("new " + className + "()");
76:                                                 if (!VdmHelper.checkForDuplicates(extractedNamesDefaultCtor, dynamicTemplateProposals)) {
77:                                                         VdmHelper.createProposal(null, extractedNamesDefaultCtor, extractedNamesDefaultCtor,
78:                                                                         "Default constructor", info, proposals, offset);
79:                                                         dynamicTemplateProposals.add(extractedNamesDefaultCtor);
80:                                                 }
81:                                         }                                        
82:
83:                                         private boolean noOperationsExist(AClassClassDefinition node) {
84:                                                 for(PDefinition def : node.getDefinitions()){
85:                                                         if(def.getClass() == AExplicitOperationDefinition.class){
86:                                                                 return false;
87:                                                         }
88:                                                 }
89:                                                 return true;
90:                                         }
91:                                 });
92:                         } catch (AnalysisException e)
93:                         {
94:                                 e.printStackTrace();
95:                                 VdmUIPlugin.log("Completion error in " + getClass().getSimpleName()
96:                                                 + "faild during populateNameList New", e);
97:                         }
98:                 }
99:         }
100: }