@Test public void testOffsetInsideFacetWithValidPrefix() throws Exception { Couple couple = prepare( "app1", "edited1.graph", 70 ); couple.text += "\nfacet f {\n\texp"; List<RoboconfCompletionProposal> proposals = couple.proposer.findProposals( couple.text ); Assert.assertEquals( 1, proposals.size()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalName()); Assert.assertEquals( PROPERTY_GRAPH_EXPORTS + ": ", proposals.get( 0 ).getProposalString()); Assert.assertNull( proposals.get( 0 ).getProposalDescription()); Assert.assertEquals( 3, proposals.get( 0 ).getReplacementOffset()); }
@Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); switch( ctx.kind ) { case NEUTRAL: if( startsWith( IMPORT_PREFIX, ctx.property )) { if( ! ctx.property.matches( "(?i)" + KEYWORD_IMPORT + "\\s+" )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.property, true )); else for( String graphImport : CompletionUtils.findGraphFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( graphImport, ctx.lastWord )) proposals.add( basicProposal( graphImport, "", false )); } } if( ! Utils.isEmptyOrWhitespaces( ctx.lastWord )) break; ctx.property = ctx.property.trim(); if( startsWith( FACET_PREFIX, ctx.property )) { proposals.add( basicProposal( FACET_PREFIX, ctx.property, true )); String proposalString = FACET_PREFIX + "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, FACET_BLOCK, FACET_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 6, 4 )); proposals.add( proposal ); } if( Utils.isEmptyOrWhitespaces( ctx.property )) { String proposalString = "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, COMPONENT_BLOCK, COMPONENT_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 0, 4 )); proposals.add( proposal ); } break; case ATTRIBUTE: String[] arr = ctx.facet ? FACET_PROPERTY_NAMES : COMPONENT_PROPERTY_NAMES; for( String s : arr ) { s += ": "; if( startsWith( s, ctx.lastWord )) proposals.add( basicProposal( s, ctx.lastWord )); } break; case PROPERTY: ctx.property = ctx.property.trim(); Map<String,String> candidates = findPropertyCandidates( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; }
GraphsCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); switch( ctx.kind ) { case NEUTRAL: if( startsWith( IMPORT_PREFIX, ctx.property )) { if( ! ctx.property.matches( "(?i)" + KEYWORD_IMPORT + "\\s+" )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.property, true )); else for( String graphImport : CompletionUtils.findGraphFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( graphImport, ctx.lastWord )) proposals.add( basicProposal( graphImport, "", false )); } } if( ! Utils.isEmptyOrWhitespaces( ctx.lastWord )) break; ctx.property = ctx.property.trim(); if( startsWith( FACET_PREFIX, ctx.property )) { proposals.add( basicProposal( FACET_PREFIX, ctx.property, true )); String proposalString = FACET_PREFIX + "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, FACET_BLOCK, FACET_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 6, 4 )); proposals.add( proposal ); } if( Utils.isEmptyOrWhitespaces( ctx.property )) { String proposalString = "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, COMPONENT_BLOCK, COMPONENT_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 0, 4 )); proposals.add( proposal ); } break; case ATTRIBUTE: String[] arr = ctx.facet ? FACET_PROPERTY_NAMES : COMPONENT_PROPERTY_NAMES; for( String s : arr ) { s += ": "; if( startsWith( s, ctx.lastWord )) proposals.add( basicProposal( s, ctx.lastWord )); } break; case PROPERTY: ctx.property = ctx.property.trim(); Map<String,String> candidates = findPropertyCandidates( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } }
GraphsCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); switch( ctx.kind ) { case NEUTRAL: if( startsWith( IMPORT_PREFIX, ctx.property )) { if( ! ctx.property.matches( "(?i)" + KEYWORD_IMPORT + "\\s+" )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.property, true )); else for( String graphImport : CompletionUtils.findGraphFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( graphImport, ctx.lastWord )) proposals.add( basicProposal( graphImport, "", false )); } } if( ! Utils.isEmptyOrWhitespaces( ctx.lastWord )) break; ctx.property = ctx.property.trim(); if( startsWith( FACET_PREFIX, ctx.property )) { proposals.add( basicProposal( FACET_PREFIX, ctx.property, true )); String proposalString = FACET_PREFIX + "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, FACET_BLOCK, FACET_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 6, 4 )); proposals.add( proposal ); } if( Utils.isEmptyOrWhitespaces( ctx.property )) { String proposalString = "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, COMPONENT_BLOCK, COMPONENT_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 0, 4 )); proposals.add( proposal ); } break; case ATTRIBUTE: String[] arr = ctx.facet ? FACET_PROPERTY_NAMES : COMPONENT_PROPERTY_NAMES; for( String s : arr ) { s += ": "; if( startsWith( s, ctx.lastWord )) proposals.add( basicProposal( s, ctx.lastWord )); } break; case PROPERTY: ctx.property = ctx.property.trim(); Map<String,String> candidates = findPropertyCandidates( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } GraphsCompletionProposer( File appDirectory, File editedFile ); }
GraphsCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); switch( ctx.kind ) { case NEUTRAL: if( startsWith( IMPORT_PREFIX, ctx.property )) { if( ! ctx.property.matches( "(?i)" + KEYWORD_IMPORT + "\\s+" )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.property, true )); else for( String graphImport : CompletionUtils.findGraphFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( graphImport, ctx.lastWord )) proposals.add( basicProposal( graphImport, "", false )); } } if( ! Utils.isEmptyOrWhitespaces( ctx.lastWord )) break; ctx.property = ctx.property.trim(); if( startsWith( FACET_PREFIX, ctx.property )) { proposals.add( basicProposal( FACET_PREFIX, ctx.property, true )); String proposalString = FACET_PREFIX + "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, FACET_BLOCK, FACET_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 6, 4 )); proposals.add( proposal ); } if( Utils.isEmptyOrWhitespaces( ctx.property )) { String proposalString = "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, COMPONENT_BLOCK, COMPONENT_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 0, 4 )); proposals.add( proposal ); } break; case ATTRIBUTE: String[] arr = ctx.facet ? FACET_PROPERTY_NAMES : COMPONENT_PROPERTY_NAMES; for( String s : arr ) { s += ": "; if( startsWith( s, ctx.lastWord )) proposals.add( basicProposal( s, ctx.lastWord )); } break; case PROPERTY: ctx.property = ctx.property.trim(); Map<String,String> candidates = findPropertyCandidates( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } GraphsCompletionProposer( File appDirectory, File editedFile ); @Override List<RoboconfCompletionProposal> findProposals( String text ); }
GraphsCompletionProposer implements ICompletionProposer { @Override public List<RoboconfCompletionProposal> findProposals( String text ) { List<RoboconfCompletionProposal> proposals = new ArrayList<> (); Ctx ctx = findContext( text ); switch( ctx.kind ) { case NEUTRAL: if( startsWith( IMPORT_PREFIX, ctx.property )) { if( ! ctx.property.matches( "(?i)" + KEYWORD_IMPORT + "\\s+" )) proposals.add( basicProposal( IMPORT_PREFIX, ctx.property, true )); else for( String graphImport : CompletionUtils.findGraphFilesToImport( this.appDirectory, this.editedFile, text )) { if( startsWith( graphImport, ctx.lastWord )) proposals.add( basicProposal( graphImport, "", false )); } } if( ! Utils.isEmptyOrWhitespaces( ctx.lastWord )) break; ctx.property = ctx.property.trim(); if( startsWith( FACET_PREFIX, ctx.property )) { proposals.add( basicProposal( FACET_PREFIX, ctx.property, true )); String proposalString = FACET_PREFIX + "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, FACET_BLOCK, FACET_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 6, 4 )); proposals.add( proposal ); } if( Utils.isEmptyOrWhitespaces( ctx.property )) { String proposalString = "name {\n\t\n}"; RoboconfCompletionProposal proposal = new RoboconfCompletionProposal( proposalString, COMPONENT_BLOCK, COMPONENT_BLOCK + "\n\n" + proposalString.trim(), ctx.property.length()); proposal.getSelection().add( new SelectionRange( 0, 4 )); proposals.add( proposal ); } break; case ATTRIBUTE: String[] arr = ctx.facet ? FACET_PROPERTY_NAMES : COMPONENT_PROPERTY_NAMES; for( String s : arr ) { s += ": "; if( startsWith( s, ctx.lastWord )) proposals.add( basicProposal( s, ctx.lastWord )); } break; case PROPERTY: ctx.property = ctx.property.trim(); Map<String,String> candidates = findPropertyCandidates( ctx ); proposals.addAll( buildProposalsFromMap( candidates, ctx.lastWord )); break; default: break; } return proposals; } GraphsCompletionProposer( File appDirectory, File editedFile ); @Override List<RoboconfCompletionProposal> findProposals( String text );  }