List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding isClass
@Override public boolean isClass()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IType lookupType(ReferenceBinding typeBinding) { if (typeBinding == null || !typeBinding.isValidBinding()) return null; char[] packageName = typeBinding.qualifiedPackageName(); IPackageFragment[] pkgs = this.nameLookup.findPackageFragments( (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME : new String(packageName), false);// www. j ava 2 s . c o m // iterate type lookup in each package fragment char[] sourceName = typeBinding.qualifiedSourceName(); String typeName = new String(sourceName); int acceptFlag = 0; if (typeBinding.isAnnotationType()) { acceptFlag = NameLookup.ACCEPT_ANNOTATIONS; } else if (typeBinding.isEnum()) { acceptFlag = NameLookup.ACCEPT_ENUMS; } else if (typeBinding.isInterface()) { acceptFlag = NameLookup.ACCEPT_INTERFACES; } else if (typeBinding.isClass()) { acceptFlag = NameLookup.ACCEPT_CLASSES; } if (pkgs != null) { for (int i = 0, length = pkgs.length; i < length; i++) { IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag, true/*consider secondary types*/); if (type != null) return type; } } // search inside enclosing element char[][] qualifiedName = CharOperation.splitOn('.', sourceName); int length = qualifiedName.length; if (length == 0) return null; IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type if (type == null) return null; for (int i = 1; i < length; i++) { type = type.getType(new String(qualifiedName[i])); if (type == null) return null; } if (type.exists()) return type; return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.SuperTypeReferenceLocator.java
License:Open Source License
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { if (elementBinding instanceof ReferenceBinding) { ReferenceBinding referenceBinding = (ReferenceBinding) elementBinding; if (referenceBinding.isClass() && this.pattern.typeSuffix == IIndexConstants.INTERFACE_SUFFIX) { // do not report class if expected types are only interfaces return; }/*from ww w.j a v a 2 s . c o m*/ if (referenceBinding.isInterface() && this.pattern.typeSuffix == IIndexConstants.CLASS_SUFFIX) { // do not report interface if expected types are only classes return; } } super.matchReportReference(reference, element, elementBinding, accuracy, locator); }
From source file:com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.java
License:Apache License
private void checkRebindResultInstantiable(MessageSendSite site, String typeName) { /*//w w w . j av a 2 s .c o m * This causes the compiler to find the additional type, possibly winding * its back to ask for the compilation unit from the source oracle. */ ReferenceBinding type = resolvePossiblyNestedType(typeName); // Sanity check rebind results. if (type == null) { FindDeferredBindingSitesVisitor.reportRebindProblem(site, "Rebind result '" + typeName + "' could not be found"); return; } if (!type.isClass()) { FindDeferredBindingSitesVisitor.reportRebindProblem(site, "Rebind result '" + typeName + "' must be a class"); return; } if (type.isAbstract()) { FindDeferredBindingSitesVisitor.reportRebindProblem(site, "Rebind result '" + typeName + "' cannot be abstract"); return; } if (type.isNestedType() && !type.isStatic()) { FindDeferredBindingSitesVisitor.reportRebindProblem(site, "Rebind result '" + typeName + "' cannot be a non-static nested class"); return; } if (type.isLocalType()) { FindDeferredBindingSitesVisitor.reportRebindProblem(site, "Rebind result '" + typeName + "' cannot be a local class"); return; } // Look for a noArg ctor. MethodBinding noArgCtor = type.getExactConstructor(Binding.NO_PARAMETERS); if (noArgCtor == null) { FindDeferredBindingSitesVisitor.reportRebindProblem(site, "Rebind result '" + typeName + "' has no default (zero argument) constructors"); return; } }
From source file:com.google.gwt.dev.jjs.impl.BuildTypeMap.java
License:Apache License
private JDeclaredType createType(String name, SourceInfo info, ReferenceBinding binding) { JDeclaredType newType;/*from w w w . ja v a 2s. c o m*/ if (binding.isClass()) { newType = program.createClass(info, name, binding.isAbstract(), binding.isFinal()); } else if (binding.isInterface() || binding.isAnnotationType()) { newType = program.createInterface(info, name); } else if (binding.isEnum()) { if (binding.isAnonymousType()) { // Don't model an enum subclass as a JEnumType. newType = program.createClass(info, name, false, true); } else { newType = program.createEnum(info, name, binding.isAbstract()); } } else { throw new InternalCompilerException("ReferenceBinding is not a class, interface, or enum."); } info.addCorrelation(info.getCorrelator().by(newType)); /** * We emulate static initializers and instance initializers as methods. As * in other cases, this gives us: simpler AST, easier to optimize, more like * output JavaScript. Clinit is always in slot 0, init (if it exists) is * always in slot 1. */ SourceInfo child = info.makeChild(); JMethod clinit = program.createMethod(child, "$clinit", newType, program.getTypeVoid(), false, true, true, AccessModifier.PRIVATE, false); clinit.freezeParamTypes(); clinit.setSynthetic(); child.addCorrelation(info.getCorrelator().by(clinit)); if (newType instanceof JClassType) { child = info.makeChild(); JMethod init = program.createMethod(child, "$init", newType, program.getTypeVoid(), false, false, true, AccessModifier.PRIVATE, false); init.freezeParamTypes(); init.setSynthetic(); child.addCorrelation(info.getCorrelator().by(init)); } newType.setExternal(linker.isExternalType(newType.getName())); return newType; }
From source file:com.google.gwt.dev.jjs.impl.ReferenceMapper.java
License:Apache License
private JDeclaredType createType(ReferenceBinding binding) { String name = JdtUtil.asDottedString(binding.compoundName); SourceInfo info = SourceOrigin.UNKNOWN; if (binding.isClass()) { return new JClassType(info, name, binding.isAbstract(), binding.isFinal()); } else if (binding.isInterface() || binding.isAnnotationType()) { return new JInterfaceType(info, name); } else if (binding.isEnum()) { if (binding.isAnonymousType()) { // Don't model an enum subclass as a JEnumType. return new JClassType(info, name, false, true); } else {//from w ww .j a va 2 s. c o m return new JEnumType(info, name, binding.isAbstract()); } } else { throw new InternalCompilerException("ReferenceBinding is not a class, interface, or enum."); } }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IType lookupType(ReferenceBinding typeBinding) { if (typeBinding == null || !typeBinding.isValidBinding()) return null; char[] packageName = typeBinding.qualifiedPackageName(); IPackageFragment[] pkgs = this.nameLookup.findPackageFragments( (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME : new String(packageName), false);//from w w w .j av a 2 s . c om // iterate type lookup in each package fragment char[] sourceName = typeBinding.qualifiedSourceName(); String typeName = new String(sourceName); int acceptFlag = 0; if (typeBinding.isAnnotationType()) { acceptFlag = NameLookup.ACCEPT_ANNOTATIONS; } else if (typeBinding.isEnum()) { acceptFlag = NameLookup.ACCEPT_ENUMS; } else if (typeBinding.isInterface()) { acceptFlag = NameLookup.ACCEPT_INTERFACES; } else if (typeBinding.isClass()) { acceptFlag = NameLookup.ACCEPT_CLASSES; } if (pkgs != null) { for (int i = 0, length = pkgs.length; i < length; i++) { IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag, false, true/*consider secondary types*/); if (type != null) return type; } } // search inside enclosing element char[][] qualifiedName = CharOperation.splitOn('.', sourceName); int length = qualifiedName.length; if (length == 0) return null; IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type if (type == null) return null; for (int i = 1; i < length; i++) { type = type.getType(new String(qualifiedName[i])); if (type == null) return null; } if (type.exists()) return type; return null; }
From source file:org.eclipse.che.jdt.internal.core.search.matching.SuperTypeReferenceLocator.java
License:Open Source License
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { if (elementBinding instanceof ReferenceBinding) { ReferenceBinding referenceBinding = (ReferenceBinding) elementBinding; if (referenceBinding.isClass() && this.pattern.typeSuffix == IIndexConstants.INTERFACE_SUFFIX) { // do not report class if expected types are only interfaces return; }// w ww .j a v a 2s. c om if (referenceBinding.isInterface() && this.pattern.typeSuffix == IIndexConstants.CLASS_SUFFIX) { // do not report interface if expected types are only classes return; } } super.matchReportReference(reference, element, elementBinding, accuracy, locator); }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IType lookupType(ReferenceBinding typeBinding) { if (typeBinding == null) return null; char[] packageName = typeBinding.qualifiedPackageName(); IPackageFragment[] pkgs = this.nameLookup.findPackageFragments( (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME : new String(packageName), false);/*from ww w . j a v a 2 s. c om*/ // iterate type lookup in each package fragment char[] sourceName = typeBinding.qualifiedSourceName(); String typeName = new String(sourceName); int acceptFlag = 0; if (typeBinding.isAnnotationType()) { acceptFlag = NameLookup.ACCEPT_ANNOTATIONS; } else if (typeBinding.isEnum()) { acceptFlag = NameLookup.ACCEPT_ENUMS; } else if (typeBinding.isInterface()) { acceptFlag = NameLookup.ACCEPT_INTERFACES; } else if (typeBinding.isClass()) { acceptFlag = NameLookup.ACCEPT_CLASSES; } if (pkgs != null) { for (int i = 0, length = pkgs.length; i < length; i++) { IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag, true/*consider secondary types*/); if (type != null) return type; } } // search inside enclosing element char[][] qualifiedName = CharOperation.splitOn('.', sourceName); int length = qualifiedName.length; if (length == 0) return null; IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type if (type == null) return null; for (int i = 1; i < length; i++) { type = type.getType(new String(qualifiedName[i])); if (type == null) return null; } if (type.exists()) return type; return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java
License:Open Source License
/** Process all late roles of teamModel, to have the same state as teamModel. */ public static void lateRolesCatchup(TeamModel teamModel) { if (teamModel.getBinding() == null) return; // too early to catch up. // TODO(SH): enable when needed: // CopyInheritance.sortRoles(teamModel.getBinding()); ReferenceBinding[] memberTypes = teamModel.getBinding().memberTypes(); int startState = StateHelper.minimalState(memberTypes) + 1; // loop over all relevant states, to ensure consistent processing of class and ifc part: for (int nextState = startState; nextState <= teamModel._state.getProcessingState(); nextState++) { if (nextState == ITranslationStates.STATE_FINAL) break; // don't try to reach STATE_FINAL via ensureRoleState. for (int i = 0; i < memberTypes.length; i++) { ReferenceBinding memberType = memberTypes[i]; if (memberType.isRole()) {// could be enum RoleModel roleModel = memberType.roleModel; // only process, if no processing is in progress: if (StateHelper.isReadyToProcess(roleModel, nextState)) ensureRoleState(roleModel, nextState); else roleModel._state.requestState(roleModel.getAst(), nextState); }/*from ww w . j a va2s. c o m*/ } } // has this team already resolved its regular memberTypes? catch up: if (teamModel.getState() == ITranslationStates.STATE_RESOLVED - 1 && teamModel._state.hasMethodResolveStarted()) { ClassScope scope = teamModel.getAst().scope; for (int i = 0; i < memberTypes.length; i++) { ReferenceBinding memberType = memberTypes[i]; if (memberType.isRole() && memberType.isClass()) {// could be enum RoleModel classModel = memberType.roleModel; if (classModel != null && classModel.getAst() != null && classModel.getAst().isRoleFile()) if (classModel._state.getProcessingState() < ITranslationStates.STATE_RESOLVED) classModel.getAst().resolve(scope); } } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java
License:Open Source License
private static boolean establishMethodsCreated(RoleModel clazz) { TypeDeclaration teamType = clazz.getTeamModel().getAst(); ReferenceBinding subRole = clazz.getBinding(); TypeDeclaration subRoleDecl = clazz.getAst(); if (subRole == null) { // extra caution, none of the code below would work clazz.setState(STATE_METHODS_CREATED); return false; }//w w w .ja v a2s . c o m if (OTNameUtils.isTSuperMarkerInterface(clazz.getInternalName()) || teamType == null) { // 0. binary only: create OTRE-generated methods: if (subRole.isBinaryBinding()) ((BinaryTypeBinding) subRole).createOTREMethods(clazz); clazz.setState(STATE_METHODS_CREATED); return true; // nothing to do } SourceTypeBinding subTeam = teamType.binding; if (subRoleDecl == null) { // 1. create creation methods from constructors (binding version): // TODO (SH): currently, this is only invoked for roles that are // explicitly mentioned in classes being compiled. // Need a place to store a list of previously compiled roles! if (subRole.isClass() // interfaces have not constructores, don't bother. && !subRole.isLocalType()) // local types need no creators, are only copied along with their containing method { createCreators(clazz, teamType, subRole, subTeam); } // no steps 2.+3. } // Next translations only for source types (no role nested types) if (subRoleDecl != null && subRole.isDirectRole()) { // 1. create creation methods from constructors (AST version) if (subRole.isClass()) // interfaces have not constructores, don't bother. createCtorsAndCreators(clazz, teamType, subRoleDecl, subTeam); // 2. create getTeam methods: if (subRoleDecl.isInterface()) { // process class and ifc at the same time, because otherwise an error // somewhere along the line may cause inconsistency between them two. StandardElementGenerator.createGetTeamMethod(subRoleDecl); TypeDeclaration classPart = clazz.getClassPartAst(); if (classPart != null) StandardElementGenerator.createGetTeamMethod(classPart); } // 3. add methods from non-role super-class to the ifc-part if (!subRole.isInterface()) RoleSplitter.setupInterfaceForExtends(clazz.getTeamModel().getAst(), subRoleDecl, clazz.getInterfaceAst()); } // 4. cast and getClass methods (independent of the source/binary difference): if (subRole.isInterface() && (subRoleDecl == null || needMethodBodies(subRoleDecl) || subRoleDecl.isRoleFile())) { TypeDeclaration sourceType = subRoleDecl != null ? subRoleDecl : teamType; TypeDeclaration classPart = clazz.getClassPartAst(); if (classPart != null) StandardElementGenerator.createCastMethod(clazz.getTeamModel(), classPart, /*dims*/ 0); // FIXME dimensions else // difference is only in source positions used. StandardElementGenerator.getCastMethod(clazz.getTeamModel(), subRole, teamType.scope, /*dims*/ 0, false, sourceType.sourceStart, sourceType.sourceEnd); // FIXME dimensions if (subRole.isPublic()) RoleClassLiteralAccess.ensureGetClassMethod(teamType.getTeamModel(), clazz); } // 5. special case roles which need an abstract _OT$getBase() method: StandardElementGenerator.createGetBaseForUnboundLowerable(clazz); // 6. resolve method mappings and create callout methods: MethodMappingResolver resolver = resolveCalloutMappings(clazz); CalloutImplementor.transformCallouts(clazz); if (resolver != null) resolver.resolve(false/*doCallout*/); // callins last so all methods incl. callout are already in place if (subRoleDecl != null) checkMissingMethods(subRole, subRoleDecl); clazz.setState(STATE_METHODS_CREATED); return true; }