spoon.reflect.code.CtConstructorCall Java Examples
The following examples show how to use
spoon.reflect.code.CtConstructorCall.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FactoryProcessorTest.java From spoon-examples with GNU General Public License v2.0 | 6 votes |
@Test public void testReferenceProcessor() throws Exception { final String[] args = { "-i", "src/test/resources/factory/", "-o", "target/spooned/" }; final Launcher launcher = new Launcher(); launcher.setArgs(args); launcher.run(); final Factory factory = launcher.getFactory(); final ProcessingManager processingManager = new QueueProcessingManager(factory); List<CtInterface> listFactoryItf = factory.getModel().getElements(new NamedElementFilter<>(CtInterface.class, "Factory")); assertThat(listFactoryItf.size(), is(1)); final FactoryProcessor processor = new FactoryProcessor(listFactoryItf.get(0).getReference()); processingManager.addProcessor(processor); List<CtConstructorCall> ctNewClasses = factory.getModel().getElements(new TypeFilter<>(CtConstructorCall.class)); processingManager.process(ctNewClasses); // implicit constructor is also counted assertThat(processor.listWrongUses.size(), is(2)); }
Example #2
Source File: SpecialStatementFixSpaceProcessor.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public void process(CtStatement element) { if (element instanceof CtIf) { add(((CtIf) element).getCondition()); } else if (element instanceof CtFor) { add(((CtFor) element).getExpression()); } else if (element instanceof CtWhile) { add(((CtWhile) element).getLoopingExpression()); } else if (element instanceof CtDo) { add(((CtDo) element).getLoopingExpression()); } else if (element instanceof CtThrow) { add(((CtThrow) element).getThrownExpression()); } else if (element instanceof CtInvocation && (element.getParent() instanceof CtBlock)) { add(element); } else if (element instanceof CtAssignment || element instanceof CtConstructorCall || element instanceof CtCFlowBreak || element instanceof CtLocalVariable) { add(element); } }
Example #3
Source File: ConstructorAnalyzer.java From coming with MIT License | 6 votes |
private void analyzeWhetherConstructorOftheclass (List<CtConstructorCall> constructorsaffected, Cntx<Object> context, CtClass parentclss) { try { for (CtConstructorCall conAffected : constructorsaffected) { boolean con5oftheclass = false; if (conAffected.getType()!=null && (conAffected.getType().getQualifiedName().endsWith(parentclss.getSimpleName()))) { con5oftheclass = true; } writeGroupedInfo(context, adjustIdentifyInJson(conAffected), CodeFeatures.CON5_Of_Class, con5oftheclass, "FEATURES_CONSTRUCTOR"); } } catch (Throwable e) { e.printStackTrace(); } }
Example #4
Source File: TransformStrategy.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { super.visitCtConstructorCall(ctConstructorCall); List<CtExpression<?>> argumentlist = ctConstructorCall.getArguments(); for (int i = 0; i < argumentlist.size(); i++) { @SuppressWarnings("rawtypes") CtExpression p = argumentlist.get(i); if (candidates.containsKey(p)) { argumentlist.set(i, candidates.get(p)); // ctConstructorCall.setArguments(argumentlist); saveSketchAndSynthesize(); argumentlist.set(i, p); resoreDiskFile(); // ctConstructorCall.setArguments(argumentlist); } } }
Example #5
Source File: ConstructorAnalyzer.java From coming with MIT License | 6 votes |
private void analyzeConstructorFeature_Extend (CtElement originalElement, Cntx<Object> context, CtClass parentClass, List<CtConstructorCall> allconstructorcallsFromClass, List<CtConstructorCall> constructorcallstostudy) { List<CtInvocation> emptyinvocationfromclass = new ArrayList<CtInvocation>(); List<CtInvocation> emptyinvocationunderstudy = new ArrayList<CtInvocation>(); for(CtConstructorCall constructorcallAffected : constructorcallstostudy) { boolean[] constructorcallfeature91012 = analyze_SamerMethodWithGuardOrTrywrap(originalElement, parentClass, emptyinvocationfromclass, emptyinvocationunderstudy, allconstructorcallsFromClass, Arrays.asList(constructorcallAffected)); if(constructorcallfeature91012 != null) { writeGroupedInfo(context, adjustIdentifyInJson(constructorcallAffected), CodeFeatures.CON9_METHOD_CALL_WITH_NORMAL_GUARD, constructorcallfeature91012[0], "FEATURES_CONSTRUCTOR"); writeGroupedInfo(context, adjustIdentifyInJson(constructorcallAffected), CodeFeatures.CON10_METHOD_CALL_WITH_NULL_GUARD, constructorcallfeature91012[1], "FEATURES_CONSTRUCTOR"); writeGroupedInfo(context, adjustIdentifyInJson(constructorcallAffected), CodeFeatures.CON12_METHOD_CALL_WITH_TRY_CATCH, constructorcallfeature91012[2], "FEATURES_CONSTRUCTOR"); } } }
Example #6
Source File: MethodAnalyzer.java From coming with MIT License | 6 votes |
private void analyzeMethodFeature_Extend (CtElement originalElement, Cntx<Object> context, CtClass parentClass, List<CtInvocation> invocationsFromClass, List<CtInvocation> invocations) { List<CtConstructorCall> emptyconstructorcallfromclass = new ArrayList<CtConstructorCall>(); List<CtConstructorCall> emptyconstructorcallunderstudy = new ArrayList<CtConstructorCall>(); for(CtInvocation invocationAffected : invocations) { boolean[] methdofeature91012 = analyze_SamerMethodWithGuardOrTrywrap(originalElement, parentClass, invocationsFromClass, Arrays.asList(invocationAffected), emptyconstructorcallfromclass, emptyconstructorcallunderstudy); if(methdofeature91012 != null) { writeGroupedInfo(context, adjustIdentifyInJson(invocationAffected), CodeFeatures.M9_METHOD_CALL_WITH_NORMAL_GUARD, methdofeature91012[0], "FEATURES_METHODS"); writeGroupedInfo(context, adjustIdentifyInJson(invocationAffected), CodeFeatures.M10_METHOD_CALL_WITH_NULL_GUARD, methdofeature91012[1], "FEATURES_METHODS"); writeGroupedInfo(context, adjustIdentifyInJson(invocationAffected), CodeFeatures.M12_METHOD_CALL_WITH_TRY_CATCH, methdofeature91012[2], "FEATURES_METHODS"); } } }
Example #7
Source File: OverloadMethodTransform.java From astor with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { super.visitCtConstructorCall(ctConstructorCall); String type = ctConstructorCall.getType().getQualifiedName(); List<CtExpression<?>> argumentlist = ctConstructorCall.getArguments(); List<String> orig = resolveTypes(argumentlist); CtClass classname = parser.getClassMap().get(type); if(classname!=null) { Set<CtConstructor<T>> constructors=classname.getConstructors(); for(CtConstructor constructor:constructors) { List<CtParameter> paramlist=constructor.getParameters(); List<String> target=resolveParams(paramlist); transformOneMethod(orig,target,ctConstructorCall); } } else { List<Class[]> params = parser.fetchMethods(type, type); for (Class[] p : params) transformOneConstructor(orig, ctConstructorCall, p); } }
Example #8
Source File: AstComparatorTest.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
@Test public void test_t_211903() throws Exception { AstComparator diff = new AstComparator(); // meld src/test/resources/examples/t_211903/left_MemberFilePersister_1.4.java // src/test/resources/examples/t_211903/right_MemberFilePersister_1.5.java File fl = new File("src/test/resources/examples/t_211903/left_MemberFilePersister_1.4.java"); File fr = new File("src/test/resources/examples/t_211903/right_MemberFilePersister_1.5.java"); Diff result = diff.compare(fl, fr); // result.debugInformation(); CtElement ancestor = result.commonAncestor(); assertTrue(ancestor instanceof CtConstructorCall); assertEquals(88, ancestor.getPosition().getLine()); List<Operation> actions = result.getRootOperations(); // result.debugInformation(); assertTrue( result.containsOperation(OperationKind.Update, "ConstructorCall", "java.io.FileReader(java.io.File)")); assertTrue(result.containsOperation(OperationKind.Insert, "ConstructorCall", "java.io.InputStreamReader(java.io.InputStream,java.lang.String)")); // additional checks on low-level actions assertTrue(result.containsOperations(result.getAllOperations(), OperationKind.Insert, "Literal", "\"UTF-8\"")); // the change is in the local variable declaration CtElement elem = actions.get(0).getNode(); assertNotNull(elem); assertNotNull(elem.getParent(CtLocalVariable.class)); }
Example #9
Source File: FactoryProcessor.java From spoon-examples with GNU General Public License v2.0 | 5 votes |
public void process(CtConstructorCall<?> newClass) { // skip factory creation if (newClass.getExecutable().getDeclaringType().isSubtypeOf(getFactoryType())) return; // skip creations in factories if (newClass.getParent(CtClass.class).isSubtypeOf(getFactoryType())) return; // only report for types created by the factory for (CtTypeReference<?> t : getCreatedTypes()) { if (newClass.getType().isSubtypeOf(t)) { this.listWrongUses.add(newClass); } } }
Example #10
Source File: InvocationResolver.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("rawtypes") public static InvocationMatching mapImplicitInvocation(CtClass ctClassMP, CtAbstractInvocation inv0) { if (inv0 instanceof CtInvocation) { CtInvocation invocation0 = (CtInvocation) inv0; CtExpression tpr = invocation0.getTarget(); if (tpr instanceof CtThisAccess) { CtThisAccess<?> targetthis = (CtThisAccess) tpr; CtTypeReference tpref = targetthis.getType(); if (ctClassMP.isSubtypeOf(tpref)) return InvocationMatching.TARGET_SAME_TYPE; else if (chechSignatures(ctClassMP.getAllExecutables(), invocation0.getExecutable(), false)) { return InvocationMatching.SAME_SIGNATURE_FROM_DIFF_TYPE; } else { log.debug("Signature " + invocation0.getExecutable().getSignature()); log.debug( "Not compatible: " + ctClassMP.getQualifiedName() + " with " + (tpref.getQualifiedName())); return InvocationMatching.TARGET_INCOMPATIBLE; } } else { log.debug("Explicit target " + tpr); return InvocationMatching.TARGET_IS_VARIABLE; } } else { if (inv0 instanceof CtConstructorCall) { return InvocationMatching.CONTRUCTOR; } return InvocationMatching.OTHER; } }
Example #11
Source File: InvocationResolver.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Return all variables related to the element passed as argument * * @param element * @return */ @SuppressWarnings("rawtypes") public static List<CtAbstractInvocation> collectInvocation(CtElement element, boolean duplicates) { List<CtAbstractInvocation> varaccess = new ArrayList<>(); CtScanner sc = new CtScanner() { public void add(CtAbstractInvocation e) { if (duplicates || !varaccess.contains(e)) varaccess.add(e); } @Override public <T> void visitCtInvocation(CtInvocation<T> invocation) { super.visitCtInvocation(invocation); add(invocation); } @Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { super.visitCtConstructorCall(ctConstructorCall); add(ctConstructorCall); } }; sc.scan(element); return varaccess; }
Example #12
Source File: NullPreconditionWithExpressionOperator.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public boolean canBeAppliedToPoint(ModificationPoint point) { if (!(point.getCodeElement() instanceof CtStatement)) return false; // do not insert after a return if (point.getCodeElement() instanceof CtConstructorCall || point.getCodeElement() instanceof CtReturn) { return false; } // Otherwise, accept the element return true; }
Example #13
Source File: NullPreconditionOperator.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public boolean canBeAppliedToPoint(ModificationPoint point) { if (!(point.getCodeElement() instanceof CtStatement)) return false; // do not insert after a return if (point.getCodeElement() instanceof CtConstructorCall || point.getCodeElement() instanceof CtReturn) { return false; } // Otherwise, accept the element return true; }
Example #14
Source File: TransformStrategy.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<String> transform () { CtStatement targetStmt = (CtStatement) this.modificationPoint.getCodeElement(); if (targetStmt instanceof CtInvocation) this.visitCtInvocation((CtInvocation) targetStmt); else if (targetStmt instanceof CtConstructorCall) this.visitCtConstructorCall((CtConstructorCall) targetStmt); else if (targetStmt instanceof CtIf) this.visitCtIf ((CtIf)targetStmt); else if (targetStmt instanceof CtReturn) this.visitCtReturn((CtReturn) targetStmt); else if (targetStmt instanceof CtSwitch) this.visitCtSwitch((CtSwitch) targetStmt); else if (targetStmt instanceof CtCase) this.visitCtCase((CtCase) targetStmt); else if (targetStmt instanceof CtAssignment) this.visitCtAssignment((CtAssignment) targetStmt); else if (targetStmt instanceof CtAssert) this.visitCtAssert((CtAssert) targetStmt); else if (targetStmt instanceof CtFor) this.visitCtFor((CtFor) targetStmt); else if (targetStmt instanceof CtForEach) this.visitCtForEach((CtForEach) targetStmt); else if (targetStmt instanceof CtWhile) this.visitCtWhile((CtWhile) targetStmt); else if (targetStmt instanceof CtUnaryOperator) this.visitCtUnaryOperator((CtUnaryOperator) targetStmt); else if (targetStmt instanceof CtSynchronized) this.visitCtSynchronized((CtSynchronized) targetStmt); return list; }
Example #15
Source File: InsertBeforeOp.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public boolean canBeAppliedToPoint(ModificationPoint point) { boolean apply = super.canBeAppliedToPoint(point); if (!apply) return apply; // do not insert after a return if (point.getCodeElement() instanceof CtConstructorCall) { return false; } // Otherwise, accept the element return true; }
Example #16
Source File: CodeElementInfo.java From coming with MIT License | 5 votes |
private void setConstructorcalls() { if (elementToStudy != null) constructorcalls = elementToStudy.getElements(e -> (e instanceof CtConstructorCall)).stream() .map(CtConstructorCall.class::cast).collect(Collectors.toList()); else constructorcalls = null; }
Example #17
Source File: CodeElementInfo.java From coming with MIT License | 5 votes |
private void setConstructorcallsFromClass() { if (parentClass != null) constructorcallsFromClass = parentClass.getElements(e -> (e instanceof CtConstructorCall)).stream() .map(CtConstructorCall.class::cast).collect(Collectors.toList()); else constructorcallsFromClass = null; }
Example #18
Source File: MethodAnalyzer.java From coming with MIT License | 5 votes |
private int[] argumentDiffMethod(List<CtElement> argumentsoriginal, List<CtElement> argumentsother, CtInvocation invocationaccess) { int numberdiffargument =0; int numberdiffmethodreplacebyvar =0; int numberdiffmethodreplacebymethod =0; for(int index=0; index<argumentsoriginal.size(); index++) { CtElement original = argumentsoriginal.get(index); CtElement other = argumentsother.get(index); if(original.equals(other) || original.toString().equals(other.toString())) { // same } else { numberdiffargument+=1; if(original instanceof CtInvocation && original.equals(invocationaccess)) { if(other instanceof CtVariableAccess) numberdiffmethodreplacebyvar+=1; else if(other instanceof CtInvocation || other instanceof CtConstructorCall) numberdiffmethodreplacebymethod+=1; else { // do nothing } } } } int diffarray[]=new int[3]; diffarray[0]=numberdiffargument; diffarray[1]=numberdiffmethodreplacebyvar; diffarray[2]=numberdiffmethodreplacebymethod; return diffarray; }
Example #19
Source File: VariableAnalyzer.java From coming with MIT License | 5 votes |
private int[] argumentDiff(List<CtElement> argumentsoriginal, List<CtElement> argumentsother, CtVariableAccess varaccess) { int numberdiffargument =0; int numberdiffvarreplacebyvar =0; int numberdiffvarreplacebymethod =0; for(int index=0; index<argumentsoriginal.size(); index++) { CtElement original = argumentsoriginal.get(index); CtElement other = argumentsother.get(index); if(original.equals(other) || original.toString().equals(other.toString())) { // same } else { numberdiffargument+=1; if(original instanceof CtVariableAccess && original.equals(varaccess)) { if(other instanceof CtVariableAccess) numberdiffvarreplacebyvar+=1; else if(other instanceof CtInvocation || other instanceof CtConstructorCall) numberdiffvarreplacebymethod+=1; else { // do nothing } } } } int diffarray[]=new int[3]; diffarray[0]=numberdiffargument; diffarray[1]=numberdiffvarreplacebyvar; diffarray[2]=numberdiffvarreplacebymethod; return diffarray; }
Example #20
Source File: APICheckingProcessor.java From spoon-examples with GNU General Public License v2.0 | 5 votes |
@Override public void process(CtMethod method) { final Factory factory = method.getFactory(); CtBlock methodBody = method.getBody(); List<CtComment> bodyComments = new ArrayList<>(); ArrayList<CtStatement> ctStatements = new ArrayList<>(methodBody.getStatements()); for (CtStatement ctStatement : ctStatements) { String statement = ctStatement.toString(); bodyComments.add(factory.createInlineComment(statement)); methodBody.removeStatement(ctStatement); } CtClass<? extends Throwable> myExceptionClass = factory.Class().get(EXCEPTION_FQN); CtConstructorCall<? extends Throwable> myNewException = factory.createConstructorCall(myExceptionClass.getReference()); CtThrow throwMyException = factory.createThrow(); throwMyException.setThrownExpression(myNewException); methodBody.addStatement(throwMyException); bodyComments.add(factory.createInlineComment("FIXME: The private API type should never be return in a public API.")); for (CtComment bodyComment : bodyComments) { throwMyException.addComment(bodyComment); } }
Example #21
Source File: ConstructorAnalyzer.java From coming with MIT License | 4 votes |
private void analyzeCon1_ConstructorOverload(CtElement element, Cntx<Object> context, CtClass parentClass, List<CtConstructorCall> constructorcalls) { try { for (CtConstructorCall constructorcall : constructorcalls) { boolean con1SpecificHasSameName = false; List<CtConstructor> allconstructorsinclass = new ArrayList(); if(parentClass!=null) allconstructorsinclass = parentClass.getElements(new TypeFilter<>(CtConstructor.class)); for (CtConstructor certainconstructorinclass : allconstructorsinclass) { CtConstructor anotherConstructor = (CtConstructor) certainconstructorinclass; // Ignoring if it's the same if (anotherConstructor == null || anotherConstructor.getSignature(). equals(constructorcall.getExecutable().getSignature())) continue; if (anotherConstructor.getSimpleName().equals(getSimplenameForConstructorCall(constructorcall))) { // It's override con1SpecificHasSameName = true; break; } } List<CtConstructorCall> allconstructorcallsinclass = new ArrayList(); if(parentClass!=null) allconstructorcallsinclass = parentClass.getElements(new TypeFilter<>(CtConstructorCall.class)); if(!con1SpecificHasSameName) { for (CtConstructorCall certainconstructorcallinclass : allconstructorcallsinclass) { CtConstructorCall anotherConstructorCall = (CtConstructorCall) certainconstructorcallinclass; if (anotherConstructorCall == null || anotherConstructorCall.getExecutable().getSignature(). equals(constructorcall.getExecutable().getSignature())) continue; if (getSimplenameForConstructorCall(anotherConstructorCall).equals(getSimplenameForConstructorCall(constructorcall))) { con1SpecificHasSameName = true; break; } } } writeGroupedInfo(context, adjustIdentifyInJson(constructorcall), CodeFeatures.CON1_OVERLOADED_CONSTRUCTOR, con1SpecificHasSameName, "FEATURES_CONSTRUCTOR"); } } catch (Throwable e) { e.printStackTrace(); } }
Example #22
Source File: ConstructorAnalyzer.java From coming with MIT License | 4 votes |
private void analyzeWhetherConstructorreturnprimitive (List<CtConstructorCall> constructorsaffected, Cntx<Object> context) { try { for (CtConstructorCall conAffected : constructorsaffected) { boolean con4returnprimitive = false; if (conAffected.getType()!=null && (conAffected.getType().isPrimitive() || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("string") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("list") || conAffected.getType().getQualifiedName().toString().toLowerCase().indexOf("string")!=-1 || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("long") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("boolean") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("double") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("byte")|| conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("short")|| conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("float") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("chart") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("character") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("integer")|| conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("string[]") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("long[]") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("boolean[]") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("double[]") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("byte[]")|| conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("short[]")|| conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("float[]") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("chart[]") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("character[]") || conAffected.getType().getQualifiedName().toString().toLowerCase().endsWith("integer[]") || conAffected.getType().getQualifiedName().toString().toLowerCase().startsWith("java.util.") || conAffected.getType().getQualifiedName().toString().toLowerCase().startsWith("java.nio.") || conAffected.getType().getQualifiedName().toString().toLowerCase().startsWith("java.io."))) { con4returnprimitive = true; } writeGroupedInfo(context, adjustIdentifyInJson(conAffected), CodeFeatures.CON4_Return_Primitive, con4returnprimitive, "FEATURES_CONSTRUCTOR"); } } catch (Throwable e) { e.printStackTrace(); } }
Example #23
Source File: ConstructorAnalyzer.java From coming with MIT License | 4 votes |
private void analyzeVarConstructorArgumentPrimitive (List<CtConstructorCall> constructorsaffected, Cntx<Object> context) { try { for (CtConstructorCall conAffected : constructorsaffected) { boolean Con6ArgumentHasPrimitive = false; List<CtExpression> invocationArguments = conAffected.getArguments(); for(int index=0; index<invocationArguments.size(); index++ ) { CtExpression certainexpression=invocationArguments.get(index); if (certainexpression.getType()!=null && (certainexpression.getType().isPrimitive() || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("string") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("long") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("list") || certainexpression.getType().getQualifiedName().toString().toLowerCase().indexOf("string")!=-1 || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("boolean") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("double") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("byte")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("short")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("float") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("chart") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("character") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("integer")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("string[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("long[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("boolean[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("double[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("byte[]")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("short[]")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("float[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("chart[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("character[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("integer[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().startsWith("java.util.") || certainexpression.getType().getQualifiedName().toString().toLowerCase().startsWith("java.nio.") || certainexpression.getType().getQualifiedName().toString().toLowerCase().startsWith("java.io."))) { Con6ArgumentHasPrimitive = true; break; } } writeGroupedInfo(context, adjustIdentifyInJson(conAffected), CodeFeatures.CON6_Argument_Has_Primitive, Con6ArgumentHasPrimitive, "FEATURES_CONSTRUCTOR"); } } catch (Throwable e) { e.printStackTrace(); } }
Example #24
Source File: AbstractCodeAnalyzer.java From coming with MIT License | 4 votes |
public String getSimplenameForConstructorCall(CtConstructorCall call) { String[] namespace = call.getType().getQualifiedName().split("\\(")[0].split("\\."); String constructorname = namespace[namespace.length - 1]; return constructorname; }
Example #25
Source File: ExpressionAnalyzer.java From coming with MIT License | 4 votes |
private void analyzeExpressionFeatures(List<CtExpression> expressionsToStudy, CtElement originalElement, Cntx<Object> context, CtClass parentClass, List<CtStatement> allstatementsinclass, List<CtVariable> varsInScope, List allMethodsFromClass, List<CtInvocation> invocationsFromClass, List<CtConstructorCall> constructorcallsFromClass) { for(int expressionindex=0; expressionindex<expressionsToStudy.size(); expressionindex++) { CtExpression specificexpression = expressionsToStudy.get(expressionindex); List<CtVariableAccess> varsAffected = VariableResolver.collectVariableAccess(specificexpression, false); // Get all invocations inside the faulty element List<CtInvocation> invocations = specificexpression.getElements(e -> (e instanceof CtInvocation)).stream() .map(CtInvocation.class::cast).collect(Collectors.toList()); List<CtConstructorCall> constructorcall = specificexpression.getElements(e -> (e instanceof CtConstructorCall)).stream() .map(CtConstructorCall.class::cast).collect(Collectors.toList()); writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E1_LOCAL_VAR_NOT_USED, analyze_AffectedVariablesUsed (varsAffected, originalElement, allstatementsinclass), "FEATURES_EXPRESSION"); writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E1_LOCAL_VAR_NOT_ASSIGNED, analyze_AffectedAssigned (varsAffected, originalElement), "FEATURES_EXPRESSION"); boolean[] expressionfeatures = analyze_SametypewithGuard(varsAffected, originalElement, parentClass, allstatementsinclass); if(expressionfeatures != null) { writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E2_SIMILAR_OBJECT_TYPE_WITH_NORMAL_GUARD, expressionfeatures[0], "FEATURES_EXPRESSION"); writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E5_SIMILAR_PRIMITIVE_TYPE_WITH_NORMAL_GUARD, expressionfeatures[1], "FEATURES_EXPRESSION"); writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E2_SIMILAR_OBJECT_TYPE_WITH_NULL_GUARD, expressionfeatures[2], "FEATURES_EXPRESSION"); writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E5_SIMILAR_PRIMITIVE_TYPE_WITH_NULL_GUARD, expressionfeatures[3], "FEATURES_EXPRESSION"); } writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E4_Field_NOT_USED, analyze_AffectedFielfs(varsAffected, originalElement, parentClass), "FEATURES_EXPRESSION"); writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E4_Field_NOT_ASSIGNED, analyze_AffectedFieldAssigned(varsAffected, originalElement, parentClass), "FEATURES_EXPRESSION"); boolean[] expressionvalueS7S8 = analyze_AffectedObjectLastAppear(varsAffected, originalElement, allstatementsinclass); if(expressionvalueS7S8 != null) { writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E7_OBJECT_USED_IN_ASSIGNMENT, expressionvalueS7S8[0], "FEATURES_EXPRESSION"); writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E8_PRIMITIVE_USED_IN_ASSIGNMENT, expressionvalueS7S8[1], "FEATURES_EXPRESSION"); } boolean[] expressionvalueS9S10 = analyze_SamerMethodWithGuardOrTrywrap(originalElement, parentClass, invocationsFromClass, invocations, constructorcallsFromClass, constructorcall); if(expressionvalueS9S10 != null) { writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E9_METHOD_CALL_WITH_NORMAL_GUARD, expressionvalueS9S10[0], "FEATURES_EXPRESSION"); writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E10_METHOD_CALL_WITH_NULL_GUARD, expressionvalueS9S10[1], "FEATURES_EXPRESSION"); } writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E1_RETURN_PRIMITIVE, getExpressionType(specificexpression), "FEATURES_EXPRESSION"); boolean[] expressionvalueType = analyzeExpression(specificexpression, context, allMethodsFromClass, invocationsFromClass, parentClass); if(expressionvalueType != null) { writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E2_COMPATIBLE_INVOCATION_PAREMETER_RETURN, expressionvalueType[0], "FEATURES_EXPRESSION"); writeGroupedInfo(context, "expression_"+Integer.toString(expressionindex), CodeFeatures.E3_COMPATIBLE_INVOCATION_PAREMETER, expressionvalueType[1], "FEATURES_EXPRESSION"); } } }
Example #26
Source File: LabelFinder.java From gumtree-spoon-ast-diff with Apache License 2.0 | 4 votes |
@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { if (ctConstructorCall.getExecutable() != null) { label = ctConstructorCall.getExecutable().getSignature(); } }
Example #27
Source File: BigTransfoScenarioTest.java From spoon-examples with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("all") @Test public void main() { MavenLauncher launcher = new MavenLauncher( "./src/test/resources/project/", MavenLauncher.SOURCE_TYPE.APP_SOURCE); CtModel model = launcher.buildModel(); List<CtMethod> methodList = model. filterChildren(new NamedElementFilter<CtPackage>(CtPackage.class, "ow2con")). filterChildren(new NamedElementFilter<CtPackage>(CtPackage.class, "publicapi")). filterChildren(new TypeFilter<CtMethod>(CtMethod.class)). filterChildren(new Filter<CtMethod>() { @Override public boolean matches(CtMethod element) { boolean isPublic = element.isPublic(); CtTypeReference returnType = element.getType(); String privateApiPackage = "ow2con.privateapi"; boolean isTypeFromPrivateApi = returnType.getQualifiedName().contains(privateApiPackage); return isPublic && isTypeFromPrivateApi; } }).list(); Factory factory = launcher.getFactory(); CtClass<? extends Throwable> exceptionClass = factory.createClass("ow2con.PrivateAPIException"); CtConstructorCall<? extends Throwable> exceptionInstance = factory.createConstructorCall(exceptionClass.getReference()); for (CtMethod method : methodList) { CtBlock methodBody = method.getBody(); List<CtComment> bodyComments = new ArrayList<>(); ArrayList<CtStatement> ctStatements = new ArrayList<>(methodBody.getStatements()); for (CtStatement ctStatement : ctStatements) { String statement = ctStatement.toString(); CtComment statementAsComment = factory.createInlineComment(statement); bodyComments.add(statementAsComment); methodBody.removeStatement(ctStatement); } CtThrow throwMyException = factory.createThrow(); CtConstructorCall<? extends Throwable> constructorCall = exceptionInstance.clone(); throwMyException.setThrownExpression(constructorCall); methodBody.addStatement(throwMyException); bodyComments.add( factory.createInlineComment( "FIXME: The private API type should never be return in a public API." ) ); for (CtComment bodyComment : bodyComments) { throwMyException.addComment(bodyComment); } } Environment environment = launcher.getEnvironment(); environment.setCommentEnabled(true); environment.setAutoImports(true); // the transformation must produce compilable code environment.setShouldCompile(true); launcher.prettyprint(); // look in folder spooned/ow2con/publicapi/ the transformed code }
Example #28
Source File: CodeElementInfo.java From coming with MIT License | 2 votes |
private List<CtConstructorCall> getConstructorcallsFromClass() { return this.constructorcallsFromClass; }
Example #29
Source File: CodeElementInfo.java From coming with MIT License | 2 votes |
private List<CtConstructorCall> getConstructorcalls() { return this.constructorcalls; }