List of usage examples for org.eclipse.jdt.core SourceRange SourceRange
public SourceRange(int offset, int length)
From source file:com.codenvy.ide.ext.java.server.internal.core.AnnotatableInfo.java
License:Open Source License
protected ISourceRange getNameRange() { return new SourceRange(this.nameStart, this.nameEnd - this.nameStart + 1); }
From source file:com.codenvy.ide.ext.java.server.internal.core.Annotation.java
License:Open Source License
public ISourceRange getNameRange() throws JavaModelException { SourceMapper mapper = getSourceMapper(); if (mapper != null) { ClassFile classFile = (ClassFile) getClassFile(); if (classFile != null) { // ensure the class file's buffer is open so that source ranges are computed classFile.getBuffer();// w w w . j a v a 2 s .c om return mapper.getNameRange(this); } } Object info = getElementInfo(); if (info instanceof AnnotationInfo) { AnnotationInfo annotationInfo = (AnnotationInfo) info; return new SourceRange(annotationInfo.nameStart, annotationInfo.nameEnd - annotationInfo.nameStart + 1); } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFile.java
License:Open Source License
/** * @see org.eclipse.jdt.core.ISourceReference */// w ww . j a v a 2s . com public ISourceRange getSourceRange() throws JavaModelException { IBuffer buffer = getBuffer(); if (buffer != null) { String contents = buffer.getContents(); if (contents == null) return null; return new SourceRange(0, contents.length()); } else { return null; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnitElementInfo.java
License:Open Source License
protected ISourceRange getSourceRange() { return new SourceRange(0, this.sourceLength); }
From source file:com.codenvy.ide.ext.java.server.internal.core.ImportContainer.java
License:Open Source License
/** * @see org.eclipse.jdt.core.ISourceReference *///www .ja va 2 s. c om public ISourceRange getSourceRange() throws JavaModelException { IJavaElement[] imports = getChildren(); ISourceRange firstRange = ((ISourceReference) imports[0]).getSourceRange(); ISourceRange lastRange = ((ISourceReference) imports[imports.length - 1]).getSourceRange(); SourceRange range = new SourceRange(firstRange.getOffset(), lastRange.getOffset() + lastRange.getLength() - firstRange.getOffset()); return range; }
From source file:com.codenvy.ide.ext.java.server.internal.core.LocalVariable.java
License:Open Source License
private IAnnotation getAnnotation(final org.eclipse.jdt.internal.compiler.ast.Annotation annotation, JavaElement parentElement) {/*from w w w.j a v a 2s.c o m*/ final int typeStart = annotation.type.sourceStart(); final int typeEnd = annotation.type.sourceEnd(); final int sourceStart = annotation.sourceStart(); final int sourceEnd = annotation.declarationSourceEnd; class LocalVarAnnotation extends Annotation { IMemberValuePair[] memberValuePairs; public LocalVarAnnotation(JavaElement localVar, String elementName) { super(localVar, localVar.manager, elementName); } public IMemberValuePair[] getMemberValuePairs() throws JavaModelException { return this.memberValuePairs; } public ISourceRange getNameRange() throws JavaModelException { return new SourceRange(typeStart, typeEnd - typeStart + 1); } public ISourceRange getSourceRange() throws JavaModelException { return new SourceRange(sourceStart, sourceEnd - sourceStart + 1); } public boolean exists() { return this.parent.exists(); } } String annotationName = new String(CharOperation.concatWith(annotation.type.getTypeName(), '.')); LocalVarAnnotation localVarAnnotation = new LocalVarAnnotation(parentElement, annotationName); org.eclipse.jdt.internal.compiler.ast.MemberValuePair[] astMemberValuePairs = annotation.memberValuePairs(); int length; IMemberValuePair[] memberValuePairs; if (astMemberValuePairs == null || (length = astMemberValuePairs.length) == 0) { memberValuePairs = Annotation.NO_MEMBER_VALUE_PAIRS; } else { memberValuePairs = new IMemberValuePair[length]; for (int i = 0; i < length; i++) { org.eclipse.jdt.internal.compiler.ast.MemberValuePair astMemberValuePair = astMemberValuePairs[i]; MemberValuePair memberValuePair = new MemberValuePair(new String(astMemberValuePair.name)); memberValuePair.value = getAnnotationMemberValue(memberValuePair, astMemberValuePair.value, localVarAnnotation); memberValuePairs[i] = memberValuePair; } } localVarAnnotation.memberValuePairs = memberValuePairs; return localVarAnnotation; }
From source file:com.codenvy.ide.ext.java.server.internal.core.LocalVariable.java
License:Open Source License
/** * {@inheritDoc}/*from w ww . j ava 2s.c o m*/ * @since 3.7 */ public ISourceRange getNameRange() { if (this.nameEnd == -1) { SourceMapper mapper = getSourceMapper(); if (mapper != null) { try { // ensure the class file's buffer is open so that source ranges are computed ClassFile classFile = (ClassFile) getClassFile(); if (classFile != null) { classFile.getBuffer(); return mapper.getNameRange(this); } } catch (JavaModelException e) { // ignore } } return SourceMapper.UNKNOWN_RANGE; } return new SourceRange(this.nameStart, this.nameEnd - this.nameStart + 1); }
From source file:com.codenvy.ide.ext.java.server.internal.core.LocalVariable.java
License:Open Source License
/** * {@inheritDoc}//from w w w . j a va 2 s . c om * @since 3.7 */ public ISourceRange getSourceRange() throws JavaModelException { if (this.declarationSourceEnd == -1) { SourceMapper mapper = getSourceMapper(); if (mapper != null) { // ensure the class file's buffer is open so that source ranges are computed ClassFile classFile = (ClassFile) getClassFile(); if (classFile != null) { classFile.getBuffer(); return mapper.getSourceRange(this); } } return SourceMapper.UNKNOWN_RANGE; } return new SourceRange(this.declarationSourceStart, this.declarationSourceEnd - this.declarationSourceStart + 1); }
From source file:com.codenvy.ide.ext.java.server.internal.core.Member.java
License:Open Source License
public ISourceRange getJavadocRange() throws JavaModelException { ISourceRange range = getSourceRange(); if (range == null) return null; IBuffer buf = null;//from w ww . j a v a 2s.c om if (isBinary()) { buf = getClassFile().getBuffer(); } else { ICompilationUnit compilationUnit = getCompilationUnit(); if (!compilationUnit.isConsistent()) { return null; } buf = compilationUnit.getBuffer(); } final int start = range.getOffset(); final int length = range.getLength(); if (length > 0 && buf.getChar(start) == '/') { IScanner scanner = ToolFactory.createScanner(true, false, false, false); try { scanner.setSource(buf.getText(start, length).toCharArray()); int docOffset = -1; int docEnd = -1; int terminal = scanner.getNextToken(); loop: while (true) { switch (terminal) { case ITerminalSymbols.TokenNameCOMMENT_JAVADOC: docOffset = scanner.getCurrentTokenStartPosition(); docEnd = scanner.getCurrentTokenEndPosition() + 1; terminal = scanner.getNextToken(); break; case ITerminalSymbols.TokenNameCOMMENT_LINE: case ITerminalSymbols.TokenNameCOMMENT_BLOCK: terminal = scanner.getNextToken(); continue loop; default: break loop; } } if (docOffset != -1) { return new SourceRange(docOffset + start, docEnd - docOffset); } } catch (InvalidInputException ex) { // try if there is inherited Javadoc } catch (IndexOutOfBoundsException e) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305001 } } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.Member.java
License:Open Source License
/** * @see IMember// w ww .jav a 2 s.c om */ public ISourceRange getNameRange() throws JavaModelException { MemberElementInfo info = (MemberElementInfo) getElementInfo(); return new SourceRange(info.getNameSourceStart(), info.getNameSourceEnd() - info.getNameSourceStart() + 1); }