Skip to content

Commit

Permalink
Issue #28: code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Karmakulov authored and Kirill Karmakulov committed Oct 16, 2014
1 parent 3cc25fc commit 4ad077b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,27 @@
*/
public class LanguageProposalHelpGenerator implements IProposalHelpGenerator {

private enum DefinitionType {
Keyword, Type
}
/**
* Possible kinds of YANG definitions
*/
public enum DefinitionKind {

private final String definition;
private final DefinitionType definitionType;
TYPE("types"), //$NON-NLS-1$
KEYWORD("keywords"); //$NON-NLS-1$

private LanguageProposalHelpGenerator(String definition, DefinitionType definitionType) {
super();
this.definition = definition;
this.definitionType = definitionType;
}
final String subdir;

/**
* @return an implementation of {@link IProposalHelpGenerator} that generates quick help for a
* YANG built-in type
*/
public static IProposalHelpGenerator type(String definition) {
return new LanguageProposalHelpGenerator(definition, DefinitionType.Type);
DefinitionKind(String subdir) {
this.subdir = subdir;
}
}

/**
* @return an implementation of {@link IProposalHelpGenerator} that generates quick help for a
* YANG language keyword.
*/
public static IProposalHelpGenerator keyword(String definition) {
return new LanguageProposalHelpGenerator(definition, DefinitionType.Keyword);
private final String definition;
private final IPath path;

public LanguageProposalHelpGenerator(String definition, DefinitionKind kind) {
this.definition = definition;
path = new Path("help").append(kind.subdir).append(definition).addFileExtension("txt"); //$NON-NLS-1$ //$NON-NLS-2$
}

/**
Expand All @@ -73,7 +67,7 @@ public String getAdditionalInfo(YangCompletionProposal proposal, IProgressMonito
// HTML that contains it.
URL url = null;
try {
url = FileLocator.find(YangEditorPlugin.getDefault().getBundle(), getPath(), null);
url = FileLocator.find(YangEditorPlugin.getDefault().getBundle(), path, null);
if (url == null) {
YangEditorPlugin.logWarning(NLS.bind("There's no help topic about \"{0}\".", definition), null); //$NON-NLS-1$
return null;
Expand All @@ -97,25 +91,4 @@ public String getAdditionalInfo(YangCompletionProposal proposal, IProgressMonito
}
return null;
}

/**
* Computes path to a file that contains help related to the definition.
*/
private IPath getPath() {
String subdir = ""; //$NON-NLS-1$
switch (definitionType) {
case Keyword:
subdir = "keywords"; //$NON-NLS-1$
break;

case Type:
subdir = "types"; //$NON-NLS-1$
break;

default:
break;
}
return new Path("help").append(subdir).append(definition).addFileExtension("txt"); //$NON-NLS-1$ //$NON-NLS-2$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
package com.cisco.yangide.editor.editors.text.help;

import static com.cisco.yangide.editor.editors.text.help.LanguageProposalHelpGenerator.DefinitionKind.KEYWORD;
import static com.cisco.yangide.editor.editors.text.help.LanguageProposalHelpGenerator.DefinitionKind.TYPE;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -588,7 +591,7 @@ private TypedProposalsList getKeywordScopeProposals(String prefix) {
String replacement = proposal + ' ';
proposalsList.add(new YangCompletionProposal(replacement, cursorPosition - prefix.length(), prefix
.length(), replacement.length(), YangUIImages.getImage(IYangUIConstants.IMG_KEYWORD_PROPOSAL),
proposal, LanguageProposalHelpGenerator.keyword(proposal)));
proposal, new LanguageProposalHelpGenerator(proposal, KEYWORD)));
}
}

Expand All @@ -607,7 +610,7 @@ private TypedProposalsList getTypeProposals(String prefix) {
if (proposal.startsWith(prefix)) {
bltInTypesProposals.add(new YangCompletionProposal(proposal, cursorPosition - prefix.length(), prefix
.length(), proposal.length(), YangUIImages.getImage(IYangUIConstants.IMG_TYPE_PROPOSAL),
proposal, LanguageProposalHelpGenerator.type(proposal)));
proposal, new LanguageProposalHelpGenerator(proposal, TYPE)));
}
}
Collections.sort(bltInTypesProposals, proposalComparator);
Expand Down

0 comments on commit 4ad077b

Please sign in to comment.