List of usage examples for org.eclipse.jdt.core.compiler CharOperation splitAndTrimOn
public static final char[][] splitAndTrimOn(char divider, char[] array)
From source file:net.sf.j2s.core.builder.JavaBuilder.java
License:Open Source License
private int initializeBuilder(int kind, boolean forBuild) throws CoreException { // some calls just need the nameEnvironment initialized so skip the rest this.javaProject = (JavaProject) JavaCore.create(this.currentProject); this.workspaceRoot = this.currentProject.getWorkspace().getRoot(); if (forBuild) { // cache the known participants for this project this.participants = JavaModelManager.getJavaModelManager().compilationParticipants .getCompilationParticipants(this.javaProject); if (this.participants != null) for (int i = 0, l = this.participants.length; i < l; i++) if (this.participants[i] .aboutToBuild(this.javaProject) == CompilationParticipant.NEEDS_FULL_BUILD) kind = FULL_BUILD;//from ww w. j a v a 2 s. c om // Flush the existing external files cache if this is the beginning of a build cycle String projectName = this.currentProject.getName(); if (builtProjects == null || builtProjects.contains(projectName)) { try { Method method = JavaModel.class.getMethod("flushExternalFileCache", new Class[] { Void.class }); if (method != null) { method.invoke(JavaModel.class, new Object[0]); } } catch (Throwable e) { e.printStackTrace(); } //JavaModel.flushExternalFileCache(); builtProjects = new ArrayList(); } builtProjects.add(projectName); } this.binaryLocationsPerProject = new SimpleLookupTable(3); this.nameEnvironment = new NameEnvironment(this.workspaceRoot, this.javaProject, this.binaryLocationsPerProject, this.notifier); if (forBuild) { String filterSequence = this.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, true); char[][] filters = filterSequence != null && filterSequence.length() > 0 ? CharOperation.splitAndTrimOn(',', filterSequence.toCharArray()) : null; if (filters == null) { this.extraResourceFileFilters = null; this.extraResourceFolderFilters = null; } else { int fileCount = 0, folderCount = 0; for (int i = 0, l = filters.length; i < l; i++) { char[] f = filters[i]; if (f.length == 0) continue; if (f[f.length - 1] == '/') folderCount++; else fileCount++; } this.extraResourceFileFilters = new char[fileCount][]; this.extraResourceFolderFilters = new String[folderCount]; for (int i = 0, l = filters.length; i < l; i++) { char[] f = filters[i]; if (f.length == 0) continue; if (f[f.length - 1] == '/') this.extraResourceFolderFilters[--folderCount] = new String(f, 0, f.length - 1); else this.extraResourceFileFilters[--fileCount] = f; } } } return kind; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope.java
License:Open Source License
@Override public MethodBinding[] getAnyExtraMethods(char[] selector) { if (true) {// w w w . jav a 2 s . c o m return null; } List<MethodNode> mns = ((GroovyTypeDeclaration) referenceContext).getClassNode() .getMethods(new String(selector)); MethodBinding[] newMethods = new MethodBinding[mns.size()]; int idx = 0; for (MethodNode methodNode : mns) { TypeBinding[] parameterTypes = null; TypeBinding returnType = compilationUnitScope().environment.getResolvedType( CharOperation.splitAndTrimOn('.', methodNode.getReturnType().getName().toCharArray()), this); newMethods[idx++] = new MethodBinding(methodNode.getModifiers(), selector, returnType, parameterTypes, null, this.referenceContext.binding); } // unitScope.environment.getResolvedType(JAVA_LANG_STRING, this); return newMethods; }
From source file:org.eclipse.ajdt.core.codeconversion.AJSourceIndexerRequestor.java
License:Open Source License
/** * Here, we must index special AJ declarations like ITDs and declare parents/annotations *//* w ww.j a v a 2s .c o m*/ @Override public void enterField(FieldInfo fieldInfo) { super.enterField(fieldInfo); try { char[] fieldName = fieldInfo.name; char[] fieldType = fieldInfo.type; int last = CharOperation.lastIndexOf('$', fieldName) + 1; if (maybeDeclare(fieldName, fieldType)) { try { char[] contents = getContents(); BodyDeclaration node = PointcutUtilities.createSingleBodyDeclarationNode( fieldInfo.declarationStart, fieldInfo.node.sourceEnd, contents); if (node instanceof DeclareParentsDeclaration) { // found it! DeclareParentsDeclaration declare = (DeclareParentsDeclaration) node; // Visit the children AjASTVisitor typePatternVisitor = new AjASTVisitor() { protected void index(String tokenString) { char[][] tokens = tokenize(tokenString); for (char[] token : tokens) { // must accept an uknown reference since we don't really know if this is a type, method, or field reference // source position is wrong, but this is ok. AJSourceIndexerRequestor.super.acceptUnknownReference(token, 0); } // AJSourceIndexerRequestor.super // .acceptAnnotationTypeReference(tokens, // node.getStartPosition(), // node.getStartPosition() + node.getLength()); } public boolean visit(IdentifierTypePattern node) { index(node.getTypePatternExpression()); return true; } @Override public boolean visit(AnyWithAnnotationTypePattern node) { index(node.getTypePatternExpression()); return true; } @Override public boolean visit(TypeCategoryTypePattern node) { index(node.getTypePatternExpression()); return true; } @Override public boolean visit(SignaturePattern node) { index(node.getDetail()); return true; } //TODO: Add more as needed. Extract visitor to file if too large }; declare.accept(typePatternVisitor); } else if (node instanceof DeclareAnnotationDeclaration) { // found it! DeclareAnnotationDeclaration declare = (DeclareAnnotationDeclaration) node; SimpleName annotationName = declare.getAnnotationName(); // index the annotation name if (annotationName != null) { String annotationStr = annotationName.toString(); if (annotationStr.startsWith("@")) { annotationStr = annotationStr.substring(1, annotationStr.length()); } char[][] splitChars = CharOperation.splitOn('.', annotationStr.toCharArray()); super.acceptTypeReference(splitChars, annotationName.getStartPosition(), annotationName.getStartPosition() + annotationName.getLength()); } PatternNode targetPattern = declare.getPatternNode(); if (targetPattern instanceof IdentifierTypePattern) { String detail = ((IdentifierTypePattern) targetPattern).getTypePatternExpression(); char[][] tokens = detail != null ? CharOperation.splitOn('.', detail.toCharArray()) : null; super.acceptTypeReference(tokens, targetPattern.getStartPosition(), targetPattern.getStartPosition() + targetPattern.getLength()); } else if (targetPattern instanceof SignaturePattern) { char[][] tokens = tokenize(((SignaturePattern) targetPattern).getDetail()); for (char[] token : tokens) { // must accept an uknown reference since we don't really know if this is a type, method, or field reference // source position is wrong, but this is ok. super.acceptUnknownReference(token, targetPattern.getStartPosition()); } } } } catch (Exception e) { // lots of things can go wrong, so surround in a big try-catch block and log to the console } } else if (maybeITD(fieldName, last)) { // assume this is an itd char[][] splits = CharOperation.splitAndTrimOn('$', fieldName); // should be array of length 2 at least. Last element is the realMethodName // one before that is the simple name of the type // if more than length 2, then the rest are package names int length = splits.length; this.indexer.addFieldDeclaration(fieldInfo.type, splits[splits.length - 1]); if (length > 1) { // remove the last segment char[][] newSplits = new char[splits.length - 1][]; System.arraycopy(splits, 0, newSplits, 0, splits.length - 1); super.acceptUnknownReference(newSplits, fieldInfo.nameSourceStart, fieldInfo.nameSourceEnd - splits[length - 1].length - 1); } } } catch (Exception e) { } }
From source file:org.eclipse.ajdt.core.codeconversion.AJSourceIndexerRequestor.java
License:Open Source License
@Override public void enterMethod(MethodInfo methodInfo) { super.enterMethod(methodInfo); try {//from w w w . j ava 2s.co m char[] methodName = methodInfo.name; int last = CharOperation.lastIndexOf('$', methodName) + 1; if (maybeITD(methodName, last)) { // assume this is an itd char[] realMethodName = CharOperation.subarray(methodName, last, methodName.length); boolean isConstructor = false; if (CharOperation.equals("new".toCharArray(), realMethodName)) { isConstructor = true; } else { this.indexer.addMethodDeclaration(realMethodName, methodInfo.parameterTypes, methodInfo.returnType, methodInfo.exceptionTypes); } // now index the type if (last > 1) { char[][] splits = CharOperation.splitAndTrimOn('$', methodName); // should be array of length 2 at least. Last element is the realMethodName // one before that is the simple name of the type // if more than length 2, then the rest are package names int length = splits.length; if (length > 1) { // remove the last segment char[][] newSplits = new char[splits.length - 1][]; System.arraycopy(splits, 0, newSplits, 0, splits.length - 1); super.acceptUnknownReference(newSplits, methodInfo.nameSourceStart, methodInfo.nameSourceEnd - splits[length - 1].length - 1); if (isConstructor) { int argCount = methodInfo.parameterTypes == null ? 0 : methodInfo.parameterTypes.length; this.indexer.addConstructorDeclaration(splits[length - 2], argCount, null, methodInfo.parameterTypes, methodInfo.parameterNames, methodInfo.modifiers, methodInfo.declaringPackageName, methodInfo.declaringTypeModifiers, methodInfo.exceptionTypes, methodInfo.extraFlags); } } } } } catch (Exception e) { } }