List of usage examples for org.eclipse.jdt.internal.compiler.env IBinaryType getName
char[] getName();
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ClassFileMatchLocator.java
License:Open Source License
private boolean checkDeclaringType(IBinaryType enclosingBinaryType, char[] simpleName, char[] qualification, boolean isCaseSensitive, boolean isCamelCase) { if (simpleName == null && qualification == null) return true; if (enclosingBinaryType == null) return true; char[] declaringTypeName = convertClassFileFormat(enclosingBinaryType.getName()); return checkTypeName(simpleName, qualification, declaringTypeName, isCaseSensitive, isCamelCase); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ClassFileMatchLocator.java
License:Open Source License
boolean matchTypeDeclaration(TypeDeclarationPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) { if (!(binaryInfo instanceof IBinaryType)) return false; IBinaryType type = (IBinaryType) binaryInfo; char[] fullyQualifiedTypeName = convertClassFileFormat(type.getName()); boolean qualifiedPattern = pattern instanceof QualifiedTypeDeclarationPattern; if (pattern.enclosingTypeNames == null || qualifiedPattern) { char[] simpleName = (pattern.getMatchMode() == SearchPattern.R_PREFIX_MATCH) ? CharOperation.concat(pattern.simpleName, IIndexConstants.ONE_STAR) : pattern.simpleName;//w w w .j ava 2 s . com char[] pkg = qualifiedPattern ? ((QualifiedTypeDeclarationPattern) pattern).qualification : pattern.pkg; if (!checkTypeName(simpleName, pkg, fullyQualifiedTypeName, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; } else { char[] enclosingTypeName = CharOperation.concatWith(pattern.enclosingTypeNames, '.'); char[] patternString = pattern.pkg == null ? enclosingTypeName : CharOperation.concat(pattern.pkg, enclosingTypeName, '.'); if (!checkTypeName(pattern.simpleName, patternString, fullyQualifiedTypeName, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; } int kind = TypeDeclaration.kind(type.getModifiers()); switch (pattern.typeSuffix) { case CLASS_SUFFIX: return kind == TypeDeclaration.CLASS_DECL; case INTERFACE_SUFFIX: return kind == TypeDeclaration.INTERFACE_DECL; case ENUM_SUFFIX: return kind == TypeDeclaration.ENUM_DECL; case ANNOTATION_TYPE_SUFFIX: return kind == TypeDeclaration.ANNOTATION_TYPE_DECL; case CLASS_AND_INTERFACE_SUFFIX: return kind == TypeDeclaration.CLASS_DECL || kind == TypeDeclaration.INTERFACE_DECL; case CLASS_AND_ENUM_SUFFIX: return kind == TypeDeclaration.CLASS_DECL || kind == TypeDeclaration.ENUM_DECL; case INTERFACE_AND_ANNOTATION_SUFFIX: return kind == TypeDeclaration.INTERFACE_DECL || kind == TypeDeclaration.ANNOTATION_TYPE_DECL; case TYPE_SUFFIX: // nothing } return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.SourceMapper.java
License:Open Source License
/** * Maps the given source code to the given binary type and its children. * If a non-null java element is passed, finds the name range for the * given java element without storing it. *//* w w w . ja va 2 s . c o m*/ public synchronized ISourceRange mapSource(IType type, char[] contents, IBinaryType info, IJavaElement elementToFind) { this.binaryType = (BinaryType) type; // check whether it is already mapped if (this.sourceRanges.get(type) != null) return (elementToFind != null) ? getNameRange(elementToFind) : null; this.importsTable.remove(this.binaryType); this.importsCounterTable.remove(this.binaryType); this.searchedElement = elementToFind; this.types = new IType[1]; this.typeDeclarationStarts = new int[1]; this.typeNameRanges = new SourceRange[1]; this.typeModifiers = new int[1]; this.typeDepth = -1; this.memberDeclarationStart = new int[1]; this.memberName = new String[1]; this.memberNameRange = new SourceRange[1]; this.methodParameterTypes = new char[1][][]; this.methodParameterNames = new char[1][][]; this.anonymousCounter = 0; HashMap oldSourceRanges = null; if (elementToFind != null) { oldSourceRanges = (HashMap) this.sourceRanges.clone(); } try { IProblemFactory factory = new DefaultProblemFactory(); SourceElementParser parser = null; this.anonymousClassName = 0; if (info == null) { try { info = (IBinaryType) this.binaryType.getElementInfo(); } catch (JavaModelException e) { return null; } } boolean isAnonymousClass = info.isAnonymous(); char[] fullName = info.getName(); if (isAnonymousClass) { String eltName = this.binaryType.getParent().getElementName(); eltName = eltName.substring(eltName.lastIndexOf('$') + 1, eltName.length()); try { this.anonymousClassName = Integer.parseInt(eltName); } catch (NumberFormatException e) { // ignore } } boolean doFullParse = hasToRetrieveSourceRangesForLocalClass(fullName); parser = new SourceElementParser(this, factory, new CompilerOptions(this.options), doFullParse, true/*optimize string literals*/); parser.javadocParser.checkDocComment = false; // disable javadoc parsing IJavaElement javaElement = this.binaryType.getCompilationUnit(); if (javaElement == null) javaElement = this.binaryType.getParent(); parser.parseCompilationUnit( new BasicCompilationUnit(contents, null, this.binaryType.sourceFileName(info), javaElement), doFullParse, null/*no progress*/); if (elementToFind != null) { ISourceRange range = getNameRange(elementToFind); return range; } else { return null; } } finally { if (elementToFind != null) { this.sourceRanges = oldSourceRanges; } this.binaryType = null; this.searchedElement = null; this.types = null; this.typeDeclarationStarts = null; this.typeNameRanges = null; this.typeDepth = -1; } }
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTModelLoader.java
License:Open Source License
private ClassMirror buildClassMirror(String name) { try {//from ww w .ja v a 2 s .co m IType type = javaProject.findType(name); if (type == null) { return null; } LookupEnvironment theLookupEnvironment = getLookupEnvironment(); if (type.isBinary()) { ClassFile classFile = (ClassFile) type.getClassFile(); if (classFile != null) { IPackageFragmentRoot fragmentRoot = classFile.getPackageFragmentRoot(); if (fragmentRoot != null) { if (isInCeylonClassesOutputFolder(fragmentRoot.getPath())) { return null; } } IFile classFileRsrc = (IFile) classFile.getCorrespondingResource(); IBinaryType binaryType = classFile.getBinaryTypeInfo(classFileRsrc, true); if (classFileRsrc != null && !classFileRsrc.exists()) { //the .class file has been deleted return null; } BinaryTypeBinding binaryTypeBinding = theLookupEnvironment.cacheBinaryType(binaryType, null); if (binaryTypeBinding == null) { char[][] compoundName = CharOperation.splitOn('/', binaryType.getName()); ReferenceBinding existingType = theLookupEnvironment.getCachedType(compoundName); if (existingType == null || !(existingType instanceof BinaryTypeBinding)) { return null; } binaryTypeBinding = (BinaryTypeBinding) existingType; } return new JDTClass(binaryTypeBinding, theLookupEnvironment); } } else { char[][] compoundName = CharOperation.splitOn('.', type.getFullyQualifiedName().toCharArray()); ReferenceBinding referenceBinding = theLookupEnvironment.getType(compoundName); if (referenceBinding != null) { if (referenceBinding instanceof ProblemReferenceBinding) { ProblemReferenceBinding problemReferenceBinding = (ProblemReferenceBinding) referenceBinding; if (problemReferenceBinding.problemId() == ProblemReasons.InternalNameProvided) { referenceBinding = problemReferenceBinding.closestReferenceMatch(); } else { System.out.println(ProblemReferenceBinding .problemReasonString(problemReferenceBinding.problemId())); return null; } } return new JDTClass(referenceBinding, theLookupEnvironment); } } } catch (JavaModelException e) { e.printStackTrace(); } return null; }
From source file:io.gige.compiler.internal.HookedJavaFileObject.java
License:Open Source License
protected void closed() { if (!_closed) { _closed = true;// w ww . j a va 2 s. com // TODO: support encoding switch (this.getKind()) { case SOURCE: CompilationUnit unit = new CompilationUnit(null, _fileName, null /* encoding */); _filer.addNewUnit(unit); break; case CLASS: IBinaryType binaryType = null; try { binaryType = ClassFileReader.read(_fileName); } catch (ClassFormatException e) { /* * When the annotation processor produces garbage, javac * seems to show some resilience, by hooking the source * type, which since is resolved can answer annotations * during discovery - Not sure if this sanctioned by the * spec, to be taken up with Oracle. Here we mimic the bug, * see that addNewClassFile is simply collecting * ReferenceBinding's, so adding a SourceTypeBinding works * just fine. */ ReferenceBinding type = this._filer._env.getCompiler().lookupEnvironment .getType(CharOperation.splitOn('.', _typeName.toCharArray())); if (type != null) _filer.addNewClassFile(type); } catch (IOException e) { // ignore } if (binaryType != null) { char[] name = binaryType.getName(); ReferenceBinding type = this._filer._env.getCompiler().lookupEnvironment .getType(CharOperation.splitOn('/', name)); if (type != null && type.isValidBinding()) { if (type.isBinaryBinding()) { _filer.addNewClassFile(type); } else { BinaryTypeBinding binaryBinding = new BinaryTypeBinding(type.getPackage(), binaryType, this._filer._env.getCompiler().lookupEnvironment, true); if (binaryBinding != null) _filer.addNewClassFile(binaryBinding); } } } break; case HTML: case OTHER: break; } } }
From source file:org.eclipse.che.jdt.BinaryTypeConvector.java
License:Open Source License
public static String toJsonBinaryType(IBinaryType type) { JsonObject object = new JsonObject(); object.add("annotations", toJsonAnnotations(type.getAnnotations())); object.add("enclosingMethod", type.getEnclosingMethod() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.getEnclosingMethod()))); object.add("enclosingTypeName", type.getEnclosingTypeName() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.getEnclosingTypeName()))); object.add("fields", toJsonFields(type.getFields())); object.add("genericSignature", type.getGenericSignature() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.getGenericSignature()))); object.add("interfaceNames", toJsonArrayString(type.getInterfaceNames())); object.add("memberTypes", toJsonMemberTypes(type.getMemberTypes())); object.add("methods", toJsonMethods(type.getMethods())); object.add("missingTypeNames", toJsonMissingTypeNames(type.getMissingTypeNames())); object.add("name", type.getName() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.getName()))); object.add("sourceName", type.getSourceName() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.getSourceName()))); object.add("superclassName", type.getSuperclassName() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.getSuperclassName()))); object.add("tagBits", new JsonPrimitive(String.valueOf(type.getTagBits()))); object.add("anonymous", new JsonPrimitive(type.isAnonymous())); object.add("local", new JsonPrimitive(type.isLocal())); object.add("member", new JsonPrimitive(type.isMember())); object.add("sourceFileName", type.sourceFileName() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.sourceFileName()))); object.add("modifiers", new JsonPrimitive(type.getModifiers())); object.add("binaryType", new JsonPrimitive(type.isBinaryType())); object.add("fileName", type.getFileName() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(type.getFileName()))); return gson.toJson(object); }
From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyBuilder.java
License:Open Source License
/** * Looks up and returns a handle for the given binary info. *//*w ww .ja v a 2 s .co m*/ protected IType lookupBinaryHandle(IBinaryType typeInfo) { int flag; String qualifiedName; switch (TypeDeclaration.kind(typeInfo.getModifiers())) { case TypeDeclaration.CLASS_DECL: flag = NameLookup.ACCEPT_CLASSES; break; case TypeDeclaration.INTERFACE_DECL: flag = NameLookup.ACCEPT_INTERFACES; break; case TypeDeclaration.ENUM_DECL: flag = NameLookup.ACCEPT_ENUMS; break; default: //case IGenericType.ANNOTATION : flag = NameLookup.ACCEPT_ANNOTATIONS; break; } char[] bName = typeInfo.getName(); qualifiedName = new String(ClassFile.translatedName(bName)); if (qualifiedName.equals(this.focusQualifiedName)) return getType(); NameLookup.Answer answer = this.nameLookup.findType(qualifiedName, false, flag, true/* consider secondary types */, false/* do NOT wait for indexes */, false/*don't check restrictions*/, null); return answer == null || answer.type == null || !answer.type.isBinary() ? null : answer.type; }
From source file:org.eclipse.jdt.internal.core.SourceMapper.java
License:Open Source License
/** * Maps the given source code to the given binary type and its children. * If a non-null java element is passed, finds the name range for the * given java element without storing it. */// w w w . jav a 2s. c om public synchronized ISourceRange mapSource(IType type, char[] contents, IBinaryType info, IJavaElement elementToFind) { this.binaryType = (BinaryType) type; // check whether it is already mapped if (this.sourceRanges.get(type) != null) return (elementToFind != null) ? getNameRange(elementToFind) : null; this.importsTable.remove(this.binaryType); this.importsCounterTable.remove(this.binaryType); this.searchedElement = elementToFind; this.types = new IType[1]; this.typeDeclarationStarts = new int[1]; this.typeNameRanges = new SourceRange[1]; this.typeModifiers = new int[1]; this.typeDepth = -1; this.memberDeclarationStart = new int[1]; this.memberName = new String[1]; this.memberNameRange = new SourceRange[1]; this.methodParameterTypes = new char[1][][]; this.methodParameterNames = new char[1][][]; this.anonymousCounter = 0; HashMap oldSourceRanges = null; if (elementToFind != null) { oldSourceRanges = (HashMap) this.sourceRanges.clone(); } try { IProblemFactory factory = new DefaultProblemFactory(); SourceElementParser parser = null; this.anonymousClassName = 0; if (info == null) { try { info = (IBinaryType) this.binaryType.getElementInfo(); } catch (JavaModelException e) { return null; } } boolean isAnonymousClass = info.isAnonymous(); char[] fullName = info.getName(); if (isAnonymousClass) { String eltName = this.binaryType.getParent().getElementName(); eltName = eltName.substring(eltName.lastIndexOf('$') + 1, eltName.length()); try { this.anonymousClassName = Integer.parseInt(eltName); } catch (NumberFormatException e) { // ignore } } boolean doFullParse = hasToRetrieveSourceRangesForLocalClass(fullName); // GROOVY start /* old { parser = new SourceElementParser(this, factory, new CompilerOptions(this.options), doFullParse, true/*optimize string literals..); } new */ parser = LanguageSupportFactory.getSourceElementParser(this, factory, new CompilerOptions(this.options), doFullParse, true/*optimize string literals*/, true); // GROOVY end parser.javadocParser.checkDocComment = false; // disable javadoc parsing IJavaElement javaElement = this.binaryType.getCompilationUnit(); if (javaElement == null) javaElement = this.binaryType.getParent(); parser.parseCompilationUnit( new BasicCompilationUnit(contents, null, this.binaryType.sourceFileName(info), javaElement), doFullParse, null/*no progress*/); // GROOVY start // if this is an interesting file in an interesting project, // then filter out all binary members that do not have a direct // mapping to the source IProject project = javaElement.getJavaProject().getProject(); if (LanguageSupportFactory.isInterestingProject(project) && LanguageSupportFactory.isInterestingSourceFile(this.binaryType.getSourceFileName(info))) { LanguageSupportFactory.filterNonSourceMembers(this.binaryType); } // GROOVY end if (elementToFind != null) { ISourceRange range = getNameRange(elementToFind); return range; } else { return null; } } finally { if (elementToFind != null) { this.sourceRanges = oldSourceRanges; } this.binaryType = null; this.searchedElement = null; this.types = null; this.typeDeclarationStarts = null; this.typeNameRanges = null; this.typeDepth = -1; } }