Java NameReference类使用实例

发布时间:2025-12-09 11:55:58 浏览次数:1

实例1: getElement

import org.aikodi.chameleon.core.reference.NameReference; //导入依赖的package包/类@Overridepublic Type getElement() throws LookupException {  JLoType typeConstructor = (JLoType) typeConstructorReference().getElement();  Type result = new JLoTypeRefinement(typeConstructor);  for(KeywordTypeArgument a: arguments()) {  // The name is wrong. It won't be found!  NameReference<TypeMemberDeclarator> nameReference = new NameReference<>(a.name(), TypeMemberDeclarator.class);  // The constructor sets the unidirectional parent of the name reference.  new LookupRedirector(typeConstructor,nameReference);  TypeMemberDeclarator element = nameReference.getElement();    TypeParameter typeArgument = new InstantiatedTypeParameter(element.parameter().name(), a.argument());    TypeMemberDeclarator declarator = new TypeMemberDeclarator(new SimpleNameSignature(a.name()), typeArgument);    result.add(declarator);  }  return result;} 

实例2: erasure

import org.aikodi.chameleon.core.reference.NameReference; //导入依赖的package包/类@Overridepublic Type erasure() {Element el = farthestOrigin();if(el != this) {return ((JavaType)el).erasure();}// I am not sure whether this is correct. The memberInheritanceRelations are not erased in RawType.Type outmostType = lexical().farthestAncestor(Type.class);if(outmostType == null) {outmostType = this;}RawType outer;if(outmostType instanceof RawType) {outer = (RawType) outmostType;} else {outer = new RawType(outmostType);}RawType current = outer;List<Type> outerTypes = ancestors(Type.class);outerTypes.add(0, this);int size = outerTypes.size();Factory expressionFactory = language(ObjectOrientedLanguage.class).plugin(Factory.class);for(int i = size - 2; i>=0;i--) {NameReference<RawType> simpleRef = expressionFactory.createNameReference(outerTypes.get(i).name(), RawType.class);simpleRef.setUniParent(current);try {current = simpleRef.getElement();} catch (LookupException e) {e.printStackTrace();throw new ChameleonProgrammerException("An inner type of a newly created outer raw type cannot be found",e);}}return current;} 

实例3: cloneSelf

import org.aikodi.chameleon.core.reference.NameReference; //导入依赖的package包/类@Overrideprotected SubobjectConstructorCall cloneSelf() {SubobjectConstructorCall result = new SubobjectConstructorCall((NameReference)null);//FIXME This is a hack iirc. Remove it!result.setOrigin(this);return result;} 
REFERENCENAME
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477