started to implement infrastructure to parse java projects completely
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -8,11 +8,15 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
public class DefaultJavaProjectFinder implements JavaProjectFinder {
|
||||
@@ -24,10 +28,30 @@ public class DefaultJavaProjectFinder implements JavaProjectFinder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavaProject find(IDocument d) {
|
||||
public IJavaProject find(IDocument doc) {
|
||||
try {
|
||||
String uriStr = doc.getUri();
|
||||
if (StringUtil.hasText(uriStr)) {
|
||||
URI uri = new URI(uriStr);
|
||||
// TODO: This only work with File uri. Should it work with others
|
||||
// too?
|
||||
if (uri.getScheme().equalsIgnoreCase("file")) {
|
||||
File file = new File(uri).getAbsoluteFile();
|
||||
return find(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavaProject find(File file) {
|
||||
for (IJavaProjectFinderStrategy strategy : strategies) {
|
||||
try {
|
||||
IJavaProject project = strategy.find(d);
|
||||
IJavaProject project = strategy.find(file);
|
||||
if (project != null) {
|
||||
return project;
|
||||
}
|
||||
@@ -37,5 +61,19 @@ public class DefaultJavaProjectFinder implements JavaProjectFinder {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProjectRoot(File file) {
|
||||
for (IJavaProjectFinderStrategy strategy : strategies) {
|
||||
try {
|
||||
if (strategy.isProjectRoot(file)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -10,18 +10,18 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
/**
|
||||
* Strategy foe finding Java project for a document
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IJavaProjectFinderStrategy {
|
||||
|
||||
IJavaProject find(IDocument document) throws Exception;
|
||||
IJavaProject find(File file) throws Exception;
|
||||
boolean isProjectRoot(File file);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,13 +8,17 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface JavaProjectFinder {
|
||||
|
||||
IJavaProject find(IDocument doc);
|
||||
IJavaProject find(File file);
|
||||
boolean isProjectRoot(File file);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user