Skip to content

Pull request for Issue14 #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2013 Nitor Creations Oy
* Copyright 2012-2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,12 +39,17 @@ public CompletionMatchVisitor(IFile file, String userInput, List<RobotCompletion
}

protected void addProposal(String proposal, FileWithType proposalLocation) {
addProposal(proposal, proposalLocation, "");
}

protected void addProposal(String proposal, FileWithType proposalLocation, String contextInformation) {
Image image = null;
String displayString = getDisplayString(proposal, proposalLocation);
String replacementString = proposal;
String additionalProposalInfo = "I recommend: " + replacementString;
String additionalProposalInfo = "I recommend: " + replacementString + contextInformation;
String informationDisplayString = "You chose: " + replacementString;
proposals.add(new RobotCompletionProposal(proposal, proposalLocation, replacementRegion, image, displayString, informationDisplayString, additionalProposalInfo));
addedProposals.add(proposal.toLowerCase());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2013 Nitor Creations Oy
* Copyright 2012-2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,13 +34,18 @@ public KeywordCompletionMatchVisitor(IFile file, String argument, List<RobotComp

@Override
public VisitorInterest visitMatch(ParsedString match, FileWithType matchLocation) {
return visitMatch(match, matchLocation, "");
}

@Override
public VisitorInterest visitMatch(ParsedString match, FileWithType matchLocation, String context) {
if (userInput == null) {
addProposal(match.getValue(), matchLocation);
addProposal(match.getValue(), matchLocation, context);
} else {
String userInputStringLower = userInput.toLowerCase();
String matchStringLower = match.getValue().toLowerCase();
if (matchStringLower.contains(userInputStringLower) || matchesWithoutPrefix(userInputStringLower, matchStringLower, matchLocation)) {
addProposal(match.getValue(), matchLocation);
addProposal(match.getValue(), matchLocation, context);
}
// if (KeywordMatchResult.DIFFERENT == match(matchStringLower, lookFor(userInputStringLower))) {
// if (!prefixesMatch(userInputStringLower, matchLocation)) {
Expand All @@ -57,10 +62,10 @@ public VisitorInterest visitMatch(ParsedString match, FileWithType matchLocation
}

@Override
protected void addProposal(String proposal, FileWithType proposalLocation) {
protected void addProposal(String proposal, FileWithType proposalLocation, String context) {
String proposalStringLower = proposal.toLowerCase();
boolean proposalExisted = addedProposals.contains(proposalStringLower);
super.addProposal(proposal, proposalLocation);
super.addProposal(proposal, proposalLocation, context);
if (proposalExisted) {
for (RobotCompletionProposal robotCompletionProposal : proposals) {
setPrefixRequiredIfNeeded(proposalStringLower, robotCompletionProposal);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2013 Nitor Creations Oy
* Copyright 2013-2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -133,6 +133,11 @@ public VisitorInterest visitMatch(RobotLine line, FileWithType lineLocation) {
return VisitorInterest.CONTINUE;
}

@Override
public VisitorInterest visitMatch(RobotLine line, FileWithType lineLocation, String keywordContext) {
return visitMatch(line, lineLocation);
}

private ParsedString lastDefinedTestcaseOrKeyword;
private ParsedString lastDefinedSetting;

Expand Down Expand Up @@ -190,6 +195,7 @@ public boolean wantsLibraryVariables() {
public boolean wantsLibraryKeywords() {
return true;
}

});
definedKeywords.remove(assumeThisKeywordIsUndefined.getValue());
if (!definedKeywords.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2013 Nitor Creations Oy
* Copyright 2012-2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,7 +75,31 @@ private String getReplacementString() {
if (prefixRequired) {
return matchLocation.getName() + "." + matchArgument;
}
return matchArgument;
String arguments = getArgumentString();
return matchArgument + arguments;
}

private String getArgumentString() {
String argumentString = "";
if (additionalProposalInfo.contains("[Arguments]")) {
int start = additionalProposalInfo.indexOf("[Arguments]");
String tempParse = additionalProposalInfo.substring(start + new String("[Arguments]").length());
start = tempParse.indexOf("[Documentation]");
if (start == -1) { // substring doesn't contain Documentation, Arguments go right to the end
argumentString = tempParse;
} else { // substring contains Documentation, we strip it out
argumentString = tempParse.substring(0, start);
}
argumentString = argumentString.trim();
String tempSubstring = "";
String[] arguments = argumentString.split(" ");
for (int i = 0; i < arguments.length; i++) {
tempSubstring = tempSubstring + " ";
tempSubstring = tempSubstring + arguments[i];
}
argumentString = tempSubstring;
}
return argumentString;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2013 Nitor Creations Oy
* Copyright 2012-2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,11 @@ public VariableCompletionMatchVisitor(IFile file, String userInput, List<RobotCo
this.maxSettingCharPos = maxSettingCharPos;
}

@Override
public VisitorInterest visitMatch(ParsedString match, FileWithType matchLocation, String context) {
return visitMatch(match, matchLocation);
}

@Override
public VisitorInterest visitMatch(ParsedString match, FileWithType matchLocation) {
if (match.getArgCharPos() > maxVariableCharPos) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2013 Nitor Creations Oy
* Copyright 2012-2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,6 +71,11 @@ public VisitorInterest visitMatch(ParsedString match, FileWithType location) {
return VisitorInterest.CONTINUE;
}

@Override
public VisitorInterest visitMatch(ParsedString match, FileWithType location, String context) {
return visitMatch(match, location);
}

private String getMatchStringInFile(FileWithType location, String linkString) {
String filePrefix = location.getName() + ".";
if (linkString.startsWith(filePrefix)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2013 Nitor Creations Oy
* Copyright 2012-2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,6 +66,11 @@ public VisitorInterest visitMatch(ParsedString match, FileWithType location) {
return VisitorInterest.CONTINUE;
}

@Override
public VisitorInterest visitMatch(ParsedString match, FileWithType location, String context) {
return visitMatch(match, location);
}

@Override
public LineType getWantedLineType() {
return LineType.VARIABLE_TABLE_LINE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012 Nitor Creations Oy
* Copyright 2012, 2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,9 +33,14 @@ private static class LineMatchVisitorAdapter implements LineMatchVisitor {
this.delegate = delegate;
}

@Override
public VisitorInterest visitMatch(RobotLine line, FileWithType lineLocation, String context) {
return delegate.visitMatch(line.arguments.get(0), lineLocation, context);
}

@Override
public VisitorInterest visitMatch(RobotLine line, FileWithType lineLocation) {
return delegate.visitMatch(line.arguments.get(0), lineLocation);
return delegate.visitMatch(line.arguments.get(0), lineLocation, "");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2013 Nitor Creations Oy
* Copyright 2012-2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,13 +28,16 @@ public interface DefinitionMatchVisitor {
* the match
* @param matchLocation
* where match is located - null if the match is located in a variable file or a library
* @param context
*/
VisitorInterest visitMatch(ParsedString match, FileWithType matchLocation);
VisitorInterest visitMatch(ParsedString match, FileWithType matchLocation, String context);

LineType getWantedLineType();

/**
* @return true if {@link DefinitionFinder} should descend into the given import, false if not
*/
boolean visitImport(IFile currentFile, RobotLine line);

VisitorInterest visitMatch(ParsedString match, FileWithType matchLocation);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2013 Nitor Creations Oy
* Copyright 2012-2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -108,7 +109,77 @@ private static VisitorInterest acceptResourceFile(FileWithType currentFileWithTy
VisitorInterest interest = CONTINUE;
for (RobotLine line : lines) {
if (visitor.getWantedLineTypes().contains(line.type)) {
interest = visitor.visitMatch(line, currentFileWithType);
// Visit the next few lines to build the context of the keyword
String keywordContext = "";
// Flag for continuing 0 is no context, 1 is Arguments, 2 is Documentation
int contextCont = 0;
// If the Arguments are part of the line
if (line.arguments.size() > 1) {
if (line.arguments.get(1).getValue().equals("[Arguments]")) {
keywordContext = keywordContext + "<br>";
for (int i = 1; i < line.arguments.size(); i++) {
keywordContext = keywordContext + " " + line.arguments.get(i).getValue();
}
}
}
for (ListIterator<RobotLine> iter = lines.listIterator(lines.indexOf(line) + 1); iter.hasNext();) {
RobotLine contextLine = iter.next();
if (contextLine.arguments.size() <= 1) {
break;
}
if (contextCont == 0) {
if ((contextLine.arguments.get(1).getValue().equals("[Arguments]")) || (contextLine.arguments.get(1).getValue().equals("[Documentation]"))) {
keywordContext = keywordContext + "<br>";
for (int i = 1; i < contextLine.arguments.size(); i++) {
keywordContext = keywordContext + " " + contextLine.arguments.get(i).getValue();
}
if (contextLine.arguments.get(0).getValue().equals("[Arguments]")) {
contextCont = 1;
} else {
contextCont = 2;
}
} else if (contextLine.arguments.get(1).getType().name().equals("COMMENT")) {
// Do nothing if it's a comment
} else {
break;
}
} else if (contextCont == 1) {
if (contextLine.arguments.get(1).getValue().equals("[Documentation]")) {
keywordContext = keywordContext + "<br>";
for (int i = 1; i < contextLine.arguments.size(); i++) {
keywordContext = keywordContext + " " + contextLine.arguments.get(i).getValue();
}
contextCont = 0;
break;
} else if (contextLine.arguments.get(1).getValue().equals("...")) {
for (int i = 2; i < contextLine.arguments.size(); i++) {
keywordContext = keywordContext + " " + contextLine.arguments.get(i).getValue();
}
} else if (contextLine.arguments.get(1).getType().equals("COMMENT")) {
// Do nothing if it's a comment
} else {
contextCont = 0;
}
} else if (contextCont == 2) {
if (contextLine.arguments.get(1).getValue().equals("[Arguments]")) {
keywordContext = keywordContext + "<br>";
for (int i = 1; i < contextLine.arguments.size(); i++) {
keywordContext = keywordContext + " " + contextLine.arguments.get(i).getValue();
}
contextCont = 0;
break;
} else if (contextLine.arguments.get(1).getValue().equals("...")) {
for (int i = 2; i < contextLine.arguments.size(); i++) {
keywordContext = keywordContext + " " + contextLine.arguments.get(i).getValue();
}
} else if (contextLine.arguments.get(1).getType().equals("COMMENT")) {
// Do nothing if it's a comment
} else {
contextCont = 0;
}
}
}
interest = visitor.visitMatch(line, currentFileWithType, keywordContext);
if (interest == STOP) {
return STOP;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012 Nitor Creations Oy
* Copyright 2012, 2014 Nitor Creations Oy, Dreamhunters-net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,8 +29,11 @@ public interface LineMatchVisitor {
* the line
* @param lineLocation
* where line is located - null if the proposal is located in a variable file or a library
* @param keywordContext
*/
VisitorInterest visitMatch(RobotLine line, FileWithType lineLocation);
VisitorInterest visitMatch(RobotLine line, FileWithType lineLocation, String keywordContext);

VisitorInterest visitMatch(RobotLine line, FileWithType fileWithType);

Set<LineType> getWantedLineTypes();

Expand All @@ -42,4 +45,5 @@ public interface LineMatchVisitor {
* @return true if {@link DefinitionFinder} should descend into the given import, false if not
*/
boolean visitImport(IFile currentFile, RobotLine line);

}