• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CtFieldReference类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中spoon.reflect.reference.CtFieldReference的典型用法代码示例。如果您正苦于以下问题:Java CtFieldReference类的具体用法?Java CtFieldReference怎么用?Java CtFieldReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CtFieldReference类属于spoon.reflect.reference包,在下文中一共展示了CtFieldReference类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: updateFieldTypes

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
void updateFieldTypes() {
    root.getMergedClass().accept(new CtScanner() {

        @Override
        public <T> void visitCtFieldReference(CtFieldReference<T> ref) {
            CtTypeReference<?> declarationType = ref.getDeclaringType();
            if (declarationType != null) {
                CtType<?> ctType = declarationType.getDeclaration();
                if (ctType instanceof CtClass) {
                    CompilationNode node =
                            cxt.getNodeByAnyStagedClass((CtClass) ctType);
                    if (node != null) {
                        ref.setDeclaringType(node.getMergedClass().getReference());
                    }
                }
            }
            super.visitCtFieldReference(ref);
        }
    });
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:21,代码来源:Compiler.java


示例2: createVariableAccess

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
protected CtVariableAccess createVariableAccess(CtVariableReference variable, CtVariableAccess toReplace) {
    boolean isStatic = variable.getDeclaration().hasModifier(ModifierKind.STATIC);
    if(toReplace instanceof CtVariableRead) {
        return getFactory().Code().createVariableRead(variable, isStatic);
    } else {
        CtVariableAccess va;
        if (variable instanceof CtFieldReference) {
            va = getFactory().Core().createFieldWrite();
            if (!isStatic) {
                ((CtFieldAccess) va).setTarget(getFactory().Code().createThisAccess(((CtFieldReference) variable).getDeclaringType()));
            }
        } else {
            va = getFactory().Core().createVariableWrite();
        }
        va.setVariable(variable).setType(variable.getType());
        return va;
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:19,代码来源:CodeFragment.java


示例3: accessibleFieldsFrom

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
public static Collection<CtField<?>> accessibleFieldsFrom(CtTypeReference<?> accessingType, CtTypeReference<?> accessedType) {
    Collection<CtField<?>> accessibleFields = MetaList.newLinkedList();
    try {
        Collection<CtFieldReference<?>> allFields = accessedType.getAllFields();
        for (CtFieldReference<?> field : allFields) {
            CtField<?> actualField = field.getDeclaration();
            if (actualField != null && isVisibleFrom(accessingType, actualField, field.getDeclaringType(), accessedType)) {
                accessibleFields.add(actualField);
            }
        }
    } catch (Throwable e) {
        logWarning(logger(), e.toString());
    }
    return accessibleFields;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:16,代码来源:SpoonReferenceLibrary.java


示例4: buildReplacementElement

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
protected  CtCodeElement buildReplacementElement() throws BuildTransplantException {
    CtElement transplantationPoint = transformation.getTransplantationPoint().getCtCodeFragment();
    CtCodeElement copyTransplant = transformation.buildReplacementElement();

    Factory factory = copyTransplant.getFactory();

    CtFieldReference<Boolean> fieldRef = factory.Core().createFieldReference();
    fieldRef.setSimpleName("fr.inria.diversify.transformation.switchsosie.Switch.switchTransformation");

    CtIf stmtIf = factory.Core().createIf();
    stmtIf.setParent(transplantationPoint.getParent());

    stmtIf.setCondition(factory.Code().createVariableRead(fieldRef, true));

    CtBlock bodyThen = factory.Core().createBlock();
    stmtIf.setThenStatement(bodyThen);
    CtStatement tmp = (CtStatement) factory.Core().clone(copyTransplant);
    tmp.setParent(stmtIf);
    bodyThen.addStatement(tmp);

    CtBlock bodyElse = factory.Core().createBlock();
    stmtIf.setElseStatement(bodyElse);
    tmp = (CtStatement) factory.Core().clone(transplantationPoint);
    tmp.setParent(stmtIf);
    bodyElse.addStatement(tmp);


    return stmtIf;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:30,代码来源:SwitchTransformation.java


示例5: visitCtFieldRead

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
@Override
public <T> void visitCtFieldRead(CtFieldRead<T> fieldRead) {
    super.visitCtFieldRead(fieldRead);
    String string = fieldRead.toString();
    if(!string.startsWith("super")
            && (!string.contains(".") || string.contains("this."))
            && fieldRead.getParent(CtExecutable.class).equals(method)
            && !isFinalInConstructor(fieldRead)) {
        fields.put(((CtFieldReference) fieldRead.getVariable()), fieldRead.toString());
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:12,代码来源:FieldReferenceVisitor.java


示例6: visitCtFieldWrite

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
@Override
public <T> void visitCtFieldWrite(CtFieldWrite<T> fieldWrite) {
   super.visitCtFieldWrite(fieldWrite);
    String string = fieldWrite.toString();
    if(!string.startsWith("super")
            && (!string.contains(".") || string.contains("this."))
            && fieldWrite.getParent(CtExecutable.class).equals(method)
            && !isFinalInConstructor(fieldWrite)) {
        fields.put(((CtFieldReference) fieldWrite.getVariable()), fieldWrite.toString());
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:12,代码来源:FieldReferenceVisitor.java


示例7: process

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
@Override
public void process(final @NotNull CtTypeReference<?> element) {
	final CtElement parent = element.getParent();

	LOG.log(Level.INFO, () -> "PROCESSING " + element + " " + parent.getClass());

	if(parent instanceof CtField<?> || parent instanceof CtLocalVariable<?>) {
		onWidgetVar((CtVariable<?>) parent);
		return;
	}
	if(parent instanceof CtExecutableReference<?> && parent.getParent() instanceof CtConstructorCall<?>) {
		analyseWidgetConstructorCall((CtConstructorCall<?>) parent.getParent());
		return;
	}
	if(parent instanceof CtAssignment<?,?>) {
		analyseWidgetAssignment((CtAssignment<?, ?>) parent);
		return;
	}
	if(parent instanceof CtFieldReference<?>) {
		CtField<?> decl = ((CtFieldReference<?>) parent).getDeclaration();

		if(decl!=null && WidgetHelper.INSTANCE.isTypeRefAWidget(decl.getType())) {
			onWidgetVar(decl);
		}
		return;
	}
	if(parent instanceof CtMethod<?>) {
		analyseMethodUse((CtMethod<?>) parent);
		return;
	}
	if(parent instanceof CtExecutableReference<?>) {
		// A method is called on a widget, so ignored.
		return;
	}
	if(parent instanceof CtTypeAccess<?>) {
		// A static method / attribute is used on a widget class.
		return;
	}
	if(parent instanceof CtClass<?>) {
		// A widget class is used.
		return;
	}

	if(parent instanceof CtLocalVariableReference<?> || parent instanceof CtVariableRead<?>) {
		// A widget var assigned to a local var; or simply used.
		return;
	}

	if(parent instanceof CtThisAccess<?>) {
		// Use of this on a widget object.
		return;
	}

	LOG.log(Level.WARNING, "CTypeReference parent not supported or ignored: " + parent.getClass() + " " + parent);
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:56,代码来源:WidgetProcessor.java


示例8: getFields

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
public Map<CtFieldReference, String> getFields() {
    return fields;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:4,代码来源:FieldReferenceVisitor.java


示例9: visitCtFieldReference

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
public <T> void visitCtFieldReference(CtFieldReference<T> reference) {
    if(withField && !(reference.getSimpleName() == "super"))
            variableReferences.add(reference);

    super.visitCtFieldReference(reference);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:7,代码来源:VariableVisitor.java


示例10: visitCtFieldReference

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
public <T> void visitCtFieldReference(CtFieldReference<T> reference) {
	if (reference.getSimpleName().equals("this")) {
		if (context.currentThis.isEmpty()
				|| (!reference.getType().equals(context.currentThis.peek()) && !reference
						.getDeclaringType().isAnonymous())) {
			context.ignoreGenerics = true;
			scan(reference.getDeclaringType());
			printer.write(".");
			context.ignoreGenerics = false;
		}
	} else {
		boolean isStatic;
		if (reference.getSimpleName().equals("class")) {
			isStatic = true;
		} else if (reference.getSimpleName().equals("super")) {
			isStatic = false;
		} else {
			isStatic = reference.isStatic();
		}

		boolean printType = true;
		if (reference.isFinal() && reference.isStatic()) {
			if (context.currentTopLevel != null) {
				CtTypeReference<?> ref = reference.getDeclaringType();
				CtTypeReference<?> ref2;
				if(context.currentThis!=null && context.currentThis.size()>0)
					ref2 = context.currentThis.lastElement();
				else
					ref2 = context.currentTopLevel.getReference();
				// print type if not annonymous class ref and not within the
				// current scope
				printType = !ref.getSimpleName().equals("")
						&& !(ref.equals(ref2));
			} else {
				printType = true;
			}
		}

		if (isStatic && printType && !context.ignoreStaticAccess) {
			context.ignoreGenerics = true;
			scan(reference.getDeclaringType());
			context.ignoreGenerics = false;
			printer.write(".");
		}
	}
	printer.write(reference.getType().toString());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:48,代码来源:CodeFragmentEqualPrinter.java


示例11: searchVariablesInScope

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
/**
 * Returns all variables in scope, reachable from the ctelement passes as
 * argument
 * 
 * @param element
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<CtVariable> searchVariablesInScope(CtElement element) {
	List<CtVariable> variables = new ArrayList();

	if (element == null) {
		return variables;
	}

	if (element instanceof CtField) {
		return variables;
	}
	// We find the CtClass and returns the fields
	CtClass ctclass = element.getParent(CtClass.class);
	if (ctclass != null) {
		Collection<CtFieldReference<?>> vars = ctclass.getAllFields();
		for (CtFieldReference<?> ctFieldReference : vars) {
			// We dont add private fields from parent classes
			if ((!ctFieldReference.getModifiers().contains(ModifierKind.PRIVATE)
					|| ctclass.getFields().contains(ctFieldReference.getDeclaration()))) {

				// We ignore "serialVersionUID'
				if ((ctFieldReference.getDeclaration() != null)
						&& !"serialVersionUID".equals(ctFieldReference.getDeclaration().getSimpleName()))
					variables.add(ctFieldReference.getDeclaration());
			}
		}

	}

	// We find the parent method and we extract the parameters
	CtMethod method = element.getParent(CtMethod.class);
	if (method != null) {
		List<CtParameter> pars = method.getParameters();
		for (CtParameter ctParameter : pars) {
			variables.add(ctParameter);
		}
	}

	// We find the parent block and we extract the local variables before
	// the element under analysis
	CtBlock parentblock = element.getParent(CtBlock.class);
	if (parentblock != null) {
		int positionEl = parentblock.getStatements().indexOf(element);
		variables.addAll(VariableResolver.retrieveLocalVariables(positionEl, parentblock));
	}

	return variables;

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:57,代码来源:VariableResolver.java


示例12: convertIngredient

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
/**
 * Adapt the ingredient to the destination according to the mapping. We
 * directly manipulate the variables from the ingredient, which are stored
 * in VarMapping
 * 
 * @param varMapping
 * @param destination
 * @return it returns the original variable reference of each converted
 *         variable
 */
@SuppressWarnings("unchecked")
public static Map<VarAccessWrapper, CtVariableAccess> convertIngredient(VarMapping varMapping,
		Map<String, CtVariable> mapToFollow) {

	Map<VarAccessWrapper, CtVariableAccess> originalMap = new HashMap<>();

	Map<VarAccessWrapper, List<CtVariable>> mappedVars = varMapping.getMappedVariables();
	for (VarAccessWrapper var : mappedVars.keySet()) {
		CtVariable varNew = mapToFollow.get(var.getVar().getVariable().getSimpleName());
		//
		CtVariableReference newVarReference = varNew.getReference();

		CtVariableAccess originalVarAccessDestination = var.getVar();
		CtVariableAccess newVarAccessDestination = null;

		// if the var to reference is a local or parameter
		if (newVarReference instanceof CtLocalVariableReference
				|| newVarReference instanceof CtParameterReference) {
			// let's check the destination Writes or Reads
			if (originalVarAccessDestination instanceof CtFieldWrite
					|| originalVarAccessDestination instanceof CtVariableWrite) {
				// We replace the Write by a Var writter
				newVarAccessDestination = MutationSupporter.getFactory().Core().createVariableWrite();
				newVarAccessDestination.setVariable(newVarReference);

			} else { // read
				newVarAccessDestination = MutationSupporter.getFactory().Code().createVariableRead(newVarReference,
						varNew.hasModifier(ModifierKind.STATIC));
			}

		} else
		// else, if we want to reference a field
		if (newVarReference instanceof CtFieldReference) {
			// let's check the destination, write or read
			if (originalVarAccessDestination instanceof CtFieldWrite<?>
					|| originalVarAccessDestination instanceof CtFieldRead<?>) {
				newVarAccessDestination = MutationSupporter.getFactory().Core().createFieldWrite();

			} else {
				newVarAccessDestination = MutationSupporter.getFactory().Core().createFieldRead();

			}
			newVarAccessDestination.setVariable(newVarReference);
		}
		// At the end, for all cases:
		if (newVarAccessDestination != null) {
			originalMap.put(new VarAccessWrapper(newVarAccessDestination), originalVarAccessDestination);
			originalVarAccessDestination.replace(newVarAccessDestination);
		} else {
			logger.error("No destination resolved");
		}

	} // end for
	return originalMap;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:66,代码来源:VariableResolver.java


示例13: isStatic

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
public static boolean isStatic(CtVariableReference varref) {

		if (!(varref instanceof CtFieldReference)) {
			return false;
		}

		CtFieldReference fieldRef = (CtFieldReference) varref;

		return fieldRef.isStatic();

	}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:12,代码来源:VariableResolver.java


示例14: addAlwayLog

import spoon.reflect.reference.CtFieldReference; //导入依赖的package包/类
protected void addAlwayLog(Map<CtFieldReference, String> fieldUsed) {

    }
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:4,代码来源:FieldUsedInstrumenter.java



注:本文中的spoon.reflect.reference.CtFieldReference类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WeightedResponseTimeRule类代码示例发布时间:2022-05-22
下一篇:
Java ExpressionStmt类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap