From c9d63ad2fe4690ee0e9b36f50dbadb58f4cf9bef Mon Sep 17 00:00:00 2001 From: Craxy Date: Mon, 1 Oct 2018 17:55:46 +0200 Subject: [PATCH] Improved code style mostly added brackets to if-statements and for-loops renamed variables in ClientProxy to lowercase to fit the java conventions --- .../com/microsoft/javapkgsrv/ClientProxy.java | 46 +- .../javapkgsrv/JavaParamHelpMatcher.java | 538 ++++++------- .../com/microsoft/javapkgsrv/JavaParser.java | 741 +++++++++--------- .../src/com/microsoft/javapkgsrv/Start.java | 56 +- 4 files changed, 684 insertions(+), 697 deletions(-) diff --git a/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/ClientProxy.java b/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/ClientProxy.java index 931d3c6..655b308 100644 --- a/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/ClientProxy.java +++ b/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/ClientProxy.java @@ -30,27 +30,27 @@ import com.microsoft.javapkgsrv.Protocol.TypeRootIdentifier; public class ClientProxy { - private PipeChannel Pipe = null; - private JavaParser Parser = new JavaParser(); + private PipeChannel pipe = null; + private JavaParser parser = new JavaParser(); public ClientProxy() { - Pipe = new PipeChannel(); + pipe = new PipeChannel(); } public ClientProxy(String pipeName) { - Pipe = new PipeChannel(pipeName); + pipe = new PipeChannel(pipeName); } public void Run() throws IOException, JavaModelException { - Pipe.Init(); - Parser.Init(); + pipe.Init(); + parser.Init(); while (true) { try { - Protocol.Request request = Pipe.ReadMessage(); + Protocol.Request request = pipe.ReadMessage(); Protocol.Response response = ProcessRequest(request); - Pipe.WriteMessage(response); + pipe.WriteMessage(response); if (request.getRequestType().equals(RequestType.Bye)) break; // return to allow the process to exit @@ -69,7 +69,7 @@ private Protocol.Response ProcessRequest(Protocol.Request request) try { System.out.print("Parsing " + request.getFileParseRequest().getFileName()); - Integer result = Parser.ProcessParseRequest( + Integer result = parser.ProcessParseRequest( request.getFileParseRequest().getFileParseContents(), request.getFileParseRequest().getFileName()); System.out.println(" id = " + result.toString()); @@ -100,7 +100,7 @@ else if (request.getRequestType().equals(RequestType.DisposeFile)) { Integer fileId = request.getDisposeFileRequest().getFileIdentifier().getId(); System.out.println("Remove AST for id = " + fileId); - Parser.ProcessDisposeFileRequest(fileId); + parser.ProcessDisposeFileRequest(fileId); return Protocol.Response.newBuilder() .setResponseType(ResponseType.DisposeFile) @@ -110,7 +110,7 @@ else if (request.getRequestType().equals(RequestType.OutlineFile)) { Integer fileId = request.getOutlineFileRequest().getFileIdentifier().getId(); System.out.println("Creating outline for id = " + fileId); - List outline = Parser.ProcessOutlineRequest(fileId); + List outline = parser.ProcessOutlineRequest(fileId); return Protocol.Response.newBuilder() .setResponseType(ResponseType.OutlineResults) @@ -123,7 +123,7 @@ else if (request.getRequestType().equals(RequestType.FileParseMessages)) { Integer fileId = request.getFileParseMessagesRequest().getFileIdentifier().getId(); System.out.println("Sending squiggles for id = " + fileId); - List problems = Parser.ProcessFileParseMessagesRequest(fileId); + List problems = parser.ProcessFileParseMessagesRequest(fileId); return Protocol.Response.newBuilder() .setResponseType(ResponseType.FileParseMessages) @@ -137,7 +137,7 @@ else if (request.getRequestType().equals(RequestType.Autocomplete)) try { System.out.println("Autocomplete request for " + request.getAutocompleteRequest().getTypeRootIdentifier().getHandle()); - List proposals = Parser.ProcessAutocompleteRequest( + List proposals = parser.ProcessAutocompleteRequest( request.getAutocompleteRequest().getFileParseContents(), request.getAutocompleteRequest().getTypeRootIdentifier().getHandle(), request.getAutocompleteRequest().getCursorPosition()); @@ -167,10 +167,10 @@ else if (request.getRequestType().equals(RequestType.ParamHelp)) try { System.out.println("ParamHelp request for " + request.getParamHelpRequest().getTypeRootIdentifier().getHandle()); - JavaParamHelpMatcher.ParamRegion region = Parser.getScope( + JavaParamHelpMatcher.ParamRegion region = parser.getScope( request.getParamHelpRequest().getFileParseContents(), request.getParamHelpRequest().getCursorPosition()); - List signatures = Parser.ProcessParamHelpRequest( + List signatures = parser.ProcessParamHelpRequest( request.getParamHelpRequest().getFileParseContents(), request.getParamHelpRequest().getTypeRootIdentifier().getHandle(), region.region.getOffset() + 1); // Request Autocomplete right after the open brace @@ -203,7 +203,7 @@ else if (request.getRequestType().equals(RequestType.ParamHelpPositionUpdate)) try { System.out.println("ParamHelp PositionUpdate request for " + request.getParamHelpPositionUpdateRequest().getFileParseContents()); - JavaParamHelpMatcher.ParamRegion region = Parser.updateScope( + JavaParamHelpMatcher.ParamRegion region = parser.updateScope( request.getParamHelpPositionUpdateRequest().getFileParseContents(), request.getParamHelpPositionUpdateRequest().getCursorPosition()); if (region == null) @@ -233,7 +233,7 @@ else if (request.getRequestType().equals(RequestType.QuickInfo)) try { System.out.println("QuickInfo request for " + request.getQuickInfoRequest().getTypeRootIdentifier().getHandle()); - List elements = Parser.ProcessQuickInfoRequest( + List elements = parser.ProcessQuickInfoRequest( request.getQuickInfoRequest().getFileParseContents(), request.getQuickInfoRequest().getTypeRootIdentifier().getHandle(), request.getQuickInfoRequest().getCursorPosition()); @@ -260,7 +260,7 @@ else if (request.getRequestType().equals(RequestType.FindDefinition)) try { System.out.println("FindDefinition request for " + request.getFindDefinitionRequest().getTypeRootIdentifier().getHandle()); - List elements = Parser.ProcessFindDefinintionRequest( + List elements = parser.ProcessFindDefinintionRequest( request.getFindDefinitionRequest().getFileParseContents(), request.getFindDefinitionRequest().getTypeRootIdentifier().getHandle(), request.getFindDefinitionRequest().getCursorPosition()); @@ -269,7 +269,7 @@ else if (request.getRequestType().equals(RequestType.FindDefinition)) .setResponseType(ResponseType.FindDefinition) .setFindDefinitionResponse(FindDefinitionResponse.newBuilder() .setStatus(true) - .setWorkspaceRootPath(Parser.WorkspaceRoot.getLocation().toString()) + .setWorkspaceRootPath(parser.WorkspaceRoot.getLocation().toString()) .addAllElements(elements) .build()) .build(); @@ -281,7 +281,7 @@ else if (request.getRequestType().equals(RequestType.FindDefinition)) .setResponseType(ResponseType.FindDefinition) .setFindDefinitionResponse(FindDefinitionResponse.newBuilder() .setStatus(false) - .setWorkspaceRootPath(Parser.WorkspaceRoot.getLocation().toString()) + .setWorkspaceRootPath(parser.WorkspaceRoot.getLocation().toString()) .setErrorMessage(e.getMessage() != null ? e.getMessage() : e.toString()) .build()) .build(); @@ -292,7 +292,7 @@ else if (request.getRequestType().equals(RequestType.OpenTypeRoot)) try { System.out.println("OpenTypeRoot request for " + request.getOpenTypeRootRequest().getFileName()); - String typeRootHandle = Parser.ProcessOpenTypeRequest(request.getOpenTypeRootRequest().getFileName()); + String typeRootHandle = parser.ProcessOpenTypeRequest(request.getOpenTypeRootRequest().getFileName()); return Protocol.Response.newBuilder() .setResponseType(ResponseType.OpenTypeRoot) @@ -320,7 +320,7 @@ else if (request.getRequestType().equals(RequestType.DisposeTypeRoot)) { String handle = request.getDisposeTypeRootRequest().getTypeRootIdentifier().getHandle(); System.out.println("Remove typeroot for handle = " + handle); - Parser.ProcessDisposeTypeRoot(handle); + parser.ProcessDisposeTypeRoot(handle); return Protocol.Response.newBuilder() .setResponseType(ResponseType.DisposeTypeRoot) @@ -331,7 +331,7 @@ else if (request.getRequestType().equals(RequestType.AddTypeRoot)) try { System.out.println("AddTypeRoot request for " + request.getAddTypeRootRequest().getTypeRootIdentifier().getHandle()); - String typeRootHandle = Parser.ProcessAddTypeRequest(request.getAddTypeRootRequest().getTypeRootIdentifier().getHandle()); + String typeRootHandle = parser.ProcessAddTypeRequest(request.getAddTypeRootRequest().getTypeRootIdentifier().getHandle()); return Protocol.Response.newBuilder() .setResponseType(ResponseType.AddTypeRoot) diff --git a/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/JavaParamHelpMatcher.java b/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/JavaParamHelpMatcher.java index d824790..a4671d3 100644 --- a/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/JavaParamHelpMatcher.java +++ b/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/JavaParamHelpMatcher.java @@ -9,267 +9,279 @@ import org.eclipse.jface.text.Region; @SuppressWarnings("deprecation") -public class JavaParamHelpMatcher -{ - private class CharPairs { - - private final char[] fPairs; - - public CharPairs(char[] pairs) { - fPairs= pairs; - } - - /** - * Returns true if the specified character occurs in one of the character pairs. - * - * @param c a character - * @return true exactly if the character occurs in one of the pairs - */ - public boolean contains(char c) { - char[] pairs= fPairs; - for (int i= 0, n= pairs.length; i < n; i++) { - if (c == pairs[i]) - return true; - } - return false; - } - - /** - * Returns true if the specified character opens a character pair - * when scanning in the specified direction. - * - * @param c a character - * @param searchForward the direction of the search - * @return whether or not the character opens a character pair - */ - public boolean isOpeningCharacter(char c, boolean searchForward) { - for (int i= 0; i < fPairs.length; i += 2) { - if (searchForward && getStartChar(i) == c) return true; - else if (!searchForward && getEndChar(i) == c) return true; - } - return false; - } - - /** - * Returns true if the specified character is a start character. - * - * @param c a character - * @return true exactly if the character is a start character - */ - public boolean isStartCharacter(char c) { - return this.isOpeningCharacter(c, true); - } - - /** - * Returns true if the specified character is an end character. - * - * @param c a character - * @return true exactly if the character is an end character - * @since 3.8 - */ - public boolean isEndCharacter(char c) { - return this.isOpeningCharacter(c, false); - } - - /** - * Returns the matching character for the specified character. - * - * @param c a character occurring in a character pair - * @return the matching character - */ - public char getMatching(char c) { - for (int i= 0; i < fPairs.length; i += 2) { - if (getStartChar(i) == c) return getEndChar(i); - else if (getEndChar(i) == c) return getStartChar(i); - } - Assert.isTrue(false); - return '\0'; - } - - private char getStartChar(int i) { - return fPairs[i]; - } - - private char getEndChar(int i) { - return fPairs[i + 1]; - } - - } - private CharPairs fPairs; - private char[] fSeparators; - private boolean isSeparator(char c) { - for (int i= 0, n= fSeparators.length; i < n; i++) { - if (c == fSeparators[i]) - return true; - } - return false; - } - public JavaParamHelpMatcher(char[] chars, char[] separators) - { - fPairs= new CharPairs(chars); - fSeparators = separators; - } - private class DocumentAccessor - { - private IDocument fDocument; - public DocumentAccessor(IDocument document) { fDocument = document; } - public char getChar(int pos) throws BadLocationException - { - return fDocument.getChar(pos); - } - public int getNextPosition(int currentPos, boolean searchForward) - { - return currentPos + (searchForward ? 1 : -1); - } - public boolean inPartition(int pos) - { - return true; - } - } - public class ParamRegion - { - public IRegion region = null; - public int paramSeparatorCount = 0; - } - public ParamRegion findEnclosingPeerCharacters(IDocument document, int offset, int length) - { - if (document == null || offset < 0 || offset > document.getLength()) - return null; - try - { - DocumentAccessor doc = new DocumentAccessor(document); - return findEnclosingPeers(document, doc, offset, length, 0, document.getLength()); - } - catch(BadLocationException ble) - { - return null; - } - } - private ParamRegion findEnclosingPeers(IDocument document, DocumentAccessor doc, int offset, int length, int lowerBoundary, int upperBoundary) throws BadLocationException - { - char[] pairs= fPairs.fPairs; - /* Special ParamHelp added here */ - int cSeparators = 0; - /* Special ParamHelp end here */ - - int start; - int end; - if (length >= 0) { - start= offset; - end= offset + length; - } else { - end= offset; - start= offset + length; - } - - boolean lowerFound= false; - boolean upperFound= false; - int[][] counts= new int[pairs.length][2]; - char currChar= (start != document.getLength()) ? doc.getChar(start) : Character.MIN_VALUE; - int pos1; - int pos2; - if (fPairs.isEndCharacter(currChar)) { - pos1= doc.getNextPosition(start, false); - pos2= start; - } - /* Special ParamHelp added here */ - else if (isSeparator(currChar)) - { - pos1 = doc.getNextPosition(start, false); - pos2 = doc.getNextPosition(start, true); - } - /* Special ParamHelp end here */ - else { - pos1= start; - pos2= doc.getNextPosition(start, true); - } - - while ((pos1 >= lowerBoundary && !lowerFound) || (pos2 < upperBoundary && !upperFound)) { - for (int i= 0; i < counts.length; i++) { - counts[i][0]= counts[i][1]= 0; - } - - outer1: while (pos1 >= lowerBoundary && !lowerFound) { - final char c= doc.getChar(pos1); - int i= getCharacterIndex(c, document, pos1); - if (i != -1 && doc.inPartition(pos1)) { - if (i % 2 == 0) { - counts[i / 2][0]--; //start - } else { - counts[i / 2][0]++; //end - } - for (int j= 0; j < counts.length; j++) { - if (counts[j][0] == -1) { - lowerFound= true; - break outer1; - } - } - } - /* Special ParamHelp added here */ - else if (isSeparator(c)) - { - boolean nestedSeparator = false; - for (int j= 0; j < counts.length; j++) { - if (counts[j][0] != 0) { - nestedSeparator = true; - } - } - if (!nestedSeparator) - cSeparators++; - - } - /* Special ParamHelp end here */ - pos1= doc.getNextPosition(pos1, false); - } - - outer2: while (pos2 < upperBoundary && !upperFound) { - final char c= doc.getChar(pos2); - int i= getCharacterIndex(c, document, pos2); - if (i != -1 && doc.inPartition(pos2)) { - if (i % 2 == 0) { - counts[i / 2][1]++; //start - } else { - counts[i / 2][1]--; //end - } - for (int j= 0; j < counts.length; j++) { - if (counts[j][1] == -1 && counts[j][0] == -1) { - upperFound= true; - break outer2; - } - } - } - pos2= doc.getNextPosition(pos2, true); - } - - if (pos1 > start || pos2 < end - 1) { - //match inside selection => discard - pos1= doc.getNextPosition(pos1, false); - pos2= doc.getNextPosition(pos2, true); - lowerFound= false; - upperFound= false; - } - } - pos2++; - if (pos1 < lowerBoundary || pos2 > upperBoundary) - return null; - ParamRegion ret = new ParamRegion(); - ret.region = new Region(pos1, pos2 - pos1); - ret.paramSeparatorCount = cSeparators; - return ret; - } - private int getCharacterIndex(char ch, IDocument document, int offset) { - char[] pairs= fPairs.fPairs; - for (int i= 0; i < pairs.length; i++) { - if (pairs[i] == ch && isMatchedChar(ch, document, offset)) { - return i; - } - } - return -1; - } - public boolean isMatchedChar(char ch, IDocument document, int offset) { - return isMatchedChar(ch); - } - public boolean isMatchedChar(char ch) { - return fPairs.contains(ch); - } +public class JavaParamHelpMatcher { + private class CharPairs { + + private final char[] fPairs; + + public CharPairs(char[] pairs) { + fPairs = pairs; + } + + /** + * Returns true if the specified character occurs in one of the character pairs. + * + * @param c a character + * @return true exactly if the character occurs in one of the pairs + */ + public boolean contains(char c) { + char[] pairs = fPairs; + for (int i = 0, n = pairs.length; i < n; i++) { + if (c == pairs[i]) { + return true; + } + } + return false; + } + + /** + * Returns true if the specified character opens a character pair + * when scanning in the specified direction. + * + * @param c a character + * @param searchForward the direction of the search + * @return whether or not the character opens a character pair + */ + public boolean isOpeningCharacter(char c, boolean searchForward) { + for (int i = 0; i < fPairs.length; i += 2) { + if (searchForward && getStartChar(i) == c) { + return true; + } else if (!searchForward && getEndChar(i) == c) { + return true; + } + } + return false; + } + + /** + * Returns true if the specified character is a start character. + * + * @param c a character + * @return true exactly if the character is a start character + */ + public boolean isStartCharacter(char c) { + return this.isOpeningCharacter(c, true); + } + + /** + * Returns true if the specified character is an end character. + * + * @param c a character + * @return true exactly if the character is an end character + * @since 3.8 + */ + public boolean isEndCharacter(char c) { + return this.isOpeningCharacter(c, false); + } + + /** + * Returns the matching character for the specified character. + * + * @param c a character occurring in a character pair + * @return the matching character + */ + public char getMatching(char c) { + for (int i = 0; i < fPairs.length; i += 2) { + if (getStartChar(i) == c) { + return getEndChar(i); + } else if (getEndChar(i) == c) { + return getStartChar(i); + } + } + Assert.isTrue(false); + return '\0'; + } + + private char getStartChar(int i) { + return fPairs[i]; + } + + private char getEndChar(int i) { + return fPairs[i + 1]; + } + + } + + private CharPairs fPairs; + private char[] fSeparators; + + private boolean isSeparator(char c) { + for (int i = 0, n = fSeparators.length; i < n; i++) { + if (c == fSeparators[i]) { + return true; + } + } + return false; + } + + public JavaParamHelpMatcher(char[] chars, char[] separators) { + fPairs = new CharPairs(chars); + fSeparators = separators; + } + + private class DocumentAccessor { + private IDocument fDocument; + + public DocumentAccessor(IDocument document) { + fDocument = document; + } + + public char getChar(int pos) throws BadLocationException { + return fDocument.getChar(pos); + } + + public int getNextPosition(int currentPos, boolean searchForward) { + return currentPos + (searchForward ? 1 : -1); + } + + public boolean inPartition(int pos) { + return true; + } + } + + public class ParamRegion { + public IRegion region = null; + public int paramSeparatorCount = 0; + } + + public ParamRegion findEnclosingPeerCharacters(IDocument document, int offset, int length) { + if (document == null || offset < 0 || offset > document.getLength()) + return null; + try { + DocumentAccessor doc = new DocumentAccessor(document); + return findEnclosingPeers(document, doc, offset, length, 0, document.getLength()); + } catch (BadLocationException ble) { + return null; + } + } + + private ParamRegion findEnclosingPeers(IDocument document, DocumentAccessor doc, int offset, int length, int lowerBoundary, int upperBoundary) throws BadLocationException { + char[] pairs = fPairs.fPairs; + /* Special ParamHelp added here */ + int cSeparators = 0; + /* Special ParamHelp end here */ + + int start; + int end; + if (length >= 0) { + start = offset; + end = offset + length; + } else { + end = offset; + start = offset + length; + } + + boolean lowerFound = false; + boolean upperFound = false; + int[][] counts = new int[pairs.length][2]; + char currChar = (start != document.getLength()) ? doc.getChar(start) : Character.MIN_VALUE; + int pos1; + int pos2; + if (fPairs.isEndCharacter(currChar)) { + pos1 = doc.getNextPosition(start, false); + pos2 = start; + } + /* Special ParamHelp added here */ + else if (isSeparator(currChar)) { + pos1 = doc.getNextPosition(start, false); + pos2 = doc.getNextPosition(start, true); + } + /* Special ParamHelp end here */ + else { + pos1 = start; + pos2 = doc.getNextPosition(start, true); + } + + while ((pos1 >= lowerBoundary && !lowerFound) || (pos2 < upperBoundary && !upperFound)) { + for (int i = 0; i < counts.length; i++) { + counts[i][0] = counts[i][1] = 0; + } + + outer1: + while (pos1 >= lowerBoundary && !lowerFound) { + final char c = doc.getChar(pos1); + int i = getCharacterIndex(c, document, pos1); + if (i != -1 && doc.inPartition(pos1)) { + if (i % 2 == 0) { + counts[i / 2][0]--; //start + } else { + counts[i / 2][0]++; //end + } + for (int j = 0; j < counts.length; j++) { + if (counts[j][0] == -1) { + lowerFound = true; + break outer1; + } + } + } + /* Special ParamHelp added here */ + else if (isSeparator(c)) { + boolean nestedSeparator = false; + for (int j = 0; j < counts.length; j++) { + if (counts[j][0] != 0) { + nestedSeparator = true; + } + } + if (!nestedSeparator) + cSeparators++; + + } + /* Special ParamHelp end here */ + pos1 = doc.getNextPosition(pos1, false); + } + + outer2: + while (pos2 < upperBoundary && !upperFound) { + final char c = doc.getChar(pos2); + int i = getCharacterIndex(c, document, pos2); + if (i != -1 && doc.inPartition(pos2)) { + if (i % 2 == 0) { + counts[i / 2][1]++; //start + } else { + counts[i / 2][1]--; //end + } + for (int j = 0; j < counts.length; j++) { + if (counts[j][1] == -1 && counts[j][0] == -1) { + upperFound = true; + break outer2; + } + } + } + pos2 = doc.getNextPosition(pos2, true); + } + + if (pos1 > start || pos2 < end - 1) { + //match inside selection => discard + pos1 = doc.getNextPosition(pos1, false); + pos2 = doc.getNextPosition(pos2, true); + lowerFound = false; + upperFound = false; + } + } + pos2++; + if (pos1 < lowerBoundary || pos2 > upperBoundary) + return null; + ParamRegion ret = new ParamRegion(); + ret.region = new Region(pos1, pos2 - pos1); + ret.paramSeparatorCount = cSeparators; + return ret; + } + + private int getCharacterIndex(char ch, IDocument document, int offset) { + char[] pairs = fPairs.fPairs; + for (int i = 0; i < pairs.length; i++) { + if (pairs[i] == ch && isMatchedChar(ch, document, offset)) { + return i; + } + } + return -1; + } + + public boolean isMatchedChar(char ch, IDocument document, int offset) { + return isMatchedChar(ch); + } + + public boolean isMatchedChar(char ch) { + return fPairs.contains(ch); + } } diff --git a/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/JavaParser.java b/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/JavaParser.java index b97936a..9464cdb 100644 --- a/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/JavaParser.java +++ b/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/JavaParser.java @@ -40,386 +40,363 @@ import com.microsoft.javapkgsrv.Protocol.Response.*; public class JavaParser { - private HashMap ActiveUnits = new HashMap(); - private HashMap ActiveTypeRoots = new HashMap(); - public IWorkspaceRoot WorkspaceRoot = null; - public IJavaModel JavaModel = null; - - public void Init() throws JavaModelException - { - WorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - - JavaModel = JavaCore.create(WorkspaceRoot); - System.out.println("Updating external archives..."); - JavaModel.refreshExternalArchives(null, null); - } - public Integer ProcessParseRequest(String contentFile, String fileName) throws Exception - { - CompilationUnit cu = Parse(contentFile, fileName); - int hashCode = cu.hashCode(); - ActiveUnits.put(hashCode, cu); - return hashCode; - } - public void ProcessDisposeFileRequest(int fileIdentifier) - { - if (ActiveUnits.containsKey(fileIdentifier)) - ActiveUnits.remove(fileIdentifier); - } - private CompilationUnit Parse(String contentFile, String fileName) throws Exception - { - File file = new File(fileName); - IFile[] files = WorkspaceRoot.findFilesForLocationURI(file.toURI(), IResource.FILE); - - if (files.length > 1) - throw new Exception("Ambigous parse request for file: " + fileName); - else if (files.length == 0) - throw new Exception("File is not part of the enlistment: " + fileName); - - ASTParser parser = ASTParser.newParser(AST.JLS8); - parser.setKind(ASTParser.K_COMPILATION_UNIT); - parser.setSource(contentFile.toCharArray()); - parser.setUnitName(files[0].getName()); - parser.setProject(JavaCore.create(files[0].getProject())); - parser.setResolveBindings(true); - - CompilationUnit cu = (CompilationUnit)parser.createAST(null); - return cu; - } - public List ProcessOutlineRequest(Integer fileId) - { - final List ret = new ArrayList(); - if (ActiveUnits.containsKey(fileId)) - { - CompilationUnit cu = ActiveUnits.get(fileId); - cu.accept(new ASTVisitor() - { - @Override - public boolean visit(TypeDeclaration type) - { - ret.add(OutlineResultResponse.Outline.newBuilder() - .setStartPosition(type.getStartPosition()) - .setLength(type.getLength()) - .setHoverText(type.toString()) - .setSummaryText(type.getName().toString()) - .build()); - return true; - } - @Override - public boolean visit(MethodDeclaration method) - { - ret.add(OutlineResultResponse.Outline.newBuilder() - .setStartPosition(method.getStartPosition()) - .setLength(method.getLength()) - .setHoverText(method.toString()) - .setSummaryText(method.getName().toString()) - .build()); - return true; - } - }); - } - return ret; - } - public List ProcessAutocompleteRequest(String contentFile, String typeRootId, int cursorPosition) throws Exception - { - if (ActiveTypeRoots.containsKey(typeRootId)) - { - ITypeRoot typeRoot = ActiveTypeRoots.get(typeRootId); - typeRoot.getBuffer().setContents(contentFile.toCharArray()); - return Autocomplete(typeRoot, cursorPosition); - } - return null; - } - private List Autocomplete(ITypeRoot cu, int cursorPosition) throws JavaModelException - { - final List proposals = new ArrayList(); - cu.codeComplete(cursorPosition, new CompletionRequestor() - { - @Override - public void accept(CompletionProposal proposal) { - try - { - System.out.println(proposal.toString()); - proposals.add(translateToCompletion(proposal)); - } - catch(Exception e) - { - e.printStackTrace(); - } - } - }); - return proposals; - } - private AutocompleteResponse.Completion translateToCompletion(CompletionProposal proposal) - { - AutocompleteResponse.Completion.Builder builder = AutocompleteResponse.Completion.newBuilder() - .setKind(AutocompleteResponse.Completion.CompletionKind.valueOf(proposal.getKind())) - .setIsConstructor(proposal.isConstructor()) - .setCompletionText(String.copyValueOf(proposal.getCompletion())) - .setFlags(proposal.getFlags()) - .setRelevance(proposal.getRelevance()) - .setReplaceStart(proposal.getReplaceStart()) - .setReplaceEnd(proposal.getReplaceEnd()); - - char[] sig = proposal.getSignature(); - - if (sig != null) - { - if (proposal.getKind() == CompletionProposal.METHOD_REF || proposal.getKind() == CompletionProposal.JAVADOC_METHOD_REF) - builder.setSignature(new String(Signature.toCharArray(sig, proposal.getName(), null, false, true))); - else - builder.setSignature(new String(Signature.toCharArray(sig))); - } - char[] name = proposal.getName(); - if (name == null) - builder.setName(builder.getCompletionText()); - else - builder.setName(String.copyValueOf(name)); - return builder.build(); - } - public List ProcessParamHelpRequest(String contentFile, String typeRootId, int cursorPosition) throws Exception - { - if (ActiveTypeRoots.containsKey(typeRootId)) - { - ITypeRoot typeRoot = ActiveTypeRoots.get(typeRootId); - typeRoot.getBuffer().setContents(contentFile.toCharArray()); - return ParamHelp(typeRoot, cursorPosition); - } - return null; - } - private List ParamHelp(ITypeRoot cu, int cursorPosition) throws JavaModelException - { - final List proposals = new ArrayList(); - cu.codeComplete(cursorPosition, new CompletionRequestor() - { - @Override - public void accept(CompletionProposal proposal) - { - try - { - System.out.println(proposal.toString()); - if (proposal.getKind() == CompletionProposal.METHOD_REF) - { - char[] javaSig = proposal.getSignature(); - - ParamHelpResponse.Signature.Builder sig = ParamHelpResponse.Signature.newBuilder() - .setName(new String(proposal.getName())) - .setReturnValue(new String(Signature.toCharArray(Signature.getReturnType(javaSig)))); - - char[][] javaParamTypes = Signature.getParameterTypes(javaSig); - for(char[] javaParamType: javaParamTypes) - { - sig.addParameters(ParamHelpResponse.Parameter.newBuilder() - .setName(new String(Signature.toCharArray(javaParamType))) - .build()); - } - proposals.add(sig.build()); - } - } - catch(Exception e) - { - e.printStackTrace(); - } - } - }); - return proposals; - } - protected final static char[] BRACKETS= { '{', '}', '(', ')', '[', ']', '<', '>' }; - protected final static char[] SEPARATORS = { ',' }; - public JavaParamHelpMatcher.ParamRegion getScope(String fileParseContent, int cursorPosition) - { - JavaParamHelpMatcher matcher = new JavaParamHelpMatcher(BRACKETS, SEPARATORS); - Document doc = new Document(fileParseContent); - - return matcher.findEnclosingPeerCharacters(doc, cursorPosition, 0); - } - public JavaParamHelpMatcher.ParamRegion updateScope(String fileParseContents, int cursorPosition) - { - JavaParamHelpMatcher matcher = new JavaParamHelpMatcher(BRACKETS, SEPARATORS); - Document doc = new Document(fileParseContents); - - return matcher.findEnclosingPeerCharacters(doc, cursorPosition, 0); - } - public List ProcessFileParseMessagesRequest(Integer fileId) - { - List ret = new ArrayList(); - if (ActiveUnits.containsKey(fileId)) - { - CompilationUnit cu = ActiveUnits.get(fileId); - IProblem[] problems = cu.getProblems(); - - for(IProblem problem: problems) - { - System.out.println(problem.toString()); - FileParseMessagesResponse.Problem.Builder retProblem = FileParseMessagesResponse.Problem.newBuilder() - .setId(problem.getID()) - .setMessage(problem.getMessage()) - .setFileName(new String(problem.getOriginatingFileName())) - .setScopeStart(problem.getSourceStart()) - .setScopeEnd(problem.getSourceEnd() + 1) - .setLineNumber(problem.getSourceLineNumber()) - .setProblemType(GetProblemType(problem)); - for(String arg: problem.getArguments()) - retProblem.addArguments(arg); - ret.add(retProblem.build()); - } - } - return ret; - } - private FileParseMessagesResponse.Problem.ProblemType GetProblemType(IProblem problem) - { - if (problem.isError()) - return FileParseMessagesResponse.Problem.ProblemType.Error; - if (problem.isWarning()) - return FileParseMessagesResponse.Problem.ProblemType.Warning; - return FileParseMessagesResponse.Problem.ProblemType.Message; - } - public List ProcessQuickInfoRequest(String fileParseContents, String typeRootId, int cursorPosition) throws Exception - { - if (ActiveTypeRoots.containsKey(typeRootId)) - { - ITypeRoot cu = ActiveTypeRoots.get(typeRootId); - cu.getBuffer().setContents(fileParseContents.toCharArray()); - IJavaElement[] elements = cu.codeSelect(cursorPosition, 0); - - List ret = new ArrayList(); - - long flags = JavaElementLabelComposer.ALL_FULLY_QUALIFIED | JavaElementLabelComposer.ALL_DEFAULT | JavaElementLabelComposer.M_PRE_RETURNTYPE | JavaElementLabelComposer.F_PRE_TYPE_SIGNATURE; - for(IJavaElement element: elements) - { - StringBuffer buffer = new StringBuffer(); - JavaElementLabelComposer composer = new JavaElementLabelComposer(buffer); - - composer.appendElementLabel(element, flags); - System.out.println(element.getPath().toString()); - - JavaElement.Builder b = JavaElement.newBuilder() - .setDefinition(buffer.toString()); - - String javaDoc = null; - try - { - javaDoc = element.getAttachedJavadoc(null); - } - catch(JavaModelException jme) - { - jme.printStackTrace(); - } - if (javaDoc != null) b.setJavaDoc(javaDoc); - ret.add(b.build()); - } - return ret; - } - return null; - } - public List ProcessFindDefinintionRequest(String fileParseContents, String typeRootId, int cursorPosition) throws Exception - { - if (ActiveTypeRoots.containsKey(typeRootId)) - { - ITypeRoot cu = ActiveTypeRoots.get(typeRootId); - cu.getBuffer().setContents(fileParseContents.toCharArray()); - IJavaElement[] elements = cu.codeSelect(cursorPosition, 0); - - List ret = new ArrayList(); - for(IJavaElement element: elements) - { - String definition = element.toString(); - String path = element.getResource() != null ? element.getResource().getLocation().toOSString() : element.getPath().toOSString(); - //String path = element.getPath().makeAbsolute().toOSString(); // element.getPath().toString(); - - boolean isAvailable = false; - int posStart = -1; - int posLength = 0; - String contents = null; - String classFileName = null; - IClassFile classFileObj = null; - - ISourceReference srcRef = (ISourceReference)element; - if (srcRef != null) - { - ISourceRange range = srcRef.getSourceRange(); - if (SourceRange.isAvailable(range)) - { - isAvailable = true; - posStart = range.getOffset(); - posLength = range.getLength(); - - //if (path.endsWith(".jar")) - //{ - IOpenable op = element.getOpenable(); - if (op != null && op instanceof IClassFile) - { - IBuffer buff = op.getBuffer(); - classFileObj = (IClassFile)op; - classFileName = classFileObj.getElementName(); - contents = buff.getContents(); - } - //} - } - } - - FindDefinitionResponse.JavaElement.Builder retItem = FindDefinitionResponse.JavaElement.newBuilder() - .setDefinition(definition) - .setFilePath(path) - .setHasSource(isAvailable) - .setPositionStart(posStart) - .setPositionLength(posLength); - - if (contents != null) - { - //int hashCode = classFileObj.hashCode(); - String handle = classFileObj.getHandleIdentifier(); - ActiveTypeRoots.put(handle, classFileObj); - - retItem.setFileName(classFileName); - retItem.setTypeRootIdentifier(TypeRootIdentifier.newBuilder() - .setHandle(handle) - .build()); - } - System.out.println(retItem.toString()); - if (contents != null) - { - retItem.setFileContents(contents); - } - ret.add(retItem.build()); - } - return ret; - } - return null; - } - public String ProcessOpenTypeRequest(String fileName) throws Exception - { - File file = new File(fileName); - IFile[] files = WorkspaceRoot.findFilesForLocationURI(file.toURI(), IResource.FILE); - - if (files.length > 1) - throw new Exception("Ambigous parse request for file " + fileName); - else if (files.length == 0) - throw new Exception("File not found: " + fileName); - - IJavaElement javaFile = JavaCore.create(files[0]); - if (javaFile instanceof ITypeRoot) - { - //int hashCode = javaFile.hashCode(); - String handle = javaFile.getHandleIdentifier(); - ActiveTypeRoots.put(handle, (ITypeRoot)javaFile); - return handle; - } - return null; - } - public void ProcessDisposeTypeRoot(String handle) - { - if (ActiveTypeRoots.containsKey(handle)) - ActiveTypeRoots.remove(handle); - } - public String ProcessAddTypeRequest(String handle) - { - IJavaElement javaFile = JavaCore.create(handle); - if (javaFile instanceof ITypeRoot) - { - String newHandle = javaFile.getHandleIdentifier(); - ActiveTypeRoots.put(newHandle, (ITypeRoot)javaFile); - return newHandle; - } - return null; - } + private HashMap ActiveUnits = new HashMap(); + private HashMap ActiveTypeRoots = new HashMap(); + public IWorkspaceRoot WorkspaceRoot = null; + public IJavaModel JavaModel = null; + + public void Init() throws JavaModelException { + WorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + + JavaModel = JavaCore.create(WorkspaceRoot); + System.out.println("Updating external archives..."); + JavaModel.refreshExternalArchives(null, null); + } + + public Integer ProcessParseRequest(String contentFile, String fileName) throws Exception { + CompilationUnit cu = Parse(contentFile, fileName); + int hashCode = cu.hashCode(); + ActiveUnits.put(hashCode, cu); + return hashCode; + } + + public void ProcessDisposeFileRequest(int fileIdentifier) { + if (ActiveUnits.containsKey(fileIdentifier)) { + ActiveUnits.remove(fileIdentifier); + } + } + + private CompilationUnit Parse(String contentFile, String fileName) throws Exception { + File file = new File(fileName); + IFile[] files = WorkspaceRoot.findFilesForLocationURI(file.toURI(), IResource.FILE); + + if (files.length > 1) { + throw new Exception("Ambigous parse request for file: " + fileName); + } else if (files.length == 0) { + throw new Exception("File is not part of the enlistment: " + fileName); + } + + ASTParser parser = ASTParser.newParser(AST.JLS8); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setSource(contentFile.toCharArray()); + parser.setUnitName(files[0].getName()); + parser.setProject(JavaCore.create(files[0].getProject())); + parser.setResolveBindings(true); + + CompilationUnit cu = (CompilationUnit) parser.createAST(null); + return cu; + } + + public List ProcessOutlineRequest(Integer fileId) { + final List ret = new ArrayList(); + if (ActiveUnits.containsKey(fileId)) { + CompilationUnit cu = ActiveUnits.get(fileId); + cu.accept(new ASTVisitor() { + @Override + public boolean visit(TypeDeclaration type) { + ret.add(OutlineResultResponse.Outline.newBuilder() + .setStartPosition(type.getStartPosition()) + .setLength(type.getLength()) + .setHoverText(type.toString()) + .setSummaryText(type.getName().toString()) + .build()); + return true; + } + + @Override + public boolean visit(MethodDeclaration method) { + ret.add(OutlineResultResponse.Outline.newBuilder() + .setStartPosition(method.getStartPosition()) + .setLength(method.getLength()) + .setHoverText(method.toString()) + .setSummaryText(method.getName().toString()) + .build()); + return true; + } + }); + } + return ret; + } + + public List ProcessAutocompleteRequest(String contentFile, String typeRootId, int cursorPosition) throws Exception { + if (ActiveTypeRoots.containsKey(typeRootId)) { + ITypeRoot typeRoot = ActiveTypeRoots.get(typeRootId); + typeRoot.getBuffer().setContents(contentFile.toCharArray()); + return Autocomplete(typeRoot, cursorPosition); + } + return null; + } + + private List Autocomplete(ITypeRoot cu, int cursorPosition) throws JavaModelException { + final List proposals = new ArrayList(); + cu.codeComplete(cursorPosition, new CompletionRequestor() { + @Override + public void accept(CompletionProposal proposal) { + try { + System.out.println(proposal.toString()); + proposals.add(translateToCompletion(proposal)); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + return proposals; + } + + private AutocompleteResponse.Completion translateToCompletion(CompletionProposal proposal) { + AutocompleteResponse.Completion.Builder builder = AutocompleteResponse.Completion.newBuilder() + .setKind(AutocompleteResponse.Completion.CompletionKind.valueOf(proposal.getKind())) + .setIsConstructor(proposal.isConstructor()) + .setCompletionText(String.copyValueOf(proposal.getCompletion())) + .setFlags(proposal.getFlags()) + .setRelevance(proposal.getRelevance()) + .setReplaceStart(proposal.getReplaceStart()) + .setReplaceEnd(proposal.getReplaceEnd()); + + char[] sig = proposal.getSignature(); + + if (sig != null) { + if (proposal.getKind() == CompletionProposal.METHOD_REF || proposal.getKind() == CompletionProposal.JAVADOC_METHOD_REF) { + builder.setSignature(new String(Signature.toCharArray(sig, proposal.getName(), null, false, true))); + } else { + builder.setSignature(new String(Signature.toCharArray(sig))); + } + } + char[] name = proposal.getName(); + if (name == null) { + builder.setName(builder.getCompletionText()); + } else { + builder.setName(String.copyValueOf(name)); + } + return builder.build(); + } + + public List ProcessParamHelpRequest(String contentFile, String typeRootId, int cursorPosition) throws Exception { + if (ActiveTypeRoots.containsKey(typeRootId)) { + ITypeRoot typeRoot = ActiveTypeRoots.get(typeRootId); + typeRoot.getBuffer().setContents(contentFile.toCharArray()); + return ParamHelp(typeRoot, cursorPosition); + } + return null; + } + + private List ParamHelp(ITypeRoot cu, int cursorPosition) throws JavaModelException { + final List proposals = new ArrayList(); + cu.codeComplete(cursorPosition, new CompletionRequestor() { + @Override + public void accept(CompletionProposal proposal) { + try { + System.out.println(proposal.toString()); + if (proposal.getKind() == CompletionProposal.METHOD_REF) { + char[] javaSig = proposal.getSignature(); + + ParamHelpResponse.Signature.Builder sig = ParamHelpResponse.Signature.newBuilder() + .setName(new String(proposal.getName())) + .setReturnValue(new String(Signature.toCharArray(Signature.getReturnType(javaSig)))); + + char[][] javaParamTypes = Signature.getParameterTypes(javaSig); + for (char[] javaParamType : javaParamTypes) { + sig.addParameters(ParamHelpResponse.Parameter.newBuilder() + .setName(new String(Signature.toCharArray(javaParamType))) + .build()); + } + proposals.add(sig.build()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + return proposals; + } + + protected final static char[] BRACKETS = {'{', '}', '(', ')', '[', ']', '<', '>'}; + protected final static char[] SEPARATORS = {','}; + + public JavaParamHelpMatcher.ParamRegion getScope(String fileParseContent, int cursorPosition) { + JavaParamHelpMatcher matcher = new JavaParamHelpMatcher(BRACKETS, SEPARATORS); + Document doc = new Document(fileParseContent); + + return matcher.findEnclosingPeerCharacters(doc, cursorPosition, 0); + } + + public JavaParamHelpMatcher.ParamRegion updateScope(String fileParseContents, int cursorPosition) { + JavaParamHelpMatcher matcher = new JavaParamHelpMatcher(BRACKETS, SEPARATORS); + Document doc = new Document(fileParseContents); + + return matcher.findEnclosingPeerCharacters(doc, cursorPosition, 0); + } + + public List ProcessFileParseMessagesRequest(Integer fileId) { + List ret = new ArrayList(); + if (ActiveUnits.containsKey(fileId)) { + CompilationUnit cu = ActiveUnits.get(fileId); + IProblem[] problems = cu.getProblems(); + + for (IProblem problem : problems) { + System.out.println(problem.toString()); + FileParseMessagesResponse.Problem.Builder retProblem = FileParseMessagesResponse.Problem.newBuilder() + .setId(problem.getID()) + .setMessage(problem.getMessage()) + .setFileName(new String(problem.getOriginatingFileName())) + .setScopeStart(problem.getSourceStart()) + .setScopeEnd(problem.getSourceEnd() + 1) + .setLineNumber(problem.getSourceLineNumber()) + .setProblemType(GetProblemType(problem)); + for (String arg : problem.getArguments()) + retProblem.addArguments(arg); + ret.add(retProblem.build()); + } + } + return ret; + } + + private FileParseMessagesResponse.Problem.ProblemType GetProblemType(IProblem problem) { + if (problem.isError()) { + return FileParseMessagesResponse.Problem.ProblemType.Error; + } + + if (problem.isWarning()) { + return FileParseMessagesResponse.Problem.ProblemType.Warning; + } + + return FileParseMessagesResponse.Problem.ProblemType.Message; + } + + public List ProcessQuickInfoRequest(String fileParseContents, String typeRootId, int cursorPosition) throws Exception { + if (ActiveTypeRoots.containsKey(typeRootId)) { + ITypeRoot cu = ActiveTypeRoots.get(typeRootId); + cu.getBuffer().setContents(fileParseContents.toCharArray()); + IJavaElement[] elements = cu.codeSelect(cursorPosition, 0); + + List ret = new ArrayList(); + + long flags = JavaElementLabelComposer.ALL_FULLY_QUALIFIED | JavaElementLabelComposer.ALL_DEFAULT | JavaElementLabelComposer.M_PRE_RETURNTYPE | JavaElementLabelComposer.F_PRE_TYPE_SIGNATURE; + for (IJavaElement element : elements) { + StringBuffer buffer = new StringBuffer(); + JavaElementLabelComposer composer = new JavaElementLabelComposer(buffer); + + composer.appendElementLabel(element, flags); + System.out.println(element.getPath().toString()); + + JavaElement.Builder b = JavaElement.newBuilder() + .setDefinition(buffer.toString()); + + String javaDoc = null; + try { + javaDoc = element.getAttachedJavadoc(null); + } catch (JavaModelException jme) { + jme.printStackTrace(); + } + if (javaDoc != null) b.setJavaDoc(javaDoc); + ret.add(b.build()); + } + return ret; + } + return null; + } + + public List ProcessFindDefinintionRequest(String fileParseContents, String typeRootId, int cursorPosition) throws Exception { + if (ActiveTypeRoots.containsKey(typeRootId)) { + ITypeRoot cu = ActiveTypeRoots.get(typeRootId); + cu.getBuffer().setContents(fileParseContents.toCharArray()); + IJavaElement[] elements = cu.codeSelect(cursorPosition, 0); + + List ret = new ArrayList(); + for (IJavaElement element : elements) { + String definition = element.toString(); + String path = element.getResource() != null ? element.getResource().getLocation().toOSString() : element.getPath().toOSString(); + //String path = element.getPath().makeAbsolute().toOSString(); // element.getPath().toString(); + + boolean isAvailable = false; + int posStart = -1; + int posLength = 0; + String contents = null; + String classFileName = null; + IClassFile classFileObj = null; + + ISourceReference srcRef = (ISourceReference) element; + if (srcRef != null) { + ISourceRange range = srcRef.getSourceRange(); + if (SourceRange.isAvailable(range)) { + isAvailable = true; + posStart = range.getOffset(); + posLength = range.getLength(); + + //if (path.endsWith(".jar")) + //{ + IOpenable op = element.getOpenable(); + if (op != null && op instanceof IClassFile) { + IBuffer buff = op.getBuffer(); + classFileObj = (IClassFile) op; + classFileName = classFileObj.getElementName(); + contents = buff.getContents(); + } + //} + } + } + + FindDefinitionResponse.JavaElement.Builder retItem = FindDefinitionResponse.JavaElement.newBuilder() + .setDefinition(definition) + .setFilePath(path) + .setHasSource(isAvailable) + .setPositionStart(posStart) + .setPositionLength(posLength); + + if (contents != null) { + //int hashCode = classFileObj.hashCode(); + String handle = classFileObj.getHandleIdentifier(); + ActiveTypeRoots.put(handle, classFileObj); + + retItem.setFileName(classFileName); + retItem.setTypeRootIdentifier(TypeRootIdentifier.newBuilder() + .setHandle(handle) + .build()); + } + System.out.println(retItem.toString()); + if (contents != null) { + retItem.setFileContents(contents); + } + ret.add(retItem.build()); + } + return ret; + } + return null; + } + + public String ProcessOpenTypeRequest(String fileName) throws Exception { + File file = new File(fileName); + IFile[] files = WorkspaceRoot.findFilesForLocationURI(file.toURI(), IResource.FILE); + + if (files.length > 1) { + throw new Exception("Ambigous parse request for file " + fileName); + } else if (files.length == 0) { + throw new Exception("File not found: " + fileName); + } + + IJavaElement javaFile = JavaCore.create(files[0]); + if (javaFile instanceof ITypeRoot) { + //int hashCode = javaFile.hashCode(); + String handle = javaFile.getHandleIdentifier(); + ActiveTypeRoots.put(handle, (ITypeRoot) javaFile); + return handle; + } + return null; + } + + public void ProcessDisposeTypeRoot(String handle) { + if (ActiveTypeRoots.containsKey(handle)) { + ActiveTypeRoots.remove(handle); + } + } + + public String ProcessAddTypeRequest(String handle) { + IJavaElement javaFile = JavaCore.create(handle); + if (javaFile instanceof ITypeRoot) { + String newHandle = javaFile.getHandleIdentifier(); + ActiveTypeRoots.put(newHandle, (ITypeRoot) javaFile); + return newHandle; + } + return null; + } } diff --git a/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/Start.java b/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/Start.java index 1ada258..cf8a59d 100644 --- a/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/Start.java +++ b/eclipseplugin/com.microsoft.javapkgsrv/src/com/microsoft/javapkgsrv/Start.java @@ -9,34 +9,32 @@ public class Start implements IApplication { - @Override - public Object start(IApplicationContext context) throws Exception - { - String[] args = (String[])context.getArguments().get("application.args"); - System.out.println("Arguments:"); - for(String arg: args) - System.out.println("\t" + arg); - - ClientProxy proxy; - if (args.length == 1) - proxy = new ClientProxy(args[0]); - else - proxy = new ClientProxy(); - - try - { - proxy.Run(); - } - catch(IOException e) - { - e.printStackTrace(); - } - - return null; - } - - @Override - public void stop() { - } + @Override + public Object start(IApplicationContext context) throws Exception { + String[] args = (String[]) context.getArguments().get("application.args"); + System.out.println("Arguments:"); + for (String arg : args) { + System.out.println("\t" + arg); + } + + ClientProxy proxy; + if (args.length == 1) { + proxy = new ClientProxy(args[0]); + } else { + proxy = new ClientProxy(); + } + + try { + proxy.Run(); + } catch (IOException e) { + e.printStackTrace(); + } + + return null; + } + + @Override + public void stop() { + } }