@Test public void testOffsetForRootComponentNameWithGraph() throws Exception { Couple couple = prepare( "app3", "initial.instances", 91 ); List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( "c2", proposals.get( 0 ).getProposalName()); Assert.assertEquals( "c2", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 0, proposals.get( 0 ).getReplacementOffset()); }
@Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); boolean addImport = true; switch( ctx.kind ) { case IMPORT: for( String instanceImport : CompletionUtils.findInstancesFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( instanceImport, ctx.lastWord )) proposals.add( basicProposal( instanceImport, "", false )); } break; case ATTRIBUTE: addImport = false; Map<String,String> candidates = findExportedVariableNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); case NEUTRAL: if( addImport && startsWith( IMPORT_PREFIX, ctx.lastWord )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.lastWord, true )); if( startsWith( INSTANCE_OF_PREFIX, ctx.lastWord )) { proposals.add( basicProposal( INSTANCE_OF_PREFIX, ctx.lastWord, true )); StringBuilder sb = new StringBuilder( INSTANCE_OF_PREFIX ); sb.append( "component" ); sb.append( " {\n\t" ); sb.append( ctx.parentIndentation ); sb.append( PROPERTY_INSTANCE_NAME ); sb.append( ": name;\n" ); sb.append( ctx.parentIndentation ); sb.append( "}" ); String proposalString = sb.toString(); SelectionRange sel1 = new SelectionRange( KEYWORD_INSTANCE_OF.length() + 1, COMPONENT_NAME.length()); SelectionRange sel2 = new SelectionRange( sel1.getOffset() + sel1.getLength() + PROPERTY_INSTANCE_NAME.length() + 6 + ctx.parentIndentation.length(), 4 ); RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, INSTANCE_OF_BLOCK, INSTANCE_OF_BLOCK + "\n\n" + proposalString.trim(), ctx.lastWord.length()); proposal.getSelection().add( sel1 ); proposal.getSelection().add( sel2 ); proposals.add( proposal ); } break; case COMPONENT_NAME: candidates = findComponentNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; }
InstancesCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); boolean addImport = true; switch( ctx.kind ) { case IMPORT: for( String instanceImport : CompletionUtils.findInstancesFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( instanceImport, ctx.lastWord )) proposals.add( basicProposal( instanceImport, "", false )); } break; case ATTRIBUTE: addImport = false; Map<String,String> candidates = findExportedVariableNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); case NEUTRAL: if( addImport && startsWith( IMPORT_PREFIX, ctx.lastWord )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.lastWord, true )); if( startsWith( INSTANCE_OF_PREFIX, ctx.lastWord )) { proposals.add( basicProposal( INSTANCE_OF_PREFIX, ctx.lastWord, true )); StringBuilder sb = new StringBuilder( INSTANCE_OF_PREFIX ); sb.append( "component" ); sb.append( " {\n\t" ); sb.append( ctx.parentIndentation ); sb.append( PROPERTY_INSTANCE_NAME ); sb.append( ": name;\n" ); sb.append( ctx.parentIndentation ); sb.append( "}" ); String proposalString = sb.toString(); SelectionRange sel1 = new SelectionRange( KEYWORD_INSTANCE_OF.length() + 1, COMPONENT_NAME.length()); SelectionRange sel2 = new SelectionRange( sel1.getOffset() + sel1.getLength() + PROPERTY_INSTANCE_NAME.length() + 6 + ctx.parentIndentation.length(), 4 ); RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, INSTANCE_OF_BLOCK, INSTANCE_OF_BLOCK + "\n\n" + proposalString.trim(), ctx.lastWord.length()); proposal.getSelection().add( sel1 ); proposal.getSelection().add( sel2 ); proposals.add( proposal ); } break; case COMPONENT_NAME: candidates = findComponentNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } }
InstancesCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); boolean addImport = true; switch( ctx.kind ) { case IMPORT: for( String instanceImport : CompletionUtils.findInstancesFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( instanceImport, ctx.lastWord )) proposals.add( basicProposal( instanceImport, "", false )); } break; case ATTRIBUTE: addImport = false; Map<String,String> candidates = findExportedVariableNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); case NEUTRAL: if( addImport && startsWith( IMPORT_PREFIX, ctx.lastWord )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.lastWord, true )); if( startsWith( INSTANCE_OF_PREFIX, ctx.lastWord )) { proposals.add( basicProposal( INSTANCE_OF_PREFIX, ctx.lastWord, true )); StringBuilder sb = new StringBuilder( INSTANCE_OF_PREFIX ); sb.append( "component" ); sb.append( " {\n\t" ); sb.append( ctx.parentIndentation ); sb.append( PROPERTY_INSTANCE_NAME ); sb.append( ": name;\n" ); sb.append( ctx.parentIndentation ); sb.append( "}" ); String proposalString = sb.toString(); SelectionRange sel1 = new SelectionRange( KEYWORD_INSTANCE_OF.length() + 1, COMPONENT_NAME.length()); SelectionRange sel2 = new SelectionRange( sel1.getOffset() + sel1.getLength() + PROPERTY_INSTANCE_NAME.length() + 6 + ctx.parentIndentation.length(), 4 ); RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, INSTANCE_OF_BLOCK, INSTANCE_OF_BLOCK + "\n\n" + proposalString.trim(), ctx.lastWord.length()); proposal.getSelection().add( sel1 ); proposal.getSelection().add( sel2 ); proposals.add( proposal ); } break; case COMPONENT_NAME: candidates = findComponentNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } InstancesCompletionProposer( File appDirectory, File editedFile ); }
InstancesCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); boolean addImport = true; switch( ctx.kind ) { case IMPORT: for( String instanceImport : CompletionUtils.findInstancesFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( instanceImport, ctx.lastWord )) proposals.add( basicProposal( instanceImport, "", false )); } break; case ATTRIBUTE: addImport = false; Map<String,String> candidates = findExportedVariableNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); case NEUTRAL: if( addImport && startsWith( IMPORT_PREFIX, ctx.lastWord )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.lastWord, true )); if( startsWith( INSTANCE_OF_PREFIX, ctx.lastWord )) { proposals.add( basicProposal( INSTANCE_OF_PREFIX, ctx.lastWord, true )); StringBuilder sb = new StringBuilder( INSTANCE_OF_PREFIX ); sb.append( "component" ); sb.append( " {\n\t" ); sb.append( ctx.parentIndentation ); sb.append( PROPERTY_INSTANCE_NAME ); sb.append( ": name;\n" ); sb.append( ctx.parentIndentation ); sb.append( "}" ); String proposalString = sb.toString(); SelectionRange sel1 = new SelectionRange( KEYWORD_INSTANCE_OF.length() + 1, COMPONENT_NAME.length()); SelectionRange sel2 = new SelectionRange( sel1.getOffset() + sel1.getLength() + PROPERTY_INSTANCE_NAME.length() + 6 + ctx.parentIndentation.length(), 4 ); RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, INSTANCE_OF_BLOCK, INSTANCE_OF_BLOCK + "\n\n" + proposalString.trim(), ctx.lastWord.length()); proposal.getSelection().add( sel1 ); proposal.getSelection().add( sel2 ); proposals.add( proposal ); } break; case COMPONENT_NAME: candidates = findComponentNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } InstancesCompletionProposer( File appDirectory, File editedFile ); String getErrorMsg(); @Override List<RoboconfCompletionProposal> findProposals( String text ); }
InstancesCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); boolean addImport = true; switch( ctx.kind ) { case IMPORT: for( String instanceImport : CompletionUtils.findInstancesFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( instanceImport, ctx.lastWord )) proposals.add( basicProposal( instanceImport, "", false )); } break; case ATTRIBUTE: addImport = false; Map<String,String> candidates = findExportedVariableNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); case NEUTRAL: if( addImport && startsWith( IMPORT_PREFIX, ctx.lastWord )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.lastWord, true )); if( startsWith( INSTANCE_OF_PREFIX, ctx.lastWord )) { proposals.add( basicProposal( INSTANCE_OF_PREFIX, ctx.lastWord, true )); StringBuilder sb = new StringBuilder( INSTANCE_OF_PREFIX ); sb.append( "component" ); sb.append( " {\n\t" ); sb.append( ctx.parentIndentation ); sb.append( PROPERTY_INSTANCE_NAME ); sb.append( ": name;\n" ); sb.append( ctx.parentIndentation ); sb.append( "}" ); String proposalString = sb.toString(); SelectionRange sel1 = new SelectionRange( KEYWORD_INSTANCE_OF.length() + 1, COMPONENT_NAME.length()); SelectionRange sel2 = new SelectionRange( sel1.getOffset() + sel1.getLength() + PROPERTY_INSTANCE_NAME.length() + 6 + ctx.parentIndentation.length(), 4 ); RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, INSTANCE_OF_BLOCK, INSTANCE_OF_BLOCK + "\n\n" + proposalString.trim(), ctx.lastWord.length()); proposal.getSelection().add( sel1 ); proposal.getSelection().add( sel2 ); proposals.add( proposal ); } break; case COMPONENT_NAME: candidates = findComponentNames( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } InstancesCompletionProposer( File appDirectory, File editedFile ); String getErrorMsg(); @Override List<RoboconfCompletionProposal> findProposals( String text );  }