List of usage examples for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding isInterface
@Override public boolean isInterface()
From source file:com.google.gwt.dev.jjs.impl.GwtAstBuilder.java
License:Apache License
private void createTypes(TypeDeclaration x) { SourceInfo info = makeSourceInfo(x); try {// www. j a va 2 s.c o m SourceTypeBinding binding = x.binding; String name; if (binding instanceof LocalTypeBinding) { char[] localName = binding.constantPoolName(); name = new String(localName).replace('/', '.'); } else { name = JdtUtil.asDottedString(binding.compoundName); } name = intern(name); JDeclaredType type; String jsPrototype = JsInteropUtil.maybeGetJsTypePrototype(x); JsInteropType interopType = JsInteropUtil.maybeGetJsInteropType(x, jsPrototype); if (binding.isClass()) { type = new JClassType(info, name, binding.isAbstract(), binding.isFinal(), interopType); JsInteropUtil.maybeSetJsPrototypeFlag(x, (JClassType) type); } else if (binding.isInterface() || binding.isAnnotationType()) { type = new JInterfaceType(info, name, interopType, jsPrototype); } else if (binding.isEnum()) { if (binding.isAnonymousType()) { // Don't model an enum subclass as a JEnumType. type = new JClassType(info, name, false, true, interopType); } else { type = new JEnumType(info, name, binding.isAbstract(), interopType); } } else { throw new InternalCompilerException("ReferenceBinding is not a class, interface, or enum."); } typeMap.setSourceType(binding, type); newTypes.add(type); if (x.memberTypes != null) { for (TypeDeclaration memberType : x.memberTypes) { createTypes(memberType); } } } catch (Throwable e) { InternalCompilerException ice = translateException(null, e); StringBuffer sb = new StringBuffer(); x.printHeader(0, sb); ice.addNode(x.getClass().getName(), sb.toString(), info); throw ice; } }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope.java
License:Open Source License
/** * Add any groovy specific method bindings to the set determined by the compiler. These *//*from w w w . jav a2s. c o m*/ @Override protected MethodBinding[] augmentMethodBindings(MethodBinding[] methodBindings) { // Don't add these methods to annotations SourceTypeBinding binding = this.referenceContext.binding; if (binding != null && (binding.isAnnotationType() || binding.isInterface())) { return methodBindings; } boolean implementsGroovyLangObject = false; ReferenceBinding[] superInterfaces = binding.superInterfaces; if (superInterfaces != null) { for (int i = 0, max = superInterfaces.length; i < max; i++) { char[][] interfaceName = superInterfaces[i].compoundName; if (CharOperation.equals(interfaceName, GROOVY_LANG_GROOVYOBJECT)) { implementsGroovyLangObject = true; break; } } } List<MethodBinding> groovyMethods = new ArrayList<MethodBinding>(); // If we don't then a supertype did and these methods do not have to be added here if (implementsGroovyLangObject) { if (debugListener != null) { debugListener.record("augment: type " + new String(this.referenceContext.name) + " having GroovyObject methods added"); } TypeBinding bindingJLO = getJavaLangObject(); TypeBinding bindingJLS = getJavaLangString(); TypeBinding bindingGLM = getGroovyLangMetaClassBinding(); // Now add the groovy.lang.GroovyObject methods: // // Object invokeMethod(String name, Object args); // Object getProperty(String propertyName); // void setProperty(String propertyName, Object newValue); // MetaClass getMetaClass(); // void setMetaClass(MetaClass metaClass); // Note on synthetic // javac/ecj don't see synthetic methods when considering if a type implements an interface. So don't make these // synthetic // Visibility is public and possibly static/abstract depending on the containing type createMethod("invokeMethod", false, "", new TypeBinding[] { bindingJLS, bindingJLO }, bindingJLO, groovyMethods, methodBindings, null); createMethod("getProperty", false, "", new TypeBinding[] { bindingJLS }, bindingJLO, groovyMethods, methodBindings, null); createMethod("setProperty", false, "", new TypeBinding[] { bindingJLS, bindingJLO }, TypeBinding.VOID, groovyMethods, methodBindings, null); createMethod("getMetaClass", false, "", null, bindingGLM, groovyMethods, methodBindings, null); createMethod("setMetaClass", false, "", new TypeBinding[] { bindingGLM }, TypeBinding.VOID, groovyMethods, methodBindings, null); } // FIXASC decide what difference this makes - should we not be adding anything at all? // will not be an instance of GroovyTypeDeclaration if created through SourceTypeConverter if (this.referenceContext instanceof GroovyTypeDeclaration) { GroovyTypeDeclaration typeDeclaration = (GroovyTypeDeclaration) this.referenceContext; boolean useOldWay = false; if (useOldWay) { // FIXASC the methods created here need to be a subtype of // MethodBinding because they need their source position to be the // property List<PropertyNode> properties = typeDeclaration.properties; for (PropertyNode property : properties) { String name = property.getName(); FieldBinding fBinding = typeDeclaration.binding.getField(name.toCharArray(), false); // null binding indicates there was a problem resolving its type if (fBinding != null && !(fBinding.type instanceof MissingTypeBinding)) { String getterName = "get" + MetaClassHelper.capitalize(name); createMethod(getterName, property.isStatic(), "", /* TypeBinding.NO_TYPES */null, fBinding.type, groovyMethods, methodBindings, typeDeclaration); if (!fBinding.isFinal()) { String setterName = "set" + MetaClassHelper.capitalize(name); createMethod(setterName, property.isStatic(), "", new TypeBinding[] { fBinding.type }, TypeBinding.VOID, groovyMethods, methodBindings, typeDeclaration); } if (fBinding.type == TypeBinding.BOOLEAN) { createMethod("is" + MetaClassHelper.capitalize(name), property.isStatic(), "", /* TypeBinding.NO_TYPES, */ null, fBinding.type, groovyMethods, methodBindings, typeDeclaration); } } } } else { // Create getters/setters without resolving the types. List<PropertyNode> properties = typeDeclaration.properties; for (PropertyNode property : properties) { String name = property.getName(); String capitalizedName = MetaClassHelper.capitalize(name); // Create getter createGetterMethod(name, "get" + capitalizedName, property.isStatic(), groovyMethods, methodBindings, typeDeclaration); // Create setter if non-final property if (!Modifier.isFinal(property.getModifiers())) { createSetterMethod(name, "set" + capitalizedName, property.isStatic(), groovyMethods, methodBindings, typeDeclaration, property.getType().getName()); } // Create isA if type is boolean String propertyType = property.getType().getName(); if (propertyType.equals("boolean")) { createGetterMethod(name, "is" + capitalizedName, property.isStatic(), groovyMethods, methodBindings, typeDeclaration); } } } } MethodBinding[] newMethodBindings = groovyMethods .toArray(new MethodBinding[methodBindings.length + groovyMethods.size()]); System.arraycopy(methodBindings, 0, newMethodBindings, groovyMethods.size(), methodBindings.length); return newMethodBindings; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitScope.java
License:Open Source License
/** * Ensure Groovy types extend groovy.lang.GroovyObject *//*from w ww . j a v a 2s . c o m*/ private void augmentTypeHierarchy(SourceTypeBinding typeBinding) { if (typeBinding.isAnnotationType() || typeBinding.isInterface()) { return; } ReferenceBinding groovyLangObjectBinding = getGroovyLangObjectBinding(); if (!typeBinding.implementsInterface(groovyLangObjectBinding, true)) { ReferenceBinding[] superInterfaceBindings = typeBinding.superInterfaces; if (superInterfaceBindings != null) { int count = superInterfaceBindings.length; System.arraycopy(superInterfaceBindings, 0, superInterfaceBindings = new ReferenceBinding[count + 1], 0, count); superInterfaceBindings[count] = groovyLangObjectBinding; typeBinding.superInterfaces = superInterfaceBindings; } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.BytecodeTransformer.java
License:Open Source License
/** * When generating code for a role class, copy all non-wide string/integer constants * from all tsuper roles in order to reserve constant pool positions below 256. * Note, that this strategy is not safe, since multiple tsupers may introduce any * number of constants below 256 :(/*from w w w . j a v a 2 s .com*/ */ public void checkCopyNonWideConstants(Scope scope, ClassFile classFile) { SourceTypeBinding dstType = classFile.referenceBinding; this._writer = new ConstantPoolObjectWriter(classFile); if (dstType.isRole() && !dstType.isInterface()) // for all role classes { ReferenceBinding[] tsuperRoles = dstType.roleModel.getTSuperRoleBindings(); for (int i = 0; i < tsuperRoles.length; i++) // for all tsuper roles { RoleModel srcRole = tsuperRoles[i].roleModel; if (srcRole == null || !srcRole.hasByteCode()) continue; byte[] srcConstantPool = srcRole.getByteCode(); if (srcConstantPool == null) continue; // be shy, no idea how it could happen this._reader = new ConstantPoolObjectReader(srcRole, srcConstantPool, scope.environment()); copyAllNonWideConstants(srcRole.getConstantPoolOffsets().length, srcRole.getBinding().enclosingType(), dstType); } } if (dstType.isTeam()) { ReferenceBinding orgObjectteamsTeam = scope.getOrgObjectteamsTeam(); if (!TypeAnalyzer.isOrgObjectteamsTeam(dstType) && !dstType.superclass.isTeam()) { TeamMethodGenerator tmg = scope.environment().getTeamMethodGenerator(); if (tmg.requestBytes()) { // if o.o.Team is converted we don't have the bytecode - and shouldn't need it this._reader = new ConstantPoolObjectReader(tmg.classBytes, tmg.constantPoolOffsets, orgObjectteamsTeam.getTeamModel(), scope.environment()); copyAllNonWideConstants(tmg.constantPoolOffsets.length, dstType.superclass, dstType); } } TeamModel srcModel = dstType.superclass.getTeamModel(); if (srcModel == null) return; // if the team has a copied ctor (w/ arg-lifting), bytecodes // for the team need to be copied from the super-team, too: for (MethodBinding method : dstType.methods()) { method = method.copyInheritanceSrc; if (method == null || method.model == null) continue; // shouldn't happen anyway TeamModel methodSrcTeam = srcModel; if (TypeBinding.notEquals(method.declaringClass, srcModel.getBinding())) { // copied from implicit super team - find the source: if (!method.declaringClass.isTeam()) continue; methodSrcTeam = method.declaringClass.getTeamModel(); } if (!method.model.hasBytes()) continue; // method not relevant for copying this._reader = new ConstantPoolObjectReader(method.model, methodSrcTeam, scope.environment()); copyAllNonWideConstants(method.model.getConstantPoolOffsets().length, methodSrcTeam.getBinding(), dstType); return; // triggered by any method, this team class is fully handled. } } }