List of usage examples for org.eclipse.jdt.internal.core CompilationUnit getContents
@Override public char[] getContents()
From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitProblemFinder.java
License:Open Source License
/** * checks that the selection of the categorizedProblem is 'this' * @param categorizedProblem// w w w . j ava 2 s.com * @param unit * @return */ private static boolean isThisExpression(CategorizedProblem p, CompilationUnit unit) { char[] contents = unit.getContents(); return p.getSourceEnd() < contents.length && p.getSourceEnd() - p.getSourceStart() == 3 && contents[p.getSourceStart()] == 't' && contents[p.getSourceStart() + 1] == 'h' && contents[p.getSourceStart() + 2] == 'i' && contents[p.getSourceStart() + 3] == 's'; }
From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitProblemFinder.java
License:Open Source License
private static String extractProblemRegion(CategorizedProblem categorizedProblem, CompilationUnit unit) { char[] contents = unit.getContents(); StringBuffer sb = new StringBuffer(); for (int i = categorizedProblem.getSourceStart(); i < categorizedProblem.getSourceEnd() + 1 && i < contents.length; i++) { sb.append(contents[i]);/*from ww w. ja v a 2 s . c o m*/ } return sb.toString(); }
From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitProblemFinder.java
License:Open Source License
private static String extractNextJavaIdentifier(CompilationUnit unit, int start) { char[] contents = unit.getContents(); StringBuffer sb = new StringBuffer(); int next = start; while (!Character.isJavaIdentifierStart(contents[next]) && next < contents.length) { next++;/*from ww w .j av a 2 s .com*/ } while (Character.isJavaIdentifierPart(contents[next]) && next < contents.length) { sb.append(contents[next++]); } return sb.toString(); }
From source file:org.eclipse.jdt.internal.core.CompilationUnit.java
License:Open Source License
public void restore() throws JavaModelException { if (!isWorkingCopy()) return;/*from w w w . j av a 2 s . c om*/ CompilationUnit original = (CompilationUnit) getOriginalElement(); IBuffer buffer = getBuffer(); if (buffer == null) return; buffer.setContents(original.getContents()); updateTimeStamp(original); makeConsistent(null); }
From source file:org.grails.ide.eclipse.search.test.AbstractGrailsSearchParticipantTest.java
License:Open Source License
public static AbstractGrailsSearchParticipantTest.MatchInfo methodMatch(IJavaProject javaProject, String packageName, String className, String methodName, String findString) throws JavaModelException { IType type = javaProject.findType(packageName + "." + className); IMethod method = null;//from www .j a va 2 s. c o m for (IMethod m : type.getMethods()) { if (m.getElementName().equals(methodName)) { assertNull("Ambiguous: there are multple methods with the name '" + methodName + "' in the class '" + type.getFullyQualifiedName(), method); method = m; } } CompilationUnit cu = (CompilationUnit) method.getCompilationUnit(); int methodStart = method.getSourceRange().getOffset(); int methodLen = method.getSourceRange().getLength(); int start = new String(cu.getContents()).indexOf(findString, methodStart); int len = findString.length(); assertTrue(methodStart > 0); assertTrue(methodLen > 0); assertTrue(start >= methodStart); assertTrue(start + len <= methodStart + methodLen); return new AbstractGrailsSearchParticipantTest.MatchInfo(method, start, len).adjustForQuotes(findString); }
From source file:org.grails.ide.eclipse.search.test.AbstractGrailsSearchParticipantTest.java
License:Open Source License
public static AbstractGrailsSearchParticipantTest.MatchInfo fieldMatch(IJavaProject javaProject, String packageName, String className, String fieldName, String findString) throws JavaModelException { IField field = field(javaProject, packageName, className, fieldName); CompilationUnit cu = (CompilationUnit) field.getCompilationUnit(); int fieldStart = field.getSourceRange().getOffset(); int fieldLen = field.getSourceRange().getLength(); int start = new String(cu.getContents()).indexOf(findString, fieldStart); int len = findString.length(); assertTrue(fieldStart > 0);/*from w w w . j a v a 2 s .c o m*/ assertTrue(fieldLen > 0); assertTrue(start >= fieldStart); assertTrue(start + len <= fieldStart + fieldLen); return new AbstractGrailsSearchParticipantTest.MatchInfo(field, start, len).adjustForQuotes(findString); }