use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class AnonymousTypeCompletionProposal method updateReplacementString.
/*
* @see org.eclipse.jdt.internal.ui.text.java.JavaTypeCompletionProposal#updateReplacementString(org.eclipse.jface.text.IDocument, char, int, org.eclipse.jdt.core.dom.rewrite.ImportRewrite)
*/
@Override
protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException {
fImportRewrite = impRewrite;
String newBody = createNewBody(impRewrite);
if (newBody == null)
return false;
CompletionProposal coreProposal = ((MemberProposalInfo) getProposalInfo()).fProposal;
boolean isAnonymousConstructorInvoc = coreProposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION;
//$NON-NLS-1$
boolean replacementStringEndsWithParentheses = isAnonymousConstructorInvoc || getReplacementString().endsWith(")");
// construct replacement text: an expression to be formatted
//$NON-NLS-1$
StringBuffer buf = new StringBuffer("new A(");
if (!replacementStringEndsWithParentheses || isAnonymousConstructorInvoc)
buf.append(')');
buf.append(newBody);
// use the code formatter
String lineDelim = TextUtilities.getDefaultLineDelimiter(document);
final IJavaProject project = fCompilationUnit.getJavaProject();
IRegion lineInfo = document.getLineInformationOfOffset(getReplacementOffset());
int indent = Strings.computeIndentUnits(document.get(lineInfo.getOffset(), lineInfo.getLength()), project);
Map<String, String> options = project != null ? project.getOptions(true) : JavaCore.getOptions();
options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES, DefaultCodeFormatterConstants.TRUE);
String replacementString = CodeFormatterUtil.format(CodeFormatter.K_EXPRESSION, buf.toString(), 0, lineDelim, options);
int lineEndOffset = lineInfo.getOffset() + lineInfo.getLength();
int p = offset;
char ch = document.getChar(p);
while (p < lineEndOffset) {
if (ch == '(' || ch == ')' || ch == ';' || ch == ',')
break;
ch = document.getChar(++p);
}
if (ch != ';' && ch != ',' && ch != ')')
replacementString = replacementString + ';';
replacementString = Strings.changeIndent(replacementString, 0, project, CodeFormatterUtil.createIndentString(indent, project), lineDelim);
int beginIndex = replacementString.indexOf('(');
if (!isAnonymousConstructorInvoc)
beginIndex++;
replacementString = replacementString.substring(beginIndex);
int pos = offset;
if (isAnonymousConstructorInvoc && (insertCompletion() ^ isInsertModeToggled())) {
// Keep existing code
int endPos = pos;
ch = document.getChar(endPos);
while (endPos < lineEndOffset && ch != '(' && ch != ')' && ch != ';' && ch != ',' && !Character.isWhitespace(ch)) ch = document.getChar(++endPos);
int keepLength = endPos - pos;
if (keepLength > 0) {
String keepStr = document.get(pos, keepLength);
replacementString = replacementString + keepStr;
setCursorPosition(replacementString.length() - keepLength);
}
} else
setCursorPosition(replacementString.length());
setReplacementString(replacementString);
if (pos < document.getLength() && document.getChar(pos) == ')') {
int currentLength = getReplacementLength();
if (replacementStringEndsWithParentheses)
setReplacementLength(currentLength + pos - offset);
else
setReplacementLength(currentLength + pos - offset + 1);
}
return false;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class ImportCompletionProposal method isJavadocProcessingEnabled.
/**
* Returns whether Javadoc processing is enabled.
*
* @return <code>true</code> if Javadoc processing is enabled, <code>false</code> otherwise
*/
private boolean isJavadocProcessingEnabled() {
IJavaProject project = fCompilationUnit.getJavaProject();
boolean processJavadoc;
if (project == null)
processJavadoc = JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT));
else
processJavadoc = JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true));
return processJavadoc;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class LazyJavaTypeCompletionProposal method isJavadocProcessingEnabled.
private boolean isJavadocProcessingEnabled() {
IJavaProject project = fCompilationUnit.getJavaProject();
boolean processJavadoc;
if (project == null)
processJavadoc = JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT));
else
processJavadoc = JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true));
return processJavadoc;
}
use of org.eclipse.jdt.core.IJavaProject in project generator by mybatis.
the class RunGeneratorThread method getJavaProject.
private IJavaProject getJavaProject() {
IJavaProject answer = null;
IProject project = inputFile.getProject();
try {
if (project.hasNature(JavaCore.NATURE_ID)) {
answer = JavaCore.create(project);
}
} catch (CoreException e) {
// ignore - something is wrong
;
}
return answer;
}
use of org.eclipse.jdt.core.IJavaProject in project generator by mybatis.
the class RunGeneratorThread method setClassLoader.
private void setClassLoader() {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IJavaProject javaProject = getJavaProject();
try {
if (javaProject != null) {
List<URL> entries = new ArrayList<URL>();
IPath path = javaProject.getOutputLocation();
IResource iResource = root.findMember(path);
path = iResource.getLocation();
path = path.addTrailingSeparator();
entries.add(path.toFile().toURI().toURL());
IClasspathEntry[] cpEntries = javaProject.getRawClasspath();
for (IClasspathEntry cpEntry : cpEntries) {
switch(cpEntry.getEntryKind()) {
case IClasspathEntry.CPE_SOURCE:
path = cpEntry.getOutputLocation();
if (path != null) {
iResource = root.findMember(path);
path = iResource.getLocation();
path = path.addTrailingSeparator();
entries.add(path.toFile().toURI().toURL());
}
break;
case IClasspathEntry.CPE_LIBRARY:
iResource = root.findMember(cpEntry.getPath());
if (iResource == null) {
// resource is not in workspace, must be an external JAR
path = cpEntry.getPath();
} else {
path = iResource.getLocation();
}
entries.add(path.toFile().toURI().toURL());
break;
}
}
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
URL[] entryArray = new URL[entries.size()];
entries.toArray(entryArray);
ClassLoader newCl = new URLClassLoader(entryArray, oldCl);
Thread.currentThread().setContextClassLoader(newCl);
oldClassLoader = oldCl;
}
} catch (Exception e) {
// ignore - something too complex is wrong
;
}
}
Aggregations