use of org.eclipse.jdt.core.IOpenable in project che by eclipse.
the class StubUtility method getLineDelimiterUsed.
/**
* @param elem a Java element (doesn't have to exist)
* @return the existing or default line delimiter for the element
*/
public static String getLineDelimiterUsed(IJavaElement elem) {
IOpenable openable = elem.getOpenable();
if (openable instanceof ITypeRoot) {
try {
return openable.findRecommendedLineSeparator();
} catch (JavaModelException exception) {
// Use project setting
}
}
IJavaProject project = elem.getJavaProject();
return getProjectLineDelimiter(project.exists() ? project : null);
}
use of org.eclipse.jdt.core.IOpenable in project eclipse.jdt.ls by eclipse.
the class StubUtility method getLineDelimiterUsed.
/**
* @param elem
* a Java element (doesn't have to exist)
* @return the existing or default line delimiter for the element
*/
public static String getLineDelimiterUsed(IJavaElement elem) {
IOpenable openable = elem.getOpenable();
if (openable instanceof ITypeRoot) {
try {
return openable.findRecommendedLineSeparator();
} catch (JavaModelException exception) {
// Use project setting
}
}
IJavaProject project = elem.getJavaProject();
return getProjectLineDelimiter(project.exists() ? project : null);
}
use of org.eclipse.jdt.core.IOpenable in project che by eclipse.
the class JavaDocLocations method getExplanationForMissingJavadoc.
// /**
// * Returns the location of the Javadoc.
// *
// * @param element whose Javadoc location has to be found
// * @param isBinary <code>true</code> if the Java element is from a binary container
// * @return the location URL of the Javadoc or <code>null</code> if the location cannot be found
// * @throws org.eclipse.jdt.core.JavaModelException thrown when the Java element cannot be accessed
// * @since 3.9
// */
// public static String getBaseURL(IJavaElement element, boolean isBinary) throws JavaModelException {
// if (isBinary) {
// // Source attachment usually does not include Javadoc resources
// // => Always use the Javadoc location as base:
// URL baseURL= JavaUI.getJavadocLocation(element, false);
// if (baseURL != null) {
// if (baseURL.getProtocol().equals(JAR_PROTOCOL)) {
// // It's a JarURLConnection, which is not known to the browser widget.
// // Let's start the help web server:
// URL baseURL2= PlatformUI.getWorkbench().getHelpSystem().resolve(baseURL.toExternalForm(), true);
// if (baseURL2 != null) { // can be null if org.eclipse.help.ui is not available
// baseURL= baseURL2;
// }
// }
// return baseURL.toExternalForm();
// }
// } else {
// IResource resource= element.getResource();
// if (resource != null) {
// /*
// * Too bad: Browser widget knows nothing about EFS and custom URL handlers,
// * so IResource#getLocationURI() does not work in all cases.
// * We only support the local file system for now.
// * A solution could be https://bugs.eclipse.org/bugs/show_bug.cgi?id=149022 .
// */
// IPath location= resource.getLocation();
// if (location != null)
// return location.toFile().toURI().toString();
// }
// }
// return null;
// }
/**
* Returns the reason for why the Javadoc of the Java element could not be retrieved.
*
* @param element whose Javadoc could not be retrieved
* @param root the root of the Java element
* @return the String message for why the Javadoc could not be retrieved for the Java element or
* <code>null</code> if the Java element is from a source container
* @since 3.9
*/
public static String getExplanationForMissingJavadoc(IJavaElement element, IPackageFragmentRoot root) {
String message = null;
try {
boolean isBinary = (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY);
if (isBinary) {
boolean hasAttachedJavadoc = JavaDocLocations.getJavadocBaseLocation(element) != null;
boolean hasAttachedSource = root.getSourceAttachmentPath() != null;
IOpenable openable = element.getOpenable();
boolean hasSource = openable.getBuffer() != null;
// Provide hint why there's no Java doc
if (!hasAttachedSource && !hasAttachedJavadoc)
message = CorextMessages.JavaDocLocations_noAttachments;
else if (!hasAttachedJavadoc && !hasSource)
message = CorextMessages.JavaDocLocations_noAttachedJavadoc;
else if (!hasAttachedSource)
message = CorextMessages.JavaDocLocations_noAttachedSource;
else if (!hasSource)
message = CorextMessages.JavaDocLocations_noInformation;
}
} catch (JavaModelException e) {
message = CorextMessages.JavaDocLocations_error_gettingJavadoc;
LOG.error(message, e);
}
return message;
}
use of org.eclipse.jdt.core.IOpenable in project tdi-studio-se by Talend.
the class JavaCodeProblemsChecker method retrieveDetailedProblems.
/**
* DOC amaumont Comment method "retrieveDetailedProblems".
*
* @return
*/
private List<DetailedProblem> retrieveDetailedProblems(final IAloneProcessNodeConfigurer nodeConfigurer) {
final ArrayList<DetailedProblem> iproblems = new ArrayList<DetailedProblem>();
final IWorkbench workbench = PlatformUI.getWorkbench();
Display display = workbench.getDisplay();
if (display != null) {
display.syncExec(new Runnable() {
public void run() {
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
IEditorPart editorPart = page.getActiveEditor();
if (editorPart instanceof AbstractMultiPageTalendEditor) {
AbstractMultiPageTalendEditor multiPageTalendEditor = ((AbstractMultiPageTalendEditor) editorPart);
AbstractTalendEditor talendEditor = multiPageTalendEditor.getTalendEditor();
TalendJavaEditor codeEditor = (TalendJavaEditor) multiPageTalendEditor.getCodeEditor();
org.eclipse.jdt.core.ICompilationUnit compilationUnit = (org.eclipse.jdt.core.ICompilationUnit) codeEditor.getUnit();
IProcess process = talendEditor.getProcess();
if (AbstractProcessProvider.isExtensionProcessForJoblet(process)) {
// joblet
return;
}
String selectedNodeName = multiPageTalendEditor.getSelectedNodeName();
if (selectedNodeName == null) {
return;
}
String uniqueNodeName = null;
boolean found = false;
List<? extends INode> generatingNodes = process.getGeneratingNodes();
int generatingNodesListSize = generatingNodes.size();
for (int i = 0; i < generatingNodesListSize; i++) {
INode node = generatingNodes.get(i);
/* startsWith method used in case of virtual component such as 'tMap_1_TMAP_OUT' */
if (node.getUniqueName().equals(selectedNodeName) || node.getUniqueName().startsWith(selectedNodeName + "_")) {
//$NON-NLS-1$
uniqueNodeName = node.getUniqueName();
found = true;
break;
}
}
if (!found) {
// in case the component doesn't exist
return;
}
final String code = retrieveCode(process, uniqueNodeName, nodeConfigurer);
// System.out.println(code);
// create requestor for accumulating discovered problems
MyProblemRequestor problemRequestor = new MyProblemRequestor(code, iproblems, selectedNodeName);
// use working copy to hold source with error
org.eclipse.jdt.core.ICompilationUnit workingCopy = null;
try {
JavaProcessorUtilities.computeLibrariesPath(process.getNeededModules(false), process);
try {
WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {
};
workingCopy = ((org.eclipse.jdt.core.ICompilationUnit) compilationUnit).getWorkingCopy(workingCopyOwner, problemRequestor, null);
problemRequestor.setReportProblems(true);
((IOpenable) workingCopy).getBuffer().setContents(code);
((org.eclipse.jdt.core.ICompilationUnit) workingCopy).reconcile(ICompilationUnit.NO_AST, true, null, null);
problemRequestor.setReportProblems(false);
} finally {
if (workingCopy != null) {
workingCopy.discardWorkingCopy();
}
}
} catch (JavaModelException e) {
ExceptionHandler.process(e);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
}
});
}
return iproblems;
}
use of org.eclipse.jdt.core.IOpenable in project flux by eclipse.
the class StubUtility method getLineDelimiterUsed.
/**
* @param elem a Java element (doesn't have to exist)
* @return the existing or default line delimiter for the element
*/
public static String getLineDelimiterUsed(IJavaElement elem) {
IOpenable openable = elem.getOpenable();
if (openable instanceof ITypeRoot) {
try {
return openable.findRecommendedLineSeparator();
} catch (JavaModelException exception) {
// Use project setting
}
}
IJavaProject project = elem.getJavaProject();
return getProjectLineDelimiter(project.exists() ? project : null);
}
Aggregations