List of usage examples for org.eclipse.jdt.internal.core.util Util log
public static void log(Throwable e)
From source file:org.codehaus.groovy.eclipse.codebrowsing.requestor.CodeSelectRequestor.java
License:Apache License
/** * @param enclosingElement//from w w w .j a v a 2 s . c o m * @return true iff enclosingElement's source location contains the source location of {@link #nodeToLookFor} */ private boolean interestingElement(IJavaElement enclosingElement) { // the clinit is always interesting since the clinit contains static initializers if (enclosingElement.getElementName().equals("<clinit>")) { return true; } if (enclosingElement instanceof ISourceReference) { try { ISourceRange range = ((ISourceReference) enclosingElement).getSourceRange(); return range.getOffset() <= nodeToLookFor.getStart() && range.getOffset() + range.getLength() >= nodeToLookFor.getEnd(); } catch (JavaModelException e) { Util.log(e); } } return false; }
From source file:org.codehaus.groovy.eclipse.dsl.inferencing.suggestions.SuggestionsRequestor.java
License:Apache License
protected boolean interestingElement(IJavaElement enclosingElement) { // the clinit is always interesting since the clinit contains static // initializers if (enclosingElement.getElementName().equals("<clinit>")) { return true; }/*www .j ava 2 s.c om*/ if (enclosingElement instanceof NamedMember) { try { ISourceRange range = ((ISourceReference) enclosingElement).getSourceRange(); return range.getOffset() <= nodeToLookFor.getStart() && range.getOffset() + range.getLength() >= nodeToLookFor.getEnd(); } catch (JavaModelException e) { Util.log(e); } } return false; }
From source file:org.codehaus.groovy.eclipse.refactoring.core.extract.InferParameterAndReturnTypesRequestor.java
License:Apache License
/** * @param enclosingElement/* w w w. j a va 2s . c o m*/ * @return true iff enclosingElement's source location contains the source * location of {@link #selectedText} */ private boolean interestingElement(IJavaElement enclosingElement) { // the clinit is always interesting since the clinit contains static // initializers if (enclosingElement.getElementName().equals("<clinit>")) { return true; } if (enclosingElement instanceof ISourceReference) { try { ISourceRange range = ((ISourceReference) enclosingElement).getSourceRange(); return range.getOffset() <= selectedText.getOffset() && range.getOffset() + range.getLength() >= selectedText.getEnd(); } catch (JavaModelException e) { Util.log(e); } } return false; }
From source file:org.codehaus.groovy.eclipse.refactoring.core.rename.renameLocal.LocalVariableNameCheckerRequestor.java
License:Apache License
/** * @param enclosingElement/*www . j a v a 2 s . c o m*/ * @return true iff enclosingElement's source location contains the source * location of {@link #variable} */ private boolean interestingElement(IJavaElement enclosingElement) { // the clinit is always interesting since the clinit contains static // initializers if (enclosingElement.getElementName().equals("<clinit>")) { return true; } if (start >= 0 && end >= 0 && enclosingElement instanceof ISourceReference) { try { ISourceRange range = ((ISourceReference) enclosingElement).getSourceRange(); return range.getOffset() <= start && range.getOffset() + range.getLength() >= end; } catch (JavaModelException e) { Util.log(e); } } return false; }
From source file:org.codehaus.groovy.eclipse.refactoring.formatter.GroovyBeautifier.java
License:Apache License
private void formatLists(MultiTextEdit edits) { ASTScanner scanner = new ASTScanner(formatter.getProgressRootNode(), new ListInCodePredicate(), formatter.getProgressDocument()); scanner.startASTscan();//from w ww.ja v a2 s .c o m for (ASTNode _node : scanner.getMatchedNodes().keySet()) { ListExpression node = ((ListExpression) _node); GroovyDocumentScanner tokens = formatter.getTokens(); Token lastToken = null; try { lastToken = tokens.getLastNonWhitespaceTokenBefore(node.getEnd() - 1); if (lastToken == null || lastToken.getType() == GroovyTokenTypeBridge.STRING_CTOR_START) { //This means we are inside a GString and we won't apply edits here so skip this continue; } } catch (BadLocationException e) { Util.log(e); continue; } int nodeStart = node.getStart(); int nodeEnd = node.getEnd(); int nodeLen = nodeEnd - nodeStart; boolean isLong = nodeLen > preferences.getLongListLength(); List<Expression> exps = node.getExpressions(); // GRECLIPSE-1427 if the next token is 'as', then don't add a // newline or remove whitespace Token maybeAs; try { maybeAs = tokens.getNextToken(lastToken); } catch (BadLocationException e) { GroovyCore.logException("Trouble getting next token", e); maybeAs = null; } boolean nextTokenAs = maybeAs != null && maybeAs.getType() == GroovyTokenTypeBridge.LITERAL_as; if (isLong || (hasClosureElement(node) && node.getExpressions().size() > 1)) { //Split the list for (int i = 0; i < exps.size(); i++) { Expression exp = exps.get(i); Token before = tokens.getLastTokenBefore(exp.getStart()); try { while (before.getType() != GroovyTokenTypeBridge.LBRACK && before.getType() != GroovyTokenTypeBridge.COMMA) { before = tokens.getLastTokenBefore(before); } replaceWhiteSpaceAfter(edits, before, formatter.getNewLine()); } catch (BadLocationException e) { GroovyCore.logException("Trouble formatting list", e); } } if (!nextTokenAs) { replaceWhiteSpaceAfter(edits, lastToken, formatter.getNewLine()); } } else { //Compact the list for (int i = 0; i < exps.size(); i++) { Expression exp = exps.get(i); Token before = tokens.getLastTokenBefore(exp.getStart()); try { while (before.getType() != GroovyTokenTypeBridge.LBRACK && before.getType() != GroovyTokenTypeBridge.COMMA) { before = tokens.getLastTokenBefore(before); } replaceWhiteSpaceAfter(edits, before, before.getType() == GroovyTokenTypeBridge.LBRACK ? "" : " "); } catch (BadLocationException e) { Util.log(e); } } if (!nextTokenAs) { replaceWhiteSpaceAfter(edits, lastToken, lastToken.getType() == GroovyTokenTypeBridge.SL_COMMENT ? formatter.getNewLine() : ""); } } } }
From source file:org.codehaus.groovy.eclipse.refactoring.formatter.GroovyBeautifier.java
License:Apache License
/** * Create an edit that replaces whitespace tokens immediately after given * token with a String./*from w w w .ja v a 2s. c o m*/ */ private void replaceWhiteSpaceAfter(MultiTextEdit edits, Token token, String replaceWith) { GroovyDocumentScanner tokens = formatter.getTokens(); try { int editStart = tokens.getEnd(token); Token first = tokens.getNextToken(token); // First whitespace token (if any) Token last = first; // First non-whitespace token // If no white space tokens where found then first and last will be // the same token // (i.e. token just after the given token while (isWhiteSpace(last.getType())) { last = tokens.getNextToken(last); } replaceFromTo(editStart, tokens.getOffset(last), replaceWith, edits); } catch (BadLocationException e) { Util.log(e); } }
From source file:org.codehaus.groovy.eclipse.refactoring.formatter.GroovyDocumentScanner.java
License:Apache License
private List<Token> getTokensIncludingEOF() { List<Token> result = new ArrayList<Token>(); Token token;//from w ww . j av a 2 s. c o m try { do { token = nextToken(); result.add(token); } while (token.getType() != GroovyTokenTypeBridge.EOF); } catch (Exception e) { if (logLimit-- > 0) { Util.log(e); } } return result; }
From source file:org.codehaus.jdt.groovy.integration.internal.GroovyIndexingVisitor.java
License:Open Source License
void doVisit(ModuleNode node, ImportReference pkg) { if (node == null) { // there is an unrecoverable compile problem. return;/* w w w .j a v a2 s . c o m*/ } // used for GRECLIPSE-741, remove when issue is solved module = node; try { this.visitImports(node); for (ClassNode clazz : (Iterable<ClassNode>) node.getClasses()) { this.visitClass(clazz); } } catch (RuntimeException e) { Util.log(e); } }
From source file:org.codehaus.jdt.groovy.integration.internal.GroovyIndexingVisitor.java
License:Open Source License
private void handleType(ClassNode node, boolean isAnnotation, boolean useQualifiedName) { if (node == null) { // GRECLIPSE-741 Util.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, "GRECLIPSE-741: module: " + module.getDescription(), new RuntimeException())); return;//from w ww .j av a 2 s . c o m } if (isAnnotation) { requestor.acceptAnnotationTypeReference(splitName(node, useQualifiedName), node.getStart(), node.getEnd()); } else { ClassNode componentType = node.getComponentType(); requestor.acceptTypeReference(splitName(componentType != null ? componentType : node, useQualifiedName), node.getStart(), node.getEnd()); } if (node.isUsingGenerics() && node.getGenericsTypes() != null) { for (GenericsType gen : node.getGenericsTypes()) { ClassNode lowerBound = gen.getLowerBound(); if (lowerBound != null) { handleType(lowerBound, lowerBound.isAnnotationDefinition(), true); } if (gen.getUpperBounds() != null) { for (ClassNode upper : gen.getUpperBounds()) { // handle enums where the upper bound is the same as the type if (!upper.getName().equals(node.getName())) { handleType(upper, upper.isAnnotationDefinition(), true); } } } ClassNode genType = gen.getType(); if (genType != null && gen.getName().charAt(0) != '?') { handleType(genType, genType.isAnnotationDefinition(), true); } } } }
From source file:org.codehaus.jdt.groovy.internal.compiler.ScriptFolderCompilationParticipant.java
License:Open Source License
/** * Some simple checks that we can do to ensure that the builder is set up properly * // w w w .j a v a 2s . c o m * @param files */ private void sanityCheckBuilder(BuildContext[] files) { // GRECLIPSE-1230 also do a check to ensure the proper compiler is being used if (!LanguageSupportFactory.isGroovyLanguageSupportInstalled()) { for (BuildContext buildContext : files) { buildContext.recordNewProblems(createProblem(buildContext)); } } // also check if this project has the JavaBuilder. // note that other builders (like the ajbuilder) may implement the CompilationParticipant API try { ICommand[] buildSpec = project.getProject().getDescription().getBuildSpec(); boolean found = false; for (ICommand command : buildSpec) { if (command.getBuilderName().equals(JavaCore.BUILDER_ID)) { found = true; break; } } if (!found) { for (BuildContext buildContext : files) { buildContext.recordNewProblems(createProblem(buildContext)); } } } catch (CoreException e) { Util.log(e); } }